Rename: StorageContracts -> Storage

This commit is contained in:
Mark Spanbroek 2021-11-01 16:34:01 +01:00
parent eefa23ff02
commit 7b6c6c2fc5
3 changed files with 29 additions and 34 deletions

View File

@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import "./Contracts.sol"; import "./Contracts.sol";
import "./Proofs.sol"; import "./Proofs.sol";
contract StorageContracts is Contracts, Proofs { contract Storage is Contracts, Proofs {
function newContract( function newContract(
uint _duration, uint _duration,

View File

@ -2,7 +2,7 @@ const { expect } = require("chai")
const { ethers } = require("hardhat") const { ethers } = require("hardhat")
const { hashRequest, hashBid, sign } = require("./marketplace") const { hashRequest, hashBid, sign } = require("./marketplace")
describe("Storage Contracts", function () { describe("Contracts", function () {
const duration = 31 * 24 * 60 * 60 // 31 days const duration = 31 * 24 * 60 * 60 // 31 days
const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte

View File

@ -2,42 +2,37 @@ const { expect } = require("chai")
const { ethers } = require("hardhat") const { ethers } = require("hardhat")
const { hashRequest, hashBid, sign } = require("./marketplace") const { hashRequest, hashBid, sign } = require("./marketplace")
describe("Storage Contracts", function () { describe("Storage", function () {
const duration = 31 * 24 * 60 * 60 // 31 days describe("creating a new storage contract", function () {
const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte
const contentHash = ethers.utils.sha256("0xdeadbeef") // hash of content
const proofPeriod = 8 // 8 blocks ≈ 2 minutes
const proofTimeout = 4 // 4 blocks ≈ 1 minute
const price = 42
const nonce = ethers.utils.randomBytes(32)
var contracts const duration = 31 * 24 * 60 * 60 // 31 days
var client, host const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte
var bidExpiry const contentHash = ethers.utils.sha256("0xdeadbeef") // hash of content
var requestHash, bidHash const proofPeriod = 8 // 8 blocks ≈ 2 minutes
var id const proofTimeout = 4 // 4 blocks ≈ 1 minute
const price = 42
const nonce = ethers.utils.randomBytes(32)
beforeEach(async function () { let contracts
[client, host] = await ethers.getSigners() let client, host
let StorageContracts = await ethers.getContractFactory("StorageContracts") let id
contracts = await StorageContracts.deploy()
requestHash = hashRequest(
duration,
size,
contentHash,
proofPeriod,
proofTimeout,
nonce
)
bidExpiry = Math.round(Date.now() / 1000) + 60 * 60 // 1 hour from now
bidHash = hashBid(requestHash, bidExpiry, price)
id = bidHash
})
describe("when properly instantiated", function () {
beforeEach(async function () { beforeEach(async function () {
[client, host] = await ethers.getSigners()
let StorageContracts = await ethers.getContractFactory("Storage")
contracts = await StorageContracts.deploy()
let requestHash = hashRequest(
duration,
size,
contentHash,
proofPeriod,
proofTimeout,
nonce
)
let bidExpiry = Math.round(Date.now() / 1000) + 60 * 60 // 1 hour from now
let bidHash = hashBid(requestHash, bidExpiry, price)
id = bidHash
await contracts.newContract( await contracts.newContract(
duration, duration,
size, size,
@ -53,7 +48,7 @@ describe("Storage Contracts", function () {
) )
}) })
it("created a contract", async function () { it("created the contract", async function () {
expect(await contracts.duration(id)).to.equal(duration) expect(await contracts.duration(id)).to.equal(duration)
expect(await contracts.size(id)).to.equal(size) expect(await contracts.size(id)).to.equal(size)
expect(await contracts.contentHash(id)).to.equal(contentHash) expect(await contracts.contentHash(id)).to.equal(contentHash)