Skip to content

Commit

Permalink
test(viem): add viem-based hardhat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Jul 17, 2024
1 parent 3974f0c commit 52618e4
Show file tree
Hide file tree
Showing 34 changed files with 1,043 additions and 295 deletions.
1 change: 0 additions & 1 deletion packages/blue-sdk-ethers/src/fetch/User.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Provider } from "ethers";
import { ViewOverrides } from "ethers-types/dist/common";
import {} from "ethers-types/dist/token/ERC20/ERC20";

import {
Address,
Expand Down
28 changes: 6 additions & 22 deletions packages/blue-sdk-ethers/test/Holding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@ import { MAINNET_MARKETS } from "@morpho-org/blue-sdk/src/tests/mocks/markets";

import { setUp } from "@morpho-org/morpho-test";
import { ethers } from "hardhat";
import sinon from "sinon";
import "../src/augment/Holding";

describe("augment/Holding", () => {
let signer: SignerWithAddress;

setUp(async () => {
signer = (await ethers.getSigners())[0]!;

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
});

it("should fetch user token data", async () => {
Expand Down Expand Up @@ -82,14 +71,12 @@ describe("augment/Holding", () => {
expectedData.permit2Allowances.morpho.amount,
expectedData.permit2Allowances.morpho.expiration,
);
await (
await permit2.approve(
token,
addresses[ChainId.EthMainnet].bundler,
expectedData.permit2Allowances.bundler.amount,
expectedData.permit2Allowances.bundler.expiration,
)
).wait();
await permit2.approve(
token,
addresses[ChainId.EthMainnet].bundler,
expectedData.permit2Allowances.bundler.amount,
expectedData.permit2Allowances.bundler.expiration,
);

const value = await Holding.fetch(
signer.address,
Expand All @@ -98,8 +85,5 @@ describe("augment/Holding", () => {
);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
8,
);
});
});
17 changes: 1 addition & 16 deletions packages/blue-sdk-ethers/test/Market.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from "chai";
import { Wallet, parseUnits, toBigInt } from "ethers";
import { MorphoBlue__factory } from "ethers-types";
import { ethers } from "hardhat";
import sinon, { SinonSpy } from "sinon";

import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import {
Expand All @@ -23,16 +22,6 @@ describe("augment/Market", () => {

setUp(async () => {
signer = (await ethers.getSigners())[0]!;

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
});

it("should fetch market data", async () => {
Expand All @@ -51,7 +40,6 @@ describe("augment/Market", () => {
const value = await Market.fetch(MAINNET_MARKETS.usdc_wstEth.id, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as SinonSpy).getCalls()).to.have.length(3);
});

it("should fetch market data from config", async () => {
Expand All @@ -73,7 +61,6 @@ describe("augment/Market", () => {
);

expect(value).to.eql(expectedData);
expect((signer.provider.call as SinonSpy).getCalls()).to.have.length(3);
});

it("should fetch price and rate if idle market", async () => {
Expand All @@ -92,7 +79,6 @@ describe("augment/Market", () => {
const value = await Market.fetch(MAINNET_MARKETS.idle_usdc.id, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as SinonSpy).getCalls()).to.have.length(1);
});

it("should not fetch rate at target for unknown irm", async () => {
Expand All @@ -116,7 +102,7 @@ describe("augment/Market", () => {

const timestamp = toBigInt(await time.latest());
await setNextBlockTimestamp(timestamp);
await (await morpho.createMarket(config)).wait();
await morpho.createMarket(config);

const expectedData = {
config,
Expand All @@ -133,6 +119,5 @@ describe("augment/Market", () => {
const value = await Market.fetch(config.id, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as SinonSpy).getCalls()).to.have.length(3);
});
});
17 changes: 0 additions & 17 deletions packages/blue-sdk-ethers/test/MarketConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from "chai";
import { ZeroAddress } from "ethers";
import { ethers } from "hardhat";
import sinon from "sinon";

import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";

Expand All @@ -21,16 +20,6 @@ describe("augment/MarketConfig", () => {

setUp(async () => {
signer = (await ethers.getSigners())[0]!;

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
});

it("should fetch config from cache", async () => {
Expand All @@ -40,9 +29,6 @@ describe("augment/MarketConfig", () => {
);

expect(market).to.eql(MAINNET_MARKETS.usdc_wstEth);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
0,
);
});

it("should fetch config from chain", async () => {
Expand All @@ -60,8 +46,5 @@ describe("augment/MarketConfig", () => {
);

expect(market).to.eql(marketParams);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
1,
);
});
});
15 changes: 0 additions & 15 deletions packages/blue-sdk-ethers/test/Position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { MAINNET_MARKETS } from "@morpho-org/blue-sdk/src/tests/mocks/markets";
import { setUp } from "@morpho-org/morpho-test";
import "../src/augment/Position";

import sinon from "sinon";

const market = MAINNET_MARKETS.usdc_wstEth;

const supplyAssets = parseUnits("10", 6);
Expand Down Expand Up @@ -53,16 +51,6 @@ describe("augment/Position", () => {
signer.address,
signer.address,
);

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
});

it("should fetch position", async () => {
Expand All @@ -77,8 +65,5 @@ describe("augment/Position", () => {
const value = await Position.fetch(signer.address, market.id, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
1,
);
});
});
21 changes: 0 additions & 21 deletions packages/blue-sdk-ethers/test/Token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@ import {
addresses,
} from "@morpho-org/blue-sdk";
import { setUp } from "@morpho-org/morpho-test";

import sinon from "sinon";
import "../src/augment/Token";

describe("augment/Token", () => {
let signer: SignerWithAddress;

setUp(async () => {
signer = (await ethers.getSigners())[0]!;

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
});

it("should fetch token data", async () => {
Expand All @@ -42,9 +30,6 @@ describe("augment/Token", () => {
const value = await Token.fetch(addresses[ChainId.EthMainnet].usdc, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
3,
);
});

it("should fetch wrapped token data", async () => {
Expand All @@ -65,9 +50,6 @@ describe("augment/Token", () => {
);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
4,
);
});

it("Should fetch MKR token data", async () => {
Expand All @@ -81,8 +63,5 @@ describe("augment/Token", () => {
const value = await Token.fetch(addresses[ChainId.EthMainnet].mkr, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
3,
);
});
});
19 changes: 1 addition & 18 deletions packages/blue-sdk-ethers/test/User.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";

import { ChainId, User, addresses } from "@morpho-org/blue-sdk";
import { setUp } from "@morpho-org/morpho-test";

import sinon from "sinon";
import "../src/augment/User";

describe("augment/User", () => {
Expand All @@ -21,19 +19,7 @@ describe("augment/User", () => {
signer,
);

await (
await morpho.setAuthorization(addresses[ChainId.EthMainnet].bundler, true)
).wait();

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
await morpho.setAuthorization(addresses[ChainId.EthMainnet].bundler, true);
});

it("should fetch user data", async () => {
Expand All @@ -46,8 +32,5 @@ describe("augment/User", () => {
const value = await User.fetch(signer.address, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
2,
);
});
});
14 changes: 0 additions & 14 deletions packages/blue-sdk-ethers/test/Vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ChainId, Vault, addresses } from "@morpho-org/blue-sdk";
import { setUp } from "@morpho-org/morpho-test";

import "../src/augment/Vault";
import sinon from "sinon";
import { steakUsdc } from "./fixtures";

describe("augment/Vault", () => {
Expand All @@ -35,16 +34,6 @@ describe("augment/Vault", () => {

await setNextBlockTimestamp(block.timestamp);
await publicAllocator.setFee(steakUsdc.address, 1);

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
});

it("should fetch vault data", async () => {
Expand Down Expand Up @@ -90,8 +79,5 @@ describe("augment/Vault", () => {
const value = await Vault.fetch(steakUsdc.address, signer);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
26,
);
});
});
28 changes: 6 additions & 22 deletions packages/blue-sdk-ethers/test/VaultMarketConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { MAINNET_MARKETS } from "@morpho-org/blue-sdk/src/tests/mocks/markets";
import { setUp } from "@morpho-org/morpho-test";

import "../src/augment/VaultMarketConfig";
import sinon from "sinon";
import { steakUsdc } from "./fixtures";

describe("augment/VaultMarketConfig", () => {
Expand All @@ -38,24 +37,12 @@ describe("augment/VaultMarketConfig", () => {

await publicAllocator.setFee(steakUsdc.address, 1);

await (
await publicAllocator.setFlowCaps(steakUsdc.address, [
{
id: MAINNET_MARKETS.usdc_wstEth.id,
caps: { maxIn: 2, maxOut: 3 },
},
])
).wait();

sinon.spy(signer.provider, "call");
});

afterEach(() => {
(signer.provider.call as sinon.SinonSpy).resetHistory();
});

after(() => {
(signer.provider.call as sinon.SinonSpy).restore();
await publicAllocator.setFlowCaps(steakUsdc.address, [
{
id: MAINNET_MARKETS.usdc_wstEth.id,
caps: { maxIn: 2, maxOut: 3 },
},
]);
});

it("should fetch vault market data", async () => {
Expand Down Expand Up @@ -84,8 +71,5 @@ describe("augment/VaultMarketConfig", () => {
);

expect(value).to.eql(expectedData);
expect((signer.provider.call as sinon.SinonSpy).getCalls()).to.have.length(
3,
);
});
});
Loading

0 comments on commit 52618e4

Please sign in to comment.