mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-01-30 16:25:19 +00:00
Only expect proofs when the contract is started
This commit is contained in:
parent
7bb949a5cc
commit
376962322d
@ -9,6 +9,8 @@ contract Contracts {
|
|||||||
mapping(bytes32=>uint) private durations; // contract duration in blocks
|
mapping(bytes32=>uint) private durations; // contract duration in blocks
|
||||||
mapping(bytes32=>uint) private sizes; // storage size in bytes
|
mapping(bytes32=>uint) private sizes; // storage size in bytes
|
||||||
mapping(bytes32=>bytes32) private contentHashes; // hash of data to be stored
|
mapping(bytes32=>bytes32) private contentHashes; // hash of data to be stored
|
||||||
|
mapping(bytes32=>uint) private proofPeriods; // period between proofs
|
||||||
|
mapping(bytes32=>uint) private proofTimeouts; // timeout for proof submission
|
||||||
mapping(bytes32=>uint) private prices; // price in coins
|
mapping(bytes32=>uint) private prices; // price in coins
|
||||||
mapping(bytes32=>address) private hosts; // host that provides storage
|
mapping(bytes32=>address) private hosts; // host that provides storage
|
||||||
|
|
||||||
@ -24,6 +26,14 @@ contract Contracts {
|
|||||||
return contentHashes[id];
|
return contentHashes[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _proofPeriod(bytes32 id) internal view returns (uint) {
|
||||||
|
return proofPeriods[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _proofTimeout(bytes32 id) internal view returns (uint) {
|
||||||
|
return proofTimeouts[id];
|
||||||
|
}
|
||||||
|
|
||||||
function _price(bytes32 id) internal view returns (uint) {
|
function _price(bytes32 id) internal view returns (uint) {
|
||||||
return prices[id];
|
return prices[id];
|
||||||
}
|
}
|
||||||
@ -66,6 +76,8 @@ contract Contracts {
|
|||||||
durations[id] = duration;
|
durations[id] = duration;
|
||||||
sizes[id] = size;
|
sizes[id] = size;
|
||||||
contentHashes[id] = contentHash;
|
contentHashes[id] = contentHash;
|
||||||
|
proofPeriods[id] = proofPeriod;
|
||||||
|
proofTimeouts[id] = proofTimeout;
|
||||||
prices[id] = price;
|
prices[id] = price;
|
||||||
hosts[id] = host;
|
hosts[id] = host;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ contract Storage is Contracts, Proofs, Stakes {
|
|||||||
{
|
{
|
||||||
require(_stake(_host) >= stakeAmount, "Insufficient stake");
|
require(_stake(_host) >= stakeAmount, "Insufficient stake");
|
||||||
_lockStake(_host);
|
_lockStake(_host);
|
||||||
bytes32 id = _newContract(
|
_newContract(
|
||||||
_duration,
|
_duration,
|
||||||
_size,
|
_size,
|
||||||
_contentHash,
|
_contentHash,
|
||||||
@ -43,7 +43,10 @@ contract Storage is Contracts, Proofs, Stakes {
|
|||||||
requestSignature,
|
requestSignature,
|
||||||
bidSignature
|
bidSignature
|
||||||
);
|
);
|
||||||
_expectProofs(id, _proofPeriod, _proofTimeout, _duration);
|
}
|
||||||
|
|
||||||
|
function startContract(bytes32 id) public {
|
||||||
|
_expectProofs(id, proofPeriod(id), proofTimeout(id), duration(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
function duration(bytes32 contractId) public view returns (uint) {
|
function duration(bytes32 contractId) public view returns (uint) {
|
||||||
@ -67,11 +70,15 @@ contract Storage is Contracts, Proofs, Stakes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function proofPeriod(bytes32 contractId) public view returns (uint) {
|
function proofPeriod(bytes32 contractId) public view returns (uint) {
|
||||||
return _period(contractId);
|
return _proofPeriod(contractId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function proofTimeout(bytes32 contractId) public view returns (uint) {
|
function proofTimeout(bytes32 contractId) public view returns (uint) {
|
||||||
return _timeout(contractId);
|
return _proofTimeout(contractId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function proofEnd(bytes32 contractId) public view returns (uint) {
|
||||||
|
return _end(contractId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function missingProofs(bytes32 contractId) public view returns (uint) {
|
function missingProofs(bytes32 contractId) public view returns (uint) {
|
||||||
|
@ -50,20 +50,24 @@ describe("Storage", function () {
|
|||||||
expect(await storage.duration(id)).to.equal(request.duration)
|
expect(await storage.duration(id)).to.equal(request.duration)
|
||||||
expect(await storage.size(id)).to.equal(request.size)
|
expect(await storage.size(id)).to.equal(request.size)
|
||||||
expect(await storage.contentHash(id)).to.equal(request.contentHash)
|
expect(await storage.contentHash(id)).to.equal(request.contentHash)
|
||||||
expect(await storage.price(id)).to.equal(bid.price)
|
|
||||||
expect(await storage.host(id)).to.equal(await host.getAddress())
|
|
||||||
})
|
|
||||||
|
|
||||||
it("requires storage proofs", async function (){
|
|
||||||
expect(await storage.proofPeriod(id)).to.equal(request.proofPeriod)
|
expect(await storage.proofPeriod(id)).to.equal(request.proofPeriod)
|
||||||
expect(await storage.proofTimeout(id)).to.equal(request.proofTimeout)
|
expect(await storage.proofTimeout(id)).to.equal(request.proofTimeout)
|
||||||
})
|
expect(await storage.price(id)).to.equal(bid.price)
|
||||||
|
expect(await storage.host(id)).to.equal(await host.getAddress())
|
||||||
|
})
|
||||||
|
|
||||||
it("locks up host stake", async function () {
|
it("locks up host stake", async function () {
|
||||||
await expect(
|
await expect(
|
||||||
storage.connect(host).withdrawStake()
|
storage.connect(host).withdrawStake()
|
||||||
).to.be.revertedWith("Stake locked")
|
).to.be.revertedWith("Stake locked")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("starting the contract", function () {
|
||||||
|
it("starts requiring storage proofs", async function (){
|
||||||
|
await storage.connect(host).startContract(id)
|
||||||
|
expect(await storage.proofEnd(id)).to.be.gt(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("doesn't create contract with insufficient stake", async function () {
|
it("doesn't create contract with insufficient stake", async function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user