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

时间:2019-05-28 15:12:18

标签: javascript testing solidity smartcontracts

在运行智能合约的测试用例时,我想销毁智能合约并重新部署它,或者在运行每个测试用例后重置其状态。测试用例用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
    });
  });
});

1 个答案:

答案 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实例。