松露测试:返回错误:VM Exception while processing transaction: revert.



我已经看到这个错误很多次了。网上什么也解决不了

我在一行中多次使用相同的函数startProposalRegistration来测试有或没有限制的不同场景。

我正在测试我的修饰符是否如预期的那样工作,抛出如果帐户不是所有者(onlyOwner)。

事务恢复,但我没有得到太多的解释,为什么事务恢复,除了它被执行了几次

context("startProposalRegistration", () => {
it("should be status == ProposalsRegistrationStarted", async () => {
await votingInstance.startProposalRegistration({ from: owner })
const status = await votingInstance.status.call()
assert.equal(status.toNumber(), 1)
})
// it("should not be able to startProposalRegistration as non owner", async () => {
//   assert.equal(await votingInstance.startProposalRegistration({ from: account2 }), false);
// })
})
context("add/delete proposal", () => {
it("should be able to add proposal if status == ProposalsRegistrationStarted", async () => {
await votingInstance.startProposalRegistration({ from: owner })
assert.ok(await votingInstance.addProposal("Some proposal", { from: whitelisted }))
})
// it("should not be able to add proposal if status != ProposalsRegistrationStarted", async () => {
//   await votingInstance.startProposalRegistration({ from: account2 })
// })
})

测试/Voting.js(完整源代码)

const { assert } = require("chai");
const should = require("chai").should();
const Voting = artifacts.require("Voting");
contract("Voting", accounts => {
let [account1, account2] = accounts;
let [, , address3, address4] = accounts;
let owner = account1;
let whitelisted = address4;
let votingInstance;
beforeEach(async () => {
votingInstance = await Voting.deployed();
await votingInstance.addVoter(whitelisted, { from: owner }); //adding to whitelist
});
it("should deploy", async () => {
should.exist(votingInstance.address)
});
it("should be status == RegisteringVoters", async () => {
const status = await votingInstance.status.call()
assert.equal(status.toNumber(), 0)
})
context("add/delete Voter", () => {
it("should be able to add voter as a owner", async () => {
await votingInstance.addVoter(address3, { from: owner })
const voter = await votingInstance.whiteList.call(address3);
assert(voter);
})
it("should not be able to add voter as a non owner", async () => {
try {
await votingInstance.addVoter(address4, { from: account2 })
assert(false);
} catch (err) {
should.exist(err);
}
})
it("should be able to delete voter as a owner", async () => {
await votingInstance.deleteVoter(address3, { from: owner })
const voter = await votingInstance.whiteList.call(address3);
should.not.exist(voter.address);
})
it("should not be able to delete voter as non owner", async () => {
try {
await votingInstance.deleteVoter(address3, { from: account2 })
assert(false);
} catch (err) {
should.exist(err);
}
})
})
context("startProposalRegistration", () => {
it("should be status == ProposalsRegistrationStarted", async () => {
await votingInstance.startProposalRegistration({ from: owner })
const status = await votingInstance.status.call()
assert.equal(status.toNumber(), 1)
})
// it("should not be able to startProposalRegistration as non owner", async () => {
//   assert.equal(await votingInstance.startProposalRegistration({ from: account2 }), false);
// })
})
context("add/delete proposal", () => {
it("should be able to add proposal if status == ProposalsRegistrationStarted", async () => {
await votingInstance.startProposalRegistration({ from: owner })
assert.ok(await votingInstance.addProposal("Some proposal", { from: whitelisted }))
})
// it("should not be able to add proposal if status != ProposalsRegistrationStarted", async () => {
//   await votingInstance.startProposalRegistration({ from: account2 })
// })
})
})

和合同合同/Voting.sol

我一直有问题的功能:

function startProposalRegistration() public onlyOwner   {
status = WorkflowStatus.ProposalsRegistrationStarted;
emit ProposalsRegistrationStarted();
}

checkout此答案https://ethereum.stackexchange.com/questions/42995/how-to-send-ether-to-a-contract-in-truffle-test我已设法查找。这是因为合约功能要求发送以太币,特别是标记为"应付">

相关内容

最新更新