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