@ledgerhq/coin-sui 0.12.0-nightly.1 → 0.12.0-nightly.2

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 (43) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/lib/api/index.integration.test.js +9 -2
  4. package/lib/api/index.integration.test.js.map +1 -1
  5. package/lib/api/index.test.js +2 -2
  6. package/lib/api/index.test.js.map +1 -1
  7. package/lib/logic/listOperations.d.ts +1 -3
  8. package/lib/logic/listOperations.d.ts.map +1 -1
  9. package/lib/logic/listOperations.js +3 -3
  10. package/lib/logic/listOperations.js.map +1 -1
  11. package/lib/logic/listOperations.test.js +43 -39
  12. package/lib/logic/listOperations.test.js.map +1 -1
  13. package/lib/network/index.d.ts +1 -1
  14. package/lib/network/sdk.d.ts +9 -5
  15. package/lib/network/sdk.d.ts.map +1 -1
  16. package/lib/network/sdk.js +52 -25
  17. package/lib/network/sdk.js.map +1 -1
  18. package/lib/network/sdk.test.js +269 -170
  19. package/lib/network/sdk.test.js.map +1 -1
  20. package/lib-es/api/index.integration.test.js +9 -2
  21. package/lib-es/api/index.integration.test.js.map +1 -1
  22. package/lib-es/api/index.test.js +2 -2
  23. package/lib-es/api/index.test.js.map +1 -1
  24. package/lib-es/logic/listOperations.d.ts +1 -3
  25. package/lib-es/logic/listOperations.d.ts.map +1 -1
  26. package/lib-es/logic/listOperations.js +4 -4
  27. package/lib-es/logic/listOperations.js.map +1 -1
  28. package/lib-es/logic/listOperations.test.js +44 -40
  29. package/lib-es/logic/listOperations.test.js.map +1 -1
  30. package/lib-es/network/index.d.ts +1 -1
  31. package/lib-es/network/sdk.d.ts +9 -5
  32. package/lib-es/network/sdk.d.ts.map +1 -1
  33. package/lib-es/network/sdk.js +52 -25
  34. package/lib-es/network/sdk.js.map +1 -1
  35. package/lib-es/network/sdk.test.js +269 -170
  36. package/lib-es/network/sdk.test.js.map +1 -1
  37. package/package.json +4 -4
  38. package/src/api/index.integration.test.ts +10 -2
  39. package/src/api/index.test.ts +2 -2
  40. package/src/logic/listOperations.test.ts +45 -41
  41. package/src/logic/listOperations.ts +4 -4
  42. package/src/network/sdk.test.ts +309 -207
  43. package/src/network/sdk.ts +68 -30
@@ -1015,8 +1015,8 @@ describe("loadOperations", () => {
1015
1015
  order: "ascending",
1016
1016
  operations: [],
1017
1017
  });
1018
- expect(result).toHaveLength(pageSize + 1);
1019
- expect(result.map(tx => tx.digest)).toEqual([
1018
+ expect(result.operations).toHaveLength(pageSize + 1);
1019
+ expect(result.operations.map(tx => tx.digest)).toEqual([
1020
1020
  ...firstPage.map(tx => tx.digest),
1021
1021
  `tx${pageSize + 1}`,
1022
1022
  ]);
@@ -1038,7 +1038,7 @@ describe("loadOperations", () => {
1038
1038
  order: "ascending",
1039
1039
  operations: [],
1040
1040
  });
1041
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT_PER_QUERY - 1);
1041
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT_PER_QUERY - 1);
1042
1042
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(1);
1043
1043
  });
1044
1044
  it("should not exceed TRANSACTIONS_LIMIT", async () => {
@@ -1062,7 +1062,7 @@ describe("loadOperations", () => {
1062
1062
  order: "ascending",
1063
1063
  operations: [],
1064
1064
  });
1065
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT);
1065
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT);
1066
1066
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(expectedCalls);
1067
1067
  });
1068
1068
  it("should retry without cursor when InvalidParams error occurs", async () => {
@@ -1086,7 +1086,7 @@ describe("loadOperations", () => {
1086
1086
  cursor: "some-cursor",
1087
1087
  }));
1088
1088
  // Result should be empty array (no retry, just return operations)
1089
- expect(result).toHaveLength(0);
1089
+ expect(result.operations).toHaveLength(0);
1090
1090
  });
