Files
strategic/tests/unit/adapters/compoundV3.test.ts
2026-02-09 21:51:54 -08:00

71 lines
1.8 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { CompoundV3Adapter } from "../../../src/adapters/compoundV3.js";
describe("Compound V3 Adapter", () => {
let adapter: CompoundV3Adapter;
let mockProvider: any;
beforeEach(() => {
mockProvider = {
getNetwork: vi.fn().mockResolvedValue({ chainId: 1n }),
call: vi.fn(),
};
vi.spyOn(require("ethers"), "JsonRpcProvider").mockImplementation(() => mockProvider);
vi.spyOn(require("ethers"), "Contract").mockImplementation(() => ({
supply: vi.fn(),
withdraw: vi.fn(),
borrow: vi.fn(),
repay: vi.fn(),
allow: vi.fn(),
getAccountLiquidity: vi.fn(),
interface: {
parseLog: vi.fn(),
},
}));
});
it("should supply assets", async () => {
adapter = new CompoundV3Adapter("mainnet");
// Test would verify supply call encoding
expect(adapter).toBeDefined();
});
it("should withdraw assets", async () => {
adapter = new CompoundV3Adapter("mainnet");
// Test would verify withdraw call encoding
expect(adapter).toBeDefined();
});
it("should borrow assets", async () => {
adapter = new CompoundV3Adapter("mainnet");
// Test would verify borrow call encoding
expect(adapter).toBeDefined();
});
it("should repay assets", async () => {
adapter = new CompoundV3Adapter("mainnet");
// Test would verify repay call encoding
expect(adapter).toBeDefined();
});
it("should calculate account liquidity", async () => {
adapter = new CompoundV3Adapter("mainnet");
const mockLiquidity = {
isLiquid: true,
shortfall: 0n,
};
// @ts-ignore
adapter.comet.getAccountLiquidity = vi.fn().mockResolvedValue([
true,
0n,
]);
const liquidity = await adapter.getAccountLiquidity("0x123");
expect(liquidity).toBeDefined();
});
});