Skip to content

Commit

Permalink
test(hardhat): skip mining sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Jul 31, 2023
1 parent dae6eb4 commit 4b484c7
Show file tree
Hide file tree
Showing 2 changed files with 19 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
21 changes: 14 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 @@ -113,6 +113,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 @@ -123,8 +126,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);
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);
Expand All @@ -133,10 +138,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);
await blue.connect(user).borrow(market, amount.div(2), user.address);
await blue.connect(user).repay(market, amount.div(4), user.address);
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),
]);
}
}
}
Expand Down

0 comments on commit 4b484c7

Please sign in to comment.