I have the following code in my testtoken.js and am wondering why the assertion fails with "AssertionError: allowance wasn't set to 30: expected '0' to equal 30".
it("Approve an allowance of 30 between act0 and act1", function() {
return TestToken.deployed().then(function(instance) {
tt = instance;
tt.approve.call(accounts[1], 30);
return tt.allowance.call(accounts[0], accounts[1])
}).then(function(allowance) {
assert.equal(allowance.valueOf(), 30, "allowance wasn't set to 30");
});
});
This also returns 0 from the command line:
TestToken.deployed().then(function(instance){tt = instance;tt.approve.call(web3.eth.accounts[1], 30);return tt.allowance.call(web3.eth.accounts[0], web3.eth.accounts[1])});
It seems like the state isn't kept after the approval goes through?
EDIT: My fixed test case:
it("Approve an allowance of 30 between act0 and act1", function() {
return TestToken.deployed().then(function(instance){
tt = instance;
tt.approve(web3.eth.accounts[1], 30);
return tt.allowance.call(web3.eth.accounts[0], web3.eth.accounts[1]).then(function(allowance){
assert.equal(allowance.valueOf(), 30, "allowance wasn't set to 30");
})
});
})
tt.approve(accounts[1], 30).then(() => tt.allowance.call(accounts[0], accounts[1]); ).then(allowance => console.log(allowance.toNumber())). – Ismael May 28 '18 at 21:41GetBlockwithMoralisand worked – Nagibaba May 03 '22 at 12:07