From 438fb605c095103ad679e4099a2edcfe803be040 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 15 Mar 2022 16:45:35 +0100 Subject: [PATCH] Ensure local ethereum node has at least 256 blocks Storage contract cannot be deployed when block height is less than 256 blocks. --- deploy/storage.js | 13 ++++++++++++- hardhat.config.js | 9 +++++++-- test/Storage.test.js | 8 +------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/deploy/storage.js b/deploy/storage.js index 4bf482f..0fd684c 100644 --- a/deploy/storage.js +++ b/deploy/storage.js @@ -1,4 +1,4 @@ -module.exports = async ({ deployments, getNamedAccounts }) => { +async function deployStorage({ deployments, getNamedAccounts }) { const token = await deployments.get("TestToken") const proofPeriod = 10 const proofTimeout = 5 @@ -19,5 +19,16 @@ module.exports = async ({ deployments, getNamedAccounts }) => { await deployments.deploy("Storage", { args, from: deployer }) } +async function mine256blocks({ network, ethers }) { + if (network.tags.local) { + await ethers.provider.send("hardhat_mine", ["0x100"]) + } +} + +module.exports = async (environment) => { + await mine256blocks(environment) + await deployStorage(environment) +} + module.exports.tags = ["Storage"] module.exports.dependencies = ["TestToken"] diff --git a/hardhat.config.js b/hardhat.config.js index 73e04c1..6129ed5 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -5,6 +5,11 @@ require("hardhat-deploy-ethers") module.exports = { solidity: "0.8.4", namedAccounts: { - deployer: { default: 0 } - } + deployer: { default: 0 }, + }, + networks: { + hardhat: { + tags: ["local"], + }, + }, } diff --git a/test/Storage.test.js b/test/Storage.test.js index 07e987a..59caebe 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -1,12 +1,7 @@ const { expect } = require("chai") const { ethers, deployments } = require("hardhat") const { exampleRequest, exampleOffer } = require("./examples") -const { - ensureMinimumBlockHeight, - advanceTime, - advanceTimeTo, - currentTime, -} = require("./evm") +const { advanceTime, advanceTimeTo, currentTime } = require("./evm") const { requestId, offerId } = require("./ids") const { periodic } = require("./time") @@ -26,7 +21,6 @@ describe("Storage", function () { beforeEach(async function () { ;[client, host] = await ethers.getSigners() - await ensureMinimumBlockHeight(256) await deployments.fixture(["TestToken", "Storage"]) token = await ethers.getContract("TestToken") storage = await ethers.getContract("Storage")