Files
strategic/tests/e2e/fork-simulation.test.ts
2026-02-09 21:51:54 -08:00

127 lines
3.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { executeStrategy } from "../../src/engine.js";
import { loadStrategy } from "../../src/strategy.js";
import { Strategy } from "../../src/strategy.schema.js";
describe("Fork Simulation E2E", () => {
// These tests require a fork RPC endpoint
const FORK_RPC = process.env.FORK_RPC || "";
it.skipIf(!FORK_RPC)("should execute strategy on mainnet fork", async () => {
const strategy: Strategy = {
name: "Fork Test",
chain: "mainnet",
steps: [{
id: "supply",
action: {
type: "aaveV3.supply",
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
amount: "1000000",
},
}],
};
const result = await executeStrategy(strategy, {
simulate: true,
dry: false,
explain: false,
fork: FORK_RPC,
});
expect(result.success).toBeDefined();
});
it.skipIf(!FORK_RPC)("should execute flash loan on fork", async () => {
const strategy: Strategy = {
name: "Flash Loan Fork",
chain: "mainnet",
steps: [
{
id: "flashLoan",
action: {
type: "aaveV3.flashLoan",
assets: ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"],
amounts: ["1000000"],
},
},
{
id: "swap",
action: {
type: "uniswapV3.swap",
tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
tokenOut: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
fee: 3000,
amountIn: "1000000",
exactInput: true,
},
},
],
};
const result = await executeStrategy(strategy, {
simulate: true,
dry: false,
explain: false,
fork: FORK_RPC,
});
expect(result.plan?.requiresFlashLoan).toBe(true);
});
it.skipIf(!FORK_RPC)("should evaluate guards on fork", async () => {
const strategy: Strategy = {
name: "Guard Fork Test",
chain: "mainnet",
guards: [{
type: "maxGas",
params: {
maxGasLimit: "5000000",
},
}],
steps: [{
id: "supply",
action: {
type: "aaveV3.supply",
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
amount: "1000000",
},
}],
};
const result = await executeStrategy(strategy, {
simulate: true,
dry: false,
explain: false,
fork: FORK_RPC,
});
expect(result.guardResults).toBeDefined();
});
it.skipIf(!FORK_RPC)("should track state changes after execution", async () => {
const strategy: Strategy = {
name: "State Change Test",
chain: "mainnet",
steps: [{
id: "supply",
action: {
type: "aaveV3.supply",
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
amount: "1000000",
},
}],
};
const result = await executeStrategy(strategy, {
simulate: true,
dry: false,
explain: false,
fork: FORK_RPC,
});
// State changes would be tracked in simulation
expect(result.success).toBeDefined();
});
});