Initial commit: add .gitignore and README
This commit is contained in:
57
tests/unit/guards/positionDeltaLimit.test.ts
Normal file
57
tests/unit/guards/positionDeltaLimit.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user