@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
@@ -987,8 +987,8 @@ describe("loadOperations", () => {
987
987
  order: "ascending",
988
988
  operations: [],
989
989
  });
990
- expect(result).toHaveLength(pageSize + 1);
991
- expect(result.map(tx => tx.digest)).toEqual([
990
+ expect(result.operations).toHaveLength(pageSize + 1);
991
+ expect(result.operations.map(tx => tx.digest)).toEqual([
992
992
  ...firstPage.map(tx => tx.digest),
993
993
  `tx${pageSize + 1}`,
994
994
  ]);
@@ -1010,7 +1010,7 @@ describe("loadOperations", () => {
1010
1010
  order: "ascending",
1011
1011
  operations: [],
1012
1012
  });
1013
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT_PER_QUERY - 1);
1013
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT_PER_QUERY - 1);
1014
1014
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(1);
1015
1015
  });
1016
1016
  it("should not exceed TRANSACTIONS_LIMIT", async () => {
@@ -1034,7 +1034,7 @@ describe("loadOperations", () => {
1034
1034
  order: "ascending",
1035
1035
  operations: [],
1036
1036
  });
1037
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT);
1037
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT);
1038
1038
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(expectedCalls);
1039
1039
  });
1040
1040
  it("should retry without cursor when InvalidParams error occurs", async () => {
@@ -1058,7 +1058,7 @@ describe("loadOperations", () => {
1058
1058
  cursor: "some-cursor",
1059
1059
  }));
1060
1060
  // Result should be empty array (no retry, just return operations)
1061
- expect(result).toHaveLength(0);
1061
+ expect(result.operations).toHaveLength(0);
1062
1062
  });
1063
1063
  it("should should not retry after unexpected errors and return empty data", async () => {
1064
1064
  mockApi.queryTransactionBlocks.mockRejectedValueOnce(new Error("unexpected"));
@@ -1069,7 +1069,7 @@ describe("loadOperations", () => {
1069
1069
  order: "ascending",
1070
1070
  operations: [],
1071
1071
  });
1072
- expect(result).toEqual([]);
1072
+ expect(result.operations).toEqual([]);
1073
1073
  expect(mockApi.queryTransactionBlocks).toHaveBeenCalledTimes(1);
1074
1074
  });
1075
1075
  });
@@ -1140,18 +1140,24 @@ describe("getOperations filtering logic", () => {
1140
1140
  // Mock loadOperations to return different data based on operation type
1141
1141
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1142
1142
  if (type === "OUT") {
1143
- return [
1144
- createMockTransaction("sent1", "1000", mockAddr, []),
1145
- createMockTransaction("sent2", "2000", mockAddr, []),
1146
- ];
1143
+ return {
1144
+ operations: [
1145
+ createMockTransaction("sent1", "1000", mockAddr, []),
1146
+ createMockTransaction("sent2", "2000", mockAddr, []),
1147
+ ],
1148
+ cursor: null,
1149
+ };
1147
1150
  }
1148
1151
  else if (type === "IN") {
1149
- return [
1150
- createMockTransaction("received1", "1500", otherAddr, [mockAddr]),
1151
- createMockTransaction("received2", "2500", otherAddr, [mockAddr]),
1152
- ];
1152
+ return {
1153
+ operations: [
1154
+ createMockTransaction("received1", "1500", otherAddr, [mockAddr]),
1155
+ createMockTransaction("received2", "2500", otherAddr, [mockAddr]),
1156
+ ],
1157
+ cursor: null,
1158
+ };
1153
1159
  }
1154
- return [];
1160
+ return { operations: [], cursor: null };
1155
1161
  });
1156
1162
  });
1157
1163
  afterEach(() => {
@@ -1174,15 +1180,21 @@ describe("getOperations filtering logic", () => {
1174
1180
  // Mock to return enough sent operations to reach limit
1175
1181
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1176
1182
  if (type === "OUT") {
1177
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []));
1183
+ return {
1184
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, [])),
1185
+ cursor: null,
1186
+ };
1178
1187
  }
1179
1188
  else if (type === "IN") {
1180
- return [
1181
- createMockTransaction("received1", "500", otherAddr, [mockAddr]),
1182
- createMockTransaction("received2", "1500", otherAddr, [mockAddr]),
1183
- ];
1189
+ return {
1190
+ operations: [
1191
+ createMockTransaction("received1", "500", otherAddr, [mockAddr]),
1192
+ createMockTransaction("received2", "1500", otherAddr, [mockAddr]),
1193
+ ],
1194
+ cursor: null,
1195
+ };
1184
1196
  }
1185
- return [];
1197
+ return { operations: [], cursor: null };
1186
1198
  });
1187
1199
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1188
1200
  // Filter timestamp should be the maximum of the last timestamps from both arrays
@@ -1197,15 +1209,23 @@ describe("getOperations filtering logic", () => {
1197
1209
  // Mock to return enough received operations to reach limit
1198
1210
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1199
1211
  if (type === "OUT") {
1200
- return [
1201
- createMockTransaction("sent1", "500", mockAddr, []),
1202
- createMockTransaction("sent2", "1500", mockAddr, []),
1203
- ];
1212
+ return {
1213
+ operations: [
1214
+ createMockTransaction("sent1", "500", mockAddr, []),
1215
+ createMockTransaction("sent2", "1500", mockAddr, []),
1216
+ ],
1217
+ cursor: null,
1218
+ };
1204
1219
  }
1205
1220
  else if (type === "IN") {
1206
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(1000 + i * 100), otherAddr, [mockAddr]));
1221
+ return {
1222
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(1000 + i * 100), otherAddr, [
1223
+ mockAddr,
1224
+ ])),
1225
+ cursor: null,
1226
+ };
1207
1227
  }
1208
- return [];
1228
+ return { operations: [], cursor: null };
1209
1229
  });
1210
1230
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1211
1231
  // Filter timestamp should be the maximum of the last timestamps from both arrays
@@ -1220,12 +1240,20 @@ describe("getOperations filtering logic", () => {
1220
1240
  // Mock to return enough operations to reach limit for both types
1221
1241
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1222
1242
  if (type === "OUT") {
1223
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, []));
1243
+ return {
1244
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 100), mockAddr, [])),
1245
+ cursor: null,
1246
+ };
1224
1247
  }
1225
1248
  else if (type === "IN") {
1226
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(2000 + i * 100), otherAddr, [mockAddr]));
1249
+ return {
1250
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(2000 + i * 100), otherAddr, [
1251
+ mockAddr,
1252
+ ])),
1253
+ cursor: null,
1254
+ };
1227
1255
  }
1228
- return [];
1256
+ return { operations: [], cursor: null };
1229
1257
  });
1230
1258
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1231
1259
  // Filter timestamp should be the maximum of the last timestamps from both arrays
@@ -1240,21 +1268,27 @@ describe("getOperations filtering logic", () => {
1240
1268
  // Mock to return operations with null timestamps and reach limit
1241
1269
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1242
1270
  if (type === "OUT") {
1243
- return [
1244
- createMockTransaction("sent1", "1000", mockAddr, []),
1245
- createMockTransaction("sent2", null, mockAddr, []),
1246
- createMockTransaction("sent3", "3000", mockAddr, []),
1247
- ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`sent${i + 4}`, String(4000 + i * 100), mockAddr, [])),
1248
- ];
1271
+ return {
1272
+ operations: [
1273
+ createMockTransaction("sent1", "1000", mockAddr, []),
1274
+ createMockTransaction("sent2", null, mockAddr, []),
1275
+ createMockTransaction("sent3", "3000", mockAddr, []),
1276
+ ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`sent${i + 4}`, String(4000 + i * 100), mockAddr, [])),
1277
+ ],
1278
+ cursor: null,
1279
+ };
1249
1280
  }
1250
1281
  else if (type === "IN") {
1251
- return [
1252
- createMockTransaction("received1", null, otherAddr, [mockAddr]),
1253
- createMockTransaction("received2", "2000", otherAddr, [mockAddr]),
1254
- createMockTransaction("received3", "4000", otherAddr, [mockAddr]),
1255
- ];
1282
+ return {
1283
+ operations: [
1284
+ createMockTransaction("received1", null, otherAddr, [mockAddr]),
1285
+ createMockTransaction("received2", "2000", otherAddr, [mockAddr]),
1286
+ createMockTransaction("received3", "4000", otherAddr, [mockAddr]),
1287
+ ],
1288
+ cursor: null,
1289
+ };
1256
1290
  }
1257
- return [];
1291
+ return { operations: [], cursor: null };
1258
1292
  });
1259
1293
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1260
1294
  // Filter timestamp should be the timestamp of the last sent operation (4000 + 296*100 = 33600)
@@ -1266,12 +1300,18 @@ describe("getOperations filtering logic", () => {
1266
1300
  // Mock to return operations that reach limit
1267
1301
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1268
1302
  if (type === "OUT") {
1269
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 10), mockAddr, []));
1303
+ return {
1304
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, String(1000 + i * 10), mockAddr, [])),
1305
+ cursor: null,
1306
+ };
1270
1307
  }
1271
1308
  else if (type === "IN") {
1272
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(500 + i * 10), otherAddr, [mockAddr]));
1309
+ return {
1310
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`received${i + 1}`, String(500 + i * 10), otherAddr, [mockAddr])),
1311
+ cursor: null,
1312
+ };
1273
1313
  }
1274
- return [];
1314
+ return { operations: [], cursor: null };
1275
1315
  });
1276
1316
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1277
1317
  // Should be sorted by timestamp in descending order
@@ -1281,7 +1321,7 @@ describe("getOperations filtering logic", () => {
1281
1321
  test("should handle empty operations arrays", async () => {
1282
1322
  // Mock to return empty arrays
1283
1323
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1284
- return [];
1324
+ return { operations: [], cursor: null };
1285
1325
  });
1286
1326
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1287
1327
  expect(operations).toHaveLength(0);
@@ -1290,15 +1330,18 @@ describe("getOperations filtering logic", () => {
1290
1330
  // Mock to return only OUT operations
1291
1331
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1292
1332
  if (type === "OUT") {
1293
- return [
1294
- createMockTransaction("sent1", "1000", mockAddr, []),
1295
- createMockTransaction("sent2", "2000", mockAddr, []),
1296
- ];
1333
+ return {
1334
+ operations: [
1335
+ createMockTransaction("sent1", "1000", mockAddr, []),
1336
+ createMockTransaction("sent2", "2000", mockAddr, []),
1337
+ ],
1338
+ cursor: null,
1339
+ };
1297
1340
  }
1298
1341
  else if (type === "IN") {
1299
- return [];
1342
+ return { operations: [], cursor: null };
1300
1343
  }
1301
- return [];
1344
+ return { operations: [], cursor: null };
1302
1345
  });
1303
1346
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1304
1347
  expect(operations).toHaveLength(2);
@@ -1308,15 +1351,21 @@ describe("getOperations filtering logic", () => {
1308
1351
  // Mock to return operations with same timestamps and reach limit
1309
1352
  mockLoadOperations.mockImplementation(async ({ type, ..._params }) => {
1310
1353
  if (type === "OUT") {
1311
- return Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, "1000", mockAddr, []));
1354
+ return {
1355
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`sent${i + 1}`, "1000", mockAddr, [])),
1356
+ cursor: null,
1357
+ };
1312
1358
  }
1313
1359
  else if (type === "IN") {
1314
- return [
1315
- createMockTransaction("received1", "1000", otherAddr, [mockAddr]),
1316
- createMockTransaction("received2", "1000", otherAddr, [mockAddr]),
1317
- ];
1360
+ return {
1361
+ operations: [
1362
+ createMockTransaction("received1", "1000", otherAddr, [mockAddr]),
1363
+ createMockTransaction("received2", "1000", otherAddr, [mockAddr]),
1364
+ ],
1365
+ cursor: null,
1366
+ };
1318
1367
  }
1319
- return [];
1368
+ return { operations: [], cursor: null };
1320
1369
  });
1321
1370
  const operations = await sdk.getOperations(mockAccountId, mockAddr);
1322
1371
  // Filter timestamp should be 1000 (the common timestamp)
@@ -1372,189 +1421,239 @@ describe("filterOperations", () => {
1372
1421
  });
1373
1422
  describe("when cursor is provided", () => {
1374
1423
  test("should not apply timestamp filtering", () => {
1375
- const operationList1 = [
1376
- createMockTransaction("tx1", "1000"),
1377
- createMockTransaction("tx2", "2000"),
1378
- ];
1379
- const operationList2 = [
1380
- createMockTransaction("tx3", "1500"),
1381
- createMockTransaction("tx4", "2500"),
1382
- ];
1383
- const cursor = "test-cursor";
1384
- const result = sdk.filterOperations(operationList1, operationList2, cursor);
1424
+ const operationList1 = {
1425
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1426
+ cursor: null,
1427
+ };
1428
+ const operationList2 = {
1429
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1430
+ cursor: null,
1431
+ };
1432
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1385
1433
  // Should return all operations sorted by timestamp in descending order
1386
- expect(result).toHaveLength(4);
1387
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1434
+ expect(result.operations).toHaveLength(4);
1435
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1388
1436
  });
1389
1437
  test("should handle null cursor", () => {
1390
- const operationList1 = [
1391
- createMockTransaction("tx1", "1000"),
1392
- createMockTransaction("tx2", "2000"),
1393
- ];
1394
- const operationList2 = [
1395
- createMockTransaction("tx3", "1500"),
1396
- createMockTransaction("tx4", "2500"),
1397
- ];
1398
- const result = sdk.filterOperations(operationList1, operationList2, null);
1438
+ const operationList1 = {
1439
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1440
+ cursor: null,
1441
+ };
1442
+ const operationList2 = {
1443
+ operations: [createMockTransaction("tx3", "1500"), createMockTransaction("tx4", "2500")],
1444
+ cursor: null,
1445
+ };
1446
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1399
1447
  // Should return all operations sorted by timestamp in descending order
1400
- expect(result).toHaveLength(4);
1401
- expect(result.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1448
+ expect(result.operations).toHaveLength(4);
1449
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx4", "tx2", "tx3", "tx1"]);
1402
1450
  });
1403
1451
  test("should handle undefined cursor", () => {
1404
- const operationList1 = [
1405
- createMockTransaction("tx1", "1000"),
1406
- createMockTransaction("tx2", "2000"),
1407
- ];
1408
- const operationList2 = [
1409
- createMockTransaction("tx3", "1500"),
1410
- createMockTransaction("tx4", "2500"),
1411
- ];
1412
- const result = sdk.filterOperations(operationList1, operationList2, undefined);
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
  });
1418
1466
  describe("when cursor is not provided and operations reach limits", () => {
1419
1467
  test("should apply timestamp filtering when both lists reach limit", () => {
1420
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)));
1421
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)));
1422
- const result = sdk.filterOperations(operationList1, operationList2, null);
1468
+ const operationList1 = {
1469
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100))),
1470
+ cursor: null,
1471
+ };
1472
+ const operationList2 = {
1473
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100))),
1474
+ cursor: null,
1475
+ };
1476
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1423
1477
  // Filter timestamp should be max of last timestamps:
1424
1478
  // operationList1: 1000 + 299*100 = 30900
1425
1479
  // operationList2: 2000 + 299*100 = 31900
1426
1480
  // filter = max(30900, 31900) = 31900
1427
1481
  // Only operations with timestamp >= 31900 should remain
1428
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 31900);
1482
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 31900);
1429
1483
  expect(filteredOperations).toHaveLength(1);
1430
1484
  expect(filteredOperations[0].digest).toBe("tx2_300");
1431
1485
  });
1432
1486
  test("should apply timestamp filtering when only first list reaches limit", () => {
1433
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)));
1434
- const operationList2 = [
1435
- createMockTransaction("tx2_1", "500"),
1436
- createMockTransaction("tx2_2", "1500"),
1437
- ];
1438
- const result = sdk.filterOperations(operationList1, operationList2, null);
1487
+ const operationList1 = {
1488
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100))),
1489
+ cursor: null,
1490
+ };
1491
+ const operationList2 = {
1492
+ operations: [createMockTransaction("tx2_1", "500"), createMockTransaction("tx2_2", "1500")],
1493
+ cursor: null,
1494
+ };
1495
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1439
1496
  // Filter timestamp should be max of last timestamps:
1440
1497
  // operationList1: 1000 + 299*100 = 30900
1441
1498
  // operationList2: 1500
1442
1499
  // filter = max(30900, 1500) = 30900
1443
1500
  // Only operations with timestamp >= 30900 should remain
1444
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 30900);
1501
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 30900);
1445
1502
  expect(filteredOperations).toHaveLength(1);
1446
1503
  expect(filteredOperations[0].digest).toBe("tx1_300");
1447
1504
  });
1448
1505
  test("should apply timestamp filtering when only second list reaches limit", () => {
1449
- const operationList1 = [
1450
- createMockTransaction("tx1_1", "500"),
1451
- createMockTransaction("tx1_2", "1500"),
1452
- ];
1453
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100)));
1454
- const result = sdk.filterOperations(operationList1, operationList2, null);
1506
+ const operationList1 = {
1507
+ operations: [createMockTransaction("tx1_1", "500"), createMockTransaction("tx1_2", "1500")],
1508
+ cursor: null,
1509
+ };
1510
+ const operationList2 = {
1511
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(2000 + i * 100))),
1512
+ cursor: null,
1513
+ };
1514
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1455
1515
  // Filter timestamp should be max of last timestamps:
1456
1516
  // operationList1: 1500
1457
1517
  // operationList2: 2000 + 299*100 = 31900
1458
1518
  // filter = max(1500, 31900) = 31900
1459
1519
  // Only operations with timestamp >= 31900 should remain
1460
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 31900);
1520
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 31900);
1461
1521
  expect(filteredOperations).toHaveLength(1);
1462
1522
  expect(filteredOperations[0].digest).toBe("tx2_300");
1463
1523
  });
1464
1524
  });
1465
1525
  describe("when cursor is not provided and operations don't reach limits", () => {
1466
1526
  test("should not apply timestamp filtering when neither list reaches limit", () => {
1467
- const operationList1 = [
1468
- createMockTransaction("tx1_1", "1000"),
1469
- createMockTransaction("tx1_2", "2000"),
1470
- ];
1471
- const operationList2 = [
1472
- createMockTransaction("tx2_1", "1500"),
1473
- createMockTransaction("tx2_2", "2500"),
1474
- ];
1475
- const result = sdk.filterOperations(operationList1, operationList2, null);
1527
+ const operationList1 = {
1528
+ operations: [
1529
+ createMockTransaction("tx1_1", "1000"),
1530
+ createMockTransaction("tx1_2", "2000"),
1531
+ ],
1532
+ cursor: null,
1533
+ };
1534
+ const operationList2 = {
1535
+ operations: [
1536
+ createMockTransaction("tx2_1", "1500"),
1537
+ createMockTransaction("tx2_2", "2500"),
1538
+ ],
1539
+ cursor: null,
1540
+ };
1541
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1476
1542
  // Should return all operations sorted by timestamp in descending order
1477
- expect(result).toHaveLength(4);
1478
- expect(result.map(tx => tx.digest)).toEqual(["tx2_2", "tx1_2", "tx2_1", "tx1_1"]);
1543
+ expect(result.operations).toHaveLength(4);
1544
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx2_2", "tx1_2", "tx2_1", "tx1_1"]);
1479
1545
  });
1480
1546
  test("should apply timestamp filtering when only one list reaches limit", () => {
1481
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100)));
1482
- const operationList2 = [createMockTransaction("tx2_1", "1500")];
1483
- const result = sdk.filterOperations(operationList1, operationList2, null);
1547
+ const operationList1 = {
1548
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 100))),
1549
+ cursor: null,
1550
+ };
1551
+ const operationList2 = {
1552
+ operations: [createMockTransaction("tx2_1", "1500")],
1553
+ cursor: null,
1554
+ };
1555
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1484
1556
  // Should apply timestamp filtering since one list reaches limit
1485
1557
  // Filter timestamp should be the timestamp of the last operation in list1 (1000 + 299*100 = 30900)
1486
1558
  // Only operations with timestamp >= 30900 should remain
1487
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 30900);
1559
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 30900);
1488
1560
  expect(filteredOperations).toHaveLength(1);
1489
1561
  expect(filteredOperations[0].digest).toBe("tx1_300");
1490
1562
  });
1491
1563
  });
1492
1564
  describe("edge cases", () => {
1493
1565
  test("should handle null/undefined timestampMs values", () => {
1494
- const operationList1 = [
1495
- createMockTransaction("tx1_1", "1000"),
1496
- createMockTransaction("tx1_2", null),
1497
- createMockTransaction("tx1_3", "3000"),
1498
- ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`tx1_${i + 4}`, String(4000 + i * 100))),
1499
- ];
1500
- const operationList2 = [
1501
- createMockTransaction("tx2_1", null),
1502
- createMockTransaction("tx2_2", "2000"),
1503
- createMockTransaction("tx2_3", "4000"),
1504
- ];
1505
- const result = sdk.filterOperations(operationList1, operationList2, null);
1566
+ const operationList1 = {
1567
+ operations: [
1568
+ createMockTransaction("tx1_1", "1000"),
1569
+ createMockTransaction("tx1_2", null),
1570
+ createMockTransaction("tx1_3", "3000"),
1571
+ ...Array.from({ length: sdk.TRANSACTIONS_LIMIT - 3 }, (_, i) => createMockTransaction(`tx1_${i + 4}`, String(4000 + i * 100))),
1572
+ ],
1573
+ cursor: null,
1574
+ };
1575
+ const operationList2 = {
1576
+ operations: [
1577
+ createMockTransaction("tx2_1", null),
1578
+ createMockTransaction("tx2_2", "2000"),
1579
+ createMockTransaction("tx2_3", "4000"),
1580
+ ],
1581
+ cursor: null,
1582
+ };
1583
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1506
1584
  // Filter timestamp should be the timestamp of the last operation in list1 (4000 + 296*100 = 33600)
1507
1585
  // Only operations with timestamp >= 33600 should remain
1508
- const filteredOperations = result.filter(tx => Number(tx.timestampMs) >= 33600);
1586
+ const filteredOperations = result.operations.filter(tx => Number(tx.timestampMs) >= 33600);
1509
1587
  expect(filteredOperations).toHaveLength(1);
1510
1588
  expect(filteredOperations[0].digest).toBe("tx1_300");
1511
1589
  });
1512
1590
  test("should handle empty arrays", () => {
1513
- const result = sdk.filterOperations([], [], null);
1514
- expect(result).toHaveLength(0);
1591
+ const result = sdk.filterOperations({ operations: [], cursor: null }, { operations: [], cursor: null }, "ascending");
1592
+ expect(result.operations).toHaveLength(0);
1515
1593
  });
1516
1594
  test("should handle one empty array", () => {
1517
- const operationList1 = [
1518
- createMockTransaction("tx1_1", "1000"),
1519
- createMockTransaction("tx1_2", "2000"),
1520
- ];
1521
- const operationList2 = [];
1522
- const result = sdk.filterOperations(operationList1, operationList2, null);
1523
- expect(result).toHaveLength(2);
1524
- expect(result.map(tx => tx.digest)).toEqual(["tx1_2", "tx1_1"]);
1595
+ const operationList1 = {
1596
+ operations: [
1597
+ createMockTransaction("tx1_1", "1000"),
1598
+ createMockTransaction("tx1_2", "2000"),
1599
+ ],
1600
+ cursor: null,
1601
+ };
1602
+ const operationList2 = {
1603
+ operations: [],
1604
+ cursor: null,
1605
+ };
1606
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1607
+ expect(result.operations).toHaveLength(2);
1608
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx1_2", "tx1_1"]);
1525
1609
  });
1526
1610
  test("should remove duplicate transactions by digest", () => {
1527
- const operationList1 = [
1528
- createMockTransaction("tx1", "1000"),
1529
- createMockTransaction("tx2", "2000"),
1530
- ];
1531
- const operationList2 = [
1532
- createMockTransaction("tx2", "2000"), // Duplicate digest
1533
- createMockTransaction("tx3", "3000"),
1534
- ];
1535
- const result = sdk.filterOperations(operationList1, operationList2, null);
1611
+ const operationList1 = {
1612
+ operations: [createMockTransaction("tx1", "1000"), createMockTransaction("tx2", "2000")],
1613
+ cursor: null,
1614
+ };
1615
+ const operationList2 = {
1616
+ operations: [
1617
+ createMockTransaction("tx2", "2000"), // Duplicate digest
1618
+ createMockTransaction("tx3", "3000"),
1619
+ ],
1620
+ cursor: null,
1621
+ };
1622
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1536
1623
  // Should remove duplicate tx2
1537
- expect(result).toHaveLength(3);
1538
- expect(result.map(tx => tx.digest)).toEqual(["tx3", "tx2", "tx1"]);
1624
+ expect(result.operations).toHaveLength(3);
1625
+ expect(result.operations.map(tx => tx.digest)).toEqual(["tx3", "tx2", "tx1"]);
1539
1626
  });
1540
1627
  test("should maintain chronological order after filtering", () => {
1541
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 10)));
1542
- const operationList2 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(500 + i * 10)));
1543
- const result = sdk.filterOperations(operationList1, operationList2, null);
1628
+ const operationList1 = {
1629
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, String(1000 + i * 10))),
1630
+ cursor: null,
1631
+ };
1632
+ const operationList2 = {
1633
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx2_${i + 1}`, String(500 + i * 10))),
1634
+ cursor: null,
1635
+ };
1636
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1544
1637
  // Should be sorted by timestamp in descending order
1545
- const timestamps = result.map(tx => Number(tx.timestampMs));
1638
+ const timestamps = result.operations.map(tx => Number(tx.timestampMs));
1546
1639
  expect(timestamps).toEqual(timestamps.slice().sort((a, b) => b - a));
1547
1640
  });
1548
1641
  test("should handle operations with same timestamps", () => {
1549
- const operationList1 = Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, "1000"));
1550
- const operationList2 = [
1551
- createMockTransaction("tx2_1", "1000"),
1552
- createMockTransaction("tx2_2", "1000"),
1553
- ];
1554
- const result = sdk.filterOperations(operationList1, operationList2, null);
1642
+ const operationList1 = {
1643
+ operations: Array.from({ length: sdk.TRANSACTIONS_LIMIT }, (_, i) => createMockTransaction(`tx1_${i + 1}`, "1000")),
1644
+ cursor: null,
1645
+ };
1646
+ const operationList2 = {
1647
+ operations: [
1648
+ createMockTransaction("tx2_1", "1000"),
1649
+ createMockTransaction("tx2_2", "1000"),
1650
+ ],
1651
+ cursor: null,
1652
+ };
1653
+ const result = sdk.filterOperations(operationList1, operationList2, "ascending");
1555
1654
  // Filter timestamp should be 1000 (the common timestamp)
1556
1655
  // All operations have timestamp 1000, so all should pass the filter
1557
- expect(result).toHaveLength(sdk.TRANSACTIONS_LIMIT + 2);
1656
+ expect(result.operations).toHaveLength(sdk.TRANSACTIONS_LIMIT + 2);
1558
1657
  });
1559
1658
  });
1560
1659
  describe("conversion methods", () => {