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

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 (78) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +23 -0
  3. package/lib/api/index.d.ts +1 -1
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.integration.test.js +9 -2
  6. package/lib/api/index.integration.test.js.map +1 -1
  7. package/lib/api/index.js +1 -1
  8. package/lib/api/index.js.map +1 -1
  9. package/lib/api/index.test.js +3 -3
  10. package/lib/api/index.test.js.map +1 -1
  11. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  12. package/lib/bridge/estimateMaxSpendable.js +9 -7
  13. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  14. package/lib/bridge/estimateMaxSpendable.test.js +2 -2
  15. package/lib/bridge/estimateMaxSpendable.test.js.map +1 -1
  16. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  17. package/lib/bridge/getTransactionStatus.js +4 -1
  18. package/lib/bridge/getTransactionStatus.js.map +1 -1
  19. package/lib/bridge/utils.d.ts.map +1 -1
  20. package/lib/bridge/utils.js +2 -2
  21. package/lib/bridge/utils.js.map +1 -1
  22. package/lib/logic/listOperations.d.ts +1 -3
  23. package/lib/logic/listOperations.d.ts.map +1 -1
  24. package/lib/logic/listOperations.js +3 -3
  25. package/lib/logic/listOperations.js.map +1 -1
  26. package/lib/logic/listOperations.test.js +43 -39
  27. package/lib/logic/listOperations.test.js.map +1 -1
  28. package/lib/network/index.d.ts +1 -1
  29. package/lib/network/sdk.d.ts +9 -5
  30. package/lib/network/sdk.d.ts.map +1 -1
  31. package/lib/network/sdk.js +54 -27
  32. package/lib/network/sdk.js.map +1 -1
  33. package/lib/network/sdk.test.js +272 -170
  34. package/lib/network/sdk.test.js.map +1 -1
  35. package/lib-es/api/index.d.ts +1 -1
  36. package/lib-es/api/index.d.ts.map +1 -1
  37. package/lib-es/api/index.integration.test.js +9 -2
  38. package/lib-es/api/index.integration.test.js.map +1 -1
  39. package/lib-es/api/index.js +1 -1
  40. package/lib-es/api/index.js.map +1 -1
  41. package/lib-es/api/index.test.js +3 -3
  42. package/lib-es/api/index.test.js.map +1 -1
  43. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  44. package/lib-es/bridge/estimateMaxSpendable.js +9 -7
  45. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  46. package/lib-es/bridge/estimateMaxSpendable.test.js +2 -2
  47. package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -1
  48. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  49. package/lib-es/bridge/getTransactionStatus.js +4 -1
  50. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  51. package/lib-es/bridge/utils.d.ts.map +1 -1
  52. package/lib-es/bridge/utils.js +2 -2
  53. package/lib-es/bridge/utils.js.map +1 -1
  54. package/lib-es/logic/listOperations.d.ts +1 -3
  55. package/lib-es/logic/listOperations.d.ts.map +1 -1
  56. package/lib-es/logic/listOperations.js +4 -4
  57. package/lib-es/logic/listOperations.js.map +1 -1
  58. package/lib-es/logic/listOperations.test.js +44 -40
  59. package/lib-es/logic/listOperations.test.js.map +1 -1
  60. package/lib-es/network/index.d.ts +1 -1
  61. package/lib-es/network/sdk.d.ts +9 -5
  62. package/lib-es/network/sdk.d.ts.map +1 -1
  63. package/lib-es/network/sdk.js +54 -27
  64. package/lib-es/network/sdk.js.map +1 -1
  65. package/lib-es/network/sdk.test.js +272 -170
  66. package/lib-es/network/sdk.test.js.map +1 -1
  67. package/package.json +5 -5
  68. package/src/api/index.integration.test.ts +10 -2
  69. package/src/api/index.test.ts +3 -3
  70. package/src/api/index.ts +4 -3
  71. package/src/bridge/estimateMaxSpendable.test.ts +2 -2
  72. package/src/bridge/estimateMaxSpendable.ts +9 -8
  73. package/src/bridge/getTransactionStatus.ts +4 -2
  74. package/src/bridge/utils.ts +2 -2
  75. package/src/logic/listOperations.test.ts +45 -41
  76. package/src/logic/listOperations.ts +4 -4
  77. package/src/network/sdk.test.ts +312 -207
  78. package/src/network/sdk.ts +70 -32
@@ -490,6 +490,7 @@ describe("SDK Functions", () => {
490
490
  expect(operation.asset).toEqual({ type: "token", assetReference: "0x123::test::TOKEN" });
491
491
  expect(operation.memo).toBeUndefined();
492
492
  expect(operation.details).toBeUndefined();
493
+ expect(operation.tx.block.hash).toBeUndefined();
493
494
  expect(operation.tx).toMatchObject({
494
495
  hash: "DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt",
495
496
  block: {},
@@ -991,6 +992,7 @@ describe("Staking Operations", () => {
991
992
  expect(operation.recipients).toEqual([]);
992
993
  expect(operation.value).toEqual(1000000000n); // The function returns minus of the balance change
993
994
  expect(operation.asset).toEqual({ type: "native" });
995
+ expect(operation.tx.block.hash).toBeUndefined();
994
996
  });
995
997
 
996
998
  test("transactionToOp should map unstaking transaction correctly", () => {
@@ -1041,6 +1043,7 @@ describe("Staking Operations", () => {
1041
1043
  expect(operation.recipients).toEqual([]);
1042
1044
  expect(operation.value).toEqual(0n);
1043
1045
  expect(operation.asset).toEqual({ type: "native" });
1046
+ expect(operation.tx.block.hash).toBeUndefined();
1044
1047
  });
1045
1048
  });
1046
1049
 
@@ -1124,8 +1127,8 @@ describe("loadOperations", () => {
1124
1127
  operations: [],
1125
1128
  });
1126
1129
 
1127
- expect(result).toHaveLength(pageSize + 1);
1128
- expect(result.map(tx => tx.digest)).toEqual([
1130
+ expect(result.operations).toHaveLength(pageSize + 1);
1131
+ expect(result.operations.map(tx => tx.digest)).toEqual([
1129
1132
  ...firstPage.map(tx => tx.digest),
1130
1133
  `tx${pageSize + 1}`,
1131
1134
  ]);
@@ -1151,7 +1154,7 @@ describe("loadOperations", () => {
1151
1154
  operations: [],
1152
1155
  });
1153
1156
 
1154
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT_PER_QUERY - 1);
1157
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT_PER_QUERY - 1);
1155
1158
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(1);
1156
1159
  });
1157
1160
 
@@ -1178,7 +1181,7 @@ describe("loadOperations", () => {
1178
1181
  operations: [],
1179
1182
  });
1180
1183
 
1181
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT);
1184
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT);
1182
1185
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(expectedCalls);
1183
1186
  });
1184
1187
 
@@ -1209,7 +1212,7 @@ describe("loadOperations", () => {
1209
1212
  );
1210
1213
 
1211
1214
  // Result should be empty array (no retry, just return operations)
1212
- expect(result).toHaveLength(0);
1215
+ expect(result.operations).toHaveLength(0);
1213
1216
  });
1214
1217
 
1215
1218
  it("should should not retry after unexpected errors and return empty data", async () => {
@@ -1223,7 +1226,7 @@ describe("loadOperations", () => {
1223
1226
  operations: [],
1224
1227
  });
1225
1228
 
1226
- expect(result).toEqual([]);
1229
+ expect(result.operations).toEqual([]);
1227
1230
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(1);
1228
1231
  });
1229
1232
  });
@@ -1306,17 +1309,23 @@ describe("getOperations filtering logic", () => {
1306
1309
  // Mock loadOperations to return different data based on operation type
1307
1310
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1308
1311
  if (type === "OUT") {
1309
- return [
1310
- createMockTransaction("sent1", "1000", mockAddr, []),
1311
- createMockTransaction("sent2", "2000", mockAddr, []),
1312
- ];
1312
+ return {
1313
+ operations: [
1314
+ createMockTransaction("sent1", "1000", mockAddr, []),
1315
+ createMockTransaction("sent2", "2000", mockAddr, []),
1316
+ ],
1317
+ cursor: null,
1318
+ };
1313
1319
  } else if (type === "IN") {
1314
- return [
1315
- createMockTransaction("received1", "1500", otherAddr, [mockAddr]),
1316
- createMockTransaction("received2", "2500", otherAddr, [mockAddr]),
1317
- ];
1320
+ return {
1321
+ operations: [
1322
+ createMockTransaction("received1", "1500", otherAddr, [mockAddr]),
1323
+ createMockTransaction("received2", "2500", otherAddr, [mockAddr]),
1324
+ ],
1325
+ cursor: null,
1326
+ };
1318
1327
  }
1319
- return [];
1328
+ return { operations: [], cursor: null };
1320
1329
  });
1321
1330
  });
1322
1331
 
@@ -1346,16 +1355,22 @@ describe("getOperations filtering logic", () => {
1346
1355
  // Mock to return enough sent operations to reach limit
1347
1356
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1348
1357
  if (type === "OUT") {
1349
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1350
- createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []),
1351
- );
1358
+ return {
1359
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1360
+ createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []),
1361
+ ),
1362
+ cursor: null,
1363
+ };
1352
1364
  } else if (type === "IN") {
1353
- return [
1354
- createMockTransaction("received1", "500", otherAddr, [mockAddr]),
1355
- createMockTransaction("received2", "1500", otherAddr, [mockAddr]),
1356
- ];
1365
+ return {
1366
+ operations: [
1367
+ createMockTransaction("received1", "500", otherAddr, [mockAddr]),
1368
+ createMockTransaction("received2", "1500", otherAddr, [mockAddr]),
1369
+ ],
1370
+ cursor: null,
1371
+ };
1357
1372
  }
1358
- return [];
1373
+ return { operations: [], cursor: null };
1359
1374
  });
1360
1375
 
1361
1376
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1373,16 +1388,24 @@ describe("getOperations filtering logic", () => {
1373
1388
  // Mock to return enough received operations to reach limit
1374
1389
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1375
1390
  if (type === "OUT") {
1376
- return [
1377
- createMockTransaction("sent1", "500", mockAddr, []),
1378
- createMockTransaction("sent2", "1500", mockAddr, []),
1379
- ];
1391
+ return {
1392
+ operations: [
1393
+ createMockTransaction("sent1", "500", mockAddr, []),
1394
+ createMockTransaction("sent2", "1500", mockAddr, []),
1395
+ ],
1396
+ cursor: null,
1397
+ };
1380
1398
  } else if (type === "IN") {
1381
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1382
- createMockTransaction(`received${i + 1}`, String(1000 + i * 100), otherAddr, [mockAddr]),
1383
- );
1399
+ return {
1400
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1401
+ createMockTransaction(`received${i + 1}`, String(1000 + i * 100), otherAddr, [
1402
+ mockAddr,
1403
+ ]),
1404
+ ),
1405
+ cursor: null,
1406
+ };
1384
1407
  }
1385
- return [];
1408
+ return { operations: [], cursor: null };
1386
1409
  });
1387
1410
 
1388
1411
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1400,15 +1423,23 @@ describe("getOperations filtering logic", () => {
1400
1423
  // Mock to return enough operations to reach limit for both types
1401
1424
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1402
1425
  if (type === "OUT") {
1403
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1404
- createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []),
1405
- );
1426
+ return {
1427
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1428
+ createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []),
1429
+ ),
1430
+ cursor: null,
1431
+ };
1406
1432
  } else if (type === "IN") {
1407
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1408
- createMockTransaction(`received${i + 1}`, String(2000 + i * 100), otherAddr, [mockAddr]),
1409
- );
1433
+ return {
1434
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1435
+ createMockTransaction(`received${i + 1}`, String(2000 + i * 100), otherAddr, [
1436
+ mockAddr,
1437
+ ]),
1438
+ ),
1439
+ cursor: null,
1440
+ };
1410
1441
  }
1411
- return [];
1442
+ return { operations: [], cursor: null };
1412
1443
  });
1413
1444
 
1414
1445
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1426,22 +1457,28 @@ describe("getOperations filtering logic", () => {
1426
1457
  // Mock to return operations with null timestamps and reach limit
1427
1458
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1428
1459
  if (type === "OUT") {
1429
- return [
1430
- createMockTransaction("sent1", "1000", mockAddr, []),
1431
- createMockTransaction("sent2", null, mockAddr, []),
1432
- createMockTransaction("sent3", "3000", mockAddr, []),
1433
- ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) =>
1434
- createMockTransaction(`sent${i + 4}`, String(4000 + i * 100), mockAddr, []),
1435
- ),
1436
- ];
1460
+ return {
1461
+ operations: [
1462
+ createMockTransaction("sent1", "1000", mockAddr, []),
1463
+ createMockTransaction("sent2", null, mockAddr, []),
1464
+ createMockTransaction("sent3", "3000", mockAddr, []),
1465
+ ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) =>
1466
+ createMockTransaction(`sent${i + 4}`, String(4000 + i * 100), mockAddr, []),
1467
+ ),
1468
+ ],
1469
+ cursor: null,
1470
+ };
1437
1471
  } else if (type === "IN") {
1438
- return [
1439
- createMockTransaction("received1", null, otherAddr, [mockAddr]),
1440
- createMockTransaction("received2", "2000", otherAddr, [mockAddr]),
1441
- createMockTransaction("received3", "4000", otherAddr, [mockAddr]),
1442
- ];
1472
+ return {
1473
+ operations: [
1474
+ createMockTransaction("received1", null, otherAddr, [mockAddr]),
1475
+ createMockTransaction("received2", "2000", otherAddr, [mockAddr]),
1476
+ createMockTransaction("received3", "4000", otherAddr, [mockAddr]),
1477
+ ],
1478
+ cursor: null,
1479
+ };
1443
1480
  }
1444
- return [];
1481
+ return { operations: [], cursor: null };
1445
1482
  });
1446
1483
 
1447
1484
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1456,15 +1493,21 @@ describe("getOperations filtering logic", () => {
1456
1493
  // Mock to return operations that reach limit
1457
1494
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1458
1495
  if (type === "OUT") {
1459
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1460
- createMockTransaction(`sent${i + 1}`, String(1000 + i * 10), mockAddr, []),
1461
- );
1496
+ return {
1497
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1498
+ createMockTransaction(`sent${i + 1}`, String(1000 + i * 10), mockAddr, []),
1499
+ ),
1500
+ cursor: null,
1501
+ };
1462
1502
  } else if (type === "IN") {
1463
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1464
- createMockTransaction(`received${i + 1}`, String(500 + i * 10), otherAddr, [mockAddr]),
1465
- );
1503
+ return {
1504
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1505
+ createMockTransaction(`received${i + 1}`, String(500 + i * 10), otherAddr, [mockAddr]),
1506
+ ),
1507
+ cursor: null,
1508
+ };
1466
1509
  }
1467
- return [];
1510
+ return { operations: [], cursor: null };
1468
1511
  });
1469
1512
 
1470
1513
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1477,7 +1520,7 @@ describe("getOperations filtering logic", () => {
1477
1520
  test("should handle empty operations arrays", async () => {
1478
1521
  // Mock to return empty arrays
1479
1522
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1480
- return [];
1523
+ return { operations: [], cursor: null };
1481
1524
  });
1482
1525
 
1483
1526
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1489,14 +1532,17 @@ describe("getOperations filtering logic", () => {
1489
1532
  // Mock to return only OUT operations
1490
1533
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1491
1534
  if (type === "OUT") {
1492
- return [
1493
- createMockTransaction("sent1", "1000", mockAddr, []),
1494
- createMockTransaction("sent2", "2000", mockAddr, []),
1495
- ];
1535
+ return {
1536
+ operations: [
1537
+ createMockTransaction("sent1", "1000", mockAddr, []),
1538
+ createMockTransaction("sent2", "2000", mockAddr, []),
1539
+ ],
1540
+ cursor: null,
1541
+ };
1496
1542
  } else if (type === "IN") {
1497
- return [];
1543
+ return { operations: [], cursor: null };
1498
1544
  }
1499
- return [];
1545
+ return { operations: [], cursor: null };
1500
1546
  });
1501
1547
 
1502
1548
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1509,17 +1555,23 @@ describe("getOperations filtering logic", () => {
1509
1555
  // Mock to return operations with same timestamps and reach limit
1510
1556
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1511
1557
  if (type === "OUT") {
1512
- return Array.from(
1513
- { length: sdk.TRANSACTIONS_LIMIT },
1514
- (_, i) => createMockTransaction(`sent${i + 1}`, "1000", mockAddr, []), // All same timestamp
1515
- );
1558
+ return {
1559
+ operations: Array.from(
1560
+ { length: sdk.TRANSACTIONS_LIMIT },
1561
+ (_, i) => createMockTransaction(`sent${i + 1}`, "1000", mockAddr, []), // All same timestamp
1562
+ ),
1563
+ cursor: null,
1564
+ };
1516
1565
  } else if (type === "IN") {
1517
- return [
1518
- createMockTransaction("received1", "1000", otherAddr, [mockAddr]),
1519
- createMockTransaction("received2", "1000", otherAddr, [mockAddr]),
1520
- ];
1566
+ return {
1567
+ operations: [
1568
+ createMockTransaction("received1", "1000", otherAddr, [mockAddr]),
1569
+ createMockTransaction("received2", "1000", otherAddr, [mockAddr]),
1570
+ ],
1571
+ cursor: null,
1572
+ };
1521
1573
  }
1522
- return [];
1574
+ return { operations: [], cursor: null };
1523
1575
  });
1524
1576
 
1525
1577
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
@@ -1582,117 +1634,127 @@ describe("filterOperations", () => {
1582
1634
 
1583
1635
  describe("when cursor is provided", () => {
1584
1636
  test("should not apply timestamp filtering", () => {
1585
- const operationList1 = [
1586
- createMockTransaction("tx1", "1000"),
1587
- createMockTransaction("tx2", "2000"),
1588
- ];
1589
- const operationList2 = [
1590
- createMockTransaction("tx3", "1500"),
1591
- createMockTransaction("tx4", "2500"),
1592
- ];
1593
- const cursor = "test-cursor";
1594
-
1595
- const result = sdk.filterOperations(operationList1, operationList2, cursor);
1637
+ const operationList1 = {
1638
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1639
+ cursor: null,
1640
+ };
1641
+ const operationList2 = {
1642
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1643
+ cursor: null,
1644
+ };
1645
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1596
1646
 
1597
1647
  // Should return all operations sorted by timestamp in descending order
1598
- expect(result).toHaveLength(4);
1599
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1648
+ expect(result.operations).toHaveLength(4);
1649
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1600
1650
  });
1601
1651
 
1602
1652
  test("should handle null cursor", () => {
1603
- const operationList1 = [
1604
- createMockTransaction("tx1", "1000"),
1605
- createMockTransaction("tx2", "2000"),
1606
- ];
1607
- const operationList2 = [
1608
- createMockTransaction("tx3", "1500"),
1609
- createMockTransaction("tx4", "2500"),
1610
- ];
1653
+ const operationList1 = {
1654
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1655
+ cursor: null,
1656
+ };
1657
+ const operationList2 = {
1658
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1659
+ cursor: null,
1660
+ };
1611
1661
 
1612
- const result = sdk.filterOperations(operationList1, operationList2, null);
1662
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1613
1663
 
1614
1664
  // Should return all operations sorted by timestamp in descending order
1615
- expect(result).toHaveLength(4);
1616
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1665
+ expect(result.operations).toHaveLength(4);
1666
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1617
1667
  });
1618
1668
 
1619
1669
  test("should handle undefined cursor", () => {
1620
- const operationList1 = [
1621
- createMockTransaction("tx1", "1000"),
1622
- createMockTransaction("tx2", "2000"),
1623
- ];
1624
- const operationList2 = [
1625
- createMockTransaction("tx3", "1500"),
1626
- createMockTransaction("tx4", "2500"),
1627
- ];
1670
+ const operationList1 = {
1671
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1672
+ cursor: null,
1673
+ };
1674
+ const operationList2 = {
1675
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1676
+ cursor: null,
1677
+ };
1628
1678
 
1629
- const result = sdk.filterOperations(operationList1, operationList2, undefined);
1679
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1630
1680
 
1631
1681
  // Should return all operations sorted by timestamp in descending order
1632
- expect(result).toHaveLength(4);
1633
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1682
+ expect(result.operations).toHaveLength(4);
1683
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1634
1684
  });
1635
1685
  });
1636
1686
 
1637
1687
  describe("when cursor is not provided and operations reach limits", () => {
1638
1688
  test("should apply timestamp filtering when both lists reach limit", () => {
1639
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1640
- createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)),
1641
- );
1642
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1643
- createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)),
1644
- );
1689
+ const operationList1 = {
1690
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1691
+ createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)),
1692
+ ),
1693
+ cursor: null,
1694
+ };
1695
+ const operationList2 = {
1696
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1697
+ createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)),
1698
+ ),
1699
+ cursor: null,
1700
+ };
1645
1701
 
1646
- const result = sdk.filterOperations(operationList1, operationList2, null);
1702
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1647
1703
 
1648
1704
  // Filter timestamp should be max of last timestamps:
1649
1705
  // operationList1: 1000 + 299*100 = 30900
1650
1706
  // operationList2: 2000 + 299*100 = 31900
1651
1707
  // filter = max(30900, 31900) = 31900
1652
1708
  // Only operations with timestamp >= 31900 should remain
1653
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 31900);
1709
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 31900);
1654
1710
  expect(filteredOperations).toHaveLength(1);
1655
1711
  expect(filteredOperations[0].digest).toBe("tx2_300");
1656
1712
  });
1657
1713
 
1658
1714
  test("should apply timestamp filtering when only first list reaches limit", () => {
1659
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1660
- createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)),
1661
- );
1662
- const operationList2 = [
1663
- createMockTransaction("tx2_1", "500"),
1664
- createMockTransaction("tx2_2", "1500"),
1665
- ];
1715
+ const operationList1 = {
1716
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1717
+ createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)),
1718
+ ),
1719
+ cursor: null,
1720
+ };
1721
+ const operationList2 = {
1722
+ operations: [createMockTransaction("tx2_1", "500"), createMockTransaction("tx2_2", "1500")],
1723
+ cursor: null,
1724
+ };
1666
1725
 
1667
- const result = sdk.filterOperations(operationList1, operationList2, null);
1726
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1668
1727
 
1669
1728
  // Filter timestamp should be max of last timestamps:
1670
1729
  // operationList1: 1000 + 299*100 = 30900
1671
1730
  // operationList2: 1500
1672
1731
  // filter = max(30900, 1500) = 30900
1673
1732
  // Only operations with timestamp >= 30900 should remain
1674
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 30900);
1733
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 30900);
1675
1734
  expect(filteredOperations).toHaveLength(1);
1676
1735
  expect(filteredOperations[0].digest).toBe("tx1_300");
1677
1736
  });
1678
1737
 
1679
1738
  test("should apply timestamp filtering when only second list reaches limit", () => {
1680
- const operationList1 = [
1681
- createMockTransaction("tx1_1", "500"),
1682
- createMockTransaction("tx1_2", "1500"),
1683
- ];
1684
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1685
- createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)),
1686
- );
1739
+ const operationList1 = {
1740
+ operations: [createMockTransaction("tx1_1", "500"), createMockTransaction("tx1_2", "1500")],
1741
+ cursor: null,
1742
+ };
1743
+ const operationList2 = {
1744
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1745
+ createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)),
1746
+ ),
1747
+ cursor: null,
1748
+ };
1687
1749
 
1688
- const result = sdk.filterOperations(operationList1, operationList2, null);
1750
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1689
1751
 
1690
1752
  // Filter timestamp should be max of last timestamps:
1691
1753
  // operationList1: 1500
1692
1754
  // operationList2: 2000 + 299*100 = 31900
1693
1755
  // filter = max(1500, 31900) = 31900
1694
1756
  // Only operations with timestamp >= 31900 should remain
1695
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 31900);
1757
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 31900);
1696
1758
  expect(filteredOperations).toHaveLength(1);
1697
1759
  expect(filteredOperations[0].digest).toBe("tx2_300");
1698
1760
  });
@@ -1700,34 +1762,46 @@ describe("filterOperations", () => {
1700
1762
 
1701
1763
  describe("when cursor is not provided and operations don't reach limits", () => {
1702
1764
  test("should not apply timestamp filtering when neither list reaches limit", () => {
1703
- const operationList1 = [
1704
- createMockTransaction("tx1_1", "1000"),
1705
- createMockTransaction("tx1_2", "2000"),
1706
- ];
1707
- const operationList2 = [
1708
- createMockTransaction("tx2_1", "1500"),
1709
- createMockTransaction("tx2_2", "2500"),
1710
- ];
1765
+ const operationList1 = {
1766
+ operations: [
1767
+ createMockTransaction("tx1_1", "1000"),
1768
+ createMockTransaction("tx1_2", "2000"),
1769
+ ],
1770
+ cursor: null,
1771
+ };
1772
+ const operationList2 = {
1773
+ operations: [
1774
+ createMockTransaction("tx2_1", "1500"),
1775
+ createMockTransaction("tx2_2", "2500"),
1776
+ ],
1777
+ cursor: null,
1778
+ };
1711
1779
 
1712
- const result = sdk.filterOperations(operationList1, operationList2, null);
1780
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1713
1781
 
1714
1782
  // Should return all operations sorted by timestamp in descending order
1715
- expect(result).toHaveLength(4);
1716
- expect(result.map(tx => tx.digest)).toEqual(["tx2_2", "tx1_2", "tx2_1", "tx1_1"]);
1783
+ expect(result.operations).toHaveLength(4);
1784
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx2_2", "tx1_2", "tx2_1", "tx1_1"]);
1717
1785
  });
1718
1786
 
1719
1787
  test("should apply timestamp filtering when only one list reaches limit", () => {
1720
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1721
- createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)),
1722
- );
1723
- const operationList2 = [createMockTransaction("tx2_1", "1500")];
1788
+ const operationList1 = {
1789
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1790
+ createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)),
1791
+ ),
1792
+ cursor: null,
1793
+ };
1794
+ const operationList2 = {
1795
+ operations: [createMockTransaction("tx2_1", "1500")],
1796
+ cursor: null,
1797
+ };
1724
1798
 
1725
- const result = sdk.filterOperations(operationList1, operationList2, null);
1799
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1726
1800
 
1727
1801
  // Should apply timestamp filtering since one list reaches limit
1728
1802
  // Filter timestamp should be the timestamp of the last operation in list1 (1000 + 299*100 = 30900)
1729
1803
  // Only operations with timestamp >= 30900 should remain
1730
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 30900);
1804
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 30900);
1731
1805
  expect(filteredOperations).toHaveLength(1);
1732
1806
  expect(filteredOperations[0].digest).toBe("tx1_300");
1733
1807
  });
@@ -1735,94 +1809,125 @@ describe("filterOperations", () => {
1735
1809
 
1736
1810
  describe("edge cases", () => {
1737
1811
  test("should handle null/undefined timestampMs values", () => {
1738
- const operationList1 = [
1739
- createMockTransaction("tx1_1", "1000"),
1740
- createMockTransaction("tx1_2", null),
1741
- createMockTransaction("tx1_3", "3000"),
1742
- ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) =>
1743
- createMockTransaction(`tx1_${i + 4}`, String(4000 + i * 100)),
1744
- ),
1745
- ];
1746
- const operationList2 = [
1747
- createMockTransaction("tx2_1", null),
1748
- createMockTransaction("tx2_2", "2000"),
1749
- createMockTransaction("tx2_3", "4000"),
1750
- ];
1812
+ const operationList1 = {
1813
+ operations: [
1814
+ createMockTransaction("tx1_1", "1000"),
1815
+ createMockTransaction("tx1_2", null),
1816
+ createMockTransaction("tx1_3", "3000"),
1817
+ ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) =>
1818
+ createMockTransaction(`tx1_${i + 4}`, String(4000 + i * 100)),
1819
+ ),
1820
+ ],
1821
+ cursor: null,
1822
+ };
1823
+ const operationList2 = {
1824
+ operations: [
1825
+ createMockTransaction("tx2_1", null),
1826
+ createMockTransaction("tx2_2", "2000"),
1827
+ createMockTransaction("tx2_3", "4000"),
1828
+ ],
1829
+ cursor: null,
1830
+ };
1751
1831
 
1752
- const result = sdk.filterOperations(operationList1, operationList2, null);
1832
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1753
1833
 
1754
1834
  // Filter timestamp should be the timestamp of the last operation in list1 (4000 + 296*100 = 33600)
1755
1835
  // Only operations with timestamp >= 33600 should remain
1756
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 33600);
1836
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 33600);
1757
1837
  expect(filteredOperations).toHaveLength(1);
1758
1838
  expect(filteredOperations[0].digest).toBe("tx1_300");
1759
1839
  });
1760
1840
 
1761
1841
  test("should handle empty arrays", () => {
1762
- const result = sdk.filterOperations([], [], null);
1763
- expect(result).toHaveLength(0);
1842
+ const result = sdk.filterOperations(
1843
+ { operations: [], cursor: null },
1844
+ { operations: [], cursor: null },
1845
+ "ascending",
1846
+ );
1847
+ expect(result.operations).toHaveLength(0);
1764
1848
  });
1765
1849
 
1766
1850
  test("should handle one empty array", () => {
1767
- const operationList1 = [
1768
- createMockTransaction("tx1_1", "1000"),
1769
- createMockTransaction("tx1_2", "2000"),
1770
- ];
1771
- const operationList2: SuiTransactionBlockResponse[] = [];
1851
+ const operationList1 = {
1852
+ operations: [
1853
+ createMockTransaction("tx1_1", "1000"),
1854
+ createMockTransaction("tx1_2", "2000"),
1855
+ ],
1856
+ cursor: null,
1857
+ };
1858
+ const operationList2 = {
1859
+ operations: [],
1860
+ cursor: null,
1861
+ };
1772
1862
 
1773
- const result = sdk.filterOperations(operationList1, operationList2, null);
1863
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1774
1864
 
1775
- expect(result).toHaveLength(2);
1776
- expect(result.map(tx => tx.digest)).toEqual(["tx1_2", "tx1_1"]);
1865
+ expect(result.operations).toHaveLength(2);
1866
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx1_2", "tx1_1"]);
1777
1867
  });
1778
1868
 
1779
1869
  test("should remove duplicate transactions by digest", () => {
1780
- const operationList1 = [
1781
- createMockTransaction("tx1", "1000"),
1782
- createMockTransaction("tx2", "2000"),
1783
- ];
1784
- const operationList2 = [
1785
- createMockTransaction("tx2", "2000"), // Duplicate digest
1786
- createMockTransaction("tx3", "3000"),
1787
- ];
1870
+ const operationList1 = {
1871
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1872
+ cursor: null,
1873
+ };
1874
+ const operationList2 = {
1875
+ operations: [
1876
+ createMockTransaction("tx2", "2000"), // Duplicate digest
1877
+ createMockTransaction("tx3", "3000"),
1878
+ ],
1879
+ cursor: null,
1880
+ };
1788
1881
 
1789
- const result = sdk.filterOperations(operationList1, operationList2, null);
1882
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1790
1883
 
1791
1884
  // Should remove duplicate tx2
1792
- expect(result).toHaveLength(3);
1793
- expect(result.map(tx => tx.digest)).toEqual(["tx3", "tx2", "tx1"]);
1885
+ expect(result.operations).toHaveLength(3);
1886
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx3", "tx2", "tx1"]);
1794
1887
  });
1795
1888
 
1796
1889
  test("should maintain chronological order after filtering", () => {
1797
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1798
- createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 10)),
1799
- );
1800
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1801
- createMockTransaction(`tx2_${i + 1}`, String(500 + i * 10)),
1802
- );
1890
+ const operationList1 = {
1891
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1892
+ createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 10)),
1893
+ ),
1894
+ cursor: null,
1895
+ };
1896
+ const operationList2 = {
1897
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) =>
1898
+ createMockTransaction(`tx2_${i + 1}`, String(500 + i * 10)),
1899
+ ),
1900
+ cursor: null,
1901
+ };
1803
1902
 
1804
- const result = sdk.filterOperations(operationList1, operationList2, null);
1903
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1805
1904
 
1806
1905
  // Should be sorted by timestamp in descending order
1807
- const timestamps = result.map(tx => Number(tx.timestampMs));
1906
+ const timestamps = result.operations.map(tx => Number(tx.timestampMs));
1808
1907
  expect(timestamps).toEqual(timestamps.slice().sort((a, b) => b - a));
1809
1908
  });
1810
1909
 
1811
1910
  test("should handle operations with same timestamps", () => {
1812
- const operationList1 = Array.from(
1813
- { length: sdk.TRANSACTIONS_LIMIT },
1814
- (_, i) => createMockTransaction(`tx1_${i + 1}`, "1000"), // All same timestamp
1815
- );
1816
- const operationList2 = [
1817
- createMockTransaction("tx2_1", "1000"),
1818
- createMockTransaction("tx2_2", "1000"),
1819
- ];
1911
+ const operationList1 = {
1912
+ operations: Array.from(
1913
+ { length: sdk.TRANSACTIONS_LIMIT },
1914
+ (_, i) => createMockTransaction(`tx1_${i + 1}`, "1000"), // All same timestamp
1915
+ ),
1916
+ cursor: null,
1917
+ };
1918
+ const operationList2 = {
1919
+ operations: [
1920
+ createMockTransaction("tx2_1", "1000"),
1921
+ createMockTransaction("tx2_2", "1000"),
1922
+ ],
1923
+ cursor: null,
1924
+ };
1820
1925
 
1821
- const result = sdk.filterOperations(operationList1, operationList2, null);
1926
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1822
1927
 
1823
1928
  // Filter timestamp should be 1000 (the common timestamp)
1824
1929
  // All operations have timestamp 1000, so all should pass the filter
1825
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT + 2);
1930
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT + 2);
1826
1931
  });
1827
1932
  });
1828
1933