我一直在使用web3来做任何事情,但是现在它看起来更适合我的需要,所以我正在玩它。
我用“安全帽”来测试,就像我们所有人一样,我发现,尽管“安全帽医生”声称我需要以太和华夫饼,但我发现,只有乙醚才能正常工作。例如,让我们检查教程:
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();
expect(await greeter.greet()).to.equal("Hello, world!");
const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
// wait until the transaction is mined
await setGreetingTx.wait();
expect(await greeter.greet()).to.equal("Hola, mundo!");
});
});"Waffles“的零事件。我正在重写我的测试,但我没有找到一个不适用于普通菜式和安全帽的测试。
所以问题是:为什么硬帽子说我需要它?我遗漏了什么?
发布于 2022-04-09 08:28:25
华夫饼对于模拟智能合同的功能非常有用,无需编写新的假合同。其他的事情可能可以用正常的以太和柴。
模拟合同示例:
const { waffle, ethers } = require('hardhat');
const { deployMockContract, provider } = waffle;
...code
const mockERC20 = await deployMockContract(<params>);
await mockERC20.mock.transfer.reverts();
--> test something
await mockERC20.mock.transferFrom.returns(true);
--> test somethinghttps://ethereum.stackexchange.com/questions/125817
复制相似问题