@buildonspark/issuer-sdk 0.1.35 → 0.1.36
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/CHANGELOG.md +8 -0
- package/dist/index.browser.d.ts +2 -1
- package/dist/index.browser.js +102 -92
- package/dist/index.node.cjs +102 -92
- package/dist/index.node.d.cts +2 -1
- package/dist/index.node.d.ts +2 -1
- package/dist/index.node.js +102 -92
- package/dist/native/index.react-native.cjs +102 -92
- package/dist/native/index.react-native.d.cts +2 -1
- package/dist/native/index.react-native.d.ts +2 -1
- package/dist/native/index.react-native.js +102 -92
- package/package.json +9 -6
- package/src/issuer-wallet/issuer-spark-wallet.react-native.ts +0 -1
- package/src/issuer-wallet/issuer-spark-wallet.ts +20 -15
- package/src/issuer-wallet/types.ts +2 -1
- package/src/services/freeze.ts +3 -3
- package/src/services/token-transactions.ts +109 -101
- package/src/tests/integration/multi-token-issuer.test.ts +3 -10
- package/src/tests/integration/test-configs.ts +1 -1
- package/src/tests/integration/token-invoices.test.ts +13 -14
- package/src/tests/integration/token-lifecycle.test.ts +5 -5
- package/src/tests/integration/token-monitoring.test.ts +31 -43
- package/src/tests/integration/token-outputs.test.ts +7 -7
- package/src/tests/integration/token-transfers.test.ts +23 -23
- package/src/tests/stress/transfers.test.ts +10 -8
- package/src/tests/utils/issuer-test-wallet.ts +9 -3
- package/src/utils/token-hashing.ts +2 -2
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { jest } from "@jest/globals";
|
|
2
2
|
import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
|
|
3
3
|
import { TEST_CONFIGS_WITH_BINDINGS } from "./test-configs.js";
|
|
4
|
-
import { IssuerSparkWallet } from "../../issuer-wallet/issuer-spark-wallet.js";
|
|
5
|
-
import {
|
|
6
|
-
burnSingleIssuerToken,
|
|
7
|
-
freezeSingleIssuerToken,
|
|
8
|
-
getSingleIssuerTokenBalance,
|
|
9
|
-
getSingleIssuerTokenIdentifier,
|
|
10
|
-
mintSingleIssuerToken,
|
|
11
|
-
unfreezeSingleIssuerToken,
|
|
12
|
-
} from "../utils/multi-token-utils.js";
|
|
4
|
+
import { type IssuerSparkWallet } from "../../issuer-wallet/issuer-spark-wallet.js";
|
|
13
5
|
|
|
14
6
|
const TX_HASH_REGEX = /^[a-f0-9]{64}$/i; // valid tx hash: hex string of 64 characters
|
|
15
7
|
|
|
@@ -284,7 +276,8 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
284
276
|
issuerWallet.unfreezeTokens(receiverAddress),
|
|
285
277
|
).rejects.toThrow();
|
|
286
278
|
|
|
287
|
-
// Multi token issuer method - should succeed when using unfreezeTokens with a token
|
|
279
|
+
// Multi token issuer method - should succeed when using unfreezeTokens with a token
|
|
280
|
+
// identifier
|
|
288
281
|
const unfreezeResponse = await issuerWallet.unfreezeTokens({
|
|
289
282
|
tokenIdentifier: firstTokenIdentifier,
|
|
290
283
|
sparkAddress: receiverAddress,
|
|
@@ -47,7 +47,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
47
47
|
await getSingleIssuerTokenBalance(issuerWallet);
|
|
48
48
|
expect(issuerBalanceAfterMint).toBeDefined();
|
|
49
49
|
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
50
|
-
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier
|
|
50
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier;
|
|
51
51
|
const issuerBalanceBeforeTransfer = issuerBalanceAfterMint.balance;
|
|
52
52
|
|
|
53
53
|
const invoice = await receiverWallet.createTokensInvoice({
|
|
@@ -88,7 +88,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
88
88
|
const receiverBalanceObj = await receiverWallet.getBalance();
|
|
89
89
|
const receiverBalance = filterTokenBalanceForTokenIdentifier(
|
|
90
90
|
receiverBalanceObj?.tokenBalances,
|
|
91
|
-
tokenIdentifier
|
|
91
|
+
tokenIdentifier,
|
|
92
92
|
);
|
|
93
93
|
expect(receiverBalance.ownedBalance).toEqual(tokenAmount);
|
|
94
94
|
});
|
|
@@ -125,7 +125,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
125
125
|
await getSingleIssuerTokenBalance(issuerWallet);
|
|
126
126
|
expect(issuerBalanceAfterMint).toBeDefined();
|
|
127
127
|
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
128
|
-
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier
|
|
128
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier;
|
|
129
129
|
const issuerBalanceBeforeTransfer = issuerBalanceAfterMint.balance;
|
|
130
130
|
|
|
131
131
|
const invoice1 = await receiverWallet1.createTokensInvoice({
|
|
@@ -183,14 +183,14 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
183
183
|
const receiver1BalanceObj = await receiverWallet1.getBalance();
|
|
184
184
|
const receiver1Balance = filterTokenBalanceForTokenIdentifier(
|
|
185
185
|
receiver1BalanceObj?.tokenBalances,
|
|
186
|
-
tokenIdentifier
|
|
186
|
+
tokenIdentifier,
|
|
187
187
|
);
|
|
188
188
|
expect(receiver1Balance.ownedBalance).toEqual(amount1 + amount2);
|
|
189
189
|
|
|
190
190
|
const receiver2BalanceObj = await receiverWallet2.getBalance();
|
|
191
191
|
const receiver2Balance = filterTokenBalanceForTokenIdentifier(
|
|
192
192
|
receiver2BalanceObj?.tokenBalances,
|
|
193
|
-
tokenIdentifier
|
|
193
|
+
tokenIdentifier,
|
|
194
194
|
);
|
|
195
195
|
expect(receiver2Balance.ownedBalance).toEqual(amount3);
|
|
196
196
|
});
|
|
@@ -221,7 +221,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
221
221
|
await getSingleIssuerTokenBalance(issuerWallet);
|
|
222
222
|
expect(issuerBalanceAfterMint).toBeDefined();
|
|
223
223
|
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
224
|
-
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier
|
|
224
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier;
|
|
225
225
|
const issuerBalanceBefore = issuerBalanceAfterMint.balance;
|
|
226
226
|
|
|
227
227
|
const expiredInvoice = await receiverWallet.createTokensInvoice({
|
|
@@ -245,7 +245,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
245
245
|
const receiverBalanceObj = await receiverWallet.getBalance();
|
|
246
246
|
const receiverBalance = filterTokenBalanceForTokenIdentifier(
|
|
247
247
|
receiverBalanceObj?.tokenBalances,
|
|
248
|
-
tokenIdentifier
|
|
248
|
+
tokenIdentifier,
|
|
249
249
|
);
|
|
250
250
|
expect(receiverBalance.ownedBalance).toEqual(0n);
|
|
251
251
|
});
|
|
@@ -276,7 +276,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
276
276
|
await getSingleIssuerTokenBalance(issuerWallet);
|
|
277
277
|
expect(issuerBalanceAfterMint).toBeDefined();
|
|
278
278
|
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
279
|
-
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier
|
|
279
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier;
|
|
280
280
|
const issuerBalanceBefore = issuerBalanceAfterMint.balance;
|
|
281
281
|
|
|
282
282
|
const nullExpiryInvoice = await receiverWallet.createTokensInvoice({
|
|
@@ -317,7 +317,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
317
317
|
const receiverBalanceObj = await receiverWallet.getBalance();
|
|
318
318
|
const receiverBalance = filterTokenBalanceForTokenIdentifier(
|
|
319
319
|
receiverBalanceObj?.tokenBalances,
|
|
320
|
-
tokenIdentifier
|
|
320
|
+
tokenIdentifier,
|
|
321
321
|
);
|
|
322
322
|
expect(receiverBalance.ownedBalance).toEqual(tokenAmount);
|
|
323
323
|
});
|
|
@@ -348,7 +348,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
348
348
|
await getSingleIssuerTokenBalance(issuerWallet);
|
|
349
349
|
expect(issuerBalanceAfterMint).toBeDefined();
|
|
350
350
|
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
351
|
-
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier
|
|
351
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier;
|
|
352
352
|
const issuerBalanceBeforeTransfer = issuerBalanceAfterMint.balance;
|
|
353
353
|
|
|
354
354
|
const invoiceWithoutAmount = await receiverWallet.createTokensInvoice({
|
|
@@ -390,7 +390,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
390
390
|
const receiverBalanceObj = await receiverWallet.getBalance();
|
|
391
391
|
const receiverBalance = filterTokenBalanceForTokenIdentifier(
|
|
392
392
|
receiverBalanceObj?.tokenBalances,
|
|
393
|
-
tokenIdentifier
|
|
393
|
+
tokenIdentifier,
|
|
394
394
|
);
|
|
395
395
|
expect(receiverBalance.ownedBalance).toEqual(tokenAmount);
|
|
396
396
|
});
|
|
@@ -539,9 +539,8 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
539
539
|
sdkTwoTokenInvoiceA,
|
|
540
540
|
sdkTwoTokenNilAmountInvoiceB,
|
|
541
541
|
];
|
|
542
|
-
const queryInvoiceResponse =
|
|
543
|
-
invoicesToQuery
|
|
544
|
-
);
|
|
542
|
+
const queryInvoiceResponse =
|
|
543
|
+
await sdk.querySparkInvoices(invoicesToQuery);
|
|
545
544
|
expect(queryInvoiceResponse.invoiceStatuses.length).toBe(7);
|
|
546
545
|
for (let i = 0; i < queryInvoiceResponse.invoiceStatuses.length; i++) {
|
|
547
546
|
const response = queryInvoiceResponse.invoiceStatuses[i];
|
|
@@ -38,7 +38,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
38
38
|
expect(issuerBalanceObjAfterMint.tokenIdentifier).toBeDefined();
|
|
39
39
|
|
|
40
40
|
const issuerBalanceAfterMint = issuerBalanceObjAfterMint.balance;
|
|
41
|
-
const tokenIdentifier = issuerBalanceObjAfterMint.tokenIdentifier
|
|
41
|
+
const tokenIdentifier = issuerBalanceObjAfterMint.tokenIdentifier;
|
|
42
42
|
|
|
43
43
|
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
44
44
|
|
|
@@ -60,7 +60,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
60
60
|
const userBalanceObj = await userWallet.getBalance();
|
|
61
61
|
const userBalanceAfterTransfer = filterTokenBalanceForTokenIdentifier(
|
|
62
62
|
userBalanceObj?.tokenBalances,
|
|
63
|
-
tokenIdentifier
|
|
63
|
+
tokenIdentifier,
|
|
64
64
|
);
|
|
65
65
|
expect(userBalanceAfterTransfer.ownedBalance).toEqual(tokenAmount);
|
|
66
66
|
|
|
@@ -139,7 +139,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
139
139
|
const issuerBalanceAfterMint = issuerBalanceObjAfterMint.balance;
|
|
140
140
|
expect(issuerBalanceAfterMint).toEqual(initialBalance + tokenAmount);
|
|
141
141
|
expect(issuerBalanceObjAfterMint.tokenIdentifier).toBeDefined();
|
|
142
|
-
const tokenIdentifier = issuerBalanceObjAfterMint.tokenIdentifier
|
|
142
|
+
const tokenIdentifier = issuerBalanceObjAfterMint.tokenIdentifier;
|
|
143
143
|
const userSparkAddress = await userWallet.getSparkAddress();
|
|
144
144
|
|
|
145
145
|
await issuerWallet.transferTokens({
|
|
@@ -156,7 +156,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
156
156
|
const userBalanceObj = await userWallet.getBalance();
|
|
157
157
|
const userBalanceAfterTransfer = filterTokenBalanceForTokenIdentifier(
|
|
158
158
|
userBalanceObj?.tokenBalances,
|
|
159
|
-
tokenIdentifier
|
|
159
|
+
tokenIdentifier,
|
|
160
160
|
);
|
|
161
161
|
expect(userBalanceAfterTransfer.ownedBalance).toEqual(tokenAmount);
|
|
162
162
|
|
|
@@ -169,7 +169,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
169
169
|
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
170
170
|
const userBalanceAfterTransferBack = filterTokenBalanceForTokenIdentifier(
|
|
171
171
|
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
172
|
-
tokenIdentifier
|
|
172
|
+
tokenIdentifier,
|
|
173
173
|
);
|
|
174
174
|
|
|
175
175
|
expect(userBalanceAfterTransferBack.ownedBalance).toEqual(0n);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
filterTokenBalanceForTokenIdentifier,
|
|
3
|
-
NetworkType,
|
|
4
|
-
} from "@buildonspark/spark-sdk";
|
|
1
|
+
import { filterTokenBalanceForTokenIdentifier } from "@buildonspark/spark-sdk";
|
|
5
2
|
import { jest } from "@jest/globals";
|
|
6
3
|
import { bytesToHex, bytesToNumberBE } from "@noble/curves/utils";
|
|
7
4
|
import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
|
|
@@ -40,23 +37,21 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
40
37
|
await mintSingleIssuerToken(issuerWallet, tokenAmount);
|
|
41
38
|
const tokenIdentifier =
|
|
42
39
|
await getSingleIssuerTokenIdentifier(issuerWallet);
|
|
43
|
-
const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
44
|
-
|
|
45
40
|
await issuerWallet.transferTokens({
|
|
46
41
|
tokenAmount,
|
|
47
|
-
tokenIdentifier: tokenIdentifier
|
|
42
|
+
tokenIdentifier: tokenIdentifier,
|
|
48
43
|
receiverSparkAddress: await userWallet.getSparkAddress(),
|
|
49
44
|
});
|
|
50
45
|
|
|
51
46
|
const userBalanceObj = await userWallet.getBalance();
|
|
52
47
|
const userBalance = filterTokenBalanceForTokenIdentifier(
|
|
53
48
|
userBalanceObj?.tokenBalances,
|
|
54
|
-
tokenIdentifier
|
|
49
|
+
tokenIdentifier,
|
|
55
50
|
);
|
|
56
51
|
expect(userBalance.ownedBalance).toBeGreaterThanOrEqual(tokenAmount);
|
|
57
52
|
|
|
58
53
|
const response = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
59
|
-
tokenIdentifiers: [tokenIdentifier
|
|
54
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
60
55
|
sparkAddresses: [await issuerWallet.getSparkAddress()],
|
|
61
56
|
});
|
|
62
57
|
const transactions = response.tokenTransactionsWithStatus;
|
|
@@ -101,17 +96,15 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
101
96
|
|
|
102
97
|
const tokenIdentifier =
|
|
103
98
|
await getSingleIssuerTokenIdentifier(issuerWallet);
|
|
104
|
-
const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
105
|
-
|
|
106
99
|
await issuerWallet.transferTokens({
|
|
107
100
|
tokenAmount: 500n,
|
|
108
|
-
tokenIdentifier: tokenIdentifier
|
|
101
|
+
tokenIdentifier: tokenIdentifier,
|
|
109
102
|
receiverSparkAddress: await userWallet.getSparkAddress(),
|
|
110
103
|
});
|
|
111
104
|
|
|
112
105
|
await userWallet.transferTokens({
|
|
113
106
|
tokenAmount: 250n,
|
|
114
|
-
tokenIdentifier: tokenIdentifier
|
|
107
|
+
tokenIdentifier: tokenIdentifier,
|
|
115
108
|
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
116
109
|
});
|
|
117
110
|
|
|
@@ -120,7 +113,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
120
113
|
await burnSingleIssuerToken(issuerWallet, 250n);
|
|
121
114
|
|
|
122
115
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
123
|
-
tokenIdentifiers: [tokenIdentifier
|
|
116
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
124
117
|
sparkAddresses: [await issuerWallet.getSparkAddress()],
|
|
125
118
|
});
|
|
126
119
|
const transactions = res.tokenTransactionsWithStatus;
|
|
@@ -175,7 +168,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
175
168
|
|
|
176
169
|
{
|
|
177
170
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
178
|
-
tokenIdentifiers: [tokenIdentifier
|
|
171
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
179
172
|
});
|
|
180
173
|
const transactions = res.tokenTransactionsWithStatus;
|
|
181
174
|
const amount_of_transactions = transactions.length;
|
|
@@ -184,7 +177,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
184
177
|
|
|
185
178
|
{
|
|
186
179
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
187
|
-
tokenIdentifiers: [tokenIdentifier
|
|
180
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
188
181
|
});
|
|
189
182
|
const transactions = res.tokenTransactionsWithStatus;
|
|
190
183
|
const amount_of_transactions = transactions.length;
|
|
@@ -193,13 +186,13 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
193
186
|
|
|
194
187
|
await issuerWallet.transferTokens({
|
|
195
188
|
tokenAmount,
|
|
196
|
-
tokenIdentifier: tokenIdentifier
|
|
189
|
+
tokenIdentifier: tokenIdentifier,
|
|
197
190
|
receiverSparkAddress: userSparkAddress,
|
|
198
191
|
});
|
|
199
192
|
|
|
200
193
|
{
|
|
201
194
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
202
|
-
tokenIdentifiers: [tokenIdentifier
|
|
195
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
203
196
|
});
|
|
204
197
|
const transactions = res.tokenTransactionsWithStatus;
|
|
205
198
|
const amount_of_transactions = transactions.length;
|
|
@@ -208,7 +201,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
208
201
|
|
|
209
202
|
{
|
|
210
203
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
211
|
-
tokenIdentifiers: [tokenIdentifier
|
|
204
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
212
205
|
});
|
|
213
206
|
const transactions = res.tokenTransactionsWithStatus;
|
|
214
207
|
const amount_of_transactions = transactions.length;
|
|
@@ -220,14 +213,14 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
220
213
|
await mintSingleIssuerToken(issuerWallet, dynamicAmount);
|
|
221
214
|
await issuerWallet.transferTokens({
|
|
222
215
|
tokenAmount: dynamicAmount,
|
|
223
|
-
tokenIdentifier: tokenIdentifier
|
|
216
|
+
tokenIdentifier: tokenIdentifier,
|
|
224
217
|
receiverSparkAddress: userSparkAddress,
|
|
225
218
|
});
|
|
226
219
|
}
|
|
227
220
|
|
|
228
221
|
{
|
|
229
222
|
const res = await issuerWallet.queryTokenTransactionsByTxHashes([
|
|
230
|
-
mintTxHash
|
|
223
|
+
mintTxHash,
|
|
231
224
|
]);
|
|
232
225
|
const transactions = res.tokenTransactionsWithStatus;
|
|
233
226
|
expect(transactions.length).toEqual(1);
|
|
@@ -237,24 +230,19 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
237
230
|
expect(transactions[0].tokenTransaction?.tokenInputs?.$case).toEqual(
|
|
238
231
|
"mintInput",
|
|
239
232
|
);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
).toEqual(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
bytesToNumberBE(
|
|
249
|
-
transactions[0].tokenTransaction?.tokenOutputs?.[0]?.tokenAmount!,
|
|
250
|
-
),
|
|
251
|
-
),
|
|
252
|
-
).toEqual(tokenAmount);
|
|
233
|
+
const tokenOutput = transactions[0].tokenTransaction?.tokenOutputs?.[0];
|
|
234
|
+
if (tokenOutput === undefined) {
|
|
235
|
+
throw new Error("Mint transaction token output not found");
|
|
236
|
+
}
|
|
237
|
+
expect(bytesToHex(tokenOutput.ownerPublicKey)).toEqual(issuerPublicKey);
|
|
238
|
+
expect(BigInt(bytesToNumberBE(tokenOutput.tokenAmount))).toEqual(
|
|
239
|
+
tokenAmount,
|
|
240
|
+
);
|
|
253
241
|
}
|
|
254
242
|
|
|
255
243
|
{
|
|
256
244
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
257
|
-
tokenIdentifiers: [tokenIdentifier
|
|
245
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
258
246
|
pageSize: 10,
|
|
259
247
|
});
|
|
260
248
|
const transactions = res.tokenTransactionsWithStatus;
|
|
@@ -264,7 +252,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
264
252
|
|
|
265
253
|
{
|
|
266
254
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
267
|
-
tokenIdentifiers: [tokenIdentifier
|
|
255
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
268
256
|
pageSize: 10,
|
|
269
257
|
});
|
|
270
258
|
const transactions = res.tokenTransactionsWithStatus;
|
|
@@ -274,7 +262,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
274
262
|
|
|
275
263
|
{
|
|
276
264
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
277
|
-
tokenIdentifiers: [tokenIdentifier
|
|
265
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
278
266
|
issuerPublicKeys: [issuerPublicKey],
|
|
279
267
|
pageSize: 10,
|
|
280
268
|
});
|
|
@@ -285,7 +273,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
285
273
|
|
|
286
274
|
{
|
|
287
275
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
288
|
-
tokenIdentifiers: [tokenIdentifier
|
|
276
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
289
277
|
sparkAddresses: [issuerSparkAddress],
|
|
290
278
|
pageSize: 5,
|
|
291
279
|
});
|
|
@@ -297,7 +285,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
297
285
|
const nextCursor = pageInfo?.nextCursor ?? "";
|
|
298
286
|
|
|
299
287
|
const nextRes = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
300
|
-
tokenIdentifiers: [tokenIdentifier
|
|
288
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
301
289
|
sparkAddresses: [issuerSparkAddress],
|
|
302
290
|
pageSize: 5,
|
|
303
291
|
cursor: nextCursor,
|
|
@@ -317,7 +305,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
317
305
|
});
|
|
318
306
|
|
|
319
307
|
const prevRes = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
320
|
-
tokenIdentifiers: [tokenIdentifier
|
|
308
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
321
309
|
sparkAddresses: [issuerSparkAddress],
|
|
322
310
|
pageSize: 5,
|
|
323
311
|
cursor: nextPageInfo?.previousCursor ?? "",
|
|
@@ -336,7 +324,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
336
324
|
}
|
|
337
325
|
|
|
338
326
|
{
|
|
339
|
-
|
|
327
|
+
const hashset_of_all_transactions: Set<string> = new Set();
|
|
340
328
|
|
|
341
329
|
const pageSize = 10;
|
|
342
330
|
let page_num = 0;
|
|
@@ -344,7 +332,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
344
332
|
|
|
345
333
|
while (true) {
|
|
346
334
|
const res = await issuerWallet.queryTokenTransactionsWithFilters({
|
|
347
|
-
tokenIdentifiers: [tokenIdentifier
|
|
335
|
+
tokenIdentifiers: [tokenIdentifier],
|
|
348
336
|
pageSize,
|
|
349
337
|
cursor,
|
|
350
338
|
});
|
|
@@ -361,7 +349,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
361
349
|
for (let index = 0; index < transactions.length; ++index) {
|
|
362
350
|
const element = transactions[index];
|
|
363
351
|
if (element.tokenTransaction !== undefined) {
|
|
364
|
-
const hash:
|
|
352
|
+
const hash: string = bytesToHex(element.tokenTransactionHash);
|
|
365
353
|
if (hashset_of_all_transactions.has(hash)) {
|
|
366
354
|
expect(
|
|
367
355
|
`Duplicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: ${pageSize} ; hash_duplicate: ${hash}`,
|
|
@@ -102,7 +102,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
102
102
|
|
|
103
103
|
const transfersToUser = buildTransfers({
|
|
104
104
|
count: 60,
|
|
105
|
-
tokenIdentifier: tokenIdentifier
|
|
105
|
+
tokenIdentifier: tokenIdentifier,
|
|
106
106
|
tokenAmount: smallTransferAmount,
|
|
107
107
|
receiverSparkAddress: userSparkAddress,
|
|
108
108
|
});
|
|
@@ -111,7 +111,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
111
111
|
|
|
112
112
|
const transfersToIssuer = buildTransfers({
|
|
113
113
|
count: 60,
|
|
114
|
-
tokenIdentifier: tokenIdentifier
|
|
114
|
+
tokenIdentifier: tokenIdentifier,
|
|
115
115
|
tokenAmount: smallTransferAmount,
|
|
116
116
|
receiverSparkAddress: issuerSparkAddress,
|
|
117
117
|
});
|
|
@@ -124,13 +124,13 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
124
124
|
|
|
125
125
|
await expectOutputCount({
|
|
126
126
|
wallet: issuerWallet,
|
|
127
|
-
tokenIdentifier: tokenIdentifier
|
|
127
|
+
tokenIdentifier: tokenIdentifier,
|
|
128
128
|
expectedCount: 61,
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
await issuerWallet.optimizeTokenOutputs();
|
|
132
132
|
|
|
133
|
-
await
|
|
133
|
+
await issuerWallet.syncTokenOutputsForTesting();
|
|
134
134
|
|
|
135
135
|
const balanceAfterOptimization =
|
|
136
136
|
await getSingleIssuerTokenBalance(issuerWallet);
|
|
@@ -138,20 +138,20 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
138
138
|
|
|
139
139
|
await expectOutputCount({
|
|
140
140
|
wallet: issuerWallet,
|
|
141
|
-
tokenIdentifier: tokenIdentifier
|
|
141
|
+
tokenIdentifier: tokenIdentifier,
|
|
142
142
|
expectedCount: 1,
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
await issuerWallet.transferTokens({
|
|
146
146
|
tokenAmount: 100n,
|
|
147
|
-
tokenIdentifier: tokenIdentifier
|
|
147
|
+
tokenIdentifier: tokenIdentifier,
|
|
148
148
|
receiverSparkAddress: userSparkAddress,
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
expect(
|
|
152
152
|
await getOwnedBalance({
|
|
153
153
|
wallet: userWallet,
|
|
154
|
-
tokenIdentifier: tokenIdentifier
|
|
154
|
+
tokenIdentifier: tokenIdentifier,
|
|
155
155
|
}),
|
|
156
156
|
).toBe(100n);
|
|
157
157
|
});
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
decodeBech32mTokenIdentifier,
|
|
3
3
|
filterTokenBalanceForTokenIdentifier,
|
|
4
4
|
} from "@buildonspark/spark-sdk";
|
|
5
|
-
import { OutputWithPreviousTransactionData } from "@buildonspark/spark-sdk/proto/spark_token";
|
|
5
|
+
import { type OutputWithPreviousTransactionData } from "@buildonspark/spark-sdk/proto/spark_token";
|
|
6
6
|
import { jest } from "@jest/globals";
|
|
7
7
|
import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
|
|
8
8
|
import { SparkWalletTesting } from "@buildonspark/spark-sdk/test-utils";
|
|
@@ -42,14 +42,14 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
42
42
|
await getSingleIssuerTokenIdentifier(issuerWallet);
|
|
43
43
|
await issuerWallet.transferTokens({
|
|
44
44
|
tokenAmount,
|
|
45
|
-
tokenIdentifier: tokenIdentifier
|
|
45
|
+
tokenIdentifier: tokenIdentifier,
|
|
46
46
|
receiverSparkAddress: await userWallet.getSparkAddress(),
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
const balanceObj = await userWallet.getBalance();
|
|
50
50
|
const userBalance = filterTokenBalanceForTokenIdentifier(
|
|
51
51
|
balanceObj?.tokenBalances,
|
|
52
|
-
tokenIdentifier
|
|
52
|
+
tokenIdentifier,
|
|
53
53
|
);
|
|
54
54
|
expect(userBalance.ownedBalance).toBeGreaterThanOrEqual(tokenAmount);
|
|
55
55
|
});
|
|
@@ -90,7 +90,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
90
90
|
expect(sharedIssuerBalance).toBeDefined();
|
|
91
91
|
expect(sharedIssuerBalance.tokenIdentifier).toBeDefined();
|
|
92
92
|
|
|
93
|
-
const tokenIdentifier = sharedIssuerBalance.tokenIdentifier
|
|
93
|
+
const tokenIdentifier = sharedIssuerBalance.tokenIdentifier;
|
|
94
94
|
const sourceBalanceBefore = sharedIssuerBalance.balance;
|
|
95
95
|
|
|
96
96
|
await issuerWallet.batchTransferTokens([
|
|
@@ -119,19 +119,19 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
119
119
|
const balanceObj = await destinationWallet1.getBalance();
|
|
120
120
|
const destinationBalance = filterTokenBalanceForTokenIdentifier(
|
|
121
121
|
balanceObj?.tokenBalances,
|
|
122
|
-
tokenIdentifier
|
|
122
|
+
tokenIdentifier,
|
|
123
123
|
);
|
|
124
124
|
expect(destinationBalance.ownedBalance).toEqual(tokenAmount / 3n);
|
|
125
125
|
const balanceObj2 = await destinationWallet2.getBalance();
|
|
126
126
|
const destinationBalance2 = filterTokenBalanceForTokenIdentifier(
|
|
127
127
|
balanceObj2?.tokenBalances,
|
|
128
|
-
tokenIdentifier
|
|
128
|
+
tokenIdentifier,
|
|
129
129
|
);
|
|
130
130
|
expect(destinationBalance2.ownedBalance).toEqual(tokenAmount / 3n);
|
|
131
131
|
const balanceObj3 = await destinationWallet3.getBalance();
|
|
132
132
|
const destinationBalance3 = filterTokenBalanceForTokenIdentifier(
|
|
133
133
|
balanceObj3?.tokenBalances,
|
|
134
|
-
tokenIdentifier
|
|
134
|
+
tokenIdentifier,
|
|
135
135
|
);
|
|
136
136
|
expect(destinationBalance3.ownedBalance).toEqual(tokenAmount / 3n);
|
|
137
137
|
});
|
|
@@ -182,7 +182,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
182
182
|
issuerWallets.map(async (wallet) => {
|
|
183
183
|
const balance = await getSingleIssuerTokenBalance(wallet);
|
|
184
184
|
expect(balance.tokenIdentifier).toBeDefined();
|
|
185
|
-
return balance.tokenIdentifier
|
|
185
|
+
return balance.tokenIdentifier;
|
|
186
186
|
}),
|
|
187
187
|
);
|
|
188
188
|
|
|
@@ -261,7 +261,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
261
261
|
await expect(
|
|
262
262
|
issuerWallet.transferTokens({
|
|
263
263
|
tokenAmount: transferAmount,
|
|
264
|
-
tokenIdentifier: tokenIdentifier
|
|
264
|
+
tokenIdentifier: tokenIdentifier,
|
|
265
265
|
receiverSparkAddress: await destinationWallet1.getSparkAddress(),
|
|
266
266
|
}),
|
|
267
267
|
).rejects.toThrow(/Insufficient token amount/);
|
|
@@ -301,12 +301,12 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
301
301
|
issuerWallet.batchTransferTokens([
|
|
302
302
|
{
|
|
303
303
|
tokenAmount: transferAmount,
|
|
304
|
-
tokenIdentifier: tokenIdentifier
|
|
304
|
+
tokenIdentifier: tokenIdentifier,
|
|
305
305
|
receiverSparkAddress: await destinationWallet1.getSparkAddress(),
|
|
306
306
|
},
|
|
307
307
|
{
|
|
308
308
|
tokenAmount: transferAmount,
|
|
309
|
-
tokenIdentifier: tokenIdentifier
|
|
309
|
+
tokenIdentifier: tokenIdentifier,
|
|
310
310
|
receiverSparkAddress: await destinationWallet2.getSparkAddress(),
|
|
311
311
|
},
|
|
312
312
|
]),
|
|
@@ -362,8 +362,8 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
362
362
|
const issuerBalance1 = await getSingleIssuerTokenBalance(issuerWallet1);
|
|
363
363
|
const issuerBalance2 = await getSingleIssuerTokenBalance(issuerWallet2);
|
|
364
364
|
|
|
365
|
-
const tokenIdentifier1 = issuerBalance1.tokenIdentifier
|
|
366
|
-
const tokenIdentifier2 = issuerBalance2.tokenIdentifier
|
|
365
|
+
const tokenIdentifier1 = issuerBalance1.tokenIdentifier;
|
|
366
|
+
const tokenIdentifier2 = issuerBalance2.tokenIdentifier;
|
|
367
367
|
|
|
368
368
|
await issuerWallet1.transferTokens({
|
|
369
369
|
tokenAmount: tokenAmount1,
|
|
@@ -437,8 +437,8 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
437
437
|
const issuerBalance1 = await getSingleIssuerTokenBalance(issuerWallet1);
|
|
438
438
|
const issuerBalance2 = await getSingleIssuerTokenBalance(issuerWallet2);
|
|
439
439
|
|
|
440
|
-
const tokenIdentifier1 = issuerBalance1.tokenIdentifier
|
|
441
|
-
const tokenIdentifier2 = issuerBalance2.tokenIdentifier
|
|
440
|
+
const tokenIdentifier1 = issuerBalance1.tokenIdentifier;
|
|
441
|
+
const tokenIdentifier2 = issuerBalance2.tokenIdentifier;
|
|
442
442
|
|
|
443
443
|
await issuerWallet1.transferTokens({
|
|
444
444
|
tokenAmount: tokenAmount,
|
|
@@ -495,12 +495,12 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
495
495
|
issuerWallet.batchTransferTokens([
|
|
496
496
|
{
|
|
497
497
|
tokenAmount: 600n,
|
|
498
|
-
tokenIdentifier: tokenIdentifier
|
|
498
|
+
tokenIdentifier: tokenIdentifier,
|
|
499
499
|
receiverSparkAddress: await destinationWallet1.getSparkAddress(),
|
|
500
500
|
},
|
|
501
501
|
{
|
|
502
502
|
tokenAmount: 600n,
|
|
503
|
-
tokenIdentifier: tokenIdentifier
|
|
503
|
+
tokenIdentifier: tokenIdentifier,
|
|
504
504
|
receiverSparkAddress: await destinationWallet2.getSparkAddress(),
|
|
505
505
|
},
|
|
506
506
|
]),
|
|
@@ -532,7 +532,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
532
532
|
const tokenIdentifier =
|
|
533
533
|
await getSingleIssuerTokenIdentifier(issuerWallet);
|
|
534
534
|
const { tokenIdentifier: rawTokenIdentifier } =
|
|
535
|
-
decodeBech32mTokenIdentifier(tokenIdentifier
|
|
535
|
+
decodeBech32mTokenIdentifier(tokenIdentifier);
|
|
536
536
|
|
|
537
537
|
const fakeOutput: OutputWithPreviousTransactionData = {
|
|
538
538
|
output: {
|
|
@@ -550,7 +550,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
550
550
|
await expect(
|
|
551
551
|
issuerWallet.transferTokens({
|
|
552
552
|
tokenAmount: mintAmount,
|
|
553
|
-
tokenIdentifier: tokenIdentifier
|
|
553
|
+
tokenIdentifier: tokenIdentifier,
|
|
554
554
|
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
555
555
|
selectedOutputs: [fakeOutput],
|
|
556
556
|
}),
|
|
@@ -598,7 +598,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
598
598
|
const tokenIdentifier2 =
|
|
599
599
|
await getSingleIssuerTokenIdentifier(issuerWallet2);
|
|
600
600
|
const { tokenIdentifier: rawTokenIdentifier2 } =
|
|
601
|
-
decodeBech32mTokenIdentifier(tokenIdentifier2
|
|
601
|
+
decodeBech32mTokenIdentifier(tokenIdentifier2);
|
|
602
602
|
|
|
603
603
|
const fakeOutputWithWrongToken: OutputWithPreviousTransactionData = {
|
|
604
604
|
output: {
|
|
@@ -616,7 +616,7 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
616
616
|
await expect(
|
|
617
617
|
issuerWallet1.transferTokens({
|
|
618
618
|
tokenAmount: mintAmount,
|
|
619
|
-
tokenIdentifier: tokenIdentifier1
|
|
619
|
+
tokenIdentifier: tokenIdentifier1,
|
|
620
620
|
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
621
621
|
selectedOutputs: [fakeOutputWithWrongToken],
|
|
622
622
|
}),
|
|
@@ -666,8 +666,8 @@ describe.each(TEST_CONFIGS_WITH_BINDINGS)(
|
|
|
666
666
|
|
|
667
667
|
const issuerBalance1 = await getSingleIssuerTokenBalance(issuerWallet1);
|
|
668
668
|
const issuerBalance2 = await getSingleIssuerTokenBalance(issuerWallet2);
|
|
669
|
-
const tokenIdentifier1 = issuerBalance1.tokenIdentifier
|
|
670
|
-
const tokenIdentifier2 = issuerBalance2.tokenIdentifier
|
|
669
|
+
const tokenIdentifier1 = issuerBalance1.tokenIdentifier;
|
|
670
|
+
const tokenIdentifier2 = issuerBalance2.tokenIdentifier;
|
|
671
671
|
|
|
672
672
|
const intermediateAddress = await intermediateWallet.getSparkAddress();
|
|
673
673
|
await issuerWallet1.transferTokens({
|