forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment-prep-action.test.ts
More file actions
133 lines (117 loc) · 3.56 KB
/
Copy pathpayment-prep-action.test.ts
File metadata and controls
133 lines (117 loc) · 3.56 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { describe, expect, it } from "vitest";
import {
AgentInstanceManager,
createPaymentPrepTool,
InMemoryMemoryStore,
InMemoryRuntimeStateStore,
PAYMENT_PREP_TOOL_NAME,
RuntimeError,
UnconfiguredModelProvider
} from "../src/index.js";
import type { PaymentPrepPayload, RuntimeContext } from "../src/index.js";
describe("PaymentPrepAction", () => {
const createMockContext = (taskId: string): RuntimeContext => ({
runtimeId: "runtime-test",
taskId,
agent: new AgentInstanceManager().getOrCreate("test-agent"),
memory: new InMemoryMemoryStore(),
modelProvider: new UnconfiguredModelProvider(),
state: new InMemoryRuntimeStateStore(),
now: "2026-08-30T12:00:00.000Z"
});
it("creates a tool with correct name and description metadata", () => {
const tool = createPaymentPrepTool();
expect(tool.name).toBe(PAYMENT_PREP_TOOL_NAME);
expect(tool.description).toContain(
"without performing live Stellar network calls"
);
});
it("prepares valid payment context and transaction stub", async () => {
const tool = createPaymentPrepTool();
const context = createMockContext("task-pay-1");
const payload: PaymentPrepPayload = {
walletId: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7",
amount: "150.50",
recipientId: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
assetCode: "USDC",
memo: "Invoice #1024",
metadata: { priority: "high" }
};
const result = await tool.execute({ payload, context });
expect(result).toEqual({
status: "prepared",
walletId: payload.walletId,
amount: "150.50",
recipientId: payload.recipientId,
assetCode: "USDC",
memo: "Invoice #1024",
preparedAt: "2026-08-30T12:00:00.000Z",
transactionStubId: `stellar-stub-task-pay-1-${payload.walletId}`,
isSimulated: true,
metadata: { priority: "high" }
});
});
it("handles numeric amount and defaults assetCode to XLM", async () => {
const tool = createPaymentPrepTool();
const context = createMockContext("task-pay-2");
const result = await tool.execute({
payload: {
walletId: "GWALLET123",
amount: 25
},
context
});
expect(result.amount).toBe("25");
expect(result.assetCode).toBe("XLM");
expect(result.status).toBe("prepared");
expect(result.isSimulated).toBe(true);
});
it("rejects empty walletId", async () => {
const tool = createPaymentPrepTool();
const context = createMockContext("task-pay-3");
expect(() =>
tool.execute({
payload: {
walletId: "",
amount: "10"
},
context
})
).toThrowError(RuntimeError);
});
it("rejects missing or empty amount", async () => {
const tool = createPaymentPrepTool();
const context = createMockContext("task-pay-4");
expect(() =>
tool.execute({
payload: {
walletId: "GWALLET123",
amount: ""
},
context
})
).toThrowError(RuntimeError);
});
it("rejects negative or invalid numeric amount", async () => {
const tool = createPaymentPrepTool();
const context = createMockContext("task-pay-5");
expect(() =>
tool.execute({
payload: {
walletId: "GWALLET123",
amount: -50
},
context
})
).toThrowError(RuntimeError);
expect(() =>
tool.execute({
payload: {
walletId: "GWALLET123",
amount: "invalid-amount"
},
context
})
).toThrowError(RuntimeError);
});
});