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