[英]ExecutionError":"Smart contract panicked: panicked at 'Should be initialized before usage' error while running test:deploy [NEAR PROTOCOL]
[英]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.