Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(hardhat): skip mining sometimes #198

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
},
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
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