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})
});
});
});