1091
1091
  it("should should not retry after unexpected errors and return empty data", async () => {
1092
1092
  mockApi.queryTransactionBlocks.mockRejectedValueOnce(new Error("unexpected"));
@@ -1097,7 +1097,7 @@ describe("loadOperations", () => {
1097
1097
  order: "ascending",
1098
1098
  operations: [],
1099
1099
  });
1100
- expect(result).toEqual([]);
1100
+ expect(result.operations).toEqual([]);
1101
1101
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(1);
1102
1102
  });
1103
1103
  });
@@ -1168,18 +1168,24 @@ describe("getOperations filtering logic", () => {
1168
1168
  // Mock loadOperations to return different data based on operation type
1169
1169
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1170
1170
  if (type === "OUT") {
1171
- return [
1172
- createMockTransaction("sent1", "1000", mockAddr, []),
1173
- createMockTransaction("sent2", "2000", mockAddr, []),
1174
- ];
1171
+ return {
1172
+ operations: [
1173
+ createMockTransaction("sent1", "1000", mockAddr, []),
1174
+ createMockTransaction("sent2", "2000", mockAddr, []),
1175
+ ],
1176
+ cursor: null,
1177
+ };
1175
1178
  }
1176
1179
  else if (type === "IN") {
1177
- return [
1178
- createMockTransaction("received1", "1500", otherAddr, [mockAddr]),
1179
- createMockTransaction("received2", "2500", otherAddr, [mockAddr]),
1180
- ];
1180
+ return {
1181
+ operations: [
1182
+ createMockTransaction("received1", "1500", otherAddr, [mockAddr]),
1183
+ createMockTransaction("received2", "2500", otherAddr, [mockAddr]),
1184
+ ],
1185
+ cursor: null,
1186
+ };
1181
1187
  }
1182
- return [];
1188
+ return { operations: [], cursor: null };
1183
1189
  });
1184
1190
  });
1185
1191
  afterEach(() => {
@@ -1202,15 +1208,21 @@ describe("getOperations filtering logic", () => {
1202
1208
  // Mock to return enough sent operations to reach limit
1203
1209
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1204
1210
  if (type === "OUT") {
1205
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []));
1211
+ return {
1212
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, [])),
1213
+ cursor: null,
1214
+ };
1206
1215
  }
1207
1216
  else if (type === "IN") {
1208
- return [
1209
- createMockTransaction("received1", "500", otherAddr, [mockAddr]),
1210
- createMockTransaction("received2", "1500", otherAddr, [mockAddr]),
1211
- ];
1217
+ return {
1218
+ operations: [
1219
+ createMockTransaction("received1", "500", otherAddr, [mockAddr]),
1220
+ createMockTransaction("received2", "1500", otherAddr, [mockAddr]),
1221
+ ],
1222
+ cursor: null,
1223
+ };
1212
1224
  }
1213
- return [];
1225
+ return { operations: [], cursor: null };
1214
1226
  });
1215
1227
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1216
1228
  // Filter timestamp should be the maximum of the last timestamps from both arrays
@@ -1225,15 +1237,23 @@ describe("getOperations filtering logic", () => {
1225
1237
  // Mock to return enough received operations to reach limit
1226
1238
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1227
1239
  if (type === "OUT") {
1228
- return [
1229
- createMockTransaction("sent1", "500", mockAddr, []),
1230
- createMockTransaction("sent2", "1500", mockAddr, []),
1231
- ];
1240
+ return {
1241
+ operations: [
1242
+ createMockTransaction("sent1", "500", mockAddr, []),
1243
+ createMockTransaction("sent2", "1500", mockAddr, []),
1244
+ ],
1245
+ cursor: null,
1246
+ };
1232
1247
  }
1233
1248
  else if (type === "IN") {
1234
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(1000 + i * 100), otherAddr, [mockAddr]));
1249
+ return {
1250
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(1000 + i * 100), otherAddr, [
1251
+ mockAddr,
1252
+ ])),
1253
+ cursor: null,
1254
+ };
1235
1255
  }
1236
- return [];
1256
+ return { operations: [], cursor: null };
1237
1257
  });
