首页 > 解决方案 > AssertionError:错误消息必须包含revert

问题描述

当我运行测试时,我得到了这个错误..

我正在尝试使用 DAPPuniversity 教程制作自己的加密货币,但是,我的代码不断抛出异常。

  Contract: ValleyToken
    √ initialize the contract with correct values (363ms)
    √ sets the initial supply upon deployment (363ms)
    1) transfers token ownership
    > No events were emitted


  2 passing (869ms)
  1 failing

  1) Contract: ValleyToken
       transfers token ownership:
     ReferenceError: Faicoin is not defined
      at Context.<anonymous> (test\ValleyToken.js:47:5)
      at process._tickCallback (internal/process/next_tick.js:68:7)

标签: tokenethereumsolidityrevert

解决方案


用您的测试替换此代码:)

   it("transfers token ownership", function () {
        return ValleyToken.deployed()
          .then(function (instance) {
            tokenInstance = instance;
            return tokenInstance.transfer.call(accounts[1], 9999999999999999);
          })
          .then(assert.fail)
          .catch(function (error) {
            assert(error.message, "error message must contain revert");
            return tokenInstance.transfer.call(accounts[1], 250000, {
              from: accounts[0],
            });
          })
          .then(function (success) {
            assert(success, true, "it returns true");
            return tokenInstance.transfer(accounts[1], 250000, {
              from: accounts[0],
            });
          })
          .then(function (receipt) {
            assert.equal(receipt.logs.length, 1, "triggers one event");
            assert.equal(
              receipt.logs[0].event,
              "Transfer",
              'should be the "Transfer" event'
            );
            assert.equal(
              receipt.logs[0].args._from,
              accounts[0],
              "logs the account the tokens are transferred from"
            );
            assert.equal(
              receipt.logs[0].args._to,
              accounts[1],
              "logs the account the tokens are transferred to"
            );
            assert.equal(
              receipt.logs[0].args._value,
              250000,
              "logs the transfer amount"
            );
            return tokenInstance.balanceOf(accounts[1]);
          })
          .then(function (reciept) {
            return tokenInstance.balanceOf(accounts[1]);
          })
          .then(function (balance) {
            assert.equal(
              balance.toNumber(),
              250000,
              "adds the amount to the recieving amount"
            );
            return tokenInstance.balanceOf(accounts[0]);
          })
          .then(function (balance) {
            assert.equal(
              balance.toNumber(),
              750000,
              "deducts the amount from the sending account"
            );
          });
      });

推荐阅读