首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决“一切”之前的错误:准备套件:

如何解决“一切”之前的错误:准备套件:
EN

Stack Overflow用户
提问于 2019-09-22 03:01:58
回答 2查看 1.3K关注 0票数 2

当我测试我的合同时,我得到了这个错误“在所有”钩子:准备套件:“

有人知道如何解决这个错误吗?

这是我的依赖关系。“松露”:"5.0.7","web3":"1.0.0-beta.46“

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-05-31 13:51:37

npm卸载-g松露

npm安装-g松露@5.1.10(总是让我重回正轨)

票数 1
EN

Stack Overflow用户

发布于 2021-04-06 01:36:57

此外,当使用几个使用异步测试帮助程序而不使用等待(例如,OpenZeppelin测试助手: expectEvent,expectRevert)的测试套件时,会出现此问题。

举个例子:

合同

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;

contract Test03 {
    address public owner;
    int32 public id;

    event ContractCreated();

    constructor() {
        owner = msg.sender;

        emit ContractCreated();
    }

    function doSmth(int32 _id) public {
        require(id != 0, "id is zero");
        id= _id;
    }
}

测试

代码语言:javascript
复制
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');

const TestContract = artifacts.require('Test03');

contract('Test03', function (accounts) {
    const [owner] = accounts;
    const txParams = { from: owner };

    beforeEach(async function () {
        this.testContract = await TestContract.new(txParams);
    });

    describe('construction', function () {
        it('initial state', async function () {
            expect(await this.testContract.owner()).to.equal(owner);

            // !! DONT FORGET await before expectEvent-call <<------------------------------
            await expectEvent.inConstruction(this.testContract, 'ContractCreated');
        });
    });

    describe('doSmth', function () {
      it('fail when passed zero id', async function () {

        // !! DONT FORGET await before expectRevert-call <<------------------------------
        await expectRevert(
          this.testContract.doSmth(0, txParams),
          "id is zero");
      });
  });    
});

package.json

代码语言:javascript
复制
{
..
  "devDependencies": {
    "@openzeppelin/test-helpers": "^0.5.10"
  }
..
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58045704

复制
相关文章

相似问题

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