首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AssertionError:错误消息必须包含revert

AssertionError:错误消息必须包含revert
EN

Stack Overflow用户
提问于 2020-05-31 12:26:44
回答 1查看 559关注 0票数 0

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

我正在尝试使用DAPPuniversity教程制作自己的加密货币,然而,我的代码一直抛出异常。

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

回答 1

Stack Overflow用户

发布于 2020-05-31 12:26:44

将此代码替换为您的测试:)

代码语言:javascript
复制
   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"
            );
          });
      });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62111564

复制
相关文章

相似问题

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