Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Sep 27, 2023
2 parents 6a0a5d4 + e6887a8 commit fa14318
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { createAmountFromString } from "reverse-mirage";
import { type Hex } from "viem";
import { simulateContract, writeContract } from "viem/actions";
import { beforeEach, test } from "vitest";
import { deployPool, testClient } from "../../_test/utils.js";
import { ALICE } from "../../_test/constants.js";
import {
deployPool,
publicClient,
testClient,
walletClient,
} from "../../_test/utils.js";
import { mockErc20ABI } from "../../generated.js";
import type { PanopticPool } from "../../types/index.js";
import { simulatePanopticCollateralDeposit } from "./simulatePanopticCollateralDeposit.js";

let id: Hex | undefined = undefined;

Expand All @@ -10,20 +20,35 @@ let pool: PanopticPool;
beforeEach(async () => {
if (id === undefined) {
pool = await deployPool();

const { request: approveRequest } = await simulateContract(publicClient, {
address: pool.collateralTracker0.underlyingToken.address,
abi: mockErc20ABI,
functionName: "approve",
args: [pool.collateralTracker0.address, 10n ** 18n],
account: ALICE,
});

const approveHash = await writeContract(walletClient, approveRequest);
await publicClient.waitForTransactionReceipt({ hash: approveHash });
} else {
await testClient.revert({ id });
}
id = await testClient.snapshot();
}, 100_000);

