I'm making test script for my contract and it looks likes
contract('...', async () => {
let token = null;
before('deploy', async () => {
token = await MyContract.new(...);
});
it('should success', async() => { ... });
it('should fail', async() => { ... }); // work as intended only until here
it('should success', async() => { ... });
});
and executed with command truffle test ./test/test.js
Issue is that calls after second it(...)
, which contract call fails and invoke revert
, never succeed and raise errors similar to
AssertionError: the tx doesn't have the correct nonce. account has nonce of: 37 tx has nonce of: 36
How do I make the test script work? looks like some kind of nonce increment gone wrong, but I'm not sure what I've done wrong. I'm using Ganache GUI 2.0.1 for test network and truffle v5.0.9.
-- Edit --
as comment suggested, I check if I missed any await
keyword,
my code is all like this,
it('should deny transfer with insufficient (zero) balance', async () => {
const amount = web3.utils.toWei('1', 'ether');
const promise = token.transfer.call(accounts[3], amount, { 'from': accounts[2] });
await assert.isRejected(promise, 'revert', 'transfer transaction with insufficient (zero) balance must be denied');
});
I tried what Majd TL suggested also,
it('should deny transfer with insufficient (zero) balance', async () => {
const amount = web3.utils.toWei('1', 'ether');
const promise = token.transfer(accounts[3], amount, { 'from': accounts[2] });
await truffleAssert.reverts(promise, 'revert', 'transfer transaction with insufficient (zero) balance must be denied');
});
but it does not resolve the problem. The workaround now is to call contract call that expected to fail with .call
, like
const promise = token.nope.call(1, 2, 3, { 'from': accounts[0] });
but in case of really unexpected error, it is inevitable and should be a thing. I Also see this error when using multiple contract(...)
.
await
somewhere...amount
value stands for 1 ether, (== 10**18). It seems to big but bignumber type can store and handle it. Also I thought it's not a uncommon to use this large value in token contract.