2021-10-12 14:59:34 +00:00
|
|
|
const { expect } = require("chai")
|
|
|
|
const { ethers } = require("hardhat")
|
|
|
|
const { hashRequest, hashBid, sign } = require("./marketplace")
|
|
|
|
|
2021-10-20 07:04:03 +00:00
|
|
|
describe("Storage Contracts", function () {
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-10-14 07:10:57 +00:00
|
|
|
const duration = 31 * 24 * 60 * 60 // 31 days
|
|
|
|
const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte
|
2021-10-14 12:49:29 +00:00
|
|
|
const contentHash = ethers.utils.sha256("0xdeadbeef") // hash of content
|
2021-10-14 10:37:14 +00:00
|
|
|
const proofPeriod = 8 // 8 blocks ≈ 2 minutes
|
|
|
|
const proofTimeout = 4 // 4 blocks ≈ 1 minute
|
2021-10-12 14:59:34 +00:00
|
|
|
const price = 42
|
2021-10-20 12:28:05 +00:00
|
|
|
const nonce = ethers.utils.randomBytes(32)
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2021-10-20 10:07:35 +00:00
|
|
|
var contracts
|
2021-10-12 14:59:34 +00:00
|
|
|
var client, host
|
2021-10-18 13:29:58 +00:00
|
|
|
var bidExpiry
|
2021-10-12 14:59:34 +00:00
|
|
|
var requestHash, bidHash
|
2021-10-20 10:07:35 +00:00
|
|
|
var id
|
2021-10-12 14:59:34 +00:00
|
|
|
|
|
|
|
beforeEach(async function () {
|
|
|
|
[client, host] = await ethers.getSigners()
|
2021-10-20 10:07:35 +00:00
|
|
|
let StorageContracts = await ethers.getContractFactory("StorageContracts")
|
|
|
|
contracts = await StorageContracts.deploy()
|
2021-10-14 12:49:29 +00:00
|
|
|
requestHash = hashRequest(
|
|
|
|
duration,
|
|
|
|
size,
|
|
|
|
contentHash,
|
|
|
|
proofPeriod,
|
2021-10-20 12:28:05 +00:00
|
|
|
proofTimeout,
|
|
|
|
nonce
|
2021-10-14 12:49:29 +00:00
|
|
|
)
|
2021-10-18 13:29:58 +00:00
|
|
|
bidExpiry = Math.round(Date.now() / 1000) + 60 * 60 // 1 hour from now
|
|
|
|
bidHash = hashBid(requestHash, bidExpiry, price)
|
2021-10-20 12:28:05 +00:00
|
|
|
id = bidHash
|
2021-10-12 14:59:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("when properly instantiated", function () {
|
|
|
|
|
|
|
|
beforeEach(async function () {
|
2021-10-20 10:07:35 +00:00
|
|
|
await contracts.newContract(
|
2021-10-12 14:59:34 +00:00
|
|
|
duration,
|
|
|
|
size,
|
2021-10-14 12:49:29 +00:00
|
|
|
contentHash,
|
2021-10-14 07:10:57 +00:00
|
|
|
proofPeriod,
|
|
|
|
proofTimeout,
|
2021-10-20 12:28:05 +00:00
|
|
|
nonce,
|
2021-11-01 15:23:37 +00:00
|
|
|
price,
|
2021-10-12 14:59:34 +00:00
|
|
|
await host.getAddress(),
|
2021-11-01 15:23:37 +00:00
|
|
|
bidExpiry,
|
2021-10-12 14:59:34 +00:00
|
|
|
await sign(client, requestHash),
|
|
|
|
await sign(host, bidHash)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-11-01 15:17:42 +00:00
|
|
|
it("created a contract", async function () {
|
2021-10-20 10:07:35 +00:00
|
|
|
expect(await contracts.duration(id)).to.equal(duration)
|
|
|
|
expect(await contracts.size(id)).to.equal(size)
|
|
|
|
expect(await contracts.contentHash(id)).to.equal(contentHash)
|
|
|
|
expect(await contracts.price(id)).to.equal(price)
|
|
|
|
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-10-20 10:07:35 +00:00
|
|
|
expect(await contracts.proofPeriod(id)).to.equal(proofPeriod)
|
|
|
|
expect(await contracts.proofTimeout(id)).to.equal(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
|