Skip to content

Commit

Permalink
Merge pull request #198 from morpho-labs/test/skip-mining-sometimes
Browse files Browse the repository at this point in the history
test(hardhat): skip mining sometimes
  • Loading branch information
MathisGD authored Jul 31, 2023
2 parents 4e10a7b + 6fb2893 commit 60278e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const config: HardhatUserConfig = {
accounts: {
count: 252,
},
mining: {
mempool: {
order: "fifo",
},
},
},
},
solidity: {
Expand Down
23 changes: 16 additions & 7 deletions test/hardhat/Blue.spec.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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), "%");

Expand All @@ -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, user.address);
Promise.all([
blue.connect(user).supply(market, amount, user.address, []),
blue.connect(user).withdraw(market, amount.div(2), user.address, user.address),
]);
} else {
const totalSupply = await blue.totalSupply(id);
const totalBorrow = await blue.totalBorrow(id);
Expand All @@ -139,13 +144,17 @@ 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, 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, user.address);
Promise.all([
blue.connect(user).supplyCollateral(market, amount, user.address, []),
blue.connect(user).borrow(market, amount.div(2), user.address, user.address),
blue.connect(user).repay(market, amount.div(4), user.address, []),
blue.connect(user).withdrawCollateral(market, amount.div(8), user.address, user.address),
]);
}
}
}

await hre.network.provider.send("evm_setAutomine", [true]);
});

it("should simulate gas cost [liquidations]", async () => {
Expand Down

0 comments on commit 60278e4

Please sign in to comment.