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

88 lines
2.6 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { AaveV3Adapter } from "../../../src/adapters/aaveV3.js";
describe("Aave V3 Adapter", () => {
let adapter: AaveV3Adapter;
let mockProvider: any;
let mockSigner: any;
beforeEach(() => {
mockProvider = {
getNetwork: vi.fn().mockResolvedValue({ chainId: 1n }),
call: vi.fn(),
};
mockSigner = {
getAddress: vi.fn().mockResolvedValue("0x1234567890123456789012345678901234567890"),
};
// Mock the adapter constructor
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(),
flashLoanSimple: vi.fn(),
setUserEMode: vi.fn(),
setUserUseReserveAsCollateral: vi.fn(),
getUserAccountData: vi.fn(),
interface: {
parseLog: vi.fn(),
},
}));
});
it("should validate asset address on supply", async () => {
adapter = new AaveV3Adapter("mainnet", mockSigner as any);
await expect(
adapter.supply("0x0000000000000000000000000000000000000000", 1000n)
).rejects.toThrow("Invalid asset address");
});
it("should validate asset address on withdraw", async () => {
adapter = new AaveV3Adapter("mainnet", mockSigner as any);
await expect(
adapter.withdraw("0x0000000000000000000000000000000000000000", 1000n)
).rejects.toThrow("Invalid asset address");
});
it("should calculate health factor correctly", async () => {
adapter = new AaveV3Adapter("mainnet");
const mockData = {
totalCollateralBase: 2000000n,
totalDebtBase: 1000000n,
availableBorrowsBase: 500000n,
currentLiquidationThreshold: 8000n, // 80%
ltv: 7500n, // 75%
healthFactor: 2000000000000000000n, // 2.0
};
// @ts-ignore
adapter.dataProvider.getUserAccountData = vi.fn().mockResolvedValue([
mockData.totalCollateralBase,
mockData.totalDebtBase,
mockData.availableBorrowsBase,
mockData.currentLiquidationThreshold,
mockData.ltv,
mockData.healthFactor,
]);
const hf = await adapter.getUserHealthFactor("0x123");
expect(hf).toBeGreaterThan(0);
});
it("should handle different interest rate modes", async () => {
adapter = new AaveV3Adapter("mainnet", mockSigner as any);
// Test variable rate mode (default)
// Test stable rate mode
// These would require mocking the contract calls
expect(true).toBe(true);
});
});