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