2021-10-12 14:59:34 +00:00
|
|
|
const { expect } = require("chai")
|
|
|
|
const { ethers } = require("hardhat")
|
|
|
|
const { hashRequest, hashBid, sign } = require("./marketplace")
|
2021-11-02 08:45:49 +00:00
|
|
|
const { exampleRequest, exampleBid } = require("./examples")
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-11-01 15:34:01 +00:00
|
|
|
describe("Storage", function () {
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-11-01 15:34:01 +00:00
|
|
|
describe("creating a new storage contract", function () {
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-11-02 08:45:49 +00:00
|
|
|
const request = exampleRequest()
|
|
|
|
const bid = exampleBid()
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-11-01 15:34:01 +00:00
|
|
|
let contracts
|
|
|
|
let client, host
|
|
|
|
let id
|
2021-10-12 14:59:34 +00:00
|
|
|
|
|
|
|
beforeEach(async function () {
|
2021-11-01 15:34:01 +00:00
|
|
|
[client, host] = await ethers.getSigners()
|
|
|
|
let StorageContracts = await ethers.getContractFactory("Storage")
|
|
|
|
contracts = await StorageContracts.deploy()
|
2021-11-02 08:45:49 +00:00
|
|
|
let requestHash = hashRequest(request)
|
|
|
|
let bidHash = hashBid({...bid, requestHash})
|
2021-11-01 15:34:01 +00:00
|
|
|
id = bidHash
|
2021-10-20 10:07:35 +00:00
|
|
|
await contracts.newContract(
|
2021-11-02 08:45:49 +00:00
|
|
|
request.duration,
|
|
|
|
request.size,
|
|
|
|
request.contentHash,
|
|
|
|
request.proofPeriod,
|
|
|
|
request.proofTimeout,
|
|
|
|
request.nonce,
|
|
|
|
bid.price,
|
2021-10-12 14:59:34 +00:00
|
|
|
await host.getAddress(),
|
2021-11-02 08:45:49 +00:00
|
|
|
bid.bidExpiry,
|
2021-10-12 14:59:34 +00:00
|
|
|
await sign(client, requestHash),
|
|
|
|
await sign(host, bidHash)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-11-01 15:34:01 +00:00
|
|
|
it("created the contract", async function () {
|
2021-11-02 08:45:49 +00:00
|
|
|
expect(await contracts.duration(id)).to.equal(request.duration)
|
|
|
|
expect(await contracts.size(id)).to.equal(request.size)
|
|
|
|
expect(await contracts.contentHash(id)).to.equal(request.contentHash)
|
|
|
|
expect(await contracts.price(id)).to.equal(bid.price)
|
2021-10-20 10:07:35 +00:00
|
|
|
expect(await contracts.host(id)).to.equal(await host.getAddress())
|
2021-10-12 14:59:34 +00:00
|
|
|
})
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
it("requires storage proofs", async function (){
|
2021-11-02 08:45:49 +00:00
|
|
|
expect(await contracts.proofPeriod(id)).to.equal(request.proofPeriod)
|
|
|
|
expect(await contracts.proofTimeout(id)).to.equal(request.proofTimeout)
|
2021-10-14 07:10:57 +00:00
|
|
|
})
|
2021-10-12 14:59:34 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-10-18 12:55:59 +00:00
|
|
|
// TODO: implement checking of actual proofs of storage, instead of dummy bool
|
2021-10-12 14:59:34 +00:00
|
|
|
// TODO: payment on constructor
|
|
|
|
// TODO: contract start and timeout
|
2021-10-14 10:37:14 +00:00
|
|
|
// TODO: only allow proofs after start of contract
|
2021-10-12 14:59:34 +00:00
|
|
|
// TODO: payout
|
|
|
|
// TODO: stake
|