Initial commit: add .gitignore and README
This commit is contained in:
125
tests/integration/errors.test.ts
Normal file
125
tests/integration/errors.test.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { validateStrategy, loadStrategy } from "../../src/strategy.js";
|
||||
import { StrategyCompiler } from "../../src/planner/compiler.js";
|
||||
import { writeFileSync, unlinkSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
describe("Error Handling", () => {
|
||||
it("should handle invalid strategy JSON", () => {
|
||||
const invalidStrategy = {
|
||||
name: "Invalid",
|
||||
// Missing required fields
|
||||
};
|
||||
|
||||
const validation = validateStrategy(invalidStrategy as any);
|
||||
expect(validation.valid).toBe(false);
|
||||
expect(validation.errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("should handle missing blind values", () => {
|
||||
const strategy = {
|
||||
name: "Missing Blinds",
|
||||
chain: "mainnet",
|
||||
blinds: [
|
||||
{
|
||||
name: "amount",
|
||||
type: "uint256",
|
||||
},
|
||||
],
|
||||
steps: [
|
||||
{
|
||||
id: "step1",
|
||||
action: {
|
||||
type: "aaveV3.supply",
|
||||
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
amount: { blind: "amount" },
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Strategy should be valid but execution would fail without blind values
|
||||
const validation = validateStrategy(strategy as any);
|
||||
expect(validation.valid).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle protocol adapter failures gracefully", async () => {
|
||||
const strategy = {
|
||||
name: "Invalid Protocol",
|
||||
chain: "invalid-chain",
|
||||
steps: [
|
||||
{
|
||||
id: "step1",
|
||||
action: {
|
||||
type: "aaveV3.supply",
|
||||
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
amount: "1000000",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const compiler = new StrategyCompiler("invalid-chain");
|
||||
|
||||
// Should handle missing adapter gracefully
|
||||
await expect(compiler.compile(strategy as any)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("should handle guard failures", async () => {
|
||||
const strategy = {
|
||||
name: "Guard Failure",
|
||||
chain: "mainnet",
|
||||
guards: [
|
||||
{
|
||||
type: "maxGas",
|
||||
params: {
|
||||
maxGasLimit: "1000", // Very low limit
|
||||
},
|
||||
onFailure: "revert",
|
||||
},
|
||||
],
|
||||
steps: [
|
||||
{
|
||||
id: "step1",
|
||||
action: {
|
||||
type: "aaveV3.supply",
|
||||
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||
amount: "1000000",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Guard should fail and strategy should not execute
|
||||
const validation = validateStrategy(strategy as any);
|
||||
expect(validation.valid).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle unsupported action types", async () => {
|
||||
const strategy = {
|
||||
name: "Unsupported Action",
|
||||
chain: "mainnet",
|
||||
steps: [
|
||||
{
|
||||
id: "step1",
|
||||
action: {
|
||||
type: "unsupported.action",
|
||||
// Invalid action
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const compiler = new StrategyCompiler("mainnet");
|
||||
await expect(compiler.compile(strategy as any)).rejects.toThrow(
|
||||
"Unsupported action type"
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle execution failures gracefully", async () => {
|
||||
// This would require a mock execution environment
|
||||
// For now, just verify error handling structure exists
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user