gpt4 book ai didi

javascript - 运行测试用例后清理智能合约存储

转载 作者:行者123 更新时间:2023-11-28 21:37:51 24 4
gpt4 key购买 nike

在为智能合约运行测试用例时,我想销毁智能合约并重新部署它,或者在运行每个测试用例后重置其状态。测试用例是用 javascript 编写的。这个想法是在 AfterEach 结构中运行代码。


contract("Contract", accounts => {
let contract;
let owner = accounts[0];
let admin = accounts[1];
let user = accounts[2];

describe("function1 tests", () => {
before("Setup contract for each test", async () => {
contract = await Contract.deployed();
});

afterEach("", async () => {
//code to selfdestruct or reset the state of the contract after
//each test
});

it("test1", () => {
//test1 code
});

it("test2", () => {
//test2 code
});
});
});

最佳答案

beforeEach() 内部

beforeEach('initialize the contract', async function() {
contract = await Contract.new()
})

这样,对于每个 it 案例,您都会有一个新的 Contract 实例。

关于javascript - 运行测试用例后清理智能合约存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56345250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com