test.skip("deposit", async () => {
// const { request } = await simulatePanopticCollateralDeposit(publicClient, {
// args: {
// amount: createAmountFromString(collat.underlyingToken, "0.5"),
// to: ALICE,
// },
// account: ALICE,
// });
// const hash = await walletClient.writeContract(request);
// await publicClient.waitForTransactionReceipt({ hash });
test("simulate collateral deposit", async () => {
const { request } = await simulatePanopticCollateralDeposit(publicClient, {
args: {
collateral: pool.collateralTracker0,
amount: createAmountFromString(
pool.collateralTracker0.underlyingToken,
"0.5",
),
to: ALICE,
},
account: ALICE,
});
const hash = await walletClient.writeContract(request);
await publicClient.waitForTransactionReceipt({ hash });
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { PanopticCollateral } from "../../types/PanopticCollateral.js";
export type PanopticCollateralDepositParameters<
TPanopticCollateral extends PanopticCollateral,
> = {
collateral: TPanopticCollateral;
amount: ERC20Amount<TPanopticCollateral["underlyingToken"]>;
to: Address;
};
Expand Down Expand Up @@ -49,7 +50,7 @@ export const simulatePanopticCollateralDeposit = <
>(
client: Client<Transport, TChain>,
{
args: { amount, to },
args: { collateral, amount, to },
...request
}: SimulatePanopticCollateralDepositParameters<
TPanopticCollateral,
Expand All @@ -60,7 +61,7 @@ export const simulatePanopticCollateralDeposit = <
SimulatePanopticCollateralDepositReturnType<TChain, TChainOverride>
> =>
simulateContract(client, {
address: amount.token.address,
address: collateral.address,
abi: collateralTrackerABI,
functionName: "deposit",
args: [amount.amount, to],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { createAmountFromString } from "reverse-mirage";
import { type Hex } from "viem";
import { simulateContract, writeContract } from "viem/actions";
import { beforeEach, test } from "vitest";
import { deployPool, testClient } from "../../_test/utils.js";
import type { PanopticPool } from "../../index.js";
import { ALICE } from "../../_test/constants.js";
import {
deployPool,
publicClient,
testClient,
walletClient,
} from "../../_test/utils.js";
import { mockErc20ABI } from "../../generated.js";
import {
type PanopticPool,
simulatePanopticCollateralMint,
} from "../../index.js";

let id: Hex | undefined = undefined;

Expand All @@ -10,20 +22,30 @@ let pool: PanopticPool;
beforeEach(async () => {
if (id === undefined) {
pool = await deployPool();
const { request: approveRequest } = await simulateContract(publicClient, {
address: pool.collateralTracker0.underlyingToken.address,
abi: mockErc20ABI,
functionName: "approve",
args: [pool.collateralTracker0.address, 10n ** 18n],
account: ALICE,
});

const approveHash = await writeContract(walletClient, approveRequest);
await publicClient.waitForTransactionReceipt({ hash: approveHash });
} else {
await testClient.revert({ id });
}
id = await testClient.snapshot();
}, 100_000);

test.skip("Mint", async () => {
// const { request } = await simulatePanopticCollateralMint(publicClient, {
// args: {
// amount: createAmountFromString(collat, "0.5"),
// to: ALICE,
// },
// account: ALICE,
// });
// const hash = await walletClient.writeContract(request);
// await publicClient.waitForTransactionReceipt({ hash });
test("simulate collateral mint", async () => {
const { request } = await simulatePanopticCollateralMint(publicClient, {
args: {
amount: createAmountFromString(pool.collateralTracker0, "0.5"),
to: ALICE,
},
account: ALICE,
});
const hash = await walletClient.writeContract(request);
await publicClient.waitForTransactionReceipt({ hash });
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { createAmountFromString } from "reverse-mirage";
import { type Hex } from "viem";
import { simulateContract, writeContract } from "viem/actions";
import { beforeEach, test } from "vitest";
import { deployPool, testClient } from "../../_test/utils.js";
import type { PanopticPool } from "../../index.js";
import { ALICE } from "../../_test/constants.js";
import {
deployPool,
publicClient,
testClient,
walletClient,
} from "../../_test/utils.js";
import { mockErc20ABI } from "../../generated.js";
import {
type PanopticPool,
simulatePanopticCollateralDeposit,
simulatePanopticCollateralRedeem,
} from "../../index.js";

let id: Hex | undefined = undefined;

Expand All @@ -10,20 +23,49 @@ let pool: PanopticPool;
beforeEach(async () => {
if (id === undefined) {
pool = await deployPool();

const { request: approveRequest } = await simulateContract(publicClient, {
address: pool.collateralTracker0.underlyingToken.address,
abi: mockErc20ABI,
functionName: "approve",
args: [pool.collateralTracker0.address, 10n ** 18n],
account: ALICE,
});

const approveHash = await writeContract(walletClient, approveRequest);
await publicClient.waitForTransactionReceipt({ hash: approveHash });

const { request: depositRequest } = await simulatePanopticCollateralDeposit(
publicClient,
{
args: {
collateral: pool.collateralTracker0,
amount: createAmountFromString(
pool.collateralTracker0.underlyingToken,
"1",
),
to: ALICE,
},
account: ALICE,
},
);
const depositHash = await walletClient.writeContract(depositRequest);
await publicClient.waitForTransactionReceipt({ hash: depositHash });
} else {
await testClient.revert({ id });
}
id = await testClient.snapshot();
}, 100_000);

test.skip("Redeem", async () => {
// const { request } = await simulatePanopticCollateralRedeem(walletClient, {
// args: {
// amount: createAmountFromString(collat, "0.5"),
// from: ALICE,
// to: ALICE,
// },
// });
// const hash = await walletClient.writeContract(request);
// await publicClient.waitForTransactionReceipt({ hash });
test("simulate collateral redeem", async () => {
const { request } = await simulatePanopticCollateralRedeem(publicClient, {
args: {
amount: createAmountFromString(pool.collateralTracker0, "0.5"),
from: ALICE,
to: ALICE,
},
account: ALICE,
});
const hash = await walletClient.writeContract(request);
await publicClient.waitForTransactionReceipt({ hash });
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { createAmountFromString } from "reverse-mirage";
import { type Hex } from "viem";
import { simulateContract, writeContract } from "viem/actions";
import { beforeEach, test } from "vitest";
import { deployPool, testClient } from "../../_test/utils.js";
import type { PanopticPool } from "../../index.js";
import { ALICE } from "../../_test/constants.js";
import {
deployPool,
publicClient,
testClient,
walletClient,
} from "../../_test/utils.js";
import { mockErc20ABI } from "../../generated.js";
import {
type PanopticPool,
simulatePanopticCollateralDeposit,
simulatePanopticCollateralWithdraw,
} from "../../index.js";

let id: Hex | undefined = undefined;

Expand All @@ -10,21 +23,53 @@ let pool: PanopticPool;
beforeEach(async () => {
if (id === undefined) {
pool = await deployPool();

const { request: approveRequest } = await simulateContract(publicClient, {
address: pool.collateralTracker0.underlyingToken.address,
abi: mockErc20ABI,
functionName: "approve",
args: [pool.collateralTracker0.address, 10n ** 18n],
account: ALICE,
});

const approveHash = await writeContract(walletClient, approveRequest);
await publicClient.waitForTransactionReceipt({ hash: approveHash });

const { request: depositRequest } = await simulatePanopticCollateralDeposit(
publicClient,
{
args: {
collateral: pool.collateralTracker0,
amount: createAmountFromString(
pool.collateralTracker0.underlyingToken,
"0.5",
),
to: ALICE,
},
account: ALICE,
},
);
const depositHash = await walletClient.writeContract(depositRequest);
await publicClient.waitForTransactionReceipt({ hash: depositHash });
} else {
await testClient.revert({ id });
}
id = await testClient.snapshot();
}, 100_000);

test.skip("WithsimulatePanopticCollateralWithdraw", async () => {
// const { request } = await simulatePanopticCollateralWithdraw(publicClient, {
// args: {
// amount: createAmountFromString(collat.underlyingToken, "0.5"),
// from: ALICE,
// to: ALICE,
// },
// account: ALICE,
// });
// const hash = await walletClient.writeContract(request);
// await publicClient.waitForTransactionReceipt({ hash });
test("simulate collateral withdraw", async () => {
const { request } = await simulatePanopticCollateralWithdraw(publicClient, {
args: {
collateral: pool.collateralTracker0,
amount: createAmountFromString(
pool.collateralTracker0.underlyingToken,
"0.5",
),
from: ALICE,
to: ALICE,
},
account: ALICE,
});
const hash = await walletClient.writeContract(request);
await publicClient.waitForTransactionReceipt({ hash });
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { PanopticCollateral } from "../../types/PanopticCollateral.js";
export type PanopticCollateralWithdrawParameters<
TPanopticCollateral extends PanopticCollateral,
> = {
collateral: TPanopticCollateral;
amount: ERC20Amount<TPanopticCollateral["underlyingToken"]>;
from: Address;
to: Address;
Expand Down Expand Up @@ -50,7 +51,7 @@ export const simulatePanopticCollateralWithdraw = <
>(
client: Client<Transport, TChain>,
{
args: { amount, to, from },
args: { collateral, amount, to, from },
...request
}: SimulatePanopticCollateralWithdrawParameters<
TPanopticCollateral,
Expand All @@ -61,7 +62,7 @@ export const simulatePanopticCollateralWithdraw = <
SimulatePanopticCollateralWithdrawReturnType<TChain, TChainOverride>
> =>
simulateContract(client, {
address: amount.token.address,
address: collateral.address,
abi: collateralTrackerABI,
functionName: "withdraw",
args: [amount.amount, from, to],
Expand Down

0 comments on commit fa14318

Please sign in to comment.