我在我的testtoken.js中有以下代码,我想知道为什么断言失败了"AssertionError: AssertionError没有被设置为30:预期的'0‘等于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");
});
});这还从命令行返回0:
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("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");
})
});
})发布于 2018-05-28 19:56:05
如果您正在测试的合同是在一个真正的区块链上(ropsten,rinkeby等)而不是像Ganache这样的测试块链,更有可能的是,您没有等待事务被挖掘。您在发送交易后立即检查帐户的备抵。在检查之前,您需要等待事务被挖掘。
也可以使用像golang这样的语言来检查挂起的状态数据,在这种情况下,这是可行的,但是我不确定web3j是否有类似的东西。
由于您正在运行您的测试松露,有可能,当您提交您的呼吁,新的津贴,松露还没有完成挖掘当前块。在提交备抵更新后,在检查新补贴之前,尝试添加1秒睡眠时间。
https://ethereum.stackexchange.com/questions/49788
复制相似问题