在运行智能合约的测试用例时,我想销毁智能合约并重新部署它,或者在运行每个测试用例后重置其状态。测试用例用javascript编写。这个想法是在AfterEach结构中运行代码。
contract("Contract", accounts => {
let contract;
let owner = accounts[0];
let admin = accounts[1];
let user = accounts[2];
describe("function1 tests", () => {
beforeEach("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
});
});
});
答案 0 :(得分:0)
在 Name Fraction
0 Balkrishna Industries Ltd. Auto Ancillaries 3.54
1 Aurobindo Pharma Ltd. Pharmaceuticals 3.36
2 NIIT Technologies Ltd. Software 3.31
3 Sonata Software Ltd. Software 3.21
内
beforeEach()
这样,您将为每个beforeEach('initialize the contract', async function() {
contract = await Contract.new()
})
案例创建一个新的Contract实例。