当我测试我的合同时,我得到了这个错误“在所有”钩子:准备套件:“
有人知道如何解决这个错误吗?
这是我的依赖关系。“松露”:"5.0.7","web3":"1.0.0-beta.46“
发布于 2020-05-31 13:51:37
npm卸载-g松露
npm安装-g松露@5.1.10(总是让我重回正轨)
发布于 2021-04-06 01:36:57
此外,当使用几个使用异步测试帮助程序而不使用等待(例如,OpenZeppelin测试助手: expectEvent,expectRevert)的测试套件时,会出现此问题。
举个例子:
合同
// 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;
}
}测试
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
{
..
"devDependencies": {
"@openzeppelin/test-helpers": "^0.5.10"
}
..
}https://stackoverflow.com/questions/58045704
复制相似问题