Ensure that finishing a contract can only be done once
This commit is contained in:
parent
8fbb99630c
commit
54cc2987df
|
@ -9,6 +9,8 @@ contract Storage is Contracts, Proofs, Stakes {
|
||||||
|
|
||||||
uint private stakeAmount;
|
uint private stakeAmount;
|
||||||
|
|
||||||
|
mapping(bytes32=>bool) private finished;
|
||||||
|
|
||||||
constructor(IERC20 token, uint _stakeAmount) Stakes(token) {
|
constructor(IERC20 token, uint _stakeAmount) Stakes(token) {
|
||||||
stakeAmount = _stakeAmount;
|
stakeAmount = _stakeAmount;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,9 @@ contract Storage is Contracts, Proofs, Stakes {
|
||||||
|
|
||||||
function finishContract(bytes32 id) public {
|
function finishContract(bytes32 id) public {
|
||||||
require(block.number > proofEnd(id), "Contract has not ended yet");
|
require(block.number > proofEnd(id), "Contract has not ended yet");
|
||||||
|
require(!finished[id], "Contract already finished");
|
||||||
_unlockStake(host(id));
|
_unlockStake(host(id));
|
||||||
|
finished[id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function duration(bytes32 contractId) public view returns (uint) {
|
function duration(bytes32 contractId) public view returns (uint) {
|
||||||
|
|
|
@ -101,6 +101,17 @@ describe("Storage", function () {
|
||||||
storage.finishContract(id)
|
storage.finishContract(id)
|
||||||
).to.be.revertedWith("Contract has not ended yet")
|
).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")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue