Ensure that finishing a contract can only be done once

This commit is contained in:
Mark Spanbroek 2021-11-04 11:18:05 +01:00
parent 8fbb99630c
commit 54cc2987df
2 changed files with 15 additions and 0 deletions

View File

@ -9,6 +9,8 @@ contract Storage is Contracts, Proofs, Stakes {
uint private stakeAmount;
mapping(bytes32=>bool) private finished;
constructor(IERC20 token, uint _stakeAmount) Stakes(token) {
stakeAmount = _stakeAmount;
}
@ -56,7 +58,9 @@ contract Storage is Contracts, Proofs, Stakes {
function finishContract(bytes32 id) public {
require(block.number > proofEnd(id), "Contract has not ended yet");
require(!finished[id], "Contract already finished");
_unlockStake(host(id));
finished[id] = true;
}
function duration(bytes32 contractId) public view returns (uint) {

View File

@ -101,6 +101,17 @@ describe("Storage", function () {
storage.finishContract(id)
).to.be.revertedWith("Contract has not ended yet")
})
it("can only be done once", async function () {
const end = await storage.proofEnd(id)
while (await minedBlockNumber() < end) {
await mineBlock()
}
await storage.finishContract(id)
await expect(
storage.finishContract(id)
).to.be.revertedWith("Contract already finished")
})
})
})