@layerzerolabs/gated-transaction 0.0.61 → 0.0.63

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.
Files changed (40) hide show
  1. package/.turbo/turbo-build.log +27 -43
  2. package/.turbo/turbo-test.log +5 -6
  3. package/dist/{VH2LMV2W.js → SGAQYA4D.js} +2 -2
  4. package/dist/{VH2LMV2W.js.map → SGAQYA4D.js.map} +1 -1
  5. package/dist/{UVQ5QQ4U.cjs → UV63UNW4.cjs} +2 -2
  6. package/dist/{UVQ5QQ4U.cjs.map → UV63UNW4.cjs.map} +1 -1
  7. package/dist/index.cjs +10 -32
  8. package/dist/index.d.ts +0 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -3
  11. package/dist/schemata.cjs +10 -10
  12. package/dist/schemata.d.ts +0 -4
  13. package/dist/schemata.d.ts.map +1 -1
  14. package/dist/schemata.js +1 -1
  15. package/package.json +8 -11
  16. package/src/index.ts +0 -2
  17. package/src/schemata.ts +0 -5
  18. package/dist/CZKVKTL4.cjs +0 -107
  19. package/dist/CZKVKTL4.cjs.map +0 -1
  20. package/dist/JMMYK2SL.js +0 -103
  21. package/dist/JMMYK2SL.js.map +0 -1
  22. package/dist/ONVFWJXG.js +0 -250
  23. package/dist/ONVFWJXG.js.map +0 -1
  24. package/dist/XROB6QHI.cjs +0 -257
  25. package/dist/XROB6QHI.cjs.map +0 -1
  26. package/dist/gatedTransactionSignalLock.cjs +0 -22
  27. package/dist/gatedTransactionSignalLock.cjs.map +0 -1
  28. package/dist/gatedTransactionSignalLock.d.ts +0 -20
  29. package/dist/gatedTransactionSignalLock.d.ts.map +0 -1
  30. package/dist/gatedTransactionSignalLock.js +0 -5
  31. package/dist/gatedTransactionSignalLock.js.map +0 -1
  32. package/dist/resolver.cjs +0 -19
  33. package/dist/resolver.cjs.map +0 -1
  34. package/dist/resolver.d.ts +0 -24
  35. package/dist/resolver.d.ts.map +0 -1
  36. package/dist/resolver.js +0 -6
  37. package/dist/resolver.js.map +0 -1
  38. package/src/gatedTransactionSignalLock.ts +0 -143
  39. package/src/resolver.ts +0 -448
  40. package/test/resolver.test.ts +0 -425
