@devlab.group/agent-commerce 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -16
- package/dist/ap2.d.ts +42 -17
- package/dist/ap2.js +83 -27
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-CXWC5LWM.js → chunk-DRLBML7Z.js} +661 -75
- package/dist/chunk-DRLBML7Z.js.map +1 -0
- package/dist/{chunk-WZW5ORZH.js → chunk-G3EYYHKF.js} +3 -3
- package/dist/{chunk-WZW5ORZH.js.map → chunk-G3EYYHKF.js.map} +1 -1
- package/dist/chunk-GA3O2A7R.js +92 -0
- package/dist/chunk-GA3O2A7R.js.map +1 -0
- package/dist/{chunk-DTKU3Z2M.js → chunk-M52FBNJX.js} +36 -5
- package/dist/chunk-M52FBNJX.js.map +1 -0
- package/dist/chunk-M6BSXXTF.js +8 -0
- package/dist/chunk-M6BSXXTF.js.map +1 -0
- package/dist/{chunk-QPV3EGJO.js → chunk-M6MQ3FYS.js} +25 -4
- package/dist/chunk-M6MQ3FYS.js.map +1 -0
- package/dist/chunk-M6WW6QIT.js +18 -0
- package/dist/chunk-M6WW6QIT.js.map +1 -0
- package/dist/cli/{ap2-GWSP4LYY.js → ap2-2YMYA2H6.js} +85 -29
- package/dist/cli/ap2-2YMYA2H6.js.map +1 -0
- package/dist/cli/{chunk-OZ4LAWBK.js → chunk-3NOMLMJW.js} +29 -8
- package/dist/cli/chunk-3NOMLMJW.js.map +1 -0
- package/dist/cli/chunk-4KLYFXMW.js +8 -0
- package/dist/cli/{chunk-ITWNSS2B.js.map → chunk-4KLYFXMW.js.map} +1 -1
- package/dist/cli/chunk-663ALDZA.js +92 -0
- package/dist/cli/chunk-663ALDZA.js.map +1 -0
- package/dist/cli/chunk-6R6WJ4FD.js +18 -0
- package/dist/cli/chunk-6R6WJ4FD.js.map +1 -0
- package/dist/cli/{chunk-G2JEY7MB.js → chunk-AZL7RPFU.js} +39 -33
- package/dist/cli/chunk-AZL7RPFU.js.map +1 -0
- package/dist/cli/chunk-DHFMIBPG.js +107 -0
- package/dist/cli/chunk-DHFMIBPG.js.map +1 -0
- package/dist/cli/{chunk-QQ3WY5L3.js → chunk-GET3CZGR.js} +36 -104
- package/dist/cli/chunk-GET3CZGR.js.map +1 -0
- package/dist/cli/chunk-NSYSMDQN.js +1544 -0
- package/dist/cli/chunk-NSYSMDQN.js.map +1 -0
- package/dist/cli/{chunk-PIMFPCNZ.js → chunk-PTL7SNOI.js} +313 -138
- package/dist/cli/chunk-PTL7SNOI.js.map +1 -0
- package/dist/cli/chunk-SYQLJXIU.js +105 -0
- package/dist/cli/chunk-SYQLJXIU.js.map +1 -0
- package/dist/cli/chunk-TFV3K6YS.js +373 -0
- package/dist/cli/chunk-TFV3K6YS.js.map +1 -0
- package/dist/cli/{chunk-3MGAJ5FX.js → chunk-VJ4EO4LE.js} +3 -3
- package/dist/cli/{chunk-3MGAJ5FX.js.map → chunk-VJ4EO4LE.js.map} +1 -1
- package/dist/cli/chunk-VJH6RYRK.js +119 -0
- package/dist/cli/chunk-VJH6RYRK.js.map +1 -0
- package/dist/cli/{chunk-TNMLDPUO.js → chunk-YOF7IK4V.js} +663 -77
- package/dist/cli/chunk-YOF7IK4V.js.map +1 -0
- package/dist/cli/{chunk-WYOGIANL.js → chunk-YWG2ZN3L.js} +4 -4
- package/dist/cli/{chunk-WYOGIANL.js.map → chunk-YWG2ZN3L.js.map} +1 -1
- package/dist/cli/config-3K65QJ22.js +12 -0
- package/dist/cli/{config-UI4EDG4L.js.map → config-3K65QJ22.js.map} +1 -1
- package/dist/cli/index.js +753 -212
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-PGBRWZVA.js → mcp-6F64A7KE.js} +5 -4
- package/dist/cli/mcp-6F64A7KE.js.map +1 -0
- package/dist/cli/{near-5AY3HWYF.js → near-U6365VFX.js} +15 -4
- package/dist/cli/near-U6365VFX.js.map +1 -0
- package/dist/cli/payment-providers-2ITS6KNR.js +6 -0
- package/dist/cli/payment-providers-2ITS6KNR.js.map +1 -0
- package/dist/cli/{provider-I2ESL6RS.js → provider-5BGG5YKQ.js} +53 -24
- package/dist/cli/provider-5BGG5YKQ.js.map +1 -0
- package/dist/cli/receipts-I4IIE7U6.js +8 -0
- package/dist/cli/receipts-I4IIE7U6.js.map +1 -0
- package/dist/cli/reconcile-55WNCSFC.js +4 -0
- package/dist/cli/reconcile-55WNCSFC.js.map +1 -0
- package/dist/cli/{run-JK4ERPJV.js → run-2P6ZGFUE.js} +356 -173
- package/dist/cli/run-2P6ZGFUE.js.map +1 -0
- package/dist/cli/svm-KDSPDFJG.js +48 -0
- package/dist/cli/svm-KDSPDFJG.js.map +1 -0
- package/dist/cli/{x402-7WBFZQXV.js → x402-4LPIIELI.js} +10 -9
- package/dist/cli/x402-4LPIIELI.js.map +1 -0
- package/dist/index.d.ts +116 -113
- package/dist/index.js +1928 -351
- package/dist/index.js.map +1 -1
- package/dist/logger-CllGwQ8i.d.ts +19 -0
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.js +2 -1
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +2 -1
- package/dist/mpp.js +48 -19
- package/dist/mpp.js.map +1 -1
- package/dist/{near-D6C42VPE.js → near-FH7HPZV3.js} +15 -4
- package/dist/near-FH7HPZV3.js.map +1 -0
- package/dist/{protocol-adapter-C9odYl6l.d.ts → protocol-adapter-1WbtM3xG.d.ts} +12 -85
- package/dist/{runtime-Cl_BLVZV.d.ts → runtime-B-kARa2f.d.ts} +218 -15
- package/dist/store-kIIMpUA-.d.ts +372 -0
- package/dist/svm-KNC3PHMS.js +48 -0
- package/dist/svm-KNC3PHMS.js.map +1 -0
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +1896 -0
- package/dist/testing.js.map +1 -0
- package/dist/transaction-Dv0UFGg5.d.ts +129 -0
- package/dist/{types-j7MnUXYN.d.ts → types-DWqjz81-.d.ts} +5 -2
- package/dist/x402.d.ts +2 -1
- package/dist/x402.js +6 -5
- package/dist/x402.js.map +1 -1
- package/package.json +5 -1
- package/dist/authorization-DjAecwuW.d.ts +0 -115
- package/dist/chunk-CXWC5LWM.js.map +0 -1
- package/dist/chunk-DTKU3Z2M.js.map +0 -1
- package/dist/chunk-KA2AX5FH.js +0 -44
- package/dist/chunk-KA2AX5FH.js.map +0 -1
- package/dist/chunk-QPV3EGJO.js.map +0 -1
- package/dist/cli/ap2-GWSP4LYY.js.map +0 -1
- package/dist/cli/chunk-G2JEY7MB.js.map +0 -1
- package/dist/cli/chunk-GJIMDMYT.js +0 -639
- package/dist/cli/chunk-GJIMDMYT.js.map +0 -1
- package/dist/cli/chunk-ITWNSS2B.js +0 -8
- package/dist/cli/chunk-OSTCU6ZK.js +0 -44
- package/dist/cli/chunk-OSTCU6ZK.js.map +0 -1
- package/dist/cli/chunk-OZ4LAWBK.js.map +0 -1
- package/dist/cli/chunk-PIMFPCNZ.js.map +0 -1
- package/dist/cli/chunk-QQ3WY5L3.js.map +0 -1
- package/dist/cli/chunk-TNMLDPUO.js.map +0 -1
- package/dist/cli/config-UI4EDG4L.js +0 -11
- package/dist/cli/mcp-PGBRWZVA.js.map +0 -1
- package/dist/cli/near-5AY3HWYF.js.map +0 -1
- package/dist/cli/provider-I2ESL6RS.js.map +0 -1
- package/dist/cli/run-JK4ERPJV.js.map +0 -1
- package/dist/cli/svm-3MMYFPC7.js +0 -33
- package/dist/cli/svm-3MMYFPC7.js.map +0 -1
- package/dist/cli/x402-7WBFZQXV.js.map +0 -1
- package/dist/near-D6C42VPE.js.map +0 -1
- package/dist/svm-QEUAUNPQ.js +0 -33
- package/dist/svm-QEUAUNPQ.js.map +0 -1
package/dist/testing.js
ADDED
|
@@ -0,0 +1,1896 @@
|
|
|
1
|
+
import { STORE_METHOD_GROUPS } from './chunk-M6WW6QIT.js';
|
|
2
|
+
import { transactionState } from './chunk-M52FBNJX.js';
|
|
3
|
+
import './chunk-2CJNA7MS.js';
|
|
4
|
+
import assert2 from 'assert/strict';
|
|
5
|
+
|
|
6
|
+
var START_MS = Date.parse("2026-01-01T00:00:00.000Z");
|
|
7
|
+
function createConformanceClock() {
|
|
8
|
+
let current = START_MS;
|
|
9
|
+
return {
|
|
10
|
+
now: () => new Date(current),
|
|
11
|
+
nowIso: () => new Date(current).toISOString(),
|
|
12
|
+
monotonicMs: () => current - START_MS,
|
|
13
|
+
advance(ms) {
|
|
14
|
+
current += ms;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function isoAt(offsetMs) {
|
|
19
|
+
return new Date(START_MS + offsetMs).toISOString();
|
|
20
|
+
}
|
|
21
|
+
async function rejectsWithCode(promise, code) {
|
|
22
|
+
let caught;
|
|
23
|
+
await assert2.rejects(promise, (error) => {
|
|
24
|
+
caught = error;
|
|
25
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
26
|
+
});
|
|
27
|
+
return caught;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/testing/conformance/core-cases.ts
|
|
31
|
+
var RACERS = 8;
|
|
32
|
+
var MAX_PAGES = 50;
|
|
33
|
+
var ALL_STATUSES = [
|
|
34
|
+
"reserved",
|
|
35
|
+
"verified",
|
|
36
|
+
"settled",
|
|
37
|
+
"rejected",
|
|
38
|
+
"failed",
|
|
39
|
+
"settlement-uncertain"
|
|
40
|
+
];
|
|
41
|
+
function receipt(id, overrides = {}) {
|
|
42
|
+
return {
|
|
43
|
+
id,
|
|
44
|
+
requestId: "req_1",
|
|
45
|
+
resourceId: "resource.report",
|
|
46
|
+
deliveredAt: isoAt(0),
|
|
47
|
+
backendStatus: 200,
|
|
48
|
+
...overrides
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function event(id, overrides = {}) {
|
|
52
|
+
return { id, type: "resource.requested", requestId: "req_1", at: isoAt(0), ...overrides };
|
|
53
|
+
}
|
|
54
|
+
function reservation(n, overrides = {}) {
|
|
55
|
+
return {
|
|
56
|
+
requestId: `req_${n}`,
|
|
57
|
+
resourceId: "resource.report",
|
|
58
|
+
provider: "x402",
|
|
59
|
+
replayKey: `replay_${n}`,
|
|
60
|
+
amount: "0.01",
|
|
61
|
+
currency: "USDC",
|
|
62
|
+
...overrides
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function journaled(n, transaction = {}, overrides = {}) {
|
|
66
|
+
return reservation(n, {
|
|
67
|
+
transaction: { id: `txn_${n}`, protocol: "mcp", configDigest: "sha256:terms", ...transaction },
|
|
68
|
+
...overrides
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function hold(n) {
|
|
72
|
+
return {
|
|
73
|
+
method: "ap2",
|
|
74
|
+
reference: `sha256:mandate_${n}`,
|
|
75
|
+
metadata: { issuer: "did:web:agent.example" },
|
|
76
|
+
reservationId: `sha256:mandate_${n}`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function fullJournaled(n) {
|
|
80
|
+
return journaled(
|
|
81
|
+
n,
|
|
82
|
+
{
|
|
83
|
+
network: "eip155:31337",
|
|
84
|
+
asset: "0xasset",
|
|
85
|
+
locator: { v: 1, nonce: "0xnonce" },
|
|
86
|
+
expiresAt: isoAt(3e5),
|
|
87
|
+
authorization: hold(n),
|
|
88
|
+
inputDigest: "sha256:input"
|
|
89
|
+
},
|
|
90
|
+
{ payer: "0xbuyer", payee: "0xmerchant" }
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function factsOf(status, extra = {}) {
|
|
94
|
+
return { payment: { status }, ...extra };
|
|
95
|
+
}
|
|
96
|
+
var FULL_RECEIPT = {
|
|
97
|
+
id: "receipt_full",
|
|
98
|
+
requestId: "req_full",
|
|
99
|
+
transactionId: "txn_full",
|
|
100
|
+
resourceId: "resource.report",
|
|
101
|
+
payment: {
|
|
102
|
+
status: "settled",
|
|
103
|
+
provider: "x402",
|
|
104
|
+
externalReference: "0xabc",
|
|
105
|
+
payer: "0xbuyer",
|
|
106
|
+
payee: "0xmerchant",
|
|
107
|
+
amount: "0.01",
|
|
108
|
+
currency: "USDC",
|
|
109
|
+
network: "eip155:31337",
|
|
110
|
+
asset: "0xasset",
|
|
111
|
+
replayKey: "replay_full",
|
|
112
|
+
settledAt: isoAt(500),
|
|
113
|
+
metadata: { flow: "authorization" }
|
|
114
|
+
},
|
|
115
|
+
authorization: {
|
|
116
|
+
method: "ap2",
|
|
117
|
+
reference: "sha256:mandate",
|
|
118
|
+
metadata: { checkoutId: "checkout-1" }
|
|
119
|
+
},
|
|
120
|
+
deliveredAt: isoAt(1e3),
|
|
121
|
+
backendStatus: 200,
|
|
122
|
+
durationMs: 42,
|
|
123
|
+
protocol: "http",
|
|
124
|
+
metadata: { note: "ok" }
|
|
125
|
+
};
|
|
126
|
+
var FULL_EVENT = {
|
|
127
|
+
id: "event_full",
|
|
128
|
+
type: "payment.settled",
|
|
129
|
+
requestId: "req_full",
|
|
130
|
+
transactionId: "txn_full",
|
|
131
|
+
resourceId: "resource.report",
|
|
132
|
+
at: isoAt(0),
|
|
133
|
+
adapter: "mcp",
|
|
134
|
+
paymentProvider: "x402",
|
|
135
|
+
durationMs: 12,
|
|
136
|
+
status: "ok",
|
|
137
|
+
data: { httpStatus: 200 }
|
|
138
|
+
};
|
|
139
|
+
var RESOLUTION = {
|
|
140
|
+
method: "reconcile",
|
|
141
|
+
actor: "agent-commerce reconcile",
|
|
142
|
+
reason: "transfer_found",
|
|
143
|
+
at: isoAt(5e3),
|
|
144
|
+
externalReference: "0xlanded",
|
|
145
|
+
evidence: { blockNumber: 12 }
|
|
146
|
+
};
|
|
147
|
+
function defined(value, what) {
|
|
148
|
+
assert2.ok(value !== void 0, `${what} was not found`);
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
function only(items, what) {
|
|
152
|
+
assert2.equal(items.length, 1, what);
|
|
153
|
+
return defined(items[0], what);
|
|
154
|
+
}
|
|
155
|
+
var ids = (items) => items.map((item) => item.id);
|
|
156
|
+
function assertFiltered(actual, filtered, unfiltered) {
|
|
157
|
+
try {
|
|
158
|
+
assert2.deepEqual(actual, unfiltered);
|
|
159
|
+
} catch {
|
|
160
|
+
assert2.deepEqual(actual, filtered);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function assertIso(value) {
|
|
164
|
+
assert2.equal(new Date(value).toISOString(), value);
|
|
165
|
+
}
|
|
166
|
+
async function attemptFor(store, replayKey) {
|
|
167
|
+
const attempts = (await store.listPaymentAttempts()).filter((a) => a.replayKey === replayKey);
|
|
168
|
+
return only(attempts, `attempts for ${replayKey}`);
|
|
169
|
+
}
|
|
170
|
+
async function moveTo(store, replayKey, status, rest = {}) {
|
|
171
|
+
if (status !== "reserved") await store.updatePaymentAttempt({ replayKey, status, ...rest });
|
|
172
|
+
}
|
|
173
|
+
function codeOf(error) {
|
|
174
|
+
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
175
|
+
}
|
|
176
|
+
function reportedStatus(error) {
|
|
177
|
+
if (typeof error !== "object" || error === null || !("details" in error)) return void 0;
|
|
178
|
+
const { details } = error;
|
|
179
|
+
return typeof details === "object" && details !== null && "attemptStatus" in details ? details.attemptStatus : void 0;
|
|
180
|
+
}
|
|
181
|
+
function assertReportedStatus(error, holder) {
|
|
182
|
+
const reported = reportedStatus(error);
|
|
183
|
+
if (reported !== void 0) assert2.equal(reported, holder);
|
|
184
|
+
}
|
|
185
|
+
async function expectReplayed(call, holder) {
|
|
186
|
+
assertReportedStatus(await rejectsWithCode(call, "PAYMENT_REPLAYED"), holder);
|
|
187
|
+
}
|
|
188
|
+
async function settle(calls) {
|
|
189
|
+
const won = [];
|
|
190
|
+
const lost = [];
|
|
191
|
+
for (const result of await Promise.allSettled(calls)) {
|
|
192
|
+
if (result.status === "fulfilled") won.push(result.value);
|
|
193
|
+
else lost.push(result.reason);
|
|
194
|
+
}
|
|
195
|
+
return { won, lost };
|
|
196
|
+
}
|
|
197
|
+
function soleWinner(outcome) {
|
|
198
|
+
assert2.equal(outcome.won.length, 1, "exactly one reservation must succeed");
|
|
199
|
+
assert2.equal(outcome.lost.length, RACERS - 1);
|
|
200
|
+
for (const error of outcome.lost) {
|
|
201
|
+
assert2.equal(codeOf(error), "PAYMENT_REPLAYED");
|
|
202
|
+
assertReportedStatus(error, "reserved");
|
|
203
|
+
}
|
|
204
|
+
return defined(outcome.won[0], "the winning reservation");
|
|
205
|
+
}
|
|
206
|
+
function journalOf(store) {
|
|
207
|
+
const unsupported = (name) => assert2.fail(`the store does not implement ${name}`);
|
|
208
|
+
return {
|
|
209
|
+
record: (step) => store.recordTransactionStep?.(step) ?? unsupported("recordTransactionStep"),
|
|
210
|
+
get: (id) => store.getTransaction?.(id) ?? unsupported("getTransaction"),
|
|
211
|
+
list: (options) => store.listTransactions?.(options) ?? unsupported("listTransactions"),
|
|
212
|
+
attempt: (id) => store.getPaymentAttempt?.(id) ?? unsupported("getPaymentAttempt"),
|
|
213
|
+
resolve: (request) => store.resolvePaymentAttempt?.(request) ?? unsupported("resolvePaymentAttempt")
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
async function transactionOf(journal, id) {
|
|
217
|
+
return defined(await journal.get(id), `transaction ${id}`);
|
|
218
|
+
}
|
|
219
|
+
async function attemptById(journal, id) {
|
|
220
|
+
return defined(await journal.attempt(id), `payment attempt ${id}`);
|
|
221
|
+
}
|
|
222
|
+
function assertState(tx, facts, now) {
|
|
223
|
+
const expected = transactionState(facts, now);
|
|
224
|
+
assert2.equal(tx.state, expected);
|
|
225
|
+
assert2.equal(transactionState(tx, now), expected);
|
|
226
|
+
}
|
|
227
|
+
async function walk(journal, options = {}) {
|
|
228
|
+
const pages = [];
|
|
229
|
+
let cursor;
|
|
230
|
+
do {
|
|
231
|
+
const page = await journal.list({ ...options, ...cursor !== void 0 ? { cursor } : {} });
|
|
232
|
+
pages.push(page);
|
|
233
|
+
cursor = page.nextCursor;
|
|
234
|
+
} while (cursor !== void 0 && pages.length < MAX_PAGES);
|
|
235
|
+
assert2.equal(cursor, void 0, "pagination did not end");
|
|
236
|
+
return pages;
|
|
237
|
+
}
|
|
238
|
+
async function listAll(journal, options = {}) {
|
|
239
|
+
return (await walk(journal, options)).flatMap((page) => ids(page.transactions));
|
|
240
|
+
}
|
|
241
|
+
async function uncertain(store, n) {
|
|
242
|
+
const attempt = await store.reservePaymentAttempt(journaled(n));
|
|
243
|
+
await store.updatePaymentAttempt({
|
|
244
|
+
replayKey: attempt.replayKey,
|
|
245
|
+
status: "settlement-uncertain",
|
|
246
|
+
externalReference: "0xpending"
|
|
247
|
+
});
|
|
248
|
+
return attempt;
|
|
249
|
+
}
|
|
250
|
+
var RECEIPT_CASES = [
|
|
251
|
+
{
|
|
252
|
+
name: "a receipt reads back with every field it was saved with",
|
|
253
|
+
async run({ store }) {
|
|
254
|
+
await store.saveReceipt(FULL_RECEIPT);
|
|
255
|
+
assert2.deepEqual(await store.getReceipt(FULL_RECEIPT.id), FULL_RECEIPT);
|
|
256
|
+
assert2.deepEqual(await store.listReceipts(), [FULL_RECEIPT]);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: "a receipt saved with only its required fields reads back without optional ones",
|
|
261
|
+
async run({ store }) {
|
|
262
|
+
const minimal = receipt("receipt_min");
|
|
263
|
+
await store.saveReceipt(minimal);
|
|
264
|
+
assert2.deepEqual(await store.getReceipt(minimal.id), minimal);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: "a receipt id nobody saved reads back as undefined",
|
|
269
|
+
async run({ store }) {
|
|
270
|
+
assert2.equal(await store.getReceipt("receipt_missing"), void 0);
|
|
271
|
+
await store.saveReceipt(receipt("receipt_1"));
|
|
272
|
+
assert2.equal(await store.getReceipt("receipt_missing"), void 0);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: "receipts list newest first and honor the limit",
|
|
277
|
+
async run({ store, clock }) {
|
|
278
|
+
for (const id of ["r1", "r2", "r3"]) {
|
|
279
|
+
await store.saveReceipt(receipt(id, { deliveredAt: clock.nowIso() }));
|
|
280
|
+
clock.advance(1e3);
|
|
281
|
+
}
|
|
282
|
+
assert2.deepEqual(ids(await store.listReceipts()), ["r3", "r2", "r1"]);
|
|
283
|
+
assert2.deepEqual(ids(await store.listReceipts({ limit: 2 })), ["r3", "r2"]);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "receipts filter by request id",
|
|
288
|
+
async run({ store, clock }) {
|
|
289
|
+
for (const [id, requestId] of [
|
|
290
|
+
["r1", "req_a"],
|
|
291
|
+
["r2", "req_b"],
|
|
292
|
+
["r3", "req_a"]
|
|
293
|
+
]) {
|
|
294
|
+
await store.saveReceipt(receipt(id, { requestId, deliveredAt: clock.nowIso() }));
|
|
295
|
+
clock.advance(1e3);
|
|
296
|
+
}
|
|
297
|
+
assert2.deepEqual(ids(await store.listReceipts({ requestId: "req_a" })), ["r3", "r1"]);
|
|
298
|
+
assert2.deepEqual(await store.listReceipts({ requestId: "req_unknown" }), []);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: "the undelivered flag selects exactly the receipts outside 2xx, status 0 included",
|
|
303
|
+
async run({ store, clock }) {
|
|
304
|
+
const saved = [
|
|
305
|
+
["ok_200", 200, "req_a"],
|
|
306
|
+
["bad_0", 0, "req_b"],
|
|
307
|
+
["ok_204", 204, "req_b"],
|
|
308
|
+
["bad_199", 199, "req_a"],
|
|
309
|
+
["ok_299", 299, "req_a"],
|
|
310
|
+
["bad_300", 300, "req_b"],
|
|
311
|
+
["bad_404", 404, "req_a"],
|
|
312
|
+
["bad_500", 500, "req_b"]
|
|
313
|
+
];
|
|
314
|
+
for (const [id, backendStatus, requestId] of saved) {
|
|
315
|
+
await store.saveReceipt(
|
|
316
|
+
receipt(id, { requestId, backendStatus, deliveredAt: clock.nowIso() })
|
|
317
|
+
);
|
|
318
|
+
clock.advance(1e3);
|
|
319
|
+
}
|
|
320
|
+
const all = ids(await store.listReceipts());
|
|
321
|
+
assert2.equal(all.length, saved.length);
|
|
322
|
+
assertFiltered(
|
|
323
|
+
ids(await store.listReceipts({ undelivered: true })),
|
|
324
|
+
["bad_500", "bad_404", "bad_300", "bad_199", "bad_0"],
|
|
325
|
+
all
|
|
326
|
+
);
|
|
327
|
+
assertFiltered(
|
|
328
|
+
ids(await store.listReceipts({ requestId: "req_a", undelivered: true })),
|
|
329
|
+
["bad_404", "bad_199"],
|
|
330
|
+
ids(await store.listReceipts({ requestId: "req_a" }))
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: "receipt counts match what was saved",
|
|
336
|
+
async run({ store, clock }) {
|
|
337
|
+
assert2.equal(await store.countReceipts(), 0);
|
|
338
|
+
assert2.equal(await store.countUndeliveredReceipts(), 0);
|
|
339
|
+
for (const [id, backendStatus] of [
|
|
340
|
+
["r1", 200],
|
|
341
|
+
["r2", 500],
|
|
342
|
+
["r3", 0]
|
|
343
|
+
]) {
|
|
344
|
+
await store.saveReceipt(receipt(id, { backendStatus, deliveredAt: clock.nowIso() }));
|
|
345
|
+
clock.advance(1e3);
|
|
346
|
+
}
|
|
347
|
+
assert2.equal(await store.countReceipts(), 3);
|
|
348
|
+
assert2.equal(await store.countUndeliveredReceipts(), 2);
|
|
349
|
+
await store.saveReceipt(receipt("r4", { backendStatus: 204, deliveredAt: clock.nowIso() }));
|
|
350
|
+
assert2.equal(await store.countReceipts(), 4);
|
|
351
|
+
assert2.equal(await store.countUndeliveredReceipts(), 2);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
];
|
|
355
|
+
var EVENT_CASES = [
|
|
356
|
+
{
|
|
357
|
+
name: "an event reads back with every field it was appended with",
|
|
358
|
+
async run({ store }) {
|
|
359
|
+
await store.appendEvent(FULL_EVENT);
|
|
360
|
+
assert2.deepEqual(await store.listEvents(), [FULL_EVENT]);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "an event appended with only its required fields reads back without optional ones",
|
|
365
|
+
async run({ store }) {
|
|
366
|
+
const minimal = event("event_min");
|
|
367
|
+
await store.appendEvent(minimal);
|
|
368
|
+
assert2.deepEqual(await store.listEvents(), [minimal]);
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "events list newest first",
|
|
373
|
+
async run({ store, clock }) {
|
|
374
|
+
for (const id of ["e1", "e2", "e3"]) {
|
|
375
|
+
await store.appendEvent(event(id, { at: clock.nowIso() }));
|
|
376
|
+
clock.advance(1e3);
|
|
377
|
+
}
|
|
378
|
+
assert2.deepEqual(ids(await store.listEvents()), ["e3", "e2", "e1"]);
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
name: "events filter by request id",
|
|
383
|
+
async run({ store, clock }) {
|
|
384
|
+
for (const [id, requestId] of [
|
|
385
|
+
["e1", "req_a"],
|
|
386
|
+
["e2", "req_b"],
|
|
387
|
+
["e3", "req_a"]
|
|
388
|
+
]) {
|
|
389
|
+
await store.appendEvent(event(id, { requestId, at: clock.nowIso() }));
|
|
390
|
+
clock.advance(1e3);
|
|
391
|
+
}
|
|
392
|
+
assert2.deepEqual(ids(await store.listEvents({ requestId: "req_a" })), ["e3", "e1"]);
|
|
393
|
+
assert2.deepEqual(await store.listEvents({ requestId: "req_unknown" }), []);
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: "appending an event whose id was already used does not reject",
|
|
398
|
+
async run({ store, clock }) {
|
|
399
|
+
await store.appendEvent(event("event_1"));
|
|
400
|
+
await store.appendEvent(event("event_1", { type: "resource.delivered" }));
|
|
401
|
+
clock.advance(1e3);
|
|
402
|
+
await store.appendEvent(event("event_2", { at: clock.nowIso() }));
|
|
403
|
+
const listed = ids(await store.listEvents());
|
|
404
|
+
assert2.ok(listed.includes("event_1"));
|
|
405
|
+
assert2.ok(listed.includes("event_2"));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
];
|
|
409
|
+
var ATTEMPT_CASES = [
|
|
410
|
+
{
|
|
411
|
+
name: "a reservation returns a reserved attempt carrying the reservation fields",
|
|
412
|
+
async run({ store }) {
|
|
413
|
+
const withParties = await store.reservePaymentAttempt(
|
|
414
|
+
reservation(1, { payer: "0xbuyer", payee: "0xmerchant" })
|
|
415
|
+
);
|
|
416
|
+
assert2.ok(withParties.id !== "");
|
|
417
|
+
assertIso(withParties.createdAt);
|
|
418
|
+
assertIso(withParties.updatedAt);
|
|
419
|
+
assert2.deepEqual(withParties, {
|
|
420
|
+
id: withParties.id,
|
|
421
|
+
requestId: "req_1",
|
|
422
|
+
resourceId: "resource.report",
|
|
423
|
+
provider: "x402",
|
|
424
|
+
replayKey: "replay_1",
|
|
425
|
+
status: "reserved",
|
|
426
|
+
amount: "0.01",
|
|
427
|
+
currency: "USDC",
|
|
428
|
+
payer: "0xbuyer",
|
|
429
|
+
payee: "0xmerchant",
|
|
430
|
+
createdAt: withParties.createdAt,
|
|
431
|
+
updatedAt: withParties.updatedAt
|
|
432
|
+
});
|
|
433
|
+
const bare = await store.reservePaymentAttempt(reservation(2));
|
|
434
|
+
assert2.deepEqual(bare, {
|
|
435
|
+
id: bare.id,
|
|
436
|
+
requestId: "req_2",
|
|
437
|
+
resourceId: "resource.report",
|
|
438
|
+
provider: "x402",
|
|
439
|
+
replayKey: "replay_2",
|
|
440
|
+
status: "reserved",
|
|
441
|
+
amount: "0.01",
|
|
442
|
+
currency: "USDC",
|
|
443
|
+
createdAt: bare.createdAt,
|
|
444
|
+
updatedAt: bare.updatedAt
|
|
445
|
+
});
|
|
446
|
+
assert2.notEqual(bare.id, withParties.id);
|
|
447
|
+
assert2.deepEqual(await attemptFor(store, "replay_1"), withParties);
|
|
448
|
+
assert2.deepEqual(await attemptFor(store, "replay_2"), bare);
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "payment attempts filter by request id",
|
|
453
|
+
async run({ store, clock }) {
|
|
454
|
+
for (const [n, requestId] of [
|
|
455
|
+
[1, "req_a"],
|
|
456
|
+
[2, "req_b"],
|
|
457
|
+
[3, "req_a"]
|
|
458
|
+
]) {
|
|
459
|
+
await store.reservePaymentAttempt(reservation(n, { requestId }));
|
|
460
|
+
clock.advance(1e3);
|
|
461
|
+
}
|
|
462
|
+
const listed = await store.listPaymentAttempts({ requestId: "req_a" });
|
|
463
|
+
assert2.deepEqual(listed.map((a) => a.replayKey).sort(), ["replay_1", "replay_3"]);
|
|
464
|
+
assert2.deepEqual(await store.listPaymentAttempts({ requestId: "req_unknown" }), []);
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: "an update changes the status of the attempt it names and nothing else",
|
|
469
|
+
async run({ store, clock }) {
|
|
470
|
+
const reserved = await store.reservePaymentAttempt(reservation(1));
|
|
471
|
+
await store.reservePaymentAttempt(reservation(2));
|
|
472
|
+
clock.advance(1e3);
|
|
473
|
+
await store.updatePaymentAttempt({ replayKey: "replay_1", status: "verified" });
|
|
474
|
+
const verified = await attemptFor(store, "replay_1");
|
|
475
|
+
assert2.equal(verified.status, "verified");
|
|
476
|
+
assert2.deepEqual(
|
|
477
|
+
{ ...verified, status: "reserved", updatedAt: reserved.updatedAt },
|
|
478
|
+
reserved
|
|
479
|
+
);
|
|
480
|
+
await store.updatePaymentAttempt({
|
|
481
|
+
replayKey: "replay_1",
|
|
482
|
+
status: "settled",
|
|
483
|
+
externalReference: "0xtx"
|
|
484
|
+
});
|
|
485
|
+
const settled = await attemptFor(store, "replay_1");
|
|
486
|
+
assert2.equal(settled.status, "settled");
|
|
487
|
+
assert2.equal(settled.externalReference, "0xtx");
|
|
488
|
+
assert2.equal((await attemptFor(store, "replay_2")).status, "reserved");
|
|
489
|
+
await store.updatePaymentAttempt({
|
|
490
|
+
replayKey: "replay_2",
|
|
491
|
+
status: "rejected",
|
|
492
|
+
rejectionReason: "wrong_amount"
|
|
493
|
+
});
|
|
494
|
+
const rejected = await attemptFor(store, "replay_2");
|
|
495
|
+
assert2.equal(rejected.status, "rejected");
|
|
496
|
+
assert2.equal(rejected.rejectionReason, "wrong_amount");
|
|
497
|
+
assert2.deepEqual(await attemptFor(store, "replay_1"), settled);
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
name: "an update that omits externalReference keeps the one already stored",
|
|
502
|
+
async run({ store }) {
|
|
503
|
+
await store.reservePaymentAttempt(reservation(1));
|
|
504
|
+
await store.updatePaymentAttempt({
|
|
505
|
+
replayKey: "replay_1",
|
|
506
|
+
status: "settlement-uncertain",
|
|
507
|
+
externalReference: "0xbroadcast"
|
|
508
|
+
});
|
|
509
|
+
await store.updatePaymentAttempt({ replayKey: "replay_1", status: "settled" });
|
|
510
|
+
const attempt = await attemptFor(store, "replay_1");
|
|
511
|
+
assert2.equal(attempt.status, "settled");
|
|
512
|
+
assert2.equal(attempt.externalReference, "0xbroadcast");
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
name: "uncertain attempts are listed and counted: settlement-uncertain and legacy failed only",
|
|
517
|
+
async run({ store, clock }) {
|
|
518
|
+
assert2.equal(await store.countUncertainPaymentAttempts(), 0);
|
|
519
|
+
assert2.deepEqual(await store.listPaymentAttempts({ uncertain: true }), []);
|
|
520
|
+
for (const [index, status] of ALL_STATUSES.entries()) {
|
|
521
|
+
const n = index + 1;
|
|
522
|
+
await store.reservePaymentAttempt(reservation(n, { requestId: `req_${status}` }));
|
|
523
|
+
await moveTo(store, `replay_${n}`, status, {
|
|
524
|
+
...status === "settlement-uncertain" ? { externalReference: "0xhash" } : {}
|
|
525
|
+
});
|
|
526
|
+
clock.advance(1e3);
|
|
527
|
+
}
|
|
528
|
+
await store.reservePaymentAttempt(reservation(7, { requestId: "req_failed" }));
|
|
529
|
+
await moveTo(store, "replay_7", "settlement-uncertain");
|
|
530
|
+
assert2.equal(await store.countUncertainPaymentAttempts(), 3);
|
|
531
|
+
const keys = (attempts) => attempts.map((a) => a.replayKey).sort();
|
|
532
|
+
const listed = await store.listPaymentAttempts({ uncertain: true });
|
|
533
|
+
assert2.equal((await store.listPaymentAttempts()).length, 7);
|
|
534
|
+
assertFiltered(
|
|
535
|
+
keys(listed),
|
|
536
|
+
["replay_5", "replay_6", "replay_7"],
|
|
537
|
+
keys(await store.listPaymentAttempts())
|
|
538
|
+
);
|
|
539
|
+
assert2.equal(listed.find((a) => a.replayKey === "replay_6")?.externalReference, "0xhash");
|
|
540
|
+
for (const [requestId, expected] of [
|
|
541
|
+
["req_failed", ["replay_5", "replay_7"]],
|
|
542
|
+
["req_settled", []]
|
|
543
|
+
]) {
|
|
544
|
+
assertFiltered(
|
|
545
|
+
keys(await store.listPaymentAttempts({ requestId, uncertain: true })),
|
|
546
|
+
expected,
|
|
547
|
+
keys(await store.listPaymentAttempts({ requestId }))
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
];
|
|
553
|
+
var REPLAY_CASES = [
|
|
554
|
+
{
|
|
555
|
+
name: "a second reservation of a replay key is refused",
|
|
556
|
+
async run({ store }) {
|
|
557
|
+
const first = await store.reservePaymentAttempt(reservation(1, { payer: "0xfirst" }));
|
|
558
|
+
for (const second of [
|
|
559
|
+
reservation(1),
|
|
560
|
+
reservation(2, { replayKey: "replay_1", payer: "0xsecond" }),
|
|
561
|
+
reservation(3, { replayKey: "replay_1", provider: "mpp", resourceId: "resource.other" })
|
|
562
|
+
]) {
|
|
563
|
+
await expectReplayed(store.reservePaymentAttempt(second), "reserved");
|
|
564
|
+
}
|
|
565
|
+
assert2.deepEqual(await store.listPaymentAttempts(), [first]);
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
name: "a refused reservation reports the status of the attempt that holds the key",
|
|
570
|
+
async run({ store }) {
|
|
571
|
+
for (const [index, status] of ALL_STATUSES.entries()) {
|
|
572
|
+
const n = index + 1;
|
|
573
|
+
await store.reservePaymentAttempt(reservation(n));
|
|
574
|
+
await moveTo(store, `replay_${n}`, status);
|
|
575
|
+
await expectReplayed(
|
|
576
|
+
store.reservePaymentAttempt(reservation(n + 10, { replayKey: `replay_${n}` })),
|
|
577
|
+
status
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
name: "concurrent reservations of one replay key let exactly one win",
|
|
584
|
+
async run({ store }) {
|
|
585
|
+
const calls = Array.from(
|
|
586
|
+
{ length: RACERS },
|
|
587
|
+
(_, i) => store.reservePaymentAttempt(reservation(i, { replayKey: "replay_race" }))
|
|
588
|
+
);
|
|
589
|
+
const winner = soleWinner(await settle(calls));
|
|
590
|
+
assert2.equal(winner.status, "reserved");
|
|
591
|
+
assert2.deepEqual(await store.listPaymentAttempts(), [winner]);
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
name: "findPaymentAttemptByReplayKey reads the live attempt holding a key",
|
|
596
|
+
uses: ["findPaymentAttemptByReplayKey"],
|
|
597
|
+
async run({ store, clock }) {
|
|
598
|
+
const find = (replayKey) => store.findPaymentAttemptByReplayKey?.(replayKey) ?? assert2.fail("the store does not implement findPaymentAttemptByReplayKey");
|
|
599
|
+
const first = await store.reservePaymentAttempt(reservation(1));
|
|
600
|
+
const second = await store.reservePaymentAttempt(reservation(2));
|
|
601
|
+
assert2.deepEqual(await find("replay_1"), first);
|
|
602
|
+
assert2.deepEqual(await find("replay_2"), second);
|
|
603
|
+
assert2.equal(await find("replay_missing"), void 0);
|
|
604
|
+
clock.advance(1e3);
|
|
605
|
+
await moveTo(store, "replay_1", "settlement-uncertain");
|
|
606
|
+
assert2.deepEqual(await find("replay_1"), await attemptFor(store, "replay_1"));
|
|
607
|
+
await moveTo(store, "replay_2", "rejected", { rejectionReason: "backend_failed" });
|
|
608
|
+
const reclaimed = await store.reservePaymentAttempt(
|
|
609
|
+
reservation(3, { replayKey: "replay_2", reclaimRejected: true })
|
|
610
|
+
);
|
|
611
|
+
assert2.deepEqual(await find("replay_2"), reclaimed);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
];
|
|
615
|
+
var RECLAIM_CASES = [
|
|
616
|
+
{
|
|
617
|
+
name: "with reclaimRejected the same provider replaces its own rejected attempt",
|
|
618
|
+
async run({ store, clock }) {
|
|
619
|
+
await store.reservePaymentAttempt(reservation(1, { payer: "0xfirst" }));
|
|
620
|
+
await moveTo(store, "replay_1", "rejected", {
|
|
621
|
+
rejectionReason: "backend_failed",
|
|
622
|
+
externalReference: "0xnever"
|
|
623
|
+
});
|
|
624
|
+
clock.advance(1e3);
|
|
625
|
+
const reclaimed = await store.reservePaymentAttempt(
|
|
626
|
+
reservation(2, { replayKey: "replay_1", payer: "0xsecond", reclaimRejected: true })
|
|
627
|
+
);
|
|
628
|
+
assert2.deepEqual(reclaimed, {
|
|
629
|
+
id: reclaimed.id,
|
|
630
|
+
requestId: "req_2",
|
|
631
|
+
resourceId: "resource.report",
|
|
632
|
+
provider: "x402",
|
|
633
|
+
replayKey: "replay_1",
|
|
634
|
+
status: "reserved",
|
|
635
|
+
amount: "0.01",
|
|
636
|
+
currency: "USDC",
|
|
637
|
+
payer: "0xsecond",
|
|
638
|
+
createdAt: reclaimed.createdAt,
|
|
639
|
+
updatedAt: reclaimed.updatedAt
|
|
640
|
+
});
|
|
641
|
+
assert2.deepEqual(await store.listPaymentAttempts(), [reclaimed]);
|
|
642
|
+
await expectReplayed(
|
|
643
|
+
store.reservePaymentAttempt(
|
|
644
|
+
reservation(3, { replayKey: "replay_1", reclaimRejected: true })
|
|
645
|
+
),
|
|
646
|
+
"reserved"
|
|
647
|
+
);
|
|
648
|
+
await moveTo(store, "replay_1", "rejected", { rejectionReason: "backend_failed" });
|
|
649
|
+
const again = await store.reservePaymentAttempt(
|
|
650
|
+
reservation(4, { replayKey: "replay_1", reclaimRejected: true })
|
|
651
|
+
);
|
|
652
|
+
assert2.equal(again.requestId, "req_4");
|
|
653
|
+
assert2.equal(again.status, "reserved");
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
name: "reclaimRejected on a key nobody holds reserves it as usual",
|
|
658
|
+
async run({ store }) {
|
|
659
|
+
const attempt = await store.reservePaymentAttempt(reservation(1, { reclaimRejected: true }));
|
|
660
|
+
assert2.equal(attempt.status, "reserved");
|
|
661
|
+
assert2.deepEqual(await attemptFor(store, "replay_1"), attempt);
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
name: "a different provider cannot reclaim a rejected attempt",
|
|
666
|
+
async run({ store }) {
|
|
667
|
+
await store.reservePaymentAttempt(reservation(1));
|
|
668
|
+
await moveTo(store, "replay_1", "rejected", { rejectionReason: "backend_failed" });
|
|
669
|
+
const rejected = await attemptFor(store, "replay_1");
|
|
670
|
+
await expectReplayed(
|
|
671
|
+
store.reservePaymentAttempt(
|
|
672
|
+
reservation(2, { replayKey: "replay_1", provider: "mpp", reclaimRejected: true })
|
|
673
|
+
),
|
|
674
|
+
"rejected"
|
|
675
|
+
);
|
|
676
|
+
await expectReplayed(
|
|
677
|
+
store.reservePaymentAttempt(reservation(3, { replayKey: "replay_1" })),
|
|
678
|
+
"rejected"
|
|
679
|
+
);
|
|
680
|
+
assert2.deepEqual(await store.listPaymentAttempts(), [rejected]);
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
name: "an attempt that is not rejected cannot be reclaimed",
|
|
685
|
+
async run({ store }) {
|
|
686
|
+
const holders = ALL_STATUSES.filter((status) => status !== "rejected");
|
|
687
|
+
for (const [index, status] of holders.entries()) {
|
|
688
|
+
const n = index + 1;
|
|
689
|
+
await store.reservePaymentAttempt(reservation(n));
|
|
690
|
+
await moveTo(store, `replay_${n}`, status);
|
|
691
|
+
const before = await attemptFor(store, `replay_${n}`);
|
|
692
|
+
await expectReplayed(
|
|
693
|
+
store.reservePaymentAttempt(
|
|
694
|
+
reservation(n + 10, { replayKey: `replay_${n}`, reclaimRejected: true })
|
|
695
|
+
),
|
|
696
|
+
status
|
|
697
|
+
);
|
|
698
|
+
assert2.deepEqual(await attemptFor(store, `replay_${n}`), before);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
name: "concurrent reclaims of one rejected attempt let exactly one win",
|
|
704
|
+
async run({ store }) {
|
|
705
|
+
await store.reservePaymentAttempt(reservation(0, { replayKey: "replay_race" }));
|
|
706
|
+
await moveTo(store, "replay_race", "rejected", { rejectionReason: "backend_failed" });
|
|
707
|
+
const calls = Array.from(
|
|
708
|
+
{ length: RACERS },
|
|
709
|
+
(_, i) => store.reservePaymentAttempt(
|
|
710
|
+
reservation(i + 1, { replayKey: "replay_race", reclaimRejected: true })
|
|
711
|
+
)
|
|
712
|
+
);
|
|
713
|
+
const winner = soleWinner(await settle(calls));
|
|
714
|
+
assert2.equal(winner.status, "reserved");
|
|
715
|
+
assert2.deepEqual(await store.listPaymentAttempts(), [winner]);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
];
|
|
719
|
+
var JOURNAL_CASES = [
|
|
720
|
+
{
|
|
721
|
+
name: "a reservation with transaction data opens a transaction linked to the attempt",
|
|
722
|
+
uses: ["getTransaction"],
|
|
723
|
+
async run({ store, clock }) {
|
|
724
|
+
const attempt = await store.reservePaymentAttempt(fullJournaled(1));
|
|
725
|
+
assert2.equal(attempt.transactionId, "txn_1");
|
|
726
|
+
const tx = await transactionOf(journalOf(store), "txn_1");
|
|
727
|
+
assertIso(tx.createdAt);
|
|
728
|
+
assertIso(tx.updatedAt);
|
|
729
|
+
assert2.deepEqual(tx, {
|
|
730
|
+
id: "txn_1",
|
|
731
|
+
requestId: "req_1",
|
|
732
|
+
resourceId: "resource.report",
|
|
733
|
+
protocol: "mcp",
|
|
734
|
+
state: tx.state,
|
|
735
|
+
payment: {
|
|
736
|
+
provider: "x402",
|
|
737
|
+
attemptId: attempt.id,
|
|
738
|
+
replayKey: "replay_1",
|
|
739
|
+
status: "reserved",
|
|
740
|
+
amount: "0.01",
|
|
741
|
+
currency: "USDC",
|
|
742
|
+
network: "eip155:31337",
|
|
743
|
+
asset: "0xasset",
|
|
744
|
+
payee: "0xmerchant",
|
|
745
|
+
locator: { v: 1, nonce: "0xnonce" },
|
|
746
|
+
expiresAt: isoAt(3e5)
|
|
747
|
+
},
|
|
748
|
+
// An included authorization starts as reserved, whatever else the caller sent
|
|
749
|
+
authorization: {
|
|
750
|
+
method: "ap2",
|
|
751
|
+
reference: "sha256:mandate_1",
|
|
752
|
+
metadata: { issuer: "did:web:agent.example" },
|
|
753
|
+
hold: "reserved",
|
|
754
|
+
reservationId: "sha256:mandate_1"
|
|
755
|
+
},
|
|
756
|
+
inputDigest: "sha256:input",
|
|
757
|
+
configDigest: "sha256:terms",
|
|
758
|
+
createdAt: tx.createdAt,
|
|
759
|
+
updatedAt: tx.updatedAt
|
|
760
|
+
});
|
|
761
|
+
assertState(tx, factsOf("reserved"), clock.nowIso());
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
name: "a reservation without transaction data opens no transaction",
|
|
766
|
+
uses: ["listTransactions"],
|
|
767
|
+
async run({ store }) {
|
|
768
|
+
await store.reservePaymentAttempt(reservation(1));
|
|
769
|
+
assert2.deepEqual(await listAll(journalOf(store)), []);
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
name: "a refused reservation leaves no transaction behind",
|
|
774
|
+
uses: ["getTransaction", "listTransactions"],
|
|
775
|
+
async run({ store }) {
|
|
776
|
+
const journal = journalOf(store);
|
|
777
|
+
await store.reservePaymentAttempt(journaled(1));
|
|
778
|
+
await expectReplayed(
|
|
779
|
+
store.reservePaymentAttempt(journaled(2, {}, { replayKey: "replay_1" })),
|
|
780
|
+
"reserved"
|
|
781
|
+
);
|
|
782
|
+
assert2.equal(await journal.get("txn_2"), void 0);
|
|
783
|
+
assert2.deepEqual(await listAll(journal), ["txn_1"]);
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
name: "concurrent reservations of one replay key open exactly one transaction",
|
|
788
|
+
uses: ["listTransactions"],
|
|
789
|
+
async run({ store }) {
|
|
790
|
+
const calls = Array.from(
|
|
791
|
+
{ length: RACERS },
|
|
792
|
+
(_, i) => store.reservePaymentAttempt(journaled(i, {}, { replayKey: "replay_race" }))
|
|
793
|
+
);
|
|
794
|
+
const winner = soleWinner(await settle(calls));
|
|
795
|
+
assert2.deepEqual(await listAll(journalOf(store)), [winner.transactionId]);
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
name: "recorded steps update the transaction and its state follows the derivation",
|
|
800
|
+
uses: ["recordTransactionStep", "getTransaction"],
|
|
801
|
+
async run({ store, clock }) {
|
|
802
|
+
const journal = journalOf(store);
|
|
803
|
+
const read = () => transactionOf(journal, "txn_1");
|
|
804
|
+
const deadlineAt = isoAt(6e4);
|
|
805
|
+
await store.reservePaymentAttempt(journaled(1, { authorization: hold(1) }));
|
|
806
|
+
assertState(await read(), factsOf("reserved"), clock.nowIso());
|
|
807
|
+
clock.advance(1e3);
|
|
808
|
+
const settlingAt = clock.nowIso();
|
|
809
|
+
await journal.record({ transactionId: "txn_1", at: settlingAt, kind: "settling" });
|
|
810
|
+
assert2.equal((await read()).payment.settlingAt, settlingAt);
|
|
811
|
+
clock.advance(1e3);
|
|
812
|
+
await store.updatePaymentAttempt({
|
|
813
|
+
replayKey: "replay_1",
|
|
814
|
+
status: "settled",
|
|
815
|
+
externalReference: "0xtx"
|
|
816
|
+
});
|
|
817
|
+
let tx = await read();
|
|
818
|
+
assert2.equal(tx.payment.status, "settled");
|
|
819
|
+
assert2.equal(tx.payment.externalReference, "0xtx");
|
|
820
|
+
assertState(tx, factsOf("settled"), clock.nowIso());
|
|
821
|
+
await journal.record({
|
|
822
|
+
transactionId: "txn_1",
|
|
823
|
+
at: clock.nowIso(),
|
|
824
|
+
kind: "hold",
|
|
825
|
+
hold: "consumed"
|
|
826
|
+
});
|
|
827
|
+
assert2.equal((await read()).authorization?.hold, "consumed");
|
|
828
|
+
clock.advance(1e3);
|
|
829
|
+
const dispatchedAt = clock.nowIso();
|
|
830
|
+
await journal.record({
|
|
831
|
+
transactionId: "txn_1",
|
|
832
|
+
at: dispatchedAt,
|
|
833
|
+
kind: "backend-dispatched",
|
|
834
|
+
deadlineAt
|
|
835
|
+
});
|
|
836
|
+
tx = await read();
|
|
837
|
+
assert2.deepEqual(tx.backend, { dispatchedAt, deadlineAt });
|
|
838
|
+
assertState(
|
|
839
|
+
tx,
|
|
840
|
+
factsOf("settled", { backend: { dispatchedAt, deadlineAt } }),
|
|
841
|
+
clock.nowIso()
|
|
842
|
+
);
|
|
843
|
+
clock.advance(1e3);
|
|
844
|
+
await journal.record({
|
|
845
|
+
transactionId: "txn_1",
|
|
846
|
+
at: clock.nowIso(),
|
|
847
|
+
kind: "backend-result",
|
|
848
|
+
status: 200
|
|
849
|
+
});
|
|
850
|
+
tx = await read();
|
|
851
|
+
const backend = { dispatchedAt, deadlineAt, status: 200 };
|
|
852
|
+
assert2.deepEqual(tx.backend, backend);
|
|
853
|
+
assertState(tx, factsOf("settled", { backend }), clock.nowIso());
|
|
854
|
+
await journal.record({
|
|
855
|
+
transactionId: "txn_1",
|
|
856
|
+
at: clock.nowIso(),
|
|
857
|
+
kind: "receipt",
|
|
858
|
+
receiptId: "receipt_1"
|
|
859
|
+
});
|
|
860
|
+
assert2.equal((await read()).receiptId, "receipt_1");
|
|
861
|
+
clock.advance(1e3);
|
|
862
|
+
const completedAt = clock.nowIso();
|
|
863
|
+
await journal.record({
|
|
864
|
+
transactionId: "txn_1",
|
|
865
|
+
at: completedAt,
|
|
866
|
+
kind: "completed",
|
|
867
|
+
persistenceFailures: ["journal"]
|
|
868
|
+
});
|
|
869
|
+
tx = await read();
|
|
870
|
+
assert2.equal(tx.completedAt, completedAt);
|
|
871
|
+
assert2.deepEqual(tx.persistenceFailures, ["journal"]);
|
|
872
|
+
assertState(tx, factsOf("settled", { backend, completedAt }), clock.nowIso());
|
|
873
|
+
assert2.equal(tx.state, "delivered");
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
name: "a backend result is recorded with its status and error code",
|
|
878
|
+
uses: ["recordTransactionStep", "getTransaction"],
|
|
879
|
+
async run({ store, clock }) {
|
|
880
|
+
const journal = journalOf(store);
|
|
881
|
+
const deadlineAt = isoAt(6e4);
|
|
882
|
+
const outcomes = [
|
|
883
|
+
{ status: 200 },
|
|
884
|
+
{ status: 500 },
|
|
885
|
+
{ status: 0, errorCode: "BACKEND_TIMEOUT" }
|
|
886
|
+
];
|
|
887
|
+
for (const [index, outcome] of outcomes.entries()) {
|
|
888
|
+
const n = index + 1;
|
|
889
|
+
await store.reservePaymentAttempt(journaled(n));
|
|
890
|
+
await store.updatePaymentAttempt({ replayKey: `replay_${n}`, status: "settled" });
|
|
891
|
+
clock.advance(1e3);
|
|
892
|
+
const dispatchedAt = clock.nowIso();
|
|
893
|
+
await journal.record({
|
|
894
|
+
transactionId: `txn_${n}`,
|
|
895
|
+
at: dispatchedAt,
|
|
896
|
+
kind: "backend-dispatched",
|
|
897
|
+
deadlineAt
|
|
898
|
+
});
|
|
899
|
+
await journal.record({
|
|
900
|
+
transactionId: `txn_${n}`,
|
|
901
|
+
at: clock.nowIso(),
|
|
902
|
+
kind: "backend-result",
|
|
903
|
+
status: outcome.status,
|
|
904
|
+
...outcome.errorCode !== void 0 ? { errorCode: outcome.errorCode } : {}
|
|
905
|
+
});
|
|
906
|
+
const completedAt = clock.nowIso();
|
|
907
|
+
await journal.record({ transactionId: `txn_${n}`, at: completedAt, kind: "completed" });
|
|
908
|
+
const tx = await transactionOf(journal, `txn_${n}`);
|
|
909
|
+
const backend = { dispatchedAt, deadlineAt, ...outcome };
|
|
910
|
+
assert2.deepEqual(tx.backend, backend);
|
|
911
|
+
assert2.equal(tx.completedAt, completedAt);
|
|
912
|
+
assertState(tx, factsOf("settled", { backend, completedAt }), clock.nowIso());
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
name: "a payment attempt update moves the state of its transaction",
|
|
918
|
+
uses: ["getTransaction", "listTransactions"],
|
|
919
|
+
async run({ store, clock }) {
|
|
920
|
+
const journal = journalOf(store);
|
|
921
|
+
const statuses = ["settled", "rejected", "settlement-uncertain", "failed"];
|
|
922
|
+
for (const [index, status] of statuses.entries()) {
|
|
923
|
+
const n = index + 1;
|
|
924
|
+
await store.reservePaymentAttempt(journaled(n));
|
|
925
|
+
await store.updatePaymentAttempt({ replayKey: `replay_${n}`, status });
|
|
926
|
+
clock.advance(1e3);
|
|
927
|
+
const tx = await transactionOf(journal, `txn_${n}`);
|
|
928
|
+
assert2.equal(tx.payment.status, status);
|
|
929
|
+
assertState(tx, factsOf(status), clock.nowIso());
|
|
930
|
+
}
|
|
931
|
+
const stateOf = (status) => transactionState(factsOf(status), clock.nowIso());
|
|
932
|
+
for (const state of new Set(statuses.map(stateOf))) {
|
|
933
|
+
const expected = statuses.flatMap((status, index) => stateOf(status) === state ? [`txn_${index + 1}`] : []).reverse();
|
|
934
|
+
assert2.deepEqual(await listAll(journal, { state }), expected, state);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
{
|
|
939
|
+
name: "transactions list newest first and cursor pages continue to the end without repeats",
|
|
940
|
+
uses: ["listTransactions"],
|
|
941
|
+
async run({ store, clock }) {
|
|
942
|
+
const journal = journalOf(store);
|
|
943
|
+
for (let n = 1; n <= 5; n += 1) {
|
|
944
|
+
await store.reservePaymentAttempt(journaled(n));
|
|
945
|
+
clock.advance(1e3);
|
|
946
|
+
}
|
|
947
|
+
const newestFirst = ["txn_5", "txn_4", "txn_3", "txn_2", "txn_1"];
|
|
948
|
+
assert2.deepEqual(await listAll(journal), newestFirst);
|
|
949
|
+
const pages = await walk(journal, { limit: 2 });
|
|
950
|
+
assert2.ok(pages.every((page) => page.transactions.length <= 2));
|
|
951
|
+
assert2.deepEqual(
|
|
952
|
+
pages.flatMap((page) => ids(page.transactions)),
|
|
953
|
+
newestFirst
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
name: "transactions filter by request, state, unresolved and pending hold",
|
|
959
|
+
uses: ["recordTransactionStep", "listTransactions"],
|
|
960
|
+
async run({ store, clock }) {
|
|
961
|
+
const journal = journalOf(store);
|
|
962
|
+
const deadlineAt = isoAt(6e4);
|
|
963
|
+
await store.reservePaymentAttempt(journaled(1));
|
|
964
|
+
await moveTo(store, "replay_1", "rejected");
|
|
965
|
+
clock.advance(1e3);
|
|
966
|
+
await store.reservePaymentAttempt(journaled(2, { authorization: hold(2) }));
|
|
967
|
+
clock.advance(1e3);
|
|
968
|
+
await store.reservePaymentAttempt(journaled(3, { authorization: hold(3) }));
|
|
969
|
+
await moveTo(store, "replay_3", "settled");
|
|
970
|
+
for (const step of [
|
|
971
|
+
{ kind: "hold", hold: "consumed" },
|
|
972
|
+
{ kind: "backend-dispatched", deadlineAt },
|
|
973
|
+
{ kind: "backend-result", status: 200 },
|
|
974
|
+
{ kind: "completed" }
|
|
975
|
+
]) {
|
|
976
|
+
await journal.record({ transactionId: "txn_3", at: clock.nowIso(), ...step });
|
|
977
|
+
}
|
|
978
|
+
clock.advance(1e3);
|
|
979
|
+
await store.reservePaymentAttempt(journaled(4, { authorization: hold(4) }));
|
|
980
|
+
await moveTo(store, "replay_4", "settlement-uncertain");
|
|
981
|
+
await journal.record({
|
|
982
|
+
transactionId: "txn_4",
|
|
983
|
+
at: clock.nowIso(),
|
|
984
|
+
kind: "hold",
|
|
985
|
+
hold: "uncertain"
|
|
986
|
+
});
|
|
987
|
+
clock.advance(1e3);
|
|
988
|
+
await store.reservePaymentAttempt(journaled(5));
|
|
989
|
+
await moveTo(store, "replay_5", "settled");
|
|
990
|
+
const now = clock.nowIso();
|
|
991
|
+
const delivered = factsOf("settled", {
|
|
992
|
+
backend: { dispatchedAt: now, deadlineAt, status: 200 },
|
|
993
|
+
completedAt: now
|
|
994
|
+
});
|
|
995
|
+
const stateOf = (facts) => transactionState(facts, now);
|
|
996
|
+
assert2.deepEqual(await listAll(journal, { requestId: "req_2" }), ["txn_2"]);
|
|
997
|
+
assert2.deepEqual(await listAll(journal, { state: stateOf(factsOf("reserved")) }), ["txn_2"]);
|
|
998
|
+
assert2.deepEqual(await listAll(journal, { state: stateOf(factsOf("rejected")) }), ["txn_1"]);
|
|
999
|
+
assert2.deepEqual(
|
|
1000
|
+
await listAll(journal, { state: stateOf(factsOf("settlement-uncertain")) }),
|
|
1001
|
+
["txn_4"]
|
|
1002
|
+
);
|
|
1003
|
+
assert2.deepEqual(await listAll(journal, { state: stateOf(delivered) }), ["txn_3"]);
|
|
1004
|
+
assert2.deepEqual(await listAll(journal, { unresolved: true }), ["txn_5", "txn_4", "txn_2"]);
|
|
1005
|
+
assert2.deepEqual(await listAll(journal, { pendingHold: true }), ["txn_4", "txn_2"]);
|
|
1006
|
+
assert2.deepEqual(await listAll(journal, { unresolved: true, pendingHold: true }), [
|
|
1007
|
+
"txn_4",
|
|
1008
|
+
"txn_2"
|
|
1009
|
+
]);
|
|
1010
|
+
assert2.deepEqual(await listAll(journal, { unresolved: true, limit: 1 }), [
|
|
1011
|
+
"txn_5",
|
|
1012
|
+
"txn_4",
|
|
1013
|
+
"txn_2"
|
|
1014
|
+
]);
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
name: "getPaymentAttempt finds an attempt by id",
|
|
1019
|
+
uses: ["getPaymentAttempt"],
|
|
1020
|
+
async run({ store, clock }) {
|
|
1021
|
+
const journal = journalOf(store);
|
|
1022
|
+
const first = await store.reservePaymentAttempt(reservation(1));
|
|
1023
|
+
const second = await store.reservePaymentAttempt(reservation(2));
|
|
1024
|
+
assert2.deepEqual(await attemptById(journal, first.id), first);
|
|
1025
|
+
assert2.deepEqual(await attemptById(journal, second.id), second);
|
|
1026
|
+
clock.advance(1e3);
|
|
1027
|
+
await store.updatePaymentAttempt({ replayKey: "replay_1", status: "settled" });
|
|
1028
|
+
assert2.deepEqual(await attemptById(journal, first.id), await attemptFor(store, "replay_1"));
|
|
1029
|
+
assert2.equal(await journal.attempt("attempt_missing"), void 0);
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
name: "getPaymentAttempt still finds an attempt a reclaim replaced, and its transaction keeps it",
|
|
1034
|
+
uses: ["getPaymentAttempt", "getTransaction"],
|
|
1035
|
+
async run({ store, clock }) {
|
|
1036
|
+
const journal = journalOf(store);
|
|
1037
|
+
const replaced = await store.reservePaymentAttempt(journaled(1));
|
|
1038
|
+
await moveTo(store, "replay_1", "rejected", { rejectionReason: "backend_failed" });
|
|
1039
|
+
clock.advance(1e3);
|
|
1040
|
+
const reclaimed = await store.reservePaymentAttempt(
|
|
1041
|
+
journaled(2, {}, { replayKey: "replay_1", reclaimRejected: true })
|
|
1042
|
+
);
|
|
1043
|
+
assert2.notEqual(reclaimed.id, replaced.id);
|
|
1044
|
+
const old = await attemptById(journal, replaced.id);
|
|
1045
|
+
assert2.equal(old.requestId, "req_1");
|
|
1046
|
+
assert2.equal(old.status, "rejected");
|
|
1047
|
+
assert2.equal(old.rejectionReason, "backend_failed");
|
|
1048
|
+
assert2.deepEqual(await attemptById(journal, reclaimed.id), reclaimed);
|
|
1049
|
+
const oldTx = await transactionOf(journal, "txn_1");
|
|
1050
|
+
assert2.equal(oldTx.payment.attemptId, replaced.id);
|
|
1051
|
+
assert2.equal(oldTx.payment.status, "rejected");
|
|
1052
|
+
assertState(oldTx, factsOf("rejected"), clock.nowIso());
|
|
1053
|
+
const newTx = await transactionOf(journal, "txn_2");
|
|
1054
|
+
assert2.equal(newTx.payment.attemptId, reclaimed.id);
|
|
1055
|
+
assert2.equal(newTx.payment.status, "reserved");
|
|
1056
|
+
await store.updatePaymentAttempt({ replayKey: "replay_1", status: "settled" });
|
|
1057
|
+
assert2.equal((await transactionOf(journal, "txn_2")).payment.status, "settled");
|
|
1058
|
+
assert2.equal((await transactionOf(journal, "txn_1")).payment.status, "rejected");
|
|
1059
|
+
assert2.equal((await attemptById(journal, replaced.id)).status, "rejected");
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
];
|
|
1063
|
+
var RESOLUTION_CASES = [
|
|
1064
|
+
{
|
|
1065
|
+
name: "resolving an uncertain attempt records the resolution and moves its transaction",
|
|
1066
|
+
uses: ["resolvePaymentAttempt", "getPaymentAttempt", "getTransaction"],
|
|
1067
|
+
async run({ store, clock }) {
|
|
1068
|
+
const journal = journalOf(store);
|
|
1069
|
+
const outcomes = [
|
|
1070
|
+
{ status: "settled" },
|
|
1071
|
+
{ status: "rejected", rejectionReason: "not_settled" }
|
|
1072
|
+
];
|
|
1073
|
+
for (const [index, outcome] of outcomes.entries()) {
|
|
1074
|
+
const n = index + 1;
|
|
1075
|
+
const attempt = await uncertain(store, n);
|
|
1076
|
+
clock.advance(1e3);
|
|
1077
|
+
const won = await journal.resolve({
|
|
1078
|
+
attemptId: attempt.id,
|
|
1079
|
+
expectedStatus: "settlement-uncertain",
|
|
1080
|
+
...outcome,
|
|
1081
|
+
resolution: RESOLUTION
|
|
1082
|
+
});
|
|
1083
|
+
assert2.equal(won, true);
|
|
1084
|
+
const resolved = await attemptById(journal, attempt.id);
|
|
1085
|
+
assert2.equal(resolved.status, outcome.status);
|
|
1086
|
+
assert2.deepEqual(resolved.resolution, RESOLUTION);
|
|
1087
|
+
if ("rejectionReason" in outcome) {
|
|
1088
|
+
assert2.equal(resolved.rejectionReason, outcome.rejectionReason);
|
|
1089
|
+
}
|
|
1090
|
+
assert2.deepEqual(await attemptFor(store, `replay_${n}`), resolved);
|
|
1091
|
+
const tx = await transactionOf(journal, `txn_${n}`);
|
|
1092
|
+
assert2.equal(tx.payment.status, outcome.status);
|
|
1093
|
+
assertState(tx, factsOf(outcome.status), clock.nowIso());
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
name: "resolvePaymentAttempt returns false and writes nothing when the expected status differs",
|
|
1099
|
+
uses: ["resolvePaymentAttempt", "getPaymentAttempt", "getTransaction"],
|
|
1100
|
+
async run({ store, clock }) {
|
|
1101
|
+
const journal = journalOf(store);
|
|
1102
|
+
const attempt = await uncertain(store, 1);
|
|
1103
|
+
const before = await attemptById(journal, attempt.id);
|
|
1104
|
+
const won = await journal.resolve({
|
|
1105
|
+
attemptId: attempt.id,
|
|
1106
|
+
expectedStatus: "reserved",
|
|
1107
|
+
status: "settled",
|
|
1108
|
+
resolution: RESOLUTION
|
|
1109
|
+
});
|
|
1110
|
+
assert2.equal(won, false);
|
|
1111
|
+
assert2.deepEqual(await attemptById(journal, attempt.id), before);
|
|
1112
|
+
assertState(
|
|
1113
|
+
await transactionOf(journal, "txn_1"),
|
|
1114
|
+
factsOf("settlement-uncertain"),
|
|
1115
|
+
clock.nowIso()
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
name: "resolvePaymentAttempt refuses a second resolution even when the expected status matches",
|
|
1121
|
+
uses: ["resolvePaymentAttempt", "getPaymentAttempt"],
|
|
1122
|
+
async run({ store }) {
|
|
1123
|
+
const journal = journalOf(store);
|
|
1124
|
+
const attempt = await uncertain(store, 1);
|
|
1125
|
+
assert2.equal(
|
|
1126
|
+
await journal.resolve({
|
|
1127
|
+
attemptId: attempt.id,
|
|
1128
|
+
expectedStatus: "settlement-uncertain",
|
|
1129
|
+
status: "settled",
|
|
1130
|
+
resolution: RESOLUTION
|
|
1131
|
+
}),
|
|
1132
|
+
true
|
|
1133
|
+
);
|
|
1134
|
+
const resolved = await attemptById(journal, attempt.id);
|
|
1135
|
+
const again = await journal.resolve({
|
|
1136
|
+
attemptId: attempt.id,
|
|
1137
|
+
expectedStatus: "settled",
|
|
1138
|
+
status: "rejected",
|
|
1139
|
+
resolution: { ...RESOLUTION, method: "manual", actor: "operator" }
|
|
1140
|
+
});
|
|
1141
|
+
assert2.equal(again, false);
|
|
1142
|
+
assert2.deepEqual(await attemptById(journal, attempt.id), resolved);
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
name: "an attempt with a resolution cannot be changed by updatePaymentAttempt",
|
|
1147
|
+
uses: ["resolvePaymentAttempt", "getPaymentAttempt"],
|
|
1148
|
+
async run({ store, clock }) {
|
|
1149
|
+
const journal = journalOf(store);
|
|
1150
|
+
const attempt = await uncertain(store, 1);
|
|
1151
|
+
await journal.resolve({
|
|
1152
|
+
attemptId: attempt.id,
|
|
1153
|
+
expectedStatus: "settlement-uncertain",
|
|
1154
|
+
status: "settled",
|
|
1155
|
+
resolution: RESOLUTION
|
|
1156
|
+
});
|
|
1157
|
+
const resolved = await attemptById(journal, attempt.id);
|
|
1158
|
+
clock.advance(1e3);
|
|
1159
|
+
await assert2.rejects(
|
|
1160
|
+
store.updatePaymentAttempt({
|
|
1161
|
+
replayKey: "replay_1",
|
|
1162
|
+
status: "rejected",
|
|
1163
|
+
rejectionReason: "late_write",
|
|
1164
|
+
externalReference: "0xother"
|
|
1165
|
+
})
|
|
1166
|
+
);
|
|
1167
|
+
assert2.deepEqual(await attemptById(journal, attempt.id), resolved);
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
{
|
|
1171
|
+
name: "concurrent resolutions of one attempt let exactly one win",
|
|
1172
|
+
uses: ["resolvePaymentAttempt", "getPaymentAttempt"],
|
|
1173
|
+
async run({ store }) {
|
|
1174
|
+
const journal = journalOf(store);
|
|
1175
|
+
const attempt = await uncertain(store, 1);
|
|
1176
|
+
const results = await Promise.all(
|
|
1177
|
+
Array.from(
|
|
1178
|
+
{ length: RACERS },
|
|
1179
|
+
(_, i) => journal.resolve({
|
|
1180
|
+
attemptId: attempt.id,
|
|
1181
|
+
expectedStatus: "settlement-uncertain",
|
|
1182
|
+
status: i % 2 === 0 ? "settled" : "rejected",
|
|
1183
|
+
resolution: { ...RESOLUTION, actor: `actor_${i}` }
|
|
1184
|
+
})
|
|
1185
|
+
)
|
|
1186
|
+
);
|
|
1187
|
+
assert2.equal(results.filter((won) => won).length, 1);
|
|
1188
|
+
const winner = results.indexOf(true);
|
|
1189
|
+
const resolved = await attemptById(journal, attempt.id);
|
|
1190
|
+
assert2.equal(resolved.resolution?.actor, `actor_${winner}`);
|
|
1191
|
+
assert2.equal(resolved.status, winner % 2 === 0 ? "settled" : "rejected");
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
];
|
|
1195
|
+
var DURABILITY_CASES = [
|
|
1196
|
+
{
|
|
1197
|
+
name: "receipts, events and payment attempts read back identically after a reopen",
|
|
1198
|
+
needsReopen: true,
|
|
1199
|
+
async run({ store, clock, reopen }) {
|
|
1200
|
+
await store.saveReceipt(FULL_RECEIPT);
|
|
1201
|
+
await store.saveReceipt(receipt("receipt_failed", { backendStatus: 502 }));
|
|
1202
|
+
await store.appendEvent(FULL_EVENT);
|
|
1203
|
+
await store.reservePaymentAttempt(reservation(1, { payer: "0xbuyer", payee: "0xmerchant" }));
|
|
1204
|
+
await moveTo(store, "replay_1", "settled", { externalReference: "0xtx" });
|
|
1205
|
+
clock.advance(1e3);
|
|
1206
|
+
await store.reservePaymentAttempt(reservation(2));
|
|
1207
|
+
await moveTo(store, "replay_2", "settlement-uncertain", { externalReference: "0xhash" });
|
|
1208
|
+
clock.advance(1e3);
|
|
1209
|
+
await store.reservePaymentAttempt(reservation(3));
|
|
1210
|
+
await moveTo(store, "replay_3", "rejected", { rejectionReason: "backend_failed" });
|
|
1211
|
+
const readAttempts = (target) => Promise.all([1, 2, 3].map((n) => attemptFor(target, `replay_${n}`)));
|
|
1212
|
+
const before = await readAttempts(store);
|
|
1213
|
+
const reopened = await reopen();
|
|
1214
|
+
assert2.deepEqual(await reopened.getReceipt(FULL_RECEIPT.id), FULL_RECEIPT);
|
|
1215
|
+
assert2.equal(await reopened.countReceipts(), 2);
|
|
1216
|
+
assert2.equal(await reopened.countUndeliveredReceipts(), 1);
|
|
1217
|
+
assert2.deepEqual(await reopened.listEvents(), [FULL_EVENT]);
|
|
1218
|
+
assert2.deepEqual(await readAttempts(reopened), before);
|
|
1219
|
+
assert2.equal(await reopened.countUncertainPaymentAttempts(), 1);
|
|
1220
|
+
await expectReplayed(
|
|
1221
|
+
reopened.reservePaymentAttempt(reservation(4, { replayKey: "replay_1" })),
|
|
1222
|
+
"settled"
|
|
1223
|
+
);
|
|
1224
|
+
const fresh = await reopened.reservePaymentAttempt(reservation(5));
|
|
1225
|
+
assert2.equal(fresh.status, "reserved");
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
{
|
|
1229
|
+
name: "transactions, steps and resolutions read back identically after a reopen",
|
|
1230
|
+
uses: [
|
|
1231
|
+
"recordTransactionStep",
|
|
1232
|
+
"getTransaction",
|
|
1233
|
+
"listTransactions",
|
|
1234
|
+
"getPaymentAttempt",
|
|
1235
|
+
"resolvePaymentAttempt"
|
|
1236
|
+
],
|
|
1237
|
+
needsReopen: true,
|
|
1238
|
+
async run({ store, clock, reopen }) {
|
|
1239
|
+
const journal = journalOf(store);
|
|
1240
|
+
const first = await store.reservePaymentAttempt(fullJournaled(1));
|
|
1241
|
+
clock.advance(1e3);
|
|
1242
|
+
await journal.record({ transactionId: "txn_1", at: clock.nowIso(), kind: "settling" });
|
|
1243
|
+
await store.updatePaymentAttempt({
|
|
1244
|
+
replayKey: "replay_1",
|
|
1245
|
+
status: "settled",
|
|
1246
|
+
externalReference: "0xtx"
|
|
1247
|
+
});
|
|
1248
|
+
await journal.record({
|
|
1249
|
+
transactionId: "txn_1",
|
|
1250
|
+
at: clock.nowIso(),
|
|
1251
|
+
kind: "hold",
|
|
1252
|
+
hold: "consumed"
|
|
1253
|
+
});
|
|
1254
|
+
await journal.record({
|
|
1255
|
+
transactionId: "txn_1",
|
|
1256
|
+
at: clock.nowIso(),
|
|
1257
|
+
kind: "backend-dispatched",
|
|
1258
|
+
deadlineAt: isoAt(6e4)
|
|
1259
|
+
});
|
|
1260
|
+
await journal.record({
|
|
1261
|
+
transactionId: "txn_1",
|
|
1262
|
+
at: clock.nowIso(),
|
|
1263
|
+
kind: "backend-result",
|
|
1264
|
+
status: 200
|
|
1265
|
+
});
|
|
1266
|
+
await journal.record({
|
|
1267
|
+
transactionId: "txn_1",
|
|
1268
|
+
at: clock.nowIso(),
|
|
1269
|
+
kind: "receipt",
|
|
1270
|
+
receiptId: "receipt_1"
|
|
1271
|
+
});
|
|
1272
|
+
await journal.record({
|
|
1273
|
+
transactionId: "txn_1",
|
|
1274
|
+
at: clock.nowIso(),
|
|
1275
|
+
kind: "completed",
|
|
1276
|
+
persistenceFailures: ["journal"]
|
|
1277
|
+
});
|
|
1278
|
+
clock.advance(1e3);
|
|
1279
|
+
const second = await uncertain(store, 2);
|
|
1280
|
+
await journal.resolve({
|
|
1281
|
+
attemptId: second.id,
|
|
1282
|
+
expectedStatus: "settlement-uncertain",
|
|
1283
|
+
status: "settled",
|
|
1284
|
+
resolution: RESOLUTION
|
|
1285
|
+
});
|
|
1286
|
+
const txBefore = [
|
|
1287
|
+
await transactionOf(journal, "txn_1"),
|
|
1288
|
+
await transactionOf(journal, "txn_2")
|
|
1289
|
+
];
|
|
1290
|
+
const attemptsBefore = [
|
|
1291
|
+
await attemptById(journal, first.id),
|
|
1292
|
+
await attemptById(journal, second.id)
|
|
1293
|
+
];
|
|
1294
|
+
const listBefore = await listAll(journal);
|
|
1295
|
+
const reopened = journalOf(await reopen());
|
|
1296
|
+
assert2.deepEqual(
|
|
1297
|
+
[await transactionOf(reopened, "txn_1"), await transactionOf(reopened, "txn_2")],
|
|
1298
|
+
txBefore
|
|
1299
|
+
);
|
|
1300
|
+
assert2.deepEqual(
|
|
1301
|
+
[await attemptById(reopened, first.id), await attemptById(reopened, second.id)],
|
|
1302
|
+
attemptsBefore
|
|
1303
|
+
);
|
|
1304
|
+
assert2.deepEqual(await listAll(reopened), listBefore);
|
|
1305
|
+
assert2.deepEqual(listBefore, ["txn_2", "txn_1"]);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
];
|
|
1309
|
+
var CORE_CASES = [
|
|
1310
|
+
...RECEIPT_CASES,
|
|
1311
|
+
...EVENT_CASES,
|
|
1312
|
+
...ATTEMPT_CASES,
|
|
1313
|
+
...REPLAY_CASES,
|
|
1314
|
+
...RECLAIM_CASES,
|
|
1315
|
+
...JOURNAL_CASES,
|
|
1316
|
+
...RESOLUTION_CASES,
|
|
1317
|
+
...DURABILITY_CASES
|
|
1318
|
+
];
|
|
1319
|
+
var CLAIMS = STORE_METHOD_GROUPS.idempotency_claims;
|
|
1320
|
+
var HOLDS = STORE_METHOD_GROUPS.authorization_holds;
|
|
1321
|
+
var TASKS = STORE_METHOD_GROUPS.pending_tasks;
|
|
1322
|
+
var MINUTE = 6e4;
|
|
1323
|
+
var DAY = 24 * 60 * MINUTE;
|
|
1324
|
+
var claims = (store) => store;
|
|
1325
|
+
var holds = (store) => store;
|
|
1326
|
+
var tasks = (store) => store;
|
|
1327
|
+
var scope = (key, endpoint = "/acp/checkout_sessions") => ({
|
|
1328
|
+
deployment: "https://gateway.example",
|
|
1329
|
+
endpoint,
|
|
1330
|
+
key
|
|
1331
|
+
});
|
|
1332
|
+
var hold2 = (reference, fields = {}) => ({
|
|
1333
|
+
method: "ap2",
|
|
1334
|
+
reference,
|
|
1335
|
+
bindingReference: `binding-of-${reference}`,
|
|
1336
|
+
resourceId: "resource.report",
|
|
1337
|
+
requestId: `req-${reference}`,
|
|
1338
|
+
...fields
|
|
1339
|
+
});
|
|
1340
|
+
var task = (id, fields = {}) => ({
|
|
1341
|
+
id,
|
|
1342
|
+
protocol: "a2a",
|
|
1343
|
+
resourceId: "resource.report",
|
|
1344
|
+
input: { symbol: "ETH" },
|
|
1345
|
+
expiresAt: isoAt(10 * MINUTE),
|
|
1346
|
+
...fields
|
|
1347
|
+
});
|
|
1348
|
+
var count = (values, predicate) => values.filter(predicate).length;
|
|
1349
|
+
var CLAIM_CASES = [
|
|
1350
|
+
{
|
|
1351
|
+
name: "a new idempotency scope is reserved and a repeat while it runs is in flight",
|
|
1352
|
+
uses: CLAIMS,
|
|
1353
|
+
async run({ store }) {
|
|
1354
|
+
const s = claims(store);
|
|
1355
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
|
|
1356
|
+
kind: "reserved"
|
|
1357
|
+
});
|
|
1358
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
|
|
1359
|
+
kind: "in-flight"
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
name: "a different fingerprint conflicts whatever the claim state",
|
|
1365
|
+
uses: CLAIMS,
|
|
1366
|
+
async run({ store }) {
|
|
1367
|
+
const s = claims(store);
|
|
1368
|
+
await s.claimIdempotencyKey(scope("running"), "fp", isoAt(DAY));
|
|
1369
|
+
await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY));
|
|
1370
|
+
await s.updateIdempotencyKey(scope("done"), { kind: "completed", status: 201, body: {} });
|
|
1371
|
+
await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
|
|
1372
|
+
await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
|
|
1373
|
+
for (const key of ["running", "done", "unknown"]) {
|
|
1374
|
+
assert2.deepEqual(
|
|
1375
|
+
await s.claimIdempotencyKey(scope(key), "other", isoAt(DAY)),
|
|
1376
|
+
{ kind: "conflict" },
|
|
1377
|
+
key
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
name: "a completed claim replays its status and body",
|
|
1384
|
+
uses: CLAIMS,
|
|
1385
|
+
async run({ store }) {
|
|
1386
|
+
const s = claims(store);
|
|
1387
|
+
const body = { id: "cs_1", line_items: [{ id: "item", quantity: 2 }], note: null };
|
|
1388
|
+
await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY));
|
|
1389
|
+
await s.updateIdempotencyKey(scope("k1"), { kind: "completed", status: 201, body });
|
|
1390
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)), {
|
|
1391
|
+
kind: "replay",
|
|
1392
|
+
status: 201,
|
|
1393
|
+
body
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
name: "an unresolved claim refuses retries and a released one can be claimed again",
|
|
1399
|
+
uses: CLAIMS,
|
|
1400
|
+
async run({ store }) {
|
|
1401
|
+
const s = claims(store);
|
|
1402
|
+
await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
|
|
1403
|
+
await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
|
|
1404
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
|
|
1405
|
+
kind: "unresolved"
|
|
1406
|
+
});
|
|
1407
|
+
await s.claimIdempotencyKey(scope("freed"), "fp", isoAt(DAY));
|
|
1408
|
+
await s.updateIdempotencyKey(scope("freed"), { kind: "released" });
|
|
1409
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("freed"), "other", isoAt(DAY)), {
|
|
1410
|
+
kind: "reserved"
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
},
|
|
1414
|
+
{
|
|
1415
|
+
name: "an idempotency scope is the deployment, endpoint and key together",
|
|
1416
|
+
uses: CLAIMS,
|
|
1417
|
+
async run({ store }) {
|
|
1418
|
+
const s = claims(store);
|
|
1419
|
+
const base = scope("k1");
|
|
1420
|
+
await s.claimIdempotencyKey(base, "fp", isoAt(DAY));
|
|
1421
|
+
for (const other of [
|
|
1422
|
+
{ ...base, deployment: "https://other.example" },
|
|
1423
|
+
{ ...base, endpoint: "/acp/checkout_sessions/cs_1" },
|
|
1424
|
+
{ ...base, key: "k2" }
|
|
1425
|
+
]) {
|
|
1426
|
+
assert2.deepEqual(await s.claimIdempotencyKey(other, "fp", isoAt(DAY)), {
|
|
1427
|
+
kind: "reserved"
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
{
|
|
1433
|
+
name: "only completed claims expire",
|
|
1434
|
+
uses: CLAIMS,
|
|
1435
|
+
async run({ store, clock }) {
|
|
1436
|
+
const s = claims(store);
|
|
1437
|
+
await s.claimIdempotencyKey(scope("done"), "fp", isoAt(MINUTE));
|
|
1438
|
+
await s.updateIdempotencyKey(scope("done"), { kind: "completed", status: 200, body: {} });
|
|
1439
|
+
await s.claimIdempotencyKey(scope("running"), "fp", isoAt(MINUTE));
|
|
1440
|
+
await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(MINUTE));
|
|
1441
|
+
await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
|
|
1442
|
+
clock.advance(MINUTE - 1);
|
|
1443
|
+
assert2.equal((await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY))).kind, "replay");
|
|
1444
|
+
clock.advance(2);
|
|
1445
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("done"), "other", isoAt(DAY)), {
|
|
1446
|
+
kind: "reserved"
|
|
1447
|
+
});
|
|
1448
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("running"), "fp", isoAt(DAY)), {
|
|
1449
|
+
kind: "in-flight"
|
|
1450
|
+
});
|
|
1451
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
|
|
1452
|
+
kind: "unresolved"
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
},
|
|
1456
|
+
{
|
|
1457
|
+
name: "recovery marks in-flight claims unresolved and counts them",
|
|
1458
|
+
uses: CLAIMS,
|
|
1459
|
+
async run({ store }) {
|
|
1460
|
+
const s = claims(store);
|
|
1461
|
+
await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY));
|
|
1462
|
+
await s.claimIdempotencyKey(scope("b"), "fp", isoAt(DAY));
|
|
1463
|
+
await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY));
|
|
1464
|
+
await s.updateIdempotencyKey(scope("done"), { kind: "completed", status: 200, body: 1 });
|
|
1465
|
+
assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 2);
|
|
1466
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
|
|
1467
|
+
kind: "unresolved"
|
|
1468
|
+
});
|
|
1469
|
+
assert2.equal((await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY))).kind, "replay");
|
|
1470
|
+
assert2.equal(await s.recoverIdempotencyKeys({ release: false }), 0);
|
|
1471
|
+
}
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
name: "recovery with release deletes in-flight claims only",
|
|
1475
|
+
uses: CLAIMS,
|
|
1476
|
+
async run({ store }) {
|
|
1477
|
+
const s = claims(store);
|
|
1478
|
+
await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY));
|
|
1479
|
+
await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
|
|
1480
|
+
await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
|
|
1481
|
+
assert2.equal(await s.recoverIdempotencyKeys({ release: true }), 1);
|
|
1482
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("a"), "fp", isoAt(DAY)), {
|
|
1483
|
+
kind: "reserved"
|
|
1484
|
+
});
|
|
1485
|
+
assert2.deepEqual(await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
|
|
1486
|
+
kind: "unresolved"
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
},
|
|
1490
|
+
{
|
|
1491
|
+
name: "concurrent claims of one idempotency scope reserve it once",
|
|
1492
|
+
uses: CLAIMS,
|
|
1493
|
+
async run({ store }) {
|
|
1494
|
+
const s = claims(store);
|
|
1495
|
+
const results = await Promise.all(
|
|
1496
|
+
Array.from({ length: 8 }, () => s.claimIdempotencyKey(scope("k1"), "fp", isoAt(DAY)))
|
|
1497
|
+
);
|
|
1498
|
+
assert2.equal(
|
|
1499
|
+
count(results, (r) => r.kind === "reserved"),
|
|
1500
|
+
1
|
|
1501
|
+
);
|
|
1502
|
+
assert2.equal(
|
|
1503
|
+
count(results, (r) => r.kind === "in-flight"),
|
|
1504
|
+
7
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
},
|
|
1508
|
+
{
|
|
1509
|
+
name: "idempotency claims survive a reopen",
|
|
1510
|
+
uses: CLAIMS,
|
|
1511
|
+
needsReopen: true,
|
|
1512
|
+
async run({ store, reopen }) {
|
|
1513
|
+
const s = claims(store);
|
|
1514
|
+
await s.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY));
|
|
1515
|
+
await s.updateIdempotencyKey(scope("done"), { kind: "completed", status: 201, body: [1] });
|
|
1516
|
+
await s.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY));
|
|
1517
|
+
await s.updateIdempotencyKey(scope("unknown"), { kind: "unresolved" });
|
|
1518
|
+
const reopened = claims(await reopen());
|
|
1519
|
+
assert2.deepEqual(await reopened.claimIdempotencyKey(scope("done"), "fp", isoAt(DAY)), {
|
|
1520
|
+
kind: "replay",
|
|
1521
|
+
status: 201,
|
|
1522
|
+
body: [1]
|
|
1523
|
+
});
|
|
1524
|
+
assert2.deepEqual(await reopened.claimIdempotencyKey(scope("unknown"), "fp", isoAt(DAY)), {
|
|
1525
|
+
kind: "unresolved"
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
];
|
|
1530
|
+
var HOLD_CASES = [
|
|
1531
|
+
{
|
|
1532
|
+
name: "a new authorization hold is reserved",
|
|
1533
|
+
uses: HOLDS,
|
|
1534
|
+
async run({ store }) {
|
|
1535
|
+
const s = holds(store);
|
|
1536
|
+
assert2.equal(await s.getAuthorizationHoldState("ref1"), void 0);
|
|
1537
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref1")), { kind: "reserved" });
|
|
1538
|
+
assert2.equal(await s.getAuthorizationHoldState("ref1"), "reserved");
|
|
1539
|
+
}
|
|
1540
|
+
},
|
|
1541
|
+
{
|
|
1542
|
+
name: "a held reference is refused with its state",
|
|
1543
|
+
uses: HOLDS,
|
|
1544
|
+
async run({ store }) {
|
|
1545
|
+
const s = holds(store);
|
|
1546
|
+
for (const to of ["consumed", "uncertain"]) {
|
|
1547
|
+
const ref = `ref-${to}`;
|
|
1548
|
+
await s.reserveAuthorizationHold(hold2(ref));
|
|
1549
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2(ref, { requestId: "req-2" })), {
|
|
1550
|
+
kind: "replayed",
|
|
1551
|
+
state: "reserved"
|
|
1552
|
+
});
|
|
1553
|
+
assert2.equal(await s.transitionAuthorizationHold(ref, to), true);
|
|
1554
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2(ref, { requestId: "req-3" })), {
|
|
1555
|
+
kind: "replayed",
|
|
1556
|
+
state: to
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
},
|
|
1561
|
+
{
|
|
1562
|
+
name: "a binding takes a second reference only after the first is released",
|
|
1563
|
+
uses: HOLDS,
|
|
1564
|
+
async run({ store }) {
|
|
1565
|
+
const s = holds(store);
|
|
1566
|
+
const shared = { bindingReference: "checkout-jti" };
|
|
1567
|
+
await s.reserveAuthorizationHold(hold2("ref1", shared));
|
|
1568
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref2", shared)), {
|
|
1569
|
+
kind: "replayed",
|
|
1570
|
+
state: "reserved"
|
|
1571
|
+
});
|
|
1572
|
+
assert2.equal(await s.getAuthorizationHoldState("ref2"), void 0);
|
|
1573
|
+
await s.transitionAuthorizationHold("ref1", "released");
|
|
1574
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref2", shared)), {
|
|
1575
|
+
kind: "reserved"
|
|
1576
|
+
});
|
|
1577
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref1", shared)), {
|
|
1578
|
+
kind: "replayed",
|
|
1579
|
+
state: "reserved"
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
},
|
|
1583
|
+
{
|
|
1584
|
+
name: "consumed and released holds are final",
|
|
1585
|
+
uses: HOLDS,
|
|
1586
|
+
async run({ store }) {
|
|
1587
|
+
const s = holds(store);
|
|
1588
|
+
await s.reserveAuthorizationHold(hold2("spent"));
|
|
1589
|
+
await s.transitionAuthorizationHold("spent", "consumed");
|
|
1590
|
+
assert2.equal(await s.transitionAuthorizationHold("spent", "released"), false);
|
|
1591
|
+
assert2.equal(await s.transitionAuthorizationHold("spent", "uncertain"), false);
|
|
1592
|
+
assert2.equal(await s.getAuthorizationHoldState("spent"), "consumed");
|
|
1593
|
+
await s.reserveAuthorizationHold(hold2("freed"));
|
|
1594
|
+
await s.transitionAuthorizationHold("freed", "released");
|
|
1595
|
+
assert2.equal(await s.transitionAuthorizationHold("freed", "consumed"), false);
|
|
1596
|
+
assert2.equal(await s.getAuthorizationHoldState("freed"), "released");
|
|
1597
|
+
}
|
|
1598
|
+
},
|
|
1599
|
+
{
|
|
1600
|
+
name: "a repeated hold transition returns true, and a missing hold false",
|
|
1601
|
+
uses: HOLDS,
|
|
1602
|
+
async run({ store }) {
|
|
1603
|
+
const s = holds(store);
|
|
1604
|
+
await s.reserveAuthorizationHold(hold2("ref1"));
|
|
1605
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-ref1"), true);
|
|
1606
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-ref1"), true);
|
|
1607
|
+
assert2.equal(await s.transitionAuthorizationHold("missing", "released"), false);
|
|
1608
|
+
}
|
|
1609
|
+
},
|
|
1610
|
+
{
|
|
1611
|
+
name: "an uncertain hold can still be consumed or released",
|
|
1612
|
+
uses: HOLDS,
|
|
1613
|
+
async run({ store }) {
|
|
1614
|
+
const s = holds(store);
|
|
1615
|
+
for (const to of ["consumed", "released"]) {
|
|
1616
|
+
await s.reserveAuthorizationHold(hold2(to));
|
|
1617
|
+
assert2.equal(await s.transitionAuthorizationHold(to, "uncertain"), true);
|
|
1618
|
+
assert2.equal(await s.transitionAuthorizationHold(to, to), true);
|
|
1619
|
+
assert2.equal(await s.getAuthorizationHoldState(to), to);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1623
|
+
{
|
|
1624
|
+
name: "a former holder cannot change a hold reserved by a new request",
|
|
1625
|
+
uses: HOLDS,
|
|
1626
|
+
async run({ store }) {
|
|
1627
|
+
const s = holds(store);
|
|
1628
|
+
await s.reserveAuthorizationHold(hold2("ref1", { requestId: "req-a" }));
|
|
1629
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "released", "req-a"), true);
|
|
1630
|
+
assert2.deepEqual(await s.reserveAuthorizationHold(hold2("ref1", { requestId: "req-b" })), {
|
|
1631
|
+
kind: "reserved"
|
|
1632
|
+
});
|
|
1633
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-a"), false);
|
|
1634
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "uncertain", "req-a"), false);
|
|
1635
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "released", "req-a"), true);
|
|
1636
|
+
assert2.equal(await s.getAuthorizationHoldState("ref1"), "reserved");
|
|
1637
|
+
assert2.equal(await s.transitionAuthorizationHold("ref1", "consumed", "req-b"), true);
|
|
1638
|
+
}
|
|
1639
|
+
},
|
|
1640
|
+
{
|
|
1641
|
+
name: "orphan holds are old reserved holds whose request has no payment attempt",
|
|
1642
|
+
uses: HOLDS,
|
|
1643
|
+
async run({ store, clock }) {
|
|
1644
|
+
const s = holds(store);
|
|
1645
|
+
const attempt = (requestId, replayKey) => ({
|
|
1646
|
+
requestId,
|
|
1647
|
+
resourceId: "resource.report",
|
|
1648
|
+
provider: "x402",
|
|
1649
|
+
replayKey,
|
|
1650
|
+
amount: "0.01",
|
|
1651
|
+
currency: "USDC"
|
|
1652
|
+
});
|
|
1653
|
+
const metadata = { mandateIssuer: "https://issuer.example" };
|
|
1654
|
+
await s.reserveAuthorizationHold(hold2("orphan", { requestId: "req-orphan", metadata }));
|
|
1655
|
+
await s.reserveAuthorizationHold(hold2("paying", { requestId: "req-paying" }));
|
|
1656
|
+
await s.reservePaymentAttempt(attempt("req-paying", "rk-paying"));
|
|
1657
|
+
await s.reserveAuthorizationHold(hold2("spent", { requestId: "req-spent" }));
|
|
1658
|
+
await s.transitionAuthorizationHold("spent", "consumed");
|
|
1659
|
+
await s.reserveAuthorizationHold(hold2("replaced", { requestId: "req-replaced" }));
|
|
1660
|
+
await s.reservePaymentAttempt(attempt("req-replaced", "rk-replaced"));
|
|
1661
|
+
await s.updatePaymentAttempt({ replayKey: "rk-replaced", status: "rejected" });
|
|
1662
|
+
await s.reservePaymentAttempt({ ...attempt("req-retry", "rk-replaced"), reclaimRejected: true }).catch(() => void 0);
|
|
1663
|
+
clock.advance(10 * MINUTE);
|
|
1664
|
+
await s.reserveAuthorizationHold(hold2("young", { requestId: "req-young" }));
|
|
1665
|
+
clock.advance(MINUTE);
|
|
1666
|
+
const orphans = await s.listOrphanAuthorizationHolds({ updatedBefore: isoAt(5 * MINUTE) });
|
|
1667
|
+
assert2.deepEqual(orphans, [
|
|
1668
|
+
{
|
|
1669
|
+
...hold2("orphan", { requestId: "req-orphan", metadata }),
|
|
1670
|
+
state: "reserved",
|
|
1671
|
+
createdAt: isoAt(0),
|
|
1672
|
+
updatedAt: isoAt(0)
|
|
1673
|
+
}
|
|
1674
|
+
]);
|
|
1675
|
+
const all = await s.listOrphanAuthorizationHolds({ updatedBefore: isoAt(11 * MINUTE) });
|
|
1676
|
+
assert2.deepEqual(
|
|
1677
|
+
all.map((h) => h.reference),
|
|
1678
|
+
["orphan", "young"]
|
|
1679
|
+
);
|
|
1680
|
+
const first = await s.listOrphanAuthorizationHolds({
|
|
1681
|
+
updatedBefore: isoAt(11 * MINUTE),
|
|
1682
|
+
limit: 1
|
|
1683
|
+
});
|
|
1684
|
+
assert2.deepEqual(
|
|
1685
|
+
first.map((h) => h.reference),
|
|
1686
|
+
["orphan"]
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
name: "concurrent reservations of one reference reserve it once",
|
|
1692
|
+
uses: HOLDS,
|
|
1693
|
+
async run({ store }) {
|
|
1694
|
+
const s = holds(store);
|
|
1695
|
+
const results = await Promise.all(
|
|
1696
|
+
Array.from(
|
|
1697
|
+
{ length: 8 },
|
|
1698
|
+
(_, i) => s.reserveAuthorizationHold(hold2("ref1", { requestId: `req-${i}` }))
|
|
1699
|
+
)
|
|
1700
|
+
);
|
|
1701
|
+
assert2.equal(
|
|
1702
|
+
count(results, (r) => r.kind === "reserved"),
|
|
1703
|
+
1
|
|
1704
|
+
);
|
|
1705
|
+
assert2.equal(
|
|
1706
|
+
count(results, (r) => r.kind === "replayed"),
|
|
1707
|
+
7
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1710
|
+
},
|
|
1711
|
+
{
|
|
1712
|
+
name: "concurrent reservations of two references on one binding reserve one",
|
|
1713
|
+
uses: HOLDS,
|
|
1714
|
+
async run({ store }) {
|
|
1715
|
+
const s = holds(store);
|
|
1716
|
+
const shared = { bindingReference: "checkout-jti" };
|
|
1717
|
+
const results = await Promise.all([
|
|
1718
|
+
s.reserveAuthorizationHold(hold2("ref1", shared)),
|
|
1719
|
+
s.reserveAuthorizationHold(hold2("ref2", shared))
|
|
1720
|
+
]);
|
|
1721
|
+
assert2.equal(
|
|
1722
|
+
count(results, (r) => r.kind === "reserved"),
|
|
1723
|
+
1
|
|
1724
|
+
);
|
|
1725
|
+
}
|
|
1726
|
+
},
|
|
1727
|
+
{
|
|
1728
|
+
name: "authorization holds survive a reopen",
|
|
1729
|
+
uses: HOLDS,
|
|
1730
|
+
needsReopen: true,
|
|
1731
|
+
async run({ store, reopen }) {
|
|
1732
|
+
const s = holds(store);
|
|
1733
|
+
await s.reserveAuthorizationHold(hold2("spent"));
|
|
1734
|
+
await s.transitionAuthorizationHold("spent", "consumed");
|
|
1735
|
+
await s.reserveAuthorizationHold(hold2("held"));
|
|
1736
|
+
const reopened = holds(await reopen());
|
|
1737
|
+
assert2.equal(await reopened.getAuthorizationHoldState("spent"), "consumed");
|
|
1738
|
+
assert2.deepEqual(await reopened.reserveAuthorizationHold(hold2("spent")), {
|
|
1739
|
+
kind: "replayed",
|
|
1740
|
+
state: "consumed"
|
|
1741
|
+
});
|
|
1742
|
+
assert2.deepEqual(
|
|
1743
|
+
await reopened.reserveAuthorizationHold(
|
|
1744
|
+
hold2("other", { bindingReference: "binding-of-held" })
|
|
1745
|
+
),
|
|
1746
|
+
{ kind: "replayed", state: "reserved" }
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
];
|
|
1751
|
+
var TASK_CASES = [
|
|
1752
|
+
{
|
|
1753
|
+
name: "a pending task reads back until it is taken, and only once",
|
|
1754
|
+
uses: TASKS,
|
|
1755
|
+
async run({ store }) {
|
|
1756
|
+
const s = tasks(store);
|
|
1757
|
+
const stored = task("task1", { adapterData: { contextId: "ctx", network: "eip155:8453" } });
|
|
1758
|
+
assert2.equal(await s.putPendingTask(stored, { maxTasks: 10 }), true);
|
|
1759
|
+
assert2.deepEqual(await s.getPendingTask("task1"), stored);
|
|
1760
|
+
assert2.deepEqual(await s.takePendingTask("task1"), stored);
|
|
1761
|
+
assert2.equal(await s.getPendingTask("task1"), void 0);
|
|
1762
|
+
assert2.equal(await s.takePendingTask("task1"), void 0);
|
|
1763
|
+
const plain = task("task2");
|
|
1764
|
+
await s.putPendingTask(plain, { maxTasks: 10 });
|
|
1765
|
+
assert2.deepEqual(await s.getPendingTask("task2"), plain);
|
|
1766
|
+
}
|
|
1767
|
+
},
|
|
1768
|
+
{
|
|
1769
|
+
name: "a pending task with the same id replaces the earlier one",
|
|
1770
|
+
uses: TASKS,
|
|
1771
|
+
async run({ store }) {
|
|
1772
|
+
const s = tasks(store);
|
|
1773
|
+
await s.putPendingTask(task("task1"), { maxTasks: 10 });
|
|
1774
|
+
const replacement = task("task1", { input: { symbol: "BTC" } });
|
|
1775
|
+
await s.putPendingTask(replacement, { maxTasks: 10 });
|
|
1776
|
+
assert2.deepEqual(await s.getPendingTask("task1"), replacement);
|
|
1777
|
+
}
|
|
1778
|
+
},
|
|
1779
|
+
{
|
|
1780
|
+
name: "an expired pending task cannot be read or taken",
|
|
1781
|
+
uses: TASKS,
|
|
1782
|
+
async run({ store, clock }) {
|
|
1783
|
+
const s = tasks(store);
|
|
1784
|
+
const stored = task("task1", { expiresAt: isoAt(MINUTE) });
|
|
1785
|
+
await s.putPendingTask(stored, { maxTasks: 10 });
|
|
1786
|
+
clock.advance(MINUTE - 1);
|
|
1787
|
+
assert2.deepEqual(await s.getPendingTask("task1"), stored);
|
|
1788
|
+
clock.advance(2);
|
|
1789
|
+
assert2.equal(await s.getPendingTask("task1"), void 0);
|
|
1790
|
+
assert2.equal(await s.takePendingTask("task1"), void 0);
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
name: "maxTasks refuses a task while that many are unexpired",
|
|
1795
|
+
uses: TASKS,
|
|
1796
|
+
async run({ store, clock }) {
|
|
1797
|
+
const s = tasks(store);
|
|
1798
|
+
const soon = { expiresAt: isoAt(MINUTE) };
|
|
1799
|
+
assert2.equal(await s.putPendingTask(task("a", soon), { maxTasks: 2 }), true);
|
|
1800
|
+
assert2.equal(await s.putPendingTask(task("b", soon), { maxTasks: 2 }), true);
|
|
1801
|
+
assert2.equal(await s.putPendingTask(task("c"), { maxTasks: 2 }), false);
|
|
1802
|
+
assert2.equal(await s.getPendingTask("c"), void 0);
|
|
1803
|
+
clock.advance(MINUTE + 1);
|
|
1804
|
+
assert2.equal(await s.putPendingTask(task("c"), { maxTasks: 2 }), true);
|
|
1805
|
+
assert2.equal(await s.putPendingTask(task("d"), { maxTasks: 2 }), true);
|
|
1806
|
+
assert2.equal(await s.putPendingTask(task("e"), { maxTasks: 2 }), false);
|
|
1807
|
+
}
|
|
1808
|
+
},
|
|
1809
|
+
{
|
|
1810
|
+
name: "concurrent takes of one pending task return it once",
|
|
1811
|
+
uses: TASKS,
|
|
1812
|
+
async run({ store }) {
|
|
1813
|
+
const s = tasks(store);
|
|
1814
|
+
await s.putPendingTask(task("task1"), { maxTasks: 10 });
|
|
1815
|
+
const results = await Promise.all(
|
|
1816
|
+
Array.from({ length: 8 }, () => s.takePendingTask("task1"))
|
|
1817
|
+
);
|
|
1818
|
+
assert2.equal(
|
|
1819
|
+
count(results, (r) => r !== void 0),
|
|
1820
|
+
1
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
},
|
|
1824
|
+
{
|
|
1825
|
+
name: "pending tasks survive a reopen",
|
|
1826
|
+
uses: TASKS,
|
|
1827
|
+
needsReopen: true,
|
|
1828
|
+
async run({ store, reopen }) {
|
|
1829
|
+
const s = tasks(store);
|
|
1830
|
+
const stored = task("task1", { adapterData: { contextId: "ctx" } });
|
|
1831
|
+
await s.putPendingTask(stored, { maxTasks: 10 });
|
|
1832
|
+
const reopened = tasks(await reopen());
|
|
1833
|
+
assert2.deepEqual(await reopened.takePendingTask("task1"), stored);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
];
|
|
1837
|
+
var RECORD_CASES = [...CLAIM_CASES, ...HOLD_CASES, ...TASK_CASES];
|
|
1838
|
+
|
|
1839
|
+
// src/testing/store-conformance.ts
|
|
1840
|
+
var METHOD_GROUPS = STORE_METHOD_GROUPS;
|
|
1841
|
+
var implemented = (store, method) => typeof store[method] === "function";
|
|
1842
|
+
var GROUP_CASE = {
|
|
1843
|
+
name: "implements each optional method group completely or not at all",
|
|
1844
|
+
async run({ store }) {
|
|
1845
|
+
for (const [group, methods] of Object.entries(METHOD_GROUPS)) {
|
|
1846
|
+
const present = methods.filter((m) => implemented(store, m));
|
|
1847
|
+
if (present.length !== 0 && present.length !== methods.length) {
|
|
1848
|
+
throw new Error(`${group}: implements ${present.join(", ")} but not the rest of the group`);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
async function receiptStoreConformanceCases(open) {
|
|
1854
|
+
const probe = await open({ clock: createConformanceClock() });
|
|
1855
|
+
const canReopen = probe.reopen !== void 0;
|
|
1856
|
+
const missing = (spec) => {
|
|
1857
|
+
const absent = (spec.uses ?? []).filter((m) => !implemented(probe.store, m));
|
|
1858
|
+
if (absent.length > 0) return `the store does not implement ${absent.join(", ")}`;
|
|
1859
|
+
if (spec.needsReopen === true && !canReopen) return "the factory supplies no reopen()";
|
|
1860
|
+
return void 0;
|
|
1861
|
+
};
|
|
1862
|
+
const cases = [GROUP_CASE, ...CORE_CASES, ...RECORD_CASES].map((spec) => {
|
|
1863
|
+
const skip = missing(spec);
|
|
1864
|
+
return {
|
|
1865
|
+
name: spec.name,
|
|
1866
|
+
...skip !== void 0 ? { skip } : {},
|
|
1867
|
+
run: () => runCase(open, spec)
|
|
1868
|
+
};
|
|
1869
|
+
});
|
|
1870
|
+
await probe.store.close();
|
|
1871
|
+
return cases;
|
|
1872
|
+
}
|
|
1873
|
+
async function runCase(open, spec) {
|
|
1874
|
+
const clock = createConformanceClock();
|
|
1875
|
+
const opened = await open({ clock });
|
|
1876
|
+
let current = opened.store;
|
|
1877
|
+
try {
|
|
1878
|
+
await current.init();
|
|
1879
|
+
await spec.run({
|
|
1880
|
+
store: current,
|
|
1881
|
+
clock,
|
|
1882
|
+
async reopen() {
|
|
1883
|
+
if (opened.reopen === void 0) throw new Error("the factory supplies no reopen()");
|
|
1884
|
+
current = await opened.reopen();
|
|
1885
|
+
await current.init();
|
|
1886
|
+
return current;
|
|
1887
|
+
}
|
|
1888
|
+
});
|
|
1889
|
+
} finally {
|
|
1890
|
+
await current.close();
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
export { receiptStoreConformanceCases };
|
|
1895
|
+
//# sourceMappingURL=testing.js.map
|
|
1896
|
+
//# sourceMappingURL=testing.js.map
|