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