1238
1258
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1239
1259
  // Filter timestamp should be the maximum of the last timestamps from both arrays
@@ -1248,12 +1268,20 @@ describe("getOperations filtering logic", () => {
1248
1268
  // Mock to return enough operations to reach limit for both types
1249
1269
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1250
1270
  if (type === "OUT") {
1251
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []));
1271
+ return {
1272
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, [])),
1273
+ cursor: null,
1274
+ };
1252
1275
  }
1253
1276
  else if (type === "IN") {
1254
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(2000 + i * 100), otherAddr, [mockAddr]));
1277
+ return {
1278
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(2000 + i * 100), otherAddr, [
1279
+ mockAddr,
1280
+ ])),
1281
+ cursor: null,
1282
+ };
1255
1283
  }
1256
- return [];
1284
+ return { operations: [], cursor: null };
1257
1285
  });
1258
1286
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1259
1287
  // Filter timestamp should be the maximum of the last timestamps from both arrays
@@ -1268,21 +1296,27 @@ describe("getOperations filtering logic", () => {
1268
1296
  // Mock to return operations with null timestamps and reach limit
1269
1297
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1270
1298
  if (type === "OUT") {
1271
- return [
1272
- createMockTransaction("sent1", "1000", mockAddr, []),
1273
- createMockTransaction("sent2", null, mockAddr, []),
1274
- createMockTransaction("sent3", "3000", mockAddr, []),
1275
- ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`sent${i + 4}`, String(4000 + i * 100), mockAddr, [])),
1276
- ];
1299
+ return {
1300
+ operations: [
1301
+ createMockTransaction("sent1", "1000", mockAddr, []),
1302
+ createMockTransaction("sent2", null, mockAddr, []),
1303
+ createMockTransaction("sent3", "3000", mockAddr, []),
1304
+ ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`sent${i + 4}`, String(4000 + i * 100), mockAddr, [])),
1305
+ ],
1306
+ cursor: null,
1307
+ };
1277
1308
  }
1278
1309
  else if (type === "IN") {
1279
- return [
1280
- createMockTransaction("received1", null, otherAddr, [mockAddr]),
1281
- createMockTransaction("received2", "2000", otherAddr, [mockAddr]),
1282
- createMockTransaction("received3", "4000", otherAddr, [mockAddr]),
1283
- ];
1310
+ return {
1311
+ operations: [
1312
+ createMockTransaction("received1", null, otherAddr, [mockAddr]),
1313
+ createMockTransaction("received2", "2000", otherAddr, [mockAddr]),
1314
+ createMockTransaction("received3", "4000", otherAddr, [mockAddr]),
1315
+ ],
1316
+ cursor: null,
1317
+ };
1284
1318
  }
1285
- return [];
1319
+ return { operations: [], cursor: null };
1286
1320
  });
1287
1321
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1288
1322
  // Filter timestamp should be the timestamp of the last sent operation (4000 + 296*100 = 33600)
@@ -1294,12 +1328,18 @@ describe("getOperations filtering logic", () => {
1294
1328
  // Mock to return operations that reach limit
1295
1329
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1296
1330
  if (type === "OUT") {
1297
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 10), mockAddr, []));
1331
+ return {
1332
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 10), mockAddr, [])),
1333
+ cursor: null,
1334
+ };
1298
1335
  }
1299
1336
  else if (type === "IN") {
1300
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(500 + i * 10), otherAddr, [mockAddr]));
1337
+ return {
1338
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(500 + i * 10), otherAddr, [mockAddr])),
1339
+ cursor: null,
1340
+ };
1301
1341
  }
1302
- return [];
1342
+ return { operations: [], cursor: null };
1303
1343
  });
1304
1344
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1305
1345
  // Should be sorted by timestamp in descending order
