From 65c3cacb66e6860166e0c6c8dc25cdb2b2c22932 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 2 Nov 2021 12:50:06 +0100 Subject: [PATCH] Host stake is locked up when contract is created --- contracts/Storage.sol | 5 +++++ test/Storage.test.js | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/contracts/Storage.sol b/contracts/Storage.sol index ad8cca4..e5bc2b4 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -29,6 +29,7 @@ contract Storage is Contracts, Proofs, Stakes { public { require(_stake(_host) >= stakeAmount, "Insufficient stake"); + _lockStake(_host); bytes32 id = _newContract( _duration, _size, @@ -114,4 +115,8 @@ contract Storage is Contracts, Proofs, Stakes { function increaseStake(uint amount) public { _increaseStake(amount); } + + function withdrawStake() public { + _withdrawStake(); + } } diff --git a/test/Storage.test.js b/test/Storage.test.js index d7b433e..b8cf98e 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -58,6 +58,12 @@ describe("Storage", function () { expect(await storage.proofPeriod(id)).to.equal(request.proofPeriod) expect(await storage.proofTimeout(id)).to.equal(request.proofTimeout) }) + + it("locks up host stake", async function () { + await expect( + storage.connect(host).withdrawStake() + ).to.be.revertedWith("Stake locked") + }) }) it("doesn't create contract when insufficient stake", async function () { @@ -81,7 +87,6 @@ describe("Storage", function () { }) }) -// TODO: lock up stake when new contract // TODO: unlock stake at end of contract // TODO: payment when new contract // TODO: contract start and timeout