mardi 28 mai 2019

Cleaning smart contract storage after running a test case

When running test cases for a Smart Contract I would like to either destroy the smart contract and redeploy it or reset its state after each test case is run. The test cases are written in javascript. The idea would be to run the code inside the AfterEach structure.


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
    });
  });
});

Aucun commentaire:

Enregistrer un commentaire