@@ -1,425 +0,0 @@
1
- import { describe, expect, test, vi } from 'vitest';
2
-
3
- import { WorkflowFunctions } from '@layerzerolabs/common-workflow';
4
- import { Logger } from '@layerzerolabs/logger-node';
5
-
6
- import {
7
- constructGatedTransaction,
8
- constructGatedTransactionFromPointer,
9
- getIdForGatedTransaction,
10
- } from '../src/gatedTx';
11
- import { resolveGatedTransactions } from '../src/resolver';
12
- import type { GatedTransaction } from '../src/schemata';
13
- import { GatedTransactionStatus } from '../src/schemata';
14
-
15
- type Handler = {
16
- initial?: (...args: any[]) => any | Promise<any>;
17
- final?: (...args: any[]) => any | Promise<any>;
18
- };
19
-
20
- const makeRegistry = (handlers: Record<string, Handler>) => ({
21
- callByPointer: async (fn: string, params: any[]) => {
22
- const h = handlers[fn];
23
- if (!h) throw new Error(`No handler for ${fn}`);
24
- const isFinal = params.length > 0 || (h.final != null && h.initial == null);
25
- if (isFinal) {
26
- if (h.final) return await h.final(...params);
27
- if (h.initial) return await h.initial(...params);
28
- return undefined;
29
- }
30
- if (h.initial) return await h.initial(...params);
31
- return undefined;
32
- },
33
- });
34
-
35
- const makeTx = (name: string, functionPointer: string, expected: any, deps?: GatedTransaction[]) =>
36
- constructGatedTransaction({
37
- name,
38
- chainName: 'test-chain',
39
- transaction: { name } as any,
40
- check: {
41
- functionPointer: functionPointer as any,
42
- params: [],
43
- expectedResult: { operator: '=', comparisonValue: expected },
44
- },
45
- uniqueIdKeys: { name },
46
- dependencies: deps,
47
- });
48
-
49
- const makeProcessedTx = () =>
50
- ({
51
- chainName: 'test-chain',
52
- timestamps: { created: Date.now() },
53
- }) as any;
54
-
55
- const makeFn = (): WorkflowFunctions =>
56
- ({
57
- condition: async (predicate) => {
58
- while (true) {
59
- if (predicate()) {
60
- return true;
61
- }
62
- await new Promise((res) => setTimeout(res, 100));
63
- }
64
- },
65
- }) as WorkflowFunctions;
66
-
67
- const makeLogger = (): Logger =>
68
- ({
69
- log: vi.fn(),
70
- trace: vi.fn(),
71
- debug: vi.fn(),
72
- info: vi.fn(),
73
- warn: vi.fn(),
74
- error: vi.fn(),
75
- }) as Logger;
76
-
77
- describe('resolveGatedTransactions - dependency and edge cases', () => {
78
- test('internal dependency NO_OP enables dependent to execute and succeed', async () => {
79
- const registry = makeRegistry({
80
- checkA: { initial: () => true }, // A already satisfied
81
- checkB: {
82
- initial: () => false, // B needs sending
83
- final: () => true, // After sending, satisfied
84
- },
85
- });
86
-
87
- const processTx = vi.fn(async (_tx) => makeProcessedTx());
88
-
89
- const txA = makeTx('A', 'checkA', true);
90
- const txB = makeTx('B', 'checkB', true, [txA]);
91
-
92
- const [resA, resB] = await resolveGatedTransactions({
93
- activityRegistry: registry as any,
94
- gatedTxes: [txA, txB],
95
- processTx,
96
- fn: makeFn(),
97
- logger: makeLogger(),
98
- });
99
-
100
- expect(resA.result.status).toBe(GatedTransactionStatus.NO_OP);
101
- expect(resB.result.status).toBe(GatedTransactionStatus.SUCCESS);
102
- expect(processTx).toHaveBeenCalledTimes(1);
103
- });
104
-
105
- test('internal dependency SUCCESS enables dependent to execute', async () => {
106
- const registry = makeRegistry({
107
- checkA: { initial: () => false, final: () => true },
108
- checkB: { initial: () => false, final: () => true },
109
- });
110
- const processTx = vi.fn(async (_tx) => makeProcessedTx());
111
-
112
- const txA = makeTx('A', 'checkA', true);
113
- const txB = makeTx('B', 'checkB', true, [txA]);
114
-
115
- const [resA, resB] = await resolveGatedTransactions({
116
- activityRegistry: registry as any,
117
- gatedTxes: [txA, txB],
118
- processTx,
119
- fn: makeFn(),
120
- logger: makeLogger(),
121
- });
122
-
123
- expect(resA.result.status).toBe(GatedTransactionStatus.SUCCESS);
124
- expect(resB.result.status).toBe(GatedTransactionStatus.SUCCESS);
125
- expect(processTx).toHaveBeenCalledTimes(2);
126
- });
127
-
128
- test('internal dependency TRANSACTION_FAILED causes dependent DEPENDENCY_FAILED', async () => {
129
- const registry = makeRegistry({
130
- checkA: { initial: () => false, final: () => false },
131
- checkB: { initial: () => false, final: () => true },
132
- });
133
- const processTx = vi.fn(async (_tx) => {
134
- throw new Error('failed to submit');
135
- });
136
-
137
- const txA = makeTx('A', 'checkA', true);
138
- const txB = makeTx('B', 'checkB', true, [txA]);
139
-
140
- const [resA, resB] = await resolveGatedTransactions({
141
- activityRegistry: registry as any,
142
- gatedTxes: [txA, txB],
143
- processTx,
144
- fn: makeFn(),
145
- logger: makeLogger(),
146
- });
147
-
148
- expect(resA.result.status).toBe(GatedTransactionStatus.TRANSACTION_FAILED);
149
- expect(resB.result.status).toBe(GatedTransactionStatus.DEPENDENCY_FAILED);
150
- expect(processTx).toHaveBeenCalledTimes(1);
151
- });
152
-
153
- test('external dependency satisfied by precheck allows dependent to execute', async () => {
154
- const registry = makeRegistry({
155
- checkExt: { initial: () => true },
156
- checkB: { initial: () => false, final: () => true },
157
- });
158
- const processTx = vi.fn(async (_tx) => makeProcessedTx());
159
-
160
- const ext = makeTx('Ext', 'checkExt', true);
161
- const txB = makeTx('B', 'checkB', true, [ext]);
162
-
163
- const [resB] = await resolveGatedTransactions({
164
- activityRegistry: registry as any,
165
- gatedTxes: [txB],
166
- processTx,
167
- fn: makeFn(),
168
- logger: makeLogger(),
169
- });
170
-
171
- expect(resB.result.status).toBe(GatedTransactionStatus.SUCCESS);
172
- expect(processTx).toHaveBeenCalledTimes(1);
173
- });
174
-
175
- test('external dependency unsatisfied by precheck causes dependent DEPENDENCY_FAILED', async () => {
176
- const registry = makeRegistry({
177
- checkExt: { initial: () => false },
178
- checkB: { initial: () => false, final: () => true },
179
- });
180
- const processTx = vi.fn(async (_tx) => makeProcessedTx());
181
-
182
- const ext = makeTx('Ext', 'checkExt', true);
183
- const txB = makeTx('B', 'checkB', true, [ext]);
184
-
185
- const [resB] = await resolveGatedTransactions({
186
- activityRegistry: registry as any,
187
- gatedTxes: [txB],
188
- processTx,
189
- fn: makeFn(),
190
- logger: makeLogger(),
191
- });
192
-
193
- expect(resB.result.status).toBe(GatedTransactionStatus.DEPENDENCY_FAILED);
194
- expect(processTx).toHaveBeenCalledTimes(0);
195
- });
196
-
197
- test('confirmation denial throws before sending', async () => {
198
- const registry = makeRegistry({ checkA: { initial: () => false } });
199
- const processTx = vi.fn(async (_tx) => makeProcessedTx());
200
- const txA = makeTx('A', 'checkA', true);
201
-
202
- const result = await resolveGatedTransactions({
203
- activityRegistry: registry as any,
204
- gatedTxes: [txA],
205
- processTx,
206
- userInteractionCallbacks: { confirmationCallback: async () => false },
207
- fn: makeFn(),
208
- logger: makeLogger(),
209
- });
210
-
211
- expect(result[0].result.status).toStrictEqual(GatedTransactionStatus.DENIED);
212
- expect(processTx).toHaveBeenCalledTimes(0);
213
- });
214
-
215
- test('same name + chain, different cache keys', async () => {
216
- const registry = {
217
- callByPointer: async (_fn: string, params: any[]) => {
218
- // final check when params length > 0
219
- return params.length > 0 ? true : false;
220
- },
221
- } as any;
222
-
223
- const processTx = vi.fn(
224
- async (_tx) =>
225
- ({
226
- chainName: 'test-chain',
227
- timestamps: { created: Date.now() },
228
- }) as any,
229
- );
230
-
231
- const tx1 = constructGatedTransaction({
232
- name: 'X',
233
- chainName: 'test-chain',
234
- transaction: { name: 'X', chainName: 'chainA' } as any,
235
- check: {
236
- functionPointer: 'checkX' as any,
237
- params: [],
238
- expectedResult: { operator: '=', comparisonValue: true },
239
- },
240
- uniqueIdKeys: { key: '1' },
241
- });
242
-
243
- const tx2 = constructGatedTransaction({
244
- name: 'X',
245
- chainName: 'test-chain',
246
- transaction: { name: 'X', chainName: 'chainA' } as any,
247
- check: {
248
- functionPointer: 'checkX' as any,
249
- params: [],
250
- expectedResult: { operator: '=', comparisonValue: true },
251
- },
252
- uniqueIdKeys: { key: '2' },
253
- });
254
-
255
- const id1 = getIdForGatedTransaction(tx1);
256
- const id2 = getIdForGatedTransaction(tx2);
257
- expect(id1).not.toBe(id2);
258
-
259
- const [r1, r2] = await resolveGatedTransactions({
260
- activityRegistry: registry as any,
261
- gatedTxes: [tx1, tx2],
262
- processTx,
263
- fn: makeFn(),
264
- logger: makeLogger(),
265
- });
266
-
267
- expect(r1.result.status).toBe(GatedTransactionStatus.SUCCESS);
268
- expect(r2.result.status).toBe(GatedTransactionStatus.SUCCESS);
269
- expect(processTx).toHaveBeenCalledTimes(2);
270
- });
271
- });
272
-
273
- describe('resolveGatedTransactions - functional transactions', () => {
274
- test('functional transaction without dependencies builds and succeeds', async () => {
275
- const registry = makeRegistry({
276
- buildFn: {
277
- final: () => ({ name: 'F', built: true }) as any,
278
- },
279
- checkF: {
280
- initial: () => false,
281
- final: () => true,
282
- },
283
- });
284
-
285
- const processTx = vi.fn(async (tx) => {
286
- expect(tx).toMatchObject({ name: 'F', built: true });
287
- return makeProcessedTx();
288
- });
289
-
290
- const txF = constructGatedTransactionFromPointer({
291
- name: 'F',
292
- chainName: 'test-chain',
293
- dependencies: [],
294
- check: {
295
- functionPointer: 'checkF' as any,
296
- params: [],
297
- expectedResult: { operator: '=', comparisonValue: true },
298
- },
299
- getTransaction: {
300
- functionPointer: 'buildFn' as any,
301
- params: [],
302
- },
303
- uniqueIdKeys: { name: 'F' },
304
- });
305
-
306
- const [resF] = await resolveGatedTransactions({
307
- activityRegistry: registry as any,
308
- gatedTxes: [txF],
309
- processTx,
310
- fn: makeFn(),
311
- logger: makeLogger(),
312
- });
313
-
314
- expect(resF.result.status).toBe(GatedTransactionStatus.SUCCESS);
315
- expect(processTx).toHaveBeenCalledTimes(1);
316
- });
317
-
318
- test('functional transaction builds from dependency data and succeeds', async () => {
319
- const registry = makeRegistry({
320
- depCheck: {
321
- initial: () => false,
322
- final: () => 10,
323
- },
324
- buildFromDep: {
325
- final: (...deps: any[]) => ({ name: 'F2', builtFrom: deps[0] }) as any,
326
- },
327
- checkF2: {
328
- initial: () => false,
329
- final: () => true,
330
- },
331
- });
332
-
333
- const dep = constructGatedTransaction({
334
- name: 'Dep',
335
- chainName: 'test-chain',
336
- transaction: { name: 'DepTx' } as any,
337
- check: {
338
- functionPointer: 'depCheck' as any,
339
- params: [],
340
- expectedResult: { operator: '=', comparisonValue: 10 },
341
- },
342
- uniqueIdKeys: { name: 'Dep' },
343
- });
344
-
345
- const func = constructGatedTransactionFromPointer({
346
- name: 'F2',
347
- chainName: 'test-chain',
348
- check: {
349
- functionPointer: 'checkF2' as any,
350
- params: [],
351
- expectedResult: { operator: '=', comparisonValue: true },
352
- },
353
- getTransaction: {
354
- functionPointer: 'buildFromDep' as any,
355
- params: [],
356
- },
357
- uniqueIdKeys: { name: 'F2' },
358
- dependencies: [dep],
359
- });
360
-
361
- const processTx = vi.fn(async (tx) => {
362
- // ensure the built tx used dependency output (10)
363
- if (tx.name === 'F2') {
364
- delete (dep as any).transaction;
365
- delete (dep as any).transactionType;
366
- expect(tx.builtFrom[0]).toMatchObject(dep);
367
- }
368
- return makeProcessedTx();
369
- });
370
-
371
- const [resDep, resFunc] = await resolveGatedTransactions({
372
- activityRegistry: registry as any,
373
- gatedTxes: [dep, func],
374
- processTx,
375
- fn: makeFn(),
376
- logger: makeLogger(),
377
- });
378
-
379
- expect(resDep.result.status).toBe(GatedTransactionStatus.SUCCESS);
380
- expect(resFunc.result.status).toBe(GatedTransactionStatus.SUCCESS);
381
- expect(processTx).toHaveBeenCalledTimes(2);
382
- });
383
-
384
- test('functional getTransactionPointer error yields TRANSACTION_FAILED', async () => {
385
- const registry = makeRegistry({
386
- buildBad: {
387
- final: () => {
388
- throw new Error('build failed');
389
- },
390
- },
391
- checkFBad: {
392
- initial: () => false,
393
- },
394
- });
395
-
396
- const processTx = vi.fn(async (_tx) => makeProcessedTx());
397
-
398
- const tx = constructGatedTransactionFromPointer({
399
- name: 'FBad',
400
- chainName: 'test-chain',
401
- dependencies: [],
402
- check: {
403
- functionPointer: 'checkFBad' as any,
404
- params: [],
405
- expectedResult: { operator: '=', comparisonValue: true },
406
- },
407
- getTransaction: {
408
- functionPointer: 'buildBad' as any,
409
- params: [],
410
- },
411
- uniqueIdKeys: { name: 'FBad' },
412
- });
413
-
414
- const [res] = await resolveGatedTransactions({
415
- activityRegistry: registry as any,
416
- gatedTxes: [tx],
417
- processTx,
418
- fn: makeFn(),
419
- logger: makeLogger(),
420
- });
421
-
422
- expect(res.result.status).toBe(GatedTransactionStatus.TRANSACTION_FAILED);
423
- expect(processTx).toHaveBeenCalledTimes(0);
424
- });
425
- });