I'm writing tests for the burn func in ICO.sol
The first two tests are passing, but when I come to test where the tokens are indeed burned, the state of the ICO seems to change. To burn tokens, the ICO must have ended. So I start by checking the ICO state, and up to that point, the state is ended. When I call await ico.burn()
the state seems to change and I get the error below.
What could I be doing wrong?
error
Error: VM Exception while processing transaction: reverted with custom error 'Ico__StateShouldBeEnded()'
burn() func
function burn() public onlyManager returns (bool) {
icoState = getState();
// require(icoState == State.afterEnd);
if (icoState != State.afterEnd) {
revert Ico__StateShouldBeEnded();
}
//burn
balances[founder] = 0;
return true;
}
test file
describe("burning tokens", () => {
it("checks that the ico is ended before burning", async () => {
const icoState = await ico.getState()
assert.equal(icoState, 1) // state [1] = afterEnd on our ICO.sol
})
it("only allows manager to call", async () => {
const icoInvestor1connected = ico.connect(inverstor1)
await expect(icoInvestor1connected.burn()).to.be.rejectedWith("not owner")
})
it("should burn tokens", async () => {
const icoState = await ico.getState()
assert.equal(icoState, 1) // state [1] = afterEnd on our ICO.sol
// up to this point the test passes.
// it fails from the code below.
await ico.burn()
const founderBal = await ico.getFounderBalance()
assert.equal(founderBal.toString(), "0")
})
})