-
Notifications
You must be signed in to change notification settings - Fork 39
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. #144
Comments
Hi @MrClottom, I was not able to follow your reproduction steps. MetaCoin Truffle Box contains a migration, which does not work with Test Environment, and it's also necessary to link the contract to Can you provide complete reproduction steps? |
Removing the meta coin contracts and writing some from scratch which don't require a migration or library still leads to the |
Hi @MrClottom , Unfortunately, I wasn’t able to reproduce this issue. I tried the following: MetaCoin.solI inlined ConvertLib so we don't need to link the contract // SPDX-License-Identifier: MIT
pragma solidity >=0.4.25 <0.7.0;
//import "./ConvertLib.sol";
// This is just a simple example of a coin-like contract.
// It is not standards compatible and cannot be expected to talk to other
// coin/token contracts. If you want to create a standards-compliant
// token, see: https://github.com/ConsenSys/Tokens. Cheers!
contract MetaCoin {
mapping (address => uint) balances;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
constructor() public {
balances[tx.origin] = 10000;
}
function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
if (balances[msg.sender] < amount) return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
return true;
}
function getBalanceInEth(address addr) public view returns(uint){
//return ConvertLib.convert(getBalance(addr),2);
return convert(getBalance(addr),2);
}
function getBalance(address addr) public view returns(uint) {
return balances[addr];
}
function convert(uint amount,uint conversionRate) public pure returns (uint convertedAmount)
{
return amount * conversionRate;
}
} metacoin.jsI updated the tests to use const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const MetaCoin = contract.fromArtifact("MetaCoin");
describe('MetaCoin', () => {
it('should put 10000 MetaCoin in the first account', async () => {
const metaCoinInstance = await MetaCoin.new({from: accounts[0]});
const balance = await metaCoinInstance.getBalance.call(accounts[0]);
expect(balance.valueOf()).to.be.bignumber.equal(new BN('10000'));
});
it('should call a function that depends on a linked library', async () => {
const metaCoinInstance = await MetaCoin.new({from: accounts[0]});
const metaCoinBalance = (await metaCoinInstance.getBalance.call(accounts[0])).toNumber();
const metaCoinEthBalance = (await metaCoinInstance.getBalanceInEth.call(accounts[0])).toNumber();
expect(metaCoinEthBalance).to.be.equal(2 * metaCoinBalance);
});
it('should send coin correctly', async () => {
const metaCoinInstance = await MetaCoin.new({from: accounts[0]});
// Setup 2 accounts.
const accountOne = accounts[0];
const accountTwo = accounts[1];
// Get initial balances of first and second account.
const accountOneStartingBalance = (await metaCoinInstance.getBalance.call(accountOne)).toNumber();
const accountTwoStartingBalance = (await metaCoinInstance.getBalance.call(accountTwo)).toNumber();
// Make transaction from first account to second.
const amount = 10;
await metaCoinInstance.sendCoin(accountTwo, amount, { from: accountOne });
// Get balances of first and second account after the transactions.
const accountOneEndingBalance = (await metaCoinInstance.getBalance.call(accountOne)).toNumber();
const accountTwoEndingBalance = (await metaCoinInstance.getBalance.call(accountTwo)).toNumber();
expect(accountOneEndingBalance).to.be.equal(accountOneStartingBalance - amount);
expect(accountTwoEndingBalance).to.be.equal(accountTwoStartingBalance + amount);
});
}); npm test
EnvironmentWSL2 on Windows 10
|
See #48 for a potential cause of the error. |
I'm not running with ganache, what version is your |
Hi @MrClottom , I am using OpenZeppelin Test Environment 0.1.6. My truffle-config.jsMy module.exports = {
// Uncommenting the defaults below
// provides for an easier quick-start with Ganache.
// You can also follow this format for other networks;
// see <http://truffleframework.com/docs/advanced/configuration>
// for more details on how to specify configuration options!
//
//networks: {
// development: {
// host: "127.0.0.1",
// port: 7545,
// network_id: "*"
// },
// test: {
// host: "127.0.0.1",
// port: 7545,
// network_id: "*"
// }
//}
//
}; package.json{
"name": "test-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --exit --recursive"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"@openzeppelin/test-environment": "^0.1.6",
"@openzeppelin/test-helpers": "^0.5.9",
"chai": "^4.2.0",
"mocha": "^8.2.1",
"truffle": "^5.1.54"
}
} |
@openzeppelin-test-environment version: 0.1.6
truffle version: 5.1.13
Steps to reproduce:
mkdir test-project; cd test-project
truffle unbox metacoin
truffle test
=> tests succeeds4.1.
npm i --save-dev @openzeppelin/test-environment mocha chai
4.2. Create package.json and add test script
4.3. Replace necessary values
npm test
=> Timeout errorAdditional notes:
I tried running
--timeout 30000
but the tests still timedout. I had another project running with0.15
which worked great sad that0.16
will have to resort to normal truffle testing. Would love any help, thanks.The text was updated successfully, but these errors were encountered: