tigerbeetle-node 0.17.4 → 0.17.6
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/README.md +1 -0
- package/dist/bin/aarch64-linux-gnu/client.node +0 -0
- package/dist/bin/aarch64-linux-musl/client.node +0 -0
- package/dist/bin/aarch64-macos/client.node +0 -0
- package/dist/bin/x86_64-linux-gnu/client.node +0 -0
- package/dist/bin/x86_64-linux-musl/client.node +0 -0
- package/dist/bin/x86_64-macos/client.node +0 -0
- package/dist/bin/x86_64-windows/client.node +0 -0
- package/dist/bindings.js.map +1 -1
- package/dist/test.js +165 -69
- package/dist/test.js.map +1 -1
- package/package.json +1 -1
- package/src/bindings.ts +348 -348
- package/src/test.ts +178 -72
package/src/test.ts
CHANGED
|
@@ -17,9 +17,22 @@ import {
|
|
|
17
17
|
RequestError,
|
|
18
18
|
} from '.'
|
|
19
19
|
|
|
20
|
+
async function sleep_ms(ms: number): Promise<void> {
|
|
21
|
+
await new Promise(resolve => setTimeout(resolve, ms))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function range(n: number): number[] {
|
|
25
|
+
return Array.from({ length: n }, (_, i) => i);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function random_index(array: Array<any>): number {
|
|
29
|
+
return Math.floor(Math.random() * array.length);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const REPLICA_ADDRESSES = [process.env.TB_ADDRESS || '3000'];
|
|
20
33
|
const client = createClient({
|
|
21
34
|
cluster_id: 0n,
|
|
22
|
-
replica_addresses:
|
|
35
|
+
replica_addresses: REPLICA_ADDRESSES
|
|
23
36
|
})
|
|
24
37
|
|
|
25
38
|
// Test data
|
|
@@ -64,12 +77,61 @@ test.skip = (name: string, fn: () => Promise<void>) => {
|
|
|
64
77
|
console.log(name + ': SKIPPED')
|
|
65
78
|
}
|
|
66
79
|
|
|
80
|
+
test('Serialization: BigInt exceeds U128', async (): Promise<void> => {
|
|
81
|
+
const transfer: Transfer = {
|
|
82
|
+
id: 9999999999999999999999999999999999999999n,
|
|
83
|
+
debit_account_id: 0n,
|
|
84
|
+
credit_account_id: 0n,
|
|
85
|
+
amount: 0n,
|
|
86
|
+
user_data_128: 0n,
|
|
87
|
+
user_data_64: 0n,
|
|
88
|
+
user_data_32: 0,
|
|
89
|
+
pending_id: 0n,
|
|
90
|
+
timeout: 0,
|
|
91
|
+
ledger: 0,
|
|
92
|
+
code: 0,
|
|
93
|
+
flags: 0,
|
|
94
|
+
timestamp: 0n,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
assert.rejects(async() => await client.createTransfers([transfer]), (err) => {
|
|
98
|
+
assert.ok(err instanceof Error)
|
|
99
|
+
assert.strictEqual(err.message, "id must fit in 128 bits")
|
|
100
|
+
return true
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('Serialization: BigInt negative', async (): Promise<void> => {
|
|
105
|
+
const transfer: Transfer = {
|
|
106
|
+
id: -1n,
|
|
107
|
+
debit_account_id: 0n,
|
|
108
|
+
credit_account_id: 0n,
|
|
109
|
+
amount: 0n,
|
|
110
|
+
user_data_128: 0n,
|
|
111
|
+
user_data_64: 0n,
|
|
112
|
+
user_data_32: 0,
|
|
113
|
+
pending_id: 0n,
|
|
114
|
+
timeout: 0,
|
|
115
|
+
ledger: 0,
|
|
116
|
+
code: 0,
|
|
117
|
+
flags: 0,
|
|
118
|
+
timestamp: 0n,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
assert.rejects(async() => await client.createTransfers([transfer]), (err) => {
|
|
122
|
+
assert.ok(err instanceof Error)
|
|
123
|
+
assert.strictEqual(err.message, "id must be positive")
|
|
124
|
+
return true
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
|
|
67
129
|
test('id() monotonically increasing', async (): Promise<void> => {
|
|
68
130
|
let idA = id();
|
|
69
131
|
for (let i = 0; i < 10_000_000; i++) {
|
|
70
132
|
// Ensure ID is monotonic between milliseconds if the loop executes too fast.
|
|
71
133
|
if (i % 10_000 == 0) {
|
|
72
|
-
await
|
|
134
|
+
await sleep_ms(1)
|
|
73
135
|
}
|
|
74
136
|
|
|
75
137
|
const idB = id();
|
|
@@ -115,8 +177,8 @@ test('error if timestamp is not set to 0n on account', async (): Promise<void> =
|
|
|
115
177
|
|
|
116
178
|
test('batch max size', async (): Promise<void> => {
|
|
117
179
|
const BATCH_SIZE = 10_000;
|
|
118
|
-
|
|
119
|
-
for (
|
|
180
|
+
const transfers: Transfer[] = [];
|
|
181
|
+
for (let i=0; i<BATCH_SIZE;i++) {
|
|
120
182
|
transfers.push({
|
|
121
183
|
id: 0n,
|
|
122
184
|
debit_account_id: 0n,
|
|
@@ -140,6 +202,17 @@ test('batch max size', async (): Promise<void> => {
|
|
|
140
202
|
})
|
|
141
203
|
})
|
|
142
204
|
|
|
205
|
+
test('batch invalid size', async (): Promise<void> => {
|
|
206
|
+
const transfers: Transfer[] = [];
|
|
207
|
+
transfers.length = 0xffffffff;
|
|
208
|
+
|
|
209
|
+
assert.rejects(async() => await client.createTransfers(transfers), (err) => {
|
|
210
|
+
assert.ok(err instanceof RequestError)
|
|
211
|
+
assert.strictEqual(err.code, ErrorCodes.ERR_TOO_MUCH_DATA)
|
|
212
|
+
return true
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
|
|
143
216
|
test('can lookup accounts', async (): Promise<void> => {
|
|
144
217
|
const accounts = await client.lookupAccounts([accountA.id, accountB.id])
|
|
145
218
|
|
|
@@ -431,7 +504,7 @@ test('cannot void an expired transfer', async (): Promise<void> => {
|
|
|
431
504
|
assert.ok(transfers_results[0].timestamp > 0)
|
|
432
505
|
assert.deepStrictEqual(transfers_results[0].status, CreateTransferStatus.created)
|
|
433
506
|
|
|
434
|
-
|
|
507
|
+
let accounts = await client.lookupAccounts([accountA.id, accountB.id])
|
|
435
508
|
assert.strictEqual(accounts.length, 2)
|
|
436
509
|
assert.strictEqual(accounts[0].credits_posted, 150n)
|
|
437
510
|
assert.strictEqual(accounts[0].credits_pending, 50n)
|
|
@@ -446,9 +519,8 @@ test('cannot void an expired transfer', async (): Promise<void> => {
|
|
|
446
519
|
// We need to wait 1s for the server to expire the transfer, however the
|
|
447
520
|
// server can pulse the expiry operation anytime after the timeout,
|
|
448
521
|
// so adding an extra delay to avoid flaky tests.
|
|
449
|
-
// TODO: Use `await setTimeout(1000)` when upgrade to Node.js > 15.
|
|
450
522
|
const extra_wait_time = 500;
|
|
451
|
-
await
|
|
523
|
+
await sleep_ms((transfer.timeout * 1000) + extra_wait_time);
|
|
452
524
|
|
|
453
525
|
// Looking up the accounts again for the updated balance.
|
|
454
526
|
accounts = await client.lookupAccounts([accountA.id, accountB.id])
|
|
@@ -566,9 +638,9 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
566
638
|
assert.ok(account_results[0].timestamp > 0)
|
|
567
639
|
assert.deepStrictEqual(account_results[0].status, CreateAccountStatus.created)
|
|
568
640
|
|
|
569
|
-
|
|
641
|
+
const transfers_created : Transfer[] = [];
|
|
570
642
|
// Create transfers where the new account is either the debit or credit account:
|
|
571
|
-
for (
|
|
643
|
+
for (let i=0; i<10;i++) {
|
|
572
644
|
transfers_created.push({
|
|
573
645
|
id: BigInt(i + 10000),
|
|
574
646
|
debit_account_id: i % 2 == 0 ? accountC.id : accountA.id,
|
|
@@ -594,7 +666,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
594
666
|
}
|
|
595
667
|
|
|
596
668
|
// Query all transfers for accountC:
|
|
597
|
-
|
|
669
|
+
let filter: AccountFilter = {
|
|
598
670
|
account_id: accountC.id,
|
|
599
671
|
user_data_128: 0n,
|
|
600
672
|
user_data_64: 0n,
|
|
@@ -605,14 +677,14 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
605
677
|
limit: BATCH_MAX,
|
|
606
678
|
flags: AccountFilterFlags.credits | AccountFilterFlags.debits,
|
|
607
679
|
}
|
|
608
|
-
|
|
609
|
-
|
|
680
|
+
let transfers = await client.getAccountTransfers(filter)
|
|
681
|
+
let account_balances = await client.getAccountBalances(filter)
|
|
610
682
|
assert.strictEqual(transfers.length, transfers_created.length)
|
|
611
683
|
assert.strictEqual(account_balances.length, transfers.length)
|
|
612
684
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
for (
|
|
685
|
+
let timestamp = 0n;
|
|
686
|
+
let i = 0;
|
|
687
|
+
for (const transfer of transfers) {
|
|
616
688
|
assert.ok(timestamp < transfer.timestamp);
|
|
617
689
|
timestamp = transfer.timestamp;
|
|
618
690
|
|
|
@@ -640,7 +712,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
640
712
|
|
|
641
713
|
timestamp = 1n << 64n;
|
|
642
714
|
i = 0;
|
|
643
|
-
for (
|
|
715
|
+
for (const transfer of transfers) {
|
|
644
716
|
assert.ok(transfer.timestamp < timestamp);
|
|
645
717
|
timestamp = transfer.timestamp;
|
|
646
718
|
|
|
@@ -668,7 +740,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
668
740
|
|
|
669
741
|
timestamp = 1n << 64n;
|
|
670
742
|
i = 0;
|
|
671
|
-
for (
|
|
743
|
+
for (const transfer of transfers) {
|
|
672
744
|
assert.ok(transfer.timestamp < timestamp);
|
|
673
745
|
timestamp = transfer.timestamp;
|
|
674
746
|
|
|
@@ -696,7 +768,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
696
768
|
|
|
697
769
|
timestamp = 0n;
|
|
698
770
|
i = 0;
|
|
699
|
-
for (
|
|
771
|
+
for (const transfer of transfers) {
|
|
700
772
|
assert.ok(timestamp < transfer.timestamp);
|
|
701
773
|
timestamp = transfer.timestamp;
|
|
702
774
|
|
|
@@ -723,7 +795,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
723
795
|
assert.strictEqual(account_balances.length, transfers.length)
|
|
724
796
|
|
|
725
797
|
i = 0;
|
|
726
|
-
for (
|
|
798
|
+
for (const transfer of transfers) {
|
|
727
799
|
assert.ok(timestamp < transfer.timestamp);
|
|
728
800
|
timestamp = transfer.timestamp;
|
|
729
801
|
|
|
@@ -769,7 +841,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
769
841
|
|
|
770
842
|
timestamp = 1n << 64n;
|
|
771
843
|
i = 0;
|
|
772
|
-
for (
|
|
844
|
+
for (const transfer of transfers) {
|
|
773
845
|
assert.ok(timestamp > transfer.timestamp);
|
|
774
846
|
timestamp = transfer.timestamp;
|
|
775
847
|
|
|
@@ -796,7 +868,7 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
796
868
|
assert.strictEqual(account_balances.length, transfers.length)
|
|
797
869
|
|
|
798
870
|
i = 0;
|
|
799
|
-
for (
|
|
871
|
+
for (const transfer of transfers) {
|
|
800
872
|
assert.ok(timestamp > transfer.timestamp);
|
|
801
873
|
timestamp = transfer.timestamp;
|
|
802
874
|
|
|
@@ -954,9 +1026,9 @@ test('can get account transfers', async (): Promise<void> => {
|
|
|
954
1026
|
|
|
955
1027
|
test('can query accounts', async (): Promise<void> => {
|
|
956
1028
|
{
|
|
957
|
-
|
|
1029
|
+
const accounts : Account[] = [];
|
|
958
1030
|
// Create transfers:
|
|
959
|
-
for (
|
|
1031
|
+
for (let i=0; i<10;i++) {
|
|
960
1032
|
accounts.push({
|
|
961
1033
|
id: id(),
|
|
962
1034
|
debits_pending: 0n,
|
|
@@ -986,7 +1058,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
986
1058
|
// Querying accounts where:
|
|
987
1059
|
// `user_data_128=1000 AND user_data_64=100 AND user_data_32=10
|
|
988
1060
|
// AND code=999 AND ledger=1 ORDER BY timestamp ASC`.
|
|
989
|
-
|
|
1061
|
+
const filter: QueryFilter = {
|
|
990
1062
|
user_data_128: 1000n,
|
|
991
1063
|
user_data_64: 100n,
|
|
992
1064
|
user_data_32: 10,
|
|
@@ -997,11 +1069,11 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
997
1069
|
limit: BATCH_MAX,
|
|
998
1070
|
flags: QueryFilterFlags.none,
|
|
999
1071
|
}
|
|
1000
|
-
|
|
1072
|
+
const query: Account[] = await client.queryAccounts(filter)
|
|
1001
1073
|
assert.strictEqual(query.length, 5)
|
|
1002
1074
|
|
|
1003
|
-
|
|
1004
|
-
for (
|
|
1075
|
+
let timestamp = 0n;
|
|
1076
|
+
for (const account of query) {
|
|
1005
1077
|
assert.ok(timestamp < account.timestamp);
|
|
1006
1078
|
timestamp = account.timestamp;
|
|
1007
1079
|
|
|
@@ -1017,7 +1089,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1017
1089
|
// Querying accounts where:
|
|
1018
1090
|
// `user_data_128=2000 AND user_data_64=200 AND user_data_32=20
|
|
1019
1091
|
// AND code=999 AND ledger=1 ORDER BY timestamp DESC`.
|
|
1020
|
-
|
|
1092
|
+
const filter: QueryFilter = {
|
|
1021
1093
|
user_data_128: 2000n,
|
|
1022
1094
|
user_data_64: 200n,
|
|
1023
1095
|
user_data_32: 20,
|
|
@@ -1028,11 +1100,11 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1028
1100
|
limit: BATCH_MAX,
|
|
1029
1101
|
flags: QueryFilterFlags.reversed,
|
|
1030
1102
|
}
|
|
1031
|
-
|
|
1103
|
+
const query: Account[] = await client.queryAccounts(filter)
|
|
1032
1104
|
assert.strictEqual(query.length, 5)
|
|
1033
1105
|
|
|
1034
|
-
|
|
1035
|
-
for (
|
|
1106
|
+
let timestamp = 1n << 64n;
|
|
1107
|
+
for (const account of query) {
|
|
1036
1108
|
assert.ok(timestamp > account.timestamp);
|
|
1037
1109
|
timestamp = account.timestamp;
|
|
1038
1110
|
|
|
@@ -1047,7 +1119,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1047
1119
|
{
|
|
1048
1120
|
// Querying accounts where:
|
|
1049
1121
|
// `code=999 ORDER BY timestamp ASC`
|
|
1050
|
-
|
|
1122
|
+
const filter: QueryFilter = {
|
|
1051
1123
|
user_data_128: 0n,
|
|
1052
1124
|
user_data_64: 0n,
|
|
1053
1125
|
user_data_32: 0,
|
|
@@ -1058,11 +1130,11 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1058
1130
|
limit: BATCH_MAX,
|
|
1059
1131
|
flags: QueryFilterFlags.none,
|
|
1060
1132
|
}
|
|
1061
|
-
|
|
1133
|
+
const query: Account[] = await client.queryAccounts(filter)
|
|
1062
1134
|
assert.strictEqual(query.length, 10)
|
|
1063
1135
|
|
|
1064
|
-
|
|
1065
|
-
for (
|
|
1136
|
+
let timestamp = 0n;
|
|
1137
|
+
for (const account of query) {
|
|
1066
1138
|
assert.ok(timestamp < account.timestamp);
|
|
1067
1139
|
timestamp = account.timestamp;
|
|
1068
1140
|
|
|
@@ -1073,7 +1145,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1073
1145
|
{
|
|
1074
1146
|
// Querying accounts where:
|
|
1075
1147
|
// `code=999 ORDER BY timestamp DESC LIMIT 5`.
|
|
1076
|
-
|
|
1148
|
+
const filter: QueryFilter = {
|
|
1077
1149
|
user_data_128: 0n,
|
|
1078
1150
|
user_data_64: 0n,
|
|
1079
1151
|
user_data_32: 0,
|
|
@@ -1086,11 +1158,11 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1086
1158
|
}
|
|
1087
1159
|
|
|
1088
1160
|
// First 5 items:
|
|
1089
|
-
|
|
1161
|
+
let query: Account[] = await client.queryAccounts(filter)
|
|
1090
1162
|
assert.strictEqual(query.length, 5)
|
|
1091
1163
|
|
|
1092
|
-
|
|
1093
|
-
for (
|
|
1164
|
+
let timestamp = 1n << 64n;
|
|
1165
|
+
for (const account of query) {
|
|
1094
1166
|
assert.ok(timestamp > account.timestamp);
|
|
1095
1167
|
timestamp = account.timestamp;
|
|
1096
1168
|
|
|
@@ -1102,7 +1174,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1102
1174
|
query = await client.queryAccounts(filter)
|
|
1103
1175
|
assert.strictEqual(query.length, 5)
|
|
1104
1176
|
|
|
1105
|
-
for (
|
|
1177
|
+
for (const account of query) {
|
|
1106
1178
|
assert.ok(timestamp > account.timestamp);
|
|
1107
1179
|
timestamp = account.timestamp;
|
|
1108
1180
|
|
|
@@ -1117,7 +1189,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1117
1189
|
|
|
1118
1190
|
{
|
|
1119
1191
|
// Not found:
|
|
1120
|
-
|
|
1192
|
+
const filter: QueryFilter = {
|
|
1121
1193
|
user_data_128: 0n,
|
|
1122
1194
|
user_data_64: 200n,
|
|
1123
1195
|
user_data_32: 10,
|
|
@@ -1128,7 +1200,7 @@ test('can query accounts', async (): Promise<void> => {
|
|
|
1128
1200
|
limit: BATCH_MAX,
|
|
1129
1201
|
flags: QueryFilterFlags.none,
|
|
1130
1202
|
}
|
|
1131
|
-
|
|
1203
|
+
const query: Account[] = await client.queryAccounts(filter)
|
|
1132
1204
|
assert.strictEqual(query.length, 0)
|
|
1133
1205
|
}
|
|
1134
1206
|
})
|
|
@@ -1155,9 +1227,9 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1155
1227
|
assert.ok(account_results[0].timestamp > 0)
|
|
1156
1228
|
assert.deepStrictEqual(account_results[0].status, CreateAccountStatus.created)
|
|
1157
1229
|
|
|
1158
|
-
|
|
1230
|
+
const transfers_created : Transfer[] = [];
|
|
1159
1231
|
// Create transfers:
|
|
1160
|
-
for (
|
|
1232
|
+
for (let i=0; i<10;i++) {
|
|
1161
1233
|
transfers_created.push({
|
|
1162
1234
|
id: id(),
|
|
1163
1235
|
debit_account_id: i % 2 == 0 ? account.id : accountA.id,
|
|
@@ -1187,7 +1259,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1187
1259
|
// Querying transfers where:
|
|
1188
1260
|
// `user_data_128=1000 AND user_data_64=100 AND user_data_32=10
|
|
1189
1261
|
// AND code=999 AND ledger=1 ORDER BY timestamp ASC`.
|
|
1190
|
-
|
|
1262
|
+
const filter: QueryFilter = {
|
|
1191
1263
|
user_data_128: 1000n,
|
|
1192
1264
|
user_data_64: 100n,
|
|
1193
1265
|
user_data_32: 10,
|
|
@@ -1198,11 +1270,11 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1198
1270
|
limit: BATCH_MAX,
|
|
1199
1271
|
flags: QueryFilterFlags.none,
|
|
1200
1272
|
}
|
|
1201
|
-
|
|
1273
|
+
const query: Transfer[] = await client.queryTransfers(filter)
|
|
1202
1274
|
assert.strictEqual(query.length, 5)
|
|
1203
1275
|
|
|
1204
|
-
|
|
1205
|
-
for (
|
|
1276
|
+
let timestamp = 0n;
|
|
1277
|
+
for (const transfer of query) {
|
|
1206
1278
|
assert.ok(timestamp < transfer.timestamp);
|
|
1207
1279
|
timestamp = transfer.timestamp;
|
|
1208
1280
|
|
|
@@ -1218,7 +1290,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1218
1290
|
// Querying transfers where:
|
|
1219
1291
|
// `user_data_128=2000 AND user_data_64=200 AND user_data_32=20
|
|
1220
1292
|
// AND code=999 AND ledger=1 ORDER BY timestamp DESC`.
|
|
1221
|
-
|
|
1293
|
+
const filter: QueryFilter = {
|
|
1222
1294
|
user_data_128: 2000n,
|
|
1223
1295
|
user_data_64: 200n,
|
|
1224
1296
|
user_data_32: 20,
|
|
@@ -1229,11 +1301,11 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1229
1301
|
limit: BATCH_MAX,
|
|
1230
1302
|
flags: QueryFilterFlags.reversed,
|
|
1231
1303
|
}
|
|
1232
|
-
|
|
1304
|
+
const query: Transfer[] = await client.queryTransfers(filter)
|
|
1233
1305
|
assert.strictEqual(query.length, 5)
|
|
1234
1306
|
|
|
1235
|
-
|
|
1236
|
-
for (
|
|
1307
|
+
let timestamp = 1n << 64n;
|
|
1308
|
+
for (const transfer of query) {
|
|
1237
1309
|
assert.ok(timestamp > transfer.timestamp);
|
|
1238
1310
|
timestamp = transfer.timestamp;
|
|
1239
1311
|
|
|
@@ -1248,7 +1320,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1248
1320
|
{
|
|
1249
1321
|
// Querying transfers where:
|
|
1250
1322
|
// `code=999 ORDER BY timestamp ASC`
|
|
1251
|
-
|
|
1323
|
+
const filter: QueryFilter = {
|
|
1252
1324
|
user_data_128: 0n,
|
|
1253
1325
|
user_data_64: 0n,
|
|
1254
1326
|
user_data_32: 0,
|
|
@@ -1259,11 +1331,11 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1259
1331
|
limit: BATCH_MAX,
|
|
1260
1332
|
flags: QueryFilterFlags.none,
|
|
1261
1333
|
}
|
|
1262
|
-
|
|
1334
|
+
const query: Transfer[] = await client.queryTransfers(filter)
|
|
1263
1335
|
assert.strictEqual(query.length, 10)
|
|
1264
1336
|
|
|
1265
|
-
|
|
1266
|
-
for (
|
|
1337
|
+
let timestamp = 0n;
|
|
1338
|
+
for (const transfer of query) {
|
|
1267
1339
|
assert.ok(timestamp < transfer.timestamp);
|
|
1268
1340
|
timestamp = transfer.timestamp;
|
|
1269
1341
|
|
|
@@ -1274,7 +1346,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1274
1346
|
{
|
|
1275
1347
|
// Querying transfers where:
|
|
1276
1348
|
// `code=999 ORDER BY timestamp DESC LIMIT 5`.
|
|
1277
|
-
|
|
1349
|
+
const filter: QueryFilter = {
|
|
1278
1350
|
user_data_128: 0n,
|
|
1279
1351
|
user_data_64: 0n,
|
|
1280
1352
|
user_data_32: 0,
|
|
@@ -1287,11 +1359,11 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1287
1359
|
}
|
|
1288
1360
|
|
|
1289
1361
|
// First 5 items:
|
|
1290
|
-
|
|
1362
|
+
let query: Transfer[] = await client.queryTransfers(filter)
|
|
1291
1363
|
assert.strictEqual(query.length, 5)
|
|
1292
1364
|
|
|
1293
|
-
|
|
1294
|
-
for (
|
|
1365
|
+
let timestamp = 1n << 64n;
|
|
1366
|
+
for (const transfer of query) {
|
|
1295
1367
|
assert.ok(timestamp > transfer.timestamp);
|
|
1296
1368
|
timestamp = transfer.timestamp;
|
|
1297
1369
|
|
|
@@ -1303,7 +1375,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1303
1375
|
query = await client.queryTransfers(filter)
|
|
1304
1376
|
assert.strictEqual(query.length, 5)
|
|
1305
1377
|
|
|
1306
|
-
for (
|
|
1378
|
+
for (const transfer of query) {
|
|
1307
1379
|
assert.ok(timestamp > transfer.timestamp);
|
|
1308
1380
|
timestamp = transfer.timestamp;
|
|
1309
1381
|
|
|
@@ -1318,7 +1390,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1318
1390
|
|
|
1319
1391
|
{
|
|
1320
1392
|
// Not found:
|
|
1321
|
-
|
|
1393
|
+
const filter: QueryFilter = {
|
|
1322
1394
|
user_data_128: 0n,
|
|
1323
1395
|
user_data_64: 200n,
|
|
1324
1396
|
user_data_32: 10,
|
|
@@ -1329,7 +1401,7 @@ test('can query transfers', async (): Promise<void> => {
|
|
|
1329
1401
|
limit: BATCH_MAX,
|
|
1330
1402
|
flags: QueryFilterFlags.none,
|
|
1331
1403
|
}
|
|
1332
|
-
|
|
1404
|
+
const query: Transfer[] = await client.queryTransfers(filter)
|
|
1333
1405
|
assert.strictEqual(query.length, 0)
|
|
1334
1406
|
}
|
|
1335
1407
|
})
|
|
@@ -1461,7 +1533,7 @@ test('can import accounts and transfers', async (): Promise<void> => {
|
|
|
1461
1533
|
|
|
1462
1534
|
// Wait 10 ms so we can use the account's timestamp as the reference for past time
|
|
1463
1535
|
// after the last object inserted.
|
|
1464
|
-
await
|
|
1536
|
+
await sleep_ms(10);
|
|
1465
1537
|
|
|
1466
1538
|
const accountA: Account = {
|
|
1467
1539
|
id: id(),
|
|
@@ -1552,14 +1624,48 @@ test('accept zero-length lookup_transfers', async (): Promise<void> => {
|
|
|
1552
1624
|
})
|
|
1553
1625
|
|
|
1554
1626
|
test("destroy client in-flight", async (): Promise<void> => {
|
|
1555
|
-
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1627
|
+
const client_count = 5;
|
|
1628
|
+
const action_count = 50;
|
|
1629
|
+
|
|
1630
|
+
const clients = range(client_count).map(() =>
|
|
1631
|
+
createClient({
|
|
1632
|
+
cluster_id: 0n,
|
|
1633
|
+
replica_addresses: REPLICA_ADDRESSES,
|
|
1634
|
+
})
|
|
1635
|
+
);
|
|
1636
|
+
|
|
1637
|
+
const ids: Array<bigint> = [];
|
|
1638
|
+
const actions = range(action_count).map(() => async () => {
|
|
1639
|
+
await sleep_ms(Math.random() < 0.2 ? 0 : Math.random());
|
|
1640
|
+
const client = clients[random_index(clients)];
|
|
1641
|
+
if (Math.random() < 0.1) {
|
|
1642
|
+
client.destroy();
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
if (Math.random() < 0.7) {
|
|
1646
|
+
const id_new = id();
|
|
1647
|
+
ids.push(id_new);
|
|
1648
|
+
try {
|
|
1649
|
+
await client.createAccounts([{ ...accountA, id: id_new }]);
|
|
1650
|
+
} catch (err) {
|
|
1651
|
+
assert.ok(err instanceof RequestError);
|
|
1652
|
+
assert.strictEqual(err.code, ErrorCodes.ERR_CLIENT_CLOSED);
|
|
1653
|
+
}
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
try {
|
|
1657
|
+
const id_lookup = (Math.random() < 0.2 || ids.length == 0)
|
|
1658
|
+
? BigInt(Math.floor(Math.random() * 10000))
|
|
1659
|
+
: ids[random_index(ids)];
|
|
1660
|
+
await client.lookupAccounts([id_lookup]);
|
|
1661
|
+
} catch (err) {
|
|
1662
|
+
assert.ok(err instanceof RequestError);
|
|
1663
|
+
assert.strictEqual(err.code, ErrorCodes.ERR_CLIENT_CLOSED);
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
|
|
1667
|
+
await Promise.all(actions.map((f) => f()));
|
|
1668
|
+
for (const client of clients) client.destroy();
|
|
1563
1669
|
});
|
|
1564
1670
|
|
|
1565
1671
|
async function main () {
|