TypeError:balance.toNumber不是函数

时间:2019-01-23 12:24:07

标签: javascript ethereum solidity web3js

有人可以看看问题出在哪里吗?我全都没主意。 这是我正在关注的教程中的测试驱动代码。

it('ends token sale', function() {
  return DappToken.deployed().then(function(instance) {
    // Grab token instance first
    tokenInstance = instance;
    return DappTokenSale.deployed();
  }).then(function(instance) {
    // Then grab token sale instance
    tokenSaleInstance = instance;
    // Try to end sale from account other than the admin
    return tokenSaleInstance.endSale({
      from: buyer
    });
  }).then(assert.fail).catch(function(error) {
    assert(error.message.indexOf('revert' >= 0, 'must be admin to end sale'));
    // End sale as admin
    return tokenSaleInstance.endSale({
      from: admin
    });
  }).then(function(receipt) {
    return tokenInstance.balanceOf(admin);
  }).then(function(balance) {
    assert.equal(balance.toNumber(), 999990, 'returns all unsold dapp tokens to admin');
    // Check that the contract has no balance
    balance = web3.eth.getBalance(tokenSaleInstance.address);
    assert.equal(balance.toNumber(), 0);
  });
});

这是错误日志:

TypeError: balance.toNumber is not a function
  at test\DappTokenSale.js:127:28
  at process._tickCallback (internal/process/next_tick.js:68:7)

我已经尝试过selfdestruct(),但是我无法从任何站点找到修复程序,因此,我只是将剩余的令牌转移给管理员。但是后来,我一直遇到这个问题。这是合同供更多参考:

function endSale() public {
    //require admin(only)
    require(msg.sender == admin);
    //transfer remaining dapp tokens to admin
    require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
    admin.transfer(address(this).balance);
}

0 个答案:

没有答案