Client pays price when creating contract
This commit is contained in:
parent
afad0e49ec
commit
d2a3cc4a89
|
@ -9,8 +9,12 @@ contract Stakes {
|
||||||
mapping(address=>uint) private stakes;
|
mapping(address=>uint) private stakes;
|
||||||
mapping(address=>uint) private locks;
|
mapping(address=>uint) private locks;
|
||||||
|
|
||||||
constructor(IERC20 _token) {
|
constructor(IERC20 __token) {
|
||||||
token = _token;
|
token = __token;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _token() internal view returns (IERC20) {
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _stake(address account) internal view returns (uint) {
|
function _stake(address account) internal view returns (uint) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ contract Storage is Contracts, Proofs, Stakes {
|
||||||
{
|
{
|
||||||
require(_stake(_host) >= stakeAmount, "Insufficient stake");
|
require(_stake(_host) >= stakeAmount, "Insufficient stake");
|
||||||
_lockStake(_host);
|
_lockStake(_host);
|
||||||
|
_token().transferFrom(msg.sender, address(this), _price);
|
||||||
_newContract(
|
_newContract(
|
||||||
_duration,
|
_duration,
|
||||||
_size,
|
_size,
|
||||||
|
|
|
@ -27,7 +27,8 @@ describe("Storage", function () {
|
||||||
let id
|
let id
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await token.approve(storage.address, stakeAmount)
|
await token.connect(host).approve(storage.address, stakeAmount)
|
||||||
|
await token.connect(client).approve(storage.address, bid.price)
|
||||||
await storage.connect(host).increaseStake(stakeAmount)
|
await storage.connect(host).increaseStake(stakeAmount)
|
||||||
let requestHash = hashRequest(request)
|
let requestHash = hashRequest(request)
|
||||||
let bidHash = hashBid({...bid, requestHash})
|
let bidHash = hashBid({...bid, requestHash})
|
||||||
|
@ -116,7 +117,8 @@ describe("Storage", function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("doesn't create contract with insufficient stake", async function () {
|
it("doesn't create contract with insufficient stake", async function () {
|
||||||
await token.approve(storage.address, stakeAmount - 1)
|
await token.connect(host).approve(storage.address, stakeAmount - 1)
|
||||||
|
await token.connect(client).approve(storage.address, bid.price)
|
||||||
await storage.connect(host).increaseStake(stakeAmount - 1)
|
await storage.connect(host).increaseStake(stakeAmount - 1)
|
||||||
let requestHash = hashRequest(request)
|
let requestHash = hashRequest(request)
|
||||||
let bidHash = hashBid({...bid, requestHash})
|
let bidHash = hashBid({...bid, requestHash})
|
||||||
|
@ -134,9 +136,29 @@ describe("Storage", function () {
|
||||||
await sign(host, bidHash)
|
await sign(host, bidHash)
|
||||||
)).to.be.revertedWith("Insufficient stake")
|
)).to.be.revertedWith("Insufficient stake")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("doesn't create contract without payment of price", async function () {
|
||||||
|
await token.connect(host).approve(storage.address, stakeAmount)
|
||||||
|
await token.connect(client).approve(storage.address, bid.price - 1)
|
||||||
|
await storage.connect(host).increaseStake(stakeAmount)
|
||||||
|
let requestHash = hashRequest(request)
|
||||||
|
let bidHash = hashBid({...bid, requestHash})
|
||||||
|
await expect(storage.newContract(
|
||||||
|
request.duration,
|
||||||
|
request.size,
|
||||||
|
request.contentHash,
|
||||||
|
request.proofPeriod,
|
||||||
|
request.proofTimeout,
|
||||||
|
request.nonce,
|
||||||
|
bid.price,
|
||||||
|
await host.getAddress(),
|
||||||
|
bid.bidExpiry,
|
||||||
|
await sign(client, requestHash),
|
||||||
|
await sign(host, bidHash)
|
||||||
|
)).to.be.revertedWith("ERC20: transfer amount exceeds allowance")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: payment when new contract
|
|
||||||
// TODO: contract start and timeout
|
// TODO: contract start and timeout
|
||||||
// TODO: failure to start contract burns host and client
|
// TODO: failure to start contract burns host and client
|
||||||
// TODO: implement checking of actual proofs of storage, instead of dummy bool
|
// TODO: implement checking of actual proofs of storage, instead of dummy bool
|
||||||
|
|
Loading…
Reference in New Issue