From 9aa9e8f4f5817914142a4e9b8edab1b35558d41c Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Mon, 31 Jul 2023 10:47:35 +0200 Subject: [PATCH 1/3] test(hardhat): skip mining sometimes --- hardhat.config.ts | 5 +++++ test/hardhat/Blue.spec.ts | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 413224c1e..d0e7619f0 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -22,6 +22,11 @@ const config: HardhatUserConfig = { accounts: { count: 252, }, + mining: { + mempool: { + order: "fifo", + }, + }, }, }, solidity: { diff --git a/test/hardhat/Blue.spec.ts b/test/hardhat/Blue.spec.ts index e1ad30a06..6310b92ee 100644 --- a/test/hardhat/Blue.spec.ts +++ b/test/hardhat/Blue.spec.ts @@ -1,5 +1,5 @@ import { defaultAbiCoder } from "@ethersproject/abi"; -import { mine, setBalance } from "@nomicfoundation/hardhat-network-helpers"; +import { mine } from "@nomicfoundation/hardhat-network-helpers"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { expect } from "chai"; import { BigNumber, constants, utils } from "ethers"; @@ -119,6 +119,9 @@ describe("Blue", () => { }); it("should simulate gas cost [main]", async () => { + await hre.network.provider.send("evm_setAutomine", [false]); + await hre.network.provider.send("evm_setIntervalMining", [0]); + for (let i = 0; i < signers.length; ++i) { if (i % 20 == 0) console.log("[main]", Math.floor((100 * i) / signers.length), "%"); @@ -129,8 +132,10 @@ describe("Blue", () => { let amount = BigNumber.WAD.mul(1 + Math.floor(random() * 100)); if (random() < 2 / 3) { - await blue.connect(user).supply(market, amount, user.address, "0x"); - await blue.connect(user).withdraw(market, amount.div(2), user.address); + Promise.all([ + blue.connect(user).supply(market, amount, user.address, []), + blue.connect(user).withdraw(market, amount.div(2), user.address), + ]); } else { const totalSupply = await blue.totalSupply(id); const totalBorrow = await blue.totalBorrow(id); @@ -139,10 +144,12 @@ describe("Blue", () => { amount = BigNumber.min(amount, BigNumber.from(liquidity).div(2)); if (amount > BigNumber.from(0)) { - await blue.connect(user).supplyCollateral(market, amount, user.address, "0x"); - await blue.connect(user).borrow(market, amount.div(2), user.address); - await blue.connect(user).repay(market, amount.div(4), user.address, "0x"); - await blue.connect(user).withdrawCollateral(market, amount.div(8), user.address); + Promise.all([ + blue.connect(user).supplyCollateral(market, amount, user.address, []), + blue.connect(user).borrow(market, amount.div(2), user.address), + blue.connect(user).repay(market, amount.div(4), user.address, []), + blue.connect(user).withdrawCollateral(market, amount.div(8), user.address), + ]); } } } From 6970ae36548aafe5d864f847bb0c7f4de73d9c00 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Mon, 31 Jul 2023 11:12:18 +0200 Subject: [PATCH 2/3] test(hardhat): make sure last block is mined --- test/hardhat/Blue.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/hardhat/Blue.spec.ts b/test/hardhat/Blue.spec.ts index 6310b92ee..217bb3faa 100644 --- a/test/hardhat/Blue.spec.ts +++ b/test/hardhat/Blue.spec.ts @@ -153,6 +153,8 @@ describe("Blue", () => { } } } + + await mine(); }); it("should simulate gas cost [liquidations]", async () => { From 28604aaf447b7198a74c664b69f10ab5480525ca Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Mon, 31 Jul 2023 17:36:20 +0200 Subject: [PATCH 3/3] test(hardhat): reset automine --- test/hardhat/Blue.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hardhat/Blue.spec.ts b/test/hardhat/Blue.spec.ts index 217bb3faa..a4ad3368f 100644 --- a/test/hardhat/Blue.spec.ts +++ b/test/hardhat/Blue.spec.ts @@ -154,7 +154,7 @@ describe("Blue", () => { } } - await mine(); + await hre.network.provider.send("evm_setAutomine", [true]); }); it("should simulate gas cost [liquidations]", async () => {