@@ -1309,7 +1349,7 @@ describe("getOperations filtering logic", () => {
1309
1349
  test("should handle empty operations arrays", async () => {
1310
1350
  // Mock to return empty arrays
1311
1351
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1312
- return [];
1352
+ return { operations: [], cursor: null };
1313
1353
  });
1314
1354
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1315
1355
  expect(operations).toHaveLength(0);
@@ -1318,15 +1358,18 @@ describe("getOperations filtering logic", () => {
1318
1358
  // Mock to return only OUT operations
1319
1359
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1320
1360
  if (type === "OUT") {
1321
- return [
1322
- createMockTransaction("sent1", "1000", mockAddr, []),
1323
- createMockTransaction("sent2", "2000", mockAddr, []),
1324
- ];
1361
+ return {
1362
+ operations: [
1363
+ createMockTransaction("sent1", "1000", mockAddr, []),
1364
+ createMockTransaction("sent2", "2000", mockAddr, []),
1365
+ ],
1366
+ cursor: null,
1367
+ };
1325
1368
  }
1326
1369
  else if (type === "IN") {
1327
- return [];
1370
+ return { operations: [], cursor: null };
1328
1371
  }
1329
- return [];
1372
+ return { operations: [], cursor: null };
1330
1373
  });
1331
1374
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1332
1375
  expect(operations).toHaveLength(2);
@@ -1336,15 +1379,21 @@ describe("getOperations filtering logic", () => {
1336
1379
  // Mock to return operations with same timestamps and reach limit
1337
1380
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1338
1381
  if (type === "OUT") {
1339
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, "1000", mockAddr, []));
1382
+ return {
1383
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, "1000", mockAddr, [])),
1384
+ cursor: null,
1385
+ };
1340
1386
  }
1341
1387
  else if (type === "IN") {
1342
- return [
1343
- createMockTransaction("received1", "1000", otherAddr, [mockAddr]),
1344
- createMockTransaction("received2", "1000", otherAddr, [mockAddr]),
1345
- ];
1388
+ return {
1389
+ operations: [
1390
+ createMockTransaction("received1", "1000", otherAddr, [mockAddr]),
1391
+ createMockTransaction("received2", "1000", otherAddr, [mockAddr]),
1392
+ ],
1393
+ cursor: null,
1394
+ };
1346
1395
  }
1347
- return [];
1396
+ return { operations: [], cursor: null };
1348
1397
  });
1349
1398
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1350
1399
  // Filter timestamp should be 1000 (the common timestamp)
@@ -1400,189 +1449,239 @@ describe("filterOperations", () => {
1400
1449
  });
1401
1450
  describe("when cursor is provided", () => {
1402
1451
  test("should not apply timestamp filtering", () => {
1403
- const operationList1 = [
1404
- createMockTransaction("tx1", "1000"),
1405
- createMockTransaction("tx2", "2000"),
1406
- ];
1407
- const operationList2 = [
1408
- createMockTransaction("tx3", "1500"),
1409
- createMockTransaction("tx4", "2500"),
1410
- ];
1411
- const cursor = "test-cursor";
1412
- const result = sdk.filterOperations(operationList1, operationList2, cursor);
1452
+ const operationList1 = {
1453
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1454
+ cursor: null,
1455
+ };
1456
+ const operationList2 = {
1457
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1458
+ cursor: null,
1459
+ };
1460
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1413
1461
  // Should return all operations sorted by timestamp in descending order
1414
- expect(result).toHaveLength(4);
1415
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1462
+ expect(result.operations).toHaveLength(4);
1463
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1416
1464
  });
1417
1465
  test("should handle null cursor", () => {
1418
- const operationList1 = [
1419
- createMockTransaction("tx1", "1000"),
1420
- createMockTransaction("tx2", "2000"),
1421
- ];
1422
- const operationList2 = [
1423
- createMockTransaction("tx3", "1500"),
1424
- createMockTransaction("tx4", "2500"),
1425
- ];
1426
- const result = sdk.filterOperations(operationList1, operationList2, null);
1466
+ const operationList1 = {
1467
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1468
+ cursor: null,
1469
+ };
1470
+ const operationList2 = {
1471
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1472
+ cursor: null,
1473
+ };
1474
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1427
1475
  // Should return all operations sorted by timestamp in descending order
1428
- expect(result).toHaveLength(4);
1429
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1476
+ expect(result.operations).toHaveLength(4);
1477
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1430
1478
  });
1431
1479
  test("should handle undefined cursor", () => {
1432
- const operationList1 = [
1433
- createMockTransaction("tx1", "1000"),
1434
- createMockTransaction("tx2", "2000"),
1435
- ];
1436
- const operationList2 = [
1437
- createMockTransaction("tx3", "1500"),
1438
- createMockTransaction("tx4", "2500"),
1439
- ];
1440
- const result = sdk.filterOperations(operationList1, operationList2, undefined);
1480
+ const operationList1 = {
1481
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1482
+ cursor: null,
1483
+ };
1484
+ const operationList2 = {
1485
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1486
+ cursor: null,
1487
+ };
1488
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1441
1489
  // Should return all operations sorted by timestamp in descending order
1442
- expect(result).toHaveLength(4);
1443
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1490
+ expect(result.operations).toHaveLength(4);
1491
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1444
1492
  });
1445
1493
  });
