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

58 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { evaluatePositionDeltaLimit } from "../../../src/guards/positionDeltaLimit.js";
import { Guard } from "../../../src/strategy.schema.js";
describe("Position Delta Limit Guard", () => {
it("should pass when position delta is within limit", () => {
const guard: Guard = {
type: "positionDeltaLimit",
params: {
maxDelta: "1000000",
token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
},
};
const context = {
positionDelta: 500000n,
};
const result = evaluatePositionDeltaLimit(guard, "mainnet", context);
expect(result.passed).toBe(true);
});
it("should fail when position delta exceeds limit", () => {
const guard: Guard = {
type: "positionDeltaLimit",
params: {
maxDelta: "1000000",
token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
},
};
const context = {
positionDelta: 2000000n,
};
const result = evaluatePositionDeltaLimit(guard, "mainnet", context);
expect(result.passed).toBe(false);
expect(result.reason).toContain("exceeds");
});
it("should handle missing position delta", () => {
const guard: Guard = {
type: "positionDeltaLimit",
params: {
maxDelta: "1000000",
token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
},
};
const context = {};
const result = evaluatePositionDeltaLimit(guard, "mainnet", context);
// Should pass if no delta to check
expect(result.passed).toBe(true);
});
});