@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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +23 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integration.test.js +9 -2
- package/lib/api/index.integration.test.js.map +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +3 -3
- package/lib/api/index.test.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +9 -7
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.test.js +2 -2
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +4 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +2 -2
- package/lib/bridge/utils.js.map +1 -1
- package/lib/logic/listOperations.d.ts +1 -3
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +3 -3
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +43 -39
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/network/index.d.ts +1 -1
- package/lib/network/sdk.d.ts +9 -5
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +54 -27
- package/lib/network/sdk.js.map +1 -1
- package/lib/network/sdk.test.js +272 -170
- package/lib/network/sdk.test.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integration.test.js +9 -2
- package/lib-es/api/index.integration.test.js.map +1 -1
- package/lib-es/api/index.js +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +3 -3
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +9 -7
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.test.js +2 -2
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +4 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +2 -2
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +1 -3
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +4 -4
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +44 -40
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/network/index.d.ts +1 -1
- package/lib-es/network/sdk.d.ts +9 -5
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +54 -27
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/network/sdk.test.js +272 -170
- package/lib-es/network/sdk.test.js.map +1 -1
- package/package.json +5 -5
- package/src/api/index.integration.test.ts +10 -2
- package/src/api/index.test.ts +3 -3
- package/src/api/index.ts +4 -3
- package/src/bridge/estimateMaxSpendable.test.ts +2 -2
- package/src/bridge/estimateMaxSpendable.ts +9 -8
- package/src/bridge/getTransactionStatus.ts +4 -2
- package/src/bridge/utils.ts +2 -2
- package/src/logic/listOperations.test.ts +45 -41
- package/src/logic/listOperations.ts +4 -4
- package/src/network/sdk.test.ts +312 -207
- package/src/network/sdk.ts +70 -32
package/src/network/sdk.test.ts
CHANGED
|
@@ -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
|
-
|
|
1311
|
-
|
|
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
|
-
|
|
1316
|
-
|
|
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
|
|
1350
|
-
|
|
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
|
-
|
|
1355
|
-
|
|
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
|
-
|
|
1378
|
-
|
|
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
|
|
1382
|
-
|
|
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
|
|
1404
|
-
|
|
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
|
|
1408
|
-
|
|
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
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
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
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
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
|
|
1460
|
-
|
|
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
|
|
1464
|
-
|
|
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
|
-
|
|
1494
|
-
|
|
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
|
|
1513
|
-
|
|
1514
|
-
|
|
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
|
-
|
|
1519
|
-
|
|
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
|
-
|
|
1588
|
-
|
|
1589
|
-
const operationList2 =
|
|
1590
|
-
createMockTransaction("tx3", "1500"),
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
const
|
|
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
|
-
|
|
1606
|
-
|
|
1607
|
-
const operationList2 =
|
|
1608
|
-
createMockTransaction("tx3", "1500"),
|
|
1609
|
-
|
|
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,
|
|
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
|
-
|
|
1623
|
-
|
|
1624
|
-
const operationList2 =
|
|
1625
|
-
createMockTransaction("tx3", "1500"),
|
|
1626
|
-
|
|
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,
|
|
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 =
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
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,
|
|
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 =
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
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,
|
|
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
|
-
|
|
1683
|
-
|
|
1684
|
-
const operationList2 =
|
|
1685
|
-
|
|
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,
|
|
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
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
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,
|
|
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 =
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
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,
|
|
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
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
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,
|
|
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(
|
|
1763
|
-
|
|
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
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
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,
|
|
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
|
-
|
|
1783
|
-
|
|
1784
|
-
const operationList2 =
|
|
1785
|
-
|
|
1786
|
-
|
|
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,
|
|
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 =
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
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,
|
|
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 =
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
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,
|
|
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
|
|