1446
1494
  describe("when cursor is not provided and operations reach limits", () => {
1447
1495
  test("should apply timestamp filtering when both lists reach limit", () => {
1448
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)));
1449
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)));
1450
- const result = sdk.filterOperations(operationList1, operationList2, null);
1496
+ const operationList1 = {
1497
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100))),
1498
+ cursor: null,
1499
+ };
1500
+ const operationList2 = {
1501
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100))),
1502
+ cursor: null,
1503
+ };
1504
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1451
1505
  // Filter timestamp should be max of last timestamps:
1452
1506
  // operationList1: 1000 + 299*100 = 30900
1453
1507
  // operationList2: 2000 + 299*100 = 31900
1454
1508
  // filter = max(30900, 31900) = 31900
1455
1509
  // Only operations with timestamp >= 31900 should remain
1456
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 31900);
1510
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 31900);
1457
1511
  expect(filteredOperations).toHaveLength(1);
1458
1512
  expect(filteredOperations[0].digest).toBe("tx2_300");
1459
1513
  });
1460
1514
  test("should apply timestamp filtering when only first list reaches limit", () => {
1461
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)));
1462
- const operationList2 = [
1463
- createMockTransaction("tx2_1", "500"),
1464
- createMockTransaction("tx2_2", "1500"),
1465
- ];
1466
- const result = sdk.filterOperations(operationList1, operationList2, null);
1515
+ const operationList1 = {
1516
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100))),
1517
+ cursor: null,
1518
+ };
1519
+ const operationList2 = {
1520
+ operations: [createMockTransaction("tx2_1", "500"), createMockTransaction("tx2_2", "1500")],
1521
+ cursor: null,
1522
+ };
1523
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1467
1524
  // Filter timestamp should be max of last timestamps:
1468
1525
  // operationList1: 1000 + 299*100 = 30900
1469
1526
  // operationList2: 1500
1470
1527
  // filter = max(30900, 1500) = 30900
1471
1528
  // Only operations with timestamp >= 30900 should remain
1472
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 30900);
1529
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 30900);
1473
1530
  expect(filteredOperations).toHaveLength(1);
1474
1531
  expect(filteredOperations[0].digest).toBe("tx1_300");
1475
1532
  });
1476
1533
  test("should apply timestamp filtering when only second list reaches limit", () => {
1477
- const operationList1 = [
1478
- createMockTransaction("tx1_1", "500"),
1479
- createMockTransaction("tx1_2", "1500"),
1480
- ];
1481
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)));
1482
- const result = sdk.filterOperations(operationList1, operationList2, null);
1534
+ const operationList1 = {
1535
+ operations: [createMockTransaction("tx1_1", "500"), createMockTransaction("tx1_2", "1500")],
1536
+ cursor: null,
1537
+ };
1538
+ const operationList2 = {
1539
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100))),
1540
+ cursor: null,
1541
+ };
1542
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1483
1543
  // Filter timestamp should be max of last timestamps:
1484
1544
  // operationList1: 1500
1485
1545
  // operationList2: 2000 + 299*100 = 31900
1486
1546
  // filter = max(1500, 31900) = 31900
1487
1547
  // Only operations with timestamp >= 31900 should remain
1488
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 31900);
1548
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 31900);
1489
1549
  expect(filteredOperations).toHaveLength(1);
1490
1550
  expect(filteredOperations[0].digest).toBe("tx2_300");
1491
1551
  });
1492
1552
  });
1493
1553
  describe("when cursor is not provided and operations don't reach limits", () => {
1494
1554
  test("should not apply timestamp filtering when neither list reaches limit", () => {
1495
- const operationList1 = [
1496
- createMockTransaction("tx1_1", "1000"),
1497
- createMockTransaction("tx1_2", "2000"),
1498
- ];
1499
- const operationList2 = [
1500
- createMockTransaction("tx2_1", "1500"),
1501
- createMockTransaction("tx2_2", "2500"),
1502
- ];
1503
- const result = sdk.filterOperations(operationList1, operationList2, null);
1555
+ const operationList1 = {
1556
+ operations: [
1557
+ createMockTransaction("tx1_1", "1000"),
1558
+ createMockTransaction("tx1_2", "2000"),
1559
+ ],
1560
+ cursor: null,
1561
+ };
1562
+ const operationList2 = {
1563
+ operations: [
1564
+ createMockTransaction("tx2_1", "1500"),
1565
+ createMockTransaction("tx2_2", "2500"),
1566
+ ],
1567
+ cursor: null,
1568
+ };
1569
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1504
1570
  // Should return all operations sorted by timestamp in descending order
1505
- expect(result).toHaveLength(4);
1506
- expect(result.map(tx => tx.digest)).toEqual(["tx2_2", "tx1_2", "tx2_1", "tx1_1"]);
1571
+ expect(result.operations).toHaveLength(4);
1572
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx2_2", "tx1_2", "tx2_1", "tx1_1"]);
1507
1573
  });
1508
1574
  test("should apply timestamp filtering when only one list reaches limit", () => {
1509
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)));
1510
- const operationList2 = [createMockTransaction("tx2_1", "1500")];
1511
- const result = sdk.filterOperations(operationList1, operationList2, null);
1575
+ const operationList1 = {
1576
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100))),
1577
+ cursor: null,
1578
+ };
1579
+ const operationList2 = {
1580
+ operations: [createMockTransaction("tx2_1", "1500")],
1581
+ cursor: null,
1582
+ };
1583
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1512
1584
  // Should apply timestamp filtering since one list reaches limit
1513
1585
  // Filter timestamp should be the timestamp of the last operation in list1 (1000 + 299*100 = 30900)
1514
1586
  // Only operations with timestamp >= 30900 should remain
1515
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 30900);
1587
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 30900);
1516
1588
  expect(filteredOperations).toHaveLength(1);
1517
1589
  expect(filteredOperations[0].digest).toBe("tx1_300");
1518
1590
  });
1519
1591
  });
1520
1592
  describe("edge cases", () => {
1521
1593
  test("should handle null/undefined timestampMs values", () => {
1522
- const operationList1 = [
1523
- createMockTransaction("tx1_1", "1000"),
1524
- createMockTransaction("tx1_2", null),
1525
- createMockTransaction("tx1_3", "3000"),
1526
- ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`tx1_${i + 4}`, String(4000 + i * 100))),
1527
- ];
1528
- const operationList2 = [
1529
- createMockTransaction("tx2_1", null),
1530
- createMockTransaction("tx2_2", "2000"),
1531
- createMockTransaction("tx2_3", "4000"),
1532
- ];
1533
- const result = sdk.filterOperations(operationList1, operationList2, null);
1594
+ const operationList1 = {
1595
+ operations: [
1596
+ createMockTransaction("tx1_1", "1000"),
1597
+ createMockTransaction("tx1_2", null),
1598
+ createMockTransaction("tx1_3", "3000"),
1599
+ ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`tx1_${i + 4}`, String(4000 + i * 100))),
1600
+ ],
1601
+ cursor: null,
1602
+ };
1603
+ const operationList2 = {
1604
+ operations: [
1605
+ createMockTransaction("tx2_1", null),
1606
+ createMockTransaction("tx2_2", "2000"),
1607
+ createMockTransaction("tx2_3", "4000"),
1608
+ ],
1609
+ cursor: null,
1610
+ };
1611
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1534
1612
  // Filter timestamp should be the timestamp of the last operation in list1 (4000 + 296*100 = 33600)
1535
1613
  // Only operations with timestamp >= 33600 should remain
1536
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 33600);
1614
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 33600);
1537
1615
  expect(filteredOperations).toHaveLength(1);
1538
1616
  expect(filteredOperations[0].digest).toBe("tx1_300");
1539
1617
  });
1540
1618
  test("should handle empty arrays", () => {
1541
- const result = sdk.filterOperations([], [], null);
1542
- expect(result).toHaveLength(0);
1619
+ const result = sdk.filterOperations({ operations: [], cursor: null }, { operations: [], cursor: null }, "ascending");
1620
+ expect(result.operations).toHaveLength(0);
1543
1621
  });
1544
1622
  test("should handle one empty array", () => {
1545
- const operationList1 = [
1546
- createMockTransaction("tx1_1", "1000"),
1547
- createMockTransaction("tx1_2", "2000"),
1548
- ];
1549
- const operationList2 = [];
1550
- const result = sdk.filterOperations(operationList1, operationList2, null);
1551
- expect(result).toHaveLength(2);
1552
- expect(result.map(tx => tx.digest)).toEqual(["tx1_2", "tx1_1"]);
1623
+ const operationList1 = {
1624
+ operations: [
1625
+ createMockTransaction("tx1_1", "1000"),
1626
+ createMockTransaction("tx1_2", "2000"),
1627
+ ],
1628
+ cursor: null,
1629
+ };
1630
+ const operationList2 = {
1631
+ operations: [],
1632
+ cursor: null,
1633
+ };
1634
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1635
+ expect(result.operations).toHaveLength(2);
1636
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx1_2", "tx1_1"]);
1553
1637
  });
1554
1638
  test("should remove duplicate transactions by digest", () => {
1555
- const operationList1 = [
1556
- createMockTransaction("tx1", "1000"),
1557
- createMockTransaction("tx2", "2000"),
1558
- ];
1559
- const operationList2 = [
1560
- createMockTransaction("tx2", "2000"), // Duplicate digest
1561
- createMockTransaction("tx3", "3000"),
1562
- ];
1563
- const result = sdk.filterOperations(operationList1, operationList2, null);
1639
+ const operationList1 = {
1640
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1641
+ cursor: null,
1642
+ };
1643
+ const operationList2 = {
1644
+ operations: [
1645
+ createMockTransaction("tx2", "2000"), // Duplicate digest
1646
+ createMockTransaction("tx3", "3000"),
1647
+ ],
1648
+ cursor: null,
1649
+ };
1650
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1564
1651
  // Should remove duplicate tx2
1565
- expect(result).toHaveLength(3);
1566
- expect(result.map(tx => tx.digest)).toEqual(["tx3", "tx2", "tx1"]);
1652
+ expect(result.operations).toHaveLength(3);
1653
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx3", "tx2", "tx1"]);
1567
1654
  });
1568
1655
  test("should maintain chronological order after filtering", () => {
1569
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 10)));
1570
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(500 + i * 10)));
1571
- const result = sdk.filterOperations(operationList1, operationList2, null);
1656
+ const operationList1 = {
1657
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 10))),
1658
+ cursor: null,
1659
+ };
1660
+ const operationList2 = {
1661
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(500 + i * 10))),
1662
+ cursor: null,
1663
+ };
1664
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1572
1665
  // Should be sorted by timestamp in descending order
1573
- const timestamps = result.map(tx => Number(tx.timestampMs));
1666
+ const timestamps = result.operations.map(tx => Number(tx.timestampMs));
1574
1667
  expect(timestamps).toEqual(timestamps.slice().sort((a, b) => b - a));
1575
1668
  });
1576
1669
  test("should handle operations with same timestamps", () => {
1577
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, "1000"));
1578
- const operationList2 = [
1579
- createMockTransaction("tx2_1", "1000"),
1580
- createMockTransaction("tx2_2", "1000"),
1581
- ];
1582
- const result = sdk.filterOperations(operationList1, operationList2, null);
1670
+ const operationList1 = {
1671
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, "1000")),
1672
+ cursor: null,
1673
+ };
1674
+ const operationList2 = {
1675
+ operations: [
1676
+ createMockTransaction("tx2_1", "1000"),
1677
+ createMockTransaction("tx2_2", "1000"),
1678
+ ],
1679
+ cursor: null,
1680
+ };
1681
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1583
1682
  // Filter timestamp should be 1000 (the common timestamp)
1584
1683
  // All operations have timestamp 1000, so all should pass the filter
1585
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT + 2);
1684
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT + 2);
1586
1685
  });
1587
1686
  });
1588
1687
  describe("conversion methods", () => {