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
174 lines (153 loc) · 4.49 KB
/
Copy pathpayment-prep-action.test.ts
File metadata and controls
174 lines (153 loc) · 4.49 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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);
});
it.each(["Infinity", "NaN", "1e309"])(
"rejects non-finite amount %s with INVALID_TASK",
(amount) => {
const tool = createPaymentPrepTool();
const context = createMockContext(`task-nonfinite-${amount}`);
expect(() =>
tool.execute({
payload: {
walletId: "GWALLET123",
amount
},
context
})
).toThrowError(
expect.objectContaining({
code: "INVALID_TASK",
details: { amount }
})
);
}
);
it.each(["10.5", 10, "0.01"])(
"accepts finite positive amount %s",
async (amount) => {
const tool = createPaymentPrepTool();
const context = createMockContext(`task-finite-${amount}`);
const result = await tool.execute({
payload: {
walletId: "GWALLET123",
amount
},
context
});
expect(result.status).toBe("prepared");
}
);
});