forked from Streampay-Org/StreamPay-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescrow-invariants.test.ts
More file actions
52 lines (46 loc) · 1.75 KB
/
Copy pathescrow-invariants.test.ts
File metadata and controls
52 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { EscrowInvariants } from "./escrow-invariants";
import { ContractStreamStatus, OnChainStream } from "./types";
const mockStream: OnChainStream = {
id: "test-stream",
recipient_address: "GB...123",
total_amount: 1000n,
released_amount: 500n,
velocity: 10n,
last_update_timestamp: Date.now(),
status: ContractStreamStatus.ACTIVE,
};
describe("Escrow Invariants", () => {
describe("canSettle", () => {
it("allows settlement for active streams with balance", () => {
const result = EscrowInvariants.canSettle(mockStream);
expect(result.isValid).toBe(true);
});
it("rejects settlement if stream is already settled", () => {
const result = EscrowInvariants.canSettle({
...mockStream,
status: ContractStreamStatus.SETTLED,
});
expect(result.isValid).toBe(false);
expect(result.error).toContain("not in a settlable state");
});
});
describe("canWithdraw", () => {
it("allows withdrawal when settled and funds remain", () => {
const result = EscrowInvariants.canWithdraw({
...mockStream,
status: ContractStreamStatus.SETTLED,
});
expect(result.isValid).toBe(true);
});
it("rejects withdrawal if status is not settled", () => {
const result = EscrowInvariants.canWithdraw(mockStream);
expect(result.isValid).toBe(false);
expect(result.error).toContain("must be SETTLED");
});
it("rejects withdrawal if no funds remain", () => {
const result = EscrowInvariants.canWithdraw({ ...mockStream, status: ContractStreamStatus.SETTLED, released_amount: 1000n });
expect(result.isValid).toBe(false);
expect(result.error).toContain("No remaining funds");
});
});
});