首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ERC20 TestToken代码在批准后返回0作为备抵

ERC20 TestToken代码在批准后返回0作为备抵
EN

Ethereum用户
提问于 2018-05-28 19:36:06
回答 1查看 2.3K关注 0票数 0

我在我的testtoken.js中有以下代码,我想知道为什么断言失败了"AssertionError: AssertionError没有被设置为30:预期的'0‘等于30“。

代码语言:javascript
复制
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])});

似乎在批准通过后这个州就不存在了吗?

编辑:我的固定测试用例:

代码语言:javascript
复制
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");
      })
    });
})
EN

回答 1

Ethereum用户

发布于 2018-05-28 19:56:05

如果您正在测试的合同是在一个真正的区块链上(ropsten,rinkeby等)而不是像Ganache这样的测试块链,更有可能的是,您没有等待事务被挖掘。您在发送交易后立即检查帐户的备抵。在检查之前,您需要等待事务被挖掘。

也可以使用像golang这样的语言来检查挂起的状态数据,在这种情况下,这是可行的,但是我不确定web3j是否有类似的东西。

由于您正在运行您的测试松露,有可能,当您提交您的呼吁,新的津贴,松露还没有完成挖掘当前块。在提交备抵更新后,在检查新补贴之前,尝试添加1秒睡眠时间。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/49788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档