diff --git a/test/Contracts.test.js b/test/Contracts.test.js index 02f5aa1..527a346 100644 --- a/test/Contracts.test.js +++ b/test/Contracts.test.js @@ -1,20 +1,23 @@ const { expect } = require("chai") const { ethers } = require("hardhat") const { hashRequest, hashBid, sign } = require("./marketplace") +const { examples } = require("./examples") describe("Contracts", function () { - const duration = 31 * 24 * 60 * 60 // 31 days - const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte - const contentHash = ethers.utils.sha256("0xdeadbeef") - const proofPeriod = 8 // 8 blocks ≈ 2 minutes - const proofTimeout = 4 // 4 blocks ≈ 1 minute - const price = 42 - const nonce = ethers.utils.randomBytes(32) + const { + duration, + size, + contentHash, + proofPeriod, + proofTimeout, + price, + nonce, + bidExpiry + } = examples() let client, host let contracts - let bidExpiry let requestHash, bidHash let id @@ -30,7 +33,6 @@ describe("Contracts", function () { proofTimeout, nonce ) - bidExpiry = Math.round(Date.now() / 1000) + 60 * 60 // 1 hour from now bidHash = hashBid(requestHash, bidExpiry, price) id = bidHash }) diff --git a/test/Storage.test.js b/test/Storage.test.js index 180ecef..86d50c9 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -1,18 +1,22 @@ const { expect } = require("chai") const { ethers } = require("hardhat") const { hashRequest, hashBid, sign } = require("./marketplace") +const { examples } = require("./examples") describe("Storage", function () { describe("creating a new storage contract", function () { - const duration = 31 * 24 * 60 * 60 // 31 days - 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) + const { + duration, + size, + contentHash, + proofPeriod, + proofTimeout, + price, + nonce, + bidExpiry + } = examples() let contracts let client, host @@ -30,7 +34,6 @@ describe("Storage", function () { 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( diff --git a/test/examples.js b/test/examples.js new file mode 100644 index 0000000..0206a30 --- /dev/null +++ b/test/examples.js @@ -0,0 +1,14 @@ +const { ethers } = require("hardhat") + +const examples = () => ({ + duration: 31 * 24 * 60 * 60, // 31 days + size: 1 * 1024 * 1024 * 1024, // 1 Gigabyte + contentHash: ethers.utils.sha256("0xdeadbeef"), + proofPeriod: 8, // 8 blocks ≈ 2 minutes + proofTimeout: 4, // 4 blocks ≈ 1 minute + price: 42, + nonce: ethers.utils.randomBytes(32), + bidExpiry: Math.round(Date.now() / 1000) + 60 * 60 // 1 hour from now +}) + +module.exports = { examples }