Contract tests forking mainnet give async callback timeout

Hi,

I am trying to do mainnet forking testing with my contracts and using open zepplin thoughout,
while running my tests I get
Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout. on every test, I have defined a test-environment.config in my root directory and also get this
TypeError: usdcInstance.approve is not a function
but i am using openzepplin erc20 contract and using usdc mainnet address to get the instance
here is the test code

    const {accounts, contract, web3} = require('@openzeppelin/test-environment');
    const {expectEvent, ether, BN} = require('@openzeppelin/test-helpers');
    const timeMachine = require('ganache-time-traveler');

    const NewfiAdvisor = contract.fromArtifact('NewfiAdvisor');
    const StablePoolProxy = contract.fromArtifact('StablePoolProxy');
    const VolatilePoolProxy = contract.fromArtifact('VolatilePoolProxy');
    const MockToken = contract.fromArtifact('MockToken');
    const NewfiToken = contract.fromArtifact('NewfiToken');
    const IERC20 = contract.fromArtifact('ERC20');

    describe('NewfiAdvisor', () => {
      const [mainAdvisor, secondAdvisor, investor] = accounts;
      let divisor;
      let contract;
      let mockToken;
      let advisorToken;
      // mimicking mainnet scenario
      const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
      // // Account with mainnet usdc
      const unlockAddress = "0x2a549b4af9ec39b03142da6dc32221fc390b5533";

      beforeEach(async () => {
        // Proxy pools are initialized in the NewfiAdvisor init function.
        const stableProxy = await StablePoolProxy.new();
        const volatileProxy = await VolatilePoolProxy.new();

        divisor = new BN((10 ** 18).toString());
        advisorToken = await NewfiToken.new();
        mockToken = await MockToken.new();
        contract = await NewfiAdvisor.new(
          stableProxy.address,
          volatileProxy.address,
          advisorToken.address
        );

        // Onboard a main advisor
        await contract.createAdvisor('Mock Advisor', 60, 40, {from: mainAdvisor});

        // Onboard second advisor
        await contract.createAdvisor('Second Advisor', 50, 50, {
          from: secondAdvisor,
        });
      });

      describe('advisor', () => {
        it('can get name', async () => {
          const name = await contract.advisorName(mainAdvisor);
          expect(name).toEqual('Mock Advisor');
        });
      });

      describe('investors', () => {
        const usdcInstance = IERC20.at(USDC);
        beforeEach(async () => {
          await mockToken.mintTokens(10000, {from: investor});
          await mockToken.increaseAllowance(contract.address, 10000, {
            from: investor,
          });
        });


        it('can invest the funds into protocol', async () => {
            await usdcInstance.approve(contract.address, 1000000, {from : unlockAddress});
            let receipt = await contract.invest(
                usdcInstance.address,
                1000,
                mainAdvisor,
                0,
                100,
                { from: unlockAddress },
            );
        
            expectEvent(receipt, 'Investment', {
                investor: unlockAddress,
                // _stablecoinAmount: '0',
                // _volatileAmount: '1000',
                _advisor: mainAdvisor
            });
            receipt = await contract.protocolInvestment(usdcInstance.address, {from : mainAdvisor})
        
            expectEvent(receipt, 'ProtocolInvestment', {
                advisor: mainAdvisor,
                mstableShare: '0',
                yearnShare: '1000'
            });
        });

        it('can invest the funds into protocol and unwind the position', async () => {
            await usdcInstance.approve(contract.address, 10000000, {from : unlockAddress});
            let receipt = await contract.invest(
                usdcInstance.address,
                1000,
                mainAdvisor,
                0,
                100,
                { from: unlockAddress },
            );
        
            expectEvent(receipt, 'Investment', {
                investor: unlockAddress,
                _stablecoinAmount: '0',
                _volatileAmount: '1000',
                _advisor: mainAdvisor
            });
            receipt = await contract.protocolInvestment(usdcInstance.address, {from : mainAdvisor})
        
            expectEvent(receipt, 'ProtocolInvestment', {
                advisor: mainAdvisor,
                // mstableShare: '0',
                // yearnShare: '1000'
            });
            // advancing 1 month for yield accural
            await timeMachine.advanceTimeAndBlock(2592000);
            receipt = await contract.unwind(mainAdvisor, usdcInstance.address, {from : unlockAddress})
        });
      });
    });
1 Like

Hi @viraj124,

I recommend increasing the timeout.

Testing with a fork of mainnet is slow unfortunately. See the following post:

@abcoathup Thanks also at
await usdcInstance.approve(contract.address, 10000000, {from : unlockAddress});
I get usdc.approve is not a function i have defined it in the describe block is there something wrong with it?

1 Like

Hi @viraj124,

In your tests you could use IERC20 to interact with USDT.

Actually I tried it before got the same issue with that

1 Like

Hi @viraj124,

Are you able to share a cut down version of your test and contract, along with your setup (operating system, node version etc) and I can try to reproduce?

sure will do thanks @abcoathup

1 Like

@abcoathup these are the contracts https://github.com/newfi-labs/advisor-contracts I am on mac os and node version 12.6.0

1 Like

Hi @viraj124,

Sorry for the delay. I finally got to run your tests today.

Some tests were failing on the default timeout of 5 seconds.

I increased the timeout to 30 seconds and the test failures were not related to timeouts.

I changed the scripts in package.json to set the timeout.

    "test": "oz compile && jest --testTimeout 30000",