繁体   English   中英

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

[英]Cleaning smart contract storage after running a test case

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM