Skip to content

Commit

Permalink
test(anvil): fix block mining interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 24, 2024
1 parent 6696d5a commit 0cb3217
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 33 deletions.
13 changes: 2 additions & 11 deletions packages/blue-sdk-ethers/test/e2e/Market.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ describe("augment/Market", () => {
functionName: "enableIrm",
args: [params.irm],
});

const timestamp = (await client.timestamp()) + 3n;

await client.setNextBlockTimestamp({ timestamp });

await client.writeContract({
address: morpho,
abi: blueAbi,
Expand All @@ -94,7 +89,7 @@ describe("augment/Market", () => {
totalSupplyShares: 0n,
totalBorrowAssets: 0n,
totalBorrowShares: 0n,
lastUpdate: BigInt(timestamp),
lastUpdate: await client.timestamp(),
fee: 0n,
price: 1160095030000000000000000000000000000n,
rateAtTarget: undefined,
Expand All @@ -113,10 +108,6 @@ describe("augment/Market", () => {
...crvUsd_stkcvx2BTC,
oracle: randomAddress(),
});

const timestamp = (await client.timestamp()) + 3n;

await client.setNextBlockTimestamp({ timestamp });
await client.writeContract({
address: morpho,
abi: blueAbi,
Expand All @@ -130,7 +121,7 @@ describe("augment/Market", () => {
totalSupplyShares: 0n,
totalBorrowAssets: 0n,
totalBorrowShares: 0n,
lastUpdate: 1711597274n,
lastUpdate: 1711597272n,
fee: 0n,
rateAtTarget: 1268391679n,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/blue-sdk-ethers/test/e2e/Vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("augment/Vault", () => {
"0x3a85e619751152991742810df6ec69ce473daef99e28a64ab2340d7b7ccfee49" as MarketId,
],
lastTotalAssets: 26129569140552n,
totalAssets: 26138939802936n,
totalAssets: 26138940196162n,
totalSupply: 25752992371062043744406063n,
});

Expand Down
13 changes: 2 additions & 11 deletions packages/blue-sdk-viem/test/Market.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ describe("augment/Market", () => {
functionName: "enableIrm",
args: [params.irm],
});

const timestamp = (await client.timestamp()) + 3n;

await client.setNextBlockTimestamp({ timestamp });

await client.writeContract({
address: morpho,
abi: blueAbi,
Expand All @@ -93,7 +88,7 @@ describe("augment/Market", () => {
totalSupplyShares: 0n,
totalBorrowAssets: 0n,
totalBorrowShares: 0n,
lastUpdate: BigInt(timestamp),
lastUpdate: await client.timestamp(),
fee: 0n,
price: 1160095030000000000000000000000000000n,
rateAtTarget: undefined,
Expand All @@ -109,10 +104,6 @@ describe("augment/Market", () => {
...crvUsd_stkcvx2BTC,
oracle: randomAddress(),
});

const timestamp = (await client.timestamp()) + 3n;

await client.setNextBlockTimestamp({ timestamp });
await client.writeContract({
address: morpho,
abi: blueAbi,
Expand All @@ -126,7 +117,7 @@ describe("augment/Market", () => {
totalSupplyShares: 0n,
totalBorrowAssets: 0n,
totalBorrowShares: 0n,
lastUpdate: 1711597274n,
lastUpdate: 1711597272n,
fee: 0n,
rateAtTarget: 1268391679n,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/blue-sdk-viem/test/Vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("augment/Vault", () => {
"0x3a85e619751152991742810df6ec69ce473daef99e28a64ab2340d7b7ccfee49" as MarketId,
],
lastTotalAssets: 26129569140552n,
totalAssets: 26138939802936n,
totalAssets: 26138940196162n,
totalSupply: 25752992371062043744406063n,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ describe("erc4626-1inch", () => {
});

expect(format.number.of(decimalBalance, decimals)).toBeCloseTo(
7325.591839,
7325.591893,
6,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,6 @@ describe("useSimulationState", () => {

expect(data0).toBe(steps[0]);

await client.setNextBlockTimestamp({
timestamp: data0.block.timestamp + 1n,
});
await client.approve({
address: usdc,
args: [morpho, amount],
Expand All @@ -432,9 +429,6 @@ describe("useSimulationState", () => {
expect(data1).toStrictEqual(step1);

await client.setBalance({ address: morpho, value: parseEther("1") });
await client.setNextBlockTimestamp({
timestamp: data1.block.timestamp + 1n,
});
await client.writeContract({
account: morpho,
address: usdc,
Expand Down
7 changes: 5 additions & 2 deletions packages/test-viem/src/vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ export const createViemTest = <chain extends Chain>(
client: async ({}, use) => {
const { rpcUrl, stop } = await spawnAnvil(parameters);

let client: AnvilTestClient<chain>;
const client = createAnvilTestClient(http(rpcUrl), chain);

await use((client = createAnvilTestClient(http(rpcUrl), chain)));
// Make block timestamp 100% predictable.
await client.setBlockTimestampInterval({ interval: 1 });

await use(client);

await stop();
},
Expand Down

0 comments on commit 0cb3217

Please sign in to comment.