harb/kraiken-lib/src/tests/staking.test.ts
2025-10-01 14:43:55 +02:00

32 lines
1.1 KiB
TypeScript

import { describe, expect, test } from "@jest/globals";
import { calculateSnatchShortfall, isPositionDelinquent } from "../staking";
describe("staking", () => {
test("calculateSnatchShortfall returns zero when within cap", () => {
const outstanding = 100n;
const desired = 50n;
const total = 1000n;
const result = calculateSnatchShortfall(outstanding, desired, total, 2n, 10n);
expect(result).toBe(0n);
});
test("calculateSnatchShortfall returns positive remainder when exceeding cap", () => {
const outstanding = 200n;
const desired = 200n;
const total = 1000n;
const result = calculateSnatchShortfall(outstanding, desired, total, 2n, 10n);
expect(result).toBe(200n);
});
test("isPositionDelinquent respects tax rate windows", () => {
const now = 1_000_000;
const taxRate = 0.5; // 50%
const windowSeconds = (365 * 24 * 60 * 60) / taxRate;
expect(isPositionDelinquent(now - windowSeconds + 1, taxRate, now)).toBe(false);
expect(isPositionDelinquent(now - windowSeconds - 10, taxRate, now)).toBe(true);
expect(isPositionDelinquent(now, 0, now)).toBe(false);
});
});