@buildonspark/issuer-sdk 0.0.84 → 0.0.86

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.
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  WalletConfig,
3
3
  ConfigOptions,
4
- filterTokenBalanceForTokenPublicKey,
4
+ filterTokenBalanceForTokenIdentifier,
5
5
  } from "@buildonspark/spark-sdk";
6
6
  import { jest } from "@jest/globals";
7
7
  import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
8
8
  import { SparkWalletTesting } from "../utils/spark-testing-wallet.js";
9
+ import { BitcoinFaucet } from "@buildonspark/spark-sdk/test-utils";
10
+ import { bytesToHex } from "@noble/curves/abstract/utils";
11
+ import { IssuerSparkWallet } from "../../issuer-wallet/issuer-spark-wallet.node.js";
9
12
 
10
13
  export const TOKENS_V0_SCHNORR_CONFIG: Required<ConfigOptions> = {
11
14
  ...WalletConfig.LOCAL,
@@ -45,33 +48,72 @@ describe.each(TEST_CONFIGS)(
45
48
  ({ name, config }) => {
46
49
  jest.setTimeout(80000);
47
50
 
48
- it("should fail when minting tokens without creation", async () => {
49
- const tokenAmount: bigint = 1000n;
50
- const { wallet } = await IssuerSparkWalletTesting.initialize({
51
- options: config,
51
+ it("should create a token", async () => {
52
+ const { wallet: issuerWallet } =
53
+ await IssuerSparkWalletTesting.initialize({
54
+ options: config,
55
+ });
56
+
57
+ const tokenName = `${name}Creatable`;
58
+ const tokenTicker = "CRT";
59
+ const maxSupply = 5000n;
60
+ const decimals = 0;
61
+ const txId = await issuerWallet.createToken({
62
+ tokenName,
63
+ tokenTicker,
64
+ decimals,
65
+ isFreezable: false,
66
+ maxSupply,
52
67
  });
53
68
 
54
- await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
69
+ expect(typeof txId).toBe("string");
70
+ expect(txId.length).toBeGreaterThan(0);
71
+
72
+ const metadata = await issuerWallet.getIssuerTokenMetadata();
73
+ expect(metadata.tokenName).toEqual(tokenName);
74
+ expect(metadata.tokenTicker).toEqual(tokenTicker);
75
+ expect(metadata.maxSupply).toEqual(maxSupply);
76
+ expect(metadata.decimals).toEqual(decimals);
55
77
  });
56
78
 
57
- it("should fail when creation decimal is greater than js MAX_SAFE_INTEGER", async () => {
58
- const tokenAmount: bigint = 1000n;
59
- const { wallet } = await IssuerSparkWalletTesting.initialize({
60
- options: config,
79
+ it("should fail on duplicate token creation", async () => {
80
+ const { wallet: issuerWallet } =
81
+ await IssuerSparkWalletTesting.initialize({
82
+ options: config,
83
+ });
84
+
85
+ const tokenName = `${name}Dup`;
86
+ const tokenTicker = `DP${name}`;
87
+
88
+ await issuerWallet.createToken({
89
+ tokenName,
90
+ tokenTicker,
91
+ decimals: 0,
92
+ isFreezable: false,
93
+ maxSupply: 100n,
61
94
  });
62
95
 
63
96
  await expect(
64
- wallet.createToken({
65
- tokenName: "2Pow53Decimal",
66
- tokenTicker: "2P53D",
67
- decimals: 2 ** 53,
97
+ issuerWallet.createToken({
98
+ tokenName,
99
+ tokenTicker,
100
+ decimals: 0,
68
101
  isFreezable: false,
69
- maxSupply: tokenAmount,
102
+ maxSupply: 100n,
70
103
  }),
71
104
  ).rejects.toThrow();
72
105
  });
73
106
 
74
- it("should fail when minting more than max supply", async () => {
107
+ it("should fail when minting tokens without creation", async () => {
108
+ const tokenAmount: bigint = 1000n;
109
+ const { wallet } = await IssuerSparkWalletTesting.initialize({
110
+ options: config,
111
+ });
112
+
113
+ await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
114
+ });
115
+
116
+ it("should create, andfail when minting more than max supply", async () => {
75
117
  const tokenAmount: bigint = 1000n;
76
118
  const { wallet } = await IssuerSparkWalletTesting.initialize({
77
119
  options: config,
@@ -87,7 +129,7 @@ describe.each(TEST_CONFIGS)(
87
129
  await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
88
130
  });
89
131
 
90
- it("should mint tokens successfully", async () => {
132
+ it("should create, and mint tokens successfully", async () => {
91
133
  const tokenAmount: bigint = 1000n;
92
134
 
93
135
  const { wallet: issuerWallet } =
@@ -121,7 +163,7 @@ describe.each(TEST_CONFIGS)(
121
163
  expect(tokenBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
122
164
  });
123
165
 
124
- it("should mint and transfer tokens", async () => {
166
+ it("should create, mint, and transfer tokens", async () => {
125
167
  const tokenAmount: bigint = 1000n;
126
168
 
127
169
  const { wallet: issuerWallet } =
@@ -138,7 +180,6 @@ describe.each(TEST_CONFIGS)(
138
180
  isFreezable: false,
139
181
  maxSupply: 1_000_000n,
140
182
  });
141
- const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
142
183
 
143
184
  await issuerWallet.mintTokens(tokenAmount);
144
185
 
@@ -150,149 +191,14 @@ describe.each(TEST_CONFIGS)(
150
191
  });
151
192
 
152
193
  const balanceObj = await userWallet.getBalance();
153
- const userBalance = filterTokenBalanceForTokenPublicKey(
194
+ const userBalance = filterTokenBalanceForTokenIdentifier(
154
195
  balanceObj?.tokenBalances,
155
- issuerPublicKey,
196
+ tokenIdentifier!,
156
197
  );
157
198
  expect(userBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
158
199
  });
159
200
 
160
- // it("should announce, mint, get list all transactions, and transfer tokens multiple times, get list all transactions again and check difference", async () => {
161
- // const tokenAmount: bigint = 100n;
162
-
163
- // const { wallet: issuerWallet } =
164
- // await IssuerSparkWalletTesting.initialize({
165
- // options: config,
166
- // });
167
-
168
- // const { wallet: destinationWallet } = await SparkWalletTesting.initialize(
169
- // {
170
- // options: config,
171
- // },
172
- // );
173
-
174
- // await fundAndAnnounce(issuerWallet, 100000n, 0, `${name}Transfer`, "TTO");
175
-
176
- // {
177
- // const transactions = await issuerWallet.getIssuerTokenActivity();
178
- // const amount_of_transactions = transactions.transactions.length;
179
- // expect(amount_of_transactions).toEqual(0);
180
- // }
181
-
182
- // await issuerWallet.mintTokens(tokenAmount);
183
-
184
- // {
185
- // const transactions = await issuerWallet.getIssuerTokenActivity();
186
- // const amount_of_transactions = transactions.transactions.length;
187
- // expect(amount_of_transactions).toEqual(1);
188
- // }
189
-
190
- // await issuerWallet.transferTokens({
191
- // tokenAmount,
192
- // tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
193
- // receiverSparkAddress: await destinationWallet.getSparkAddress(),
194
- // });
195
-
196
- // {
197
- // const transactions = await issuerWallet.getIssuerTokenActivity();
198
- // const amount_of_transactions = transactions.transactions.length;
199
- // expect(amount_of_transactions).toEqual(2);
200
- // }
201
-
202
- // for (let index = 0; index < 100; ++index) {
203
- // await issuerWallet.mintTokens(tokenAmount);
204
- // await issuerWallet.transferTokens({
205
- // tokenAmount,
206
- // tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
207
- // receiverSparkAddress: await destinationWallet.getSparkAddress(),
208
- // });
209
- // } // 202 in total
210
-
211
- // let all_transactions = await issuerWallet.getIssuerTokenActivity(250);
212
- // const amount_of_transactions = all_transactions.transactions.length;
213
- // expect(amount_of_transactions).toEqual(202);
214
-
215
- // {
216
- // const transactions = await issuerWallet.getIssuerTokenActivity(10);
217
- // const amount_of_transactions = transactions.transactions.length;
218
- // expect(amount_of_transactions).toEqual(10);
219
- // }
220
-
221
- // {
222
- // let hashset_of_all_transactions: Set<String> = new Set();
223
-
224
- // let transactions = await issuerWallet.getIssuerTokenActivity(10);
225
- // let amount_of_transactions = transactions.transactions.length;
226
- // expect(amount_of_transactions).toEqual(10);
227
- // let page_num = 0;
228
- // for (let index = 0; index < transactions.transactions.length; ++index) {
229
- // const element = transactions.transactions[index];
230
- // if (!(element.transaction === undefined)) {
231
- // let hash: String = "";
232
- // if (element.transaction.$case === "spark") {
233
- // hash = element.transaction.spark.transactionHash;
234
- // } else if (element.transaction.$case === "onChain") {
235
- // hash = element.transaction.onChain.transactionHash;
236
- // }
237
- // if (hashset_of_all_transactions.has(hash)) {
238
- // expect(
239
- // `Dublicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: 10 ; hash_dublicate: ${hash}`,
240
- // ).toEqual("");
241
- // } else {
242
- // hashset_of_all_transactions.add(hash);
243
- // }
244
- // } else {
245
- // expect(
246
- // `Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: 10`,
247
- // ).toEqual("");
248
- // }
249
- // }
250
-
251
- // while (!(undefined === transactions.nextCursor)) {
252
- // let transactions_2 = await issuerWallet.getIssuerTokenActivity(10, {
253
- // lastTransactionHash: hexToBytes(
254
- // transactions.nextCursor.lastTransactionHash,
255
- // ),
256
- // layer: transactions.nextCursor.layer,
257
- // });
258
-
259
- // ++page_num;
260
-
261
- // for (
262
- // let index = 0;
263
- // index < transactions_2.transactions.length;
264
- // ++index
265
- // ) {
266
- // const element = transactions_2.transactions[index];
267
- // if (!(element.transaction === undefined)) {
268
- // let hash: String = "";
269
- // if (element.transaction.$case === "spark") {
270
- // hash = element.transaction.spark.transactionHash;
271
- // } else if (element.transaction.$case === "onChain") {
272
- // hash = element.transaction.onChain.transactionHash;
273
- // }
274
- // if (hashset_of_all_transactions.has(hash)) {
275
- // expect(
276
- // `Dublicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: 10 ; hash_dublicate: ${hash}`,
277
- // ).toEqual("");
278
- // } else {
279
- // hashset_of_all_transactions.add(hash);
280
- // }
281
- // } else {
282
- // expect(
283
- // `Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: 10`,
284
- // ).toEqual("");
285
- // }
286
- // }
287
-
288
- // transactions = transactions_2;
289
- // }
290
-
291
- // expect(hashset_of_all_transactions.size == 202);
292
- // }
293
- // });
294
-
295
- it("should mint and batchtransfer tokens", async () => {
201
+ it("should create, mint, and batchtransfer tokens", async () => {
296
202
  const tokenAmount: bigint = 999n;
297
203
 
298
204
  const { wallet: issuerWallet } =
@@ -307,8 +213,6 @@ describe.each(TEST_CONFIGS)(
307
213
  maxSupply: 1_000_000n,
308
214
  });
309
215
 
310
- const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
311
-
312
216
  const { wallet: destinationWallet } = await SparkWalletTesting.initialize(
313
217
  {
314
218
  options: config,
@@ -356,64 +260,262 @@ describe.each(TEST_CONFIGS)(
356
260
  expect(sourceBalanceAfter).toEqual(sourceBalanceBefore - tokenAmount);
357
261
 
358
262
  const balanceObj = await destinationWallet.getBalance();
359
- const destinationBalance = filterTokenBalanceForTokenPublicKey(
263
+ const destinationBalance = filterTokenBalanceForTokenIdentifier(
360
264
  balanceObj?.tokenBalances,
361
- issuerPublicKey,
265
+ tokenIdentifier!,
362
266
  );
363
267
  expect(destinationBalance.balance).toEqual(tokenAmount / 3n);
364
268
  const balanceObj2 = await destinationWallet2.getBalance();
365
- const destinationBalance2 = filterTokenBalanceForTokenPublicKey(
269
+ const destinationBalance2 = filterTokenBalanceForTokenIdentifier(
366
270
  balanceObj2?.tokenBalances,
367
- issuerPublicKey,
271
+ tokenIdentifier!,
368
272
  );
369
273
  expect(destinationBalance2.balance).toEqual(tokenAmount / 3n);
370
274
  const balanceObj3 = await destinationWallet3.getBalance();
371
- const destinationBalance3 = filterTokenBalanceForTokenPublicKey(
275
+ const destinationBalance3 = filterTokenBalanceForTokenIdentifier(
372
276
  balanceObj3?.tokenBalances,
373
- issuerPublicKey,
277
+ tokenIdentifier!,
374
278
  );
375
279
  expect(destinationBalance3.balance).toEqual(tokenAmount / 3n);
376
280
  });
377
281
 
378
- // it("should track token operations in monitoring", async () => {
379
- // const tokenAmount: bigint = 1000n;
380
-
381
- // await sharedIssuerWallet.mintTokens(tokenAmount);
382
- // await sharedIssuerWallet.transferTokens({
383
- // tokenAmount,
384
- // tokenPublicKey: sharedTokenPublicKey,
385
- // receiverSparkAddress: await sharedUserWallet.getSparkAddress(),
386
- // });
387
-
388
- // const balanceObj = await sharedUserWallet.getBalance();
389
- // const destinationBalance = filterTokenBalanceForTokenPublicKey(
390
- // balanceObj?.tokenBalances,
391
- // sharedTokenPublicKey,
392
- // );
393
- // expect(destinationBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
394
-
395
- // const issuerOperations =
396
- // await sharedIssuerWallet.getIssuerTokenActivity();
397
- // expect(issuerOperations.transactions.length).toBeGreaterThanOrEqual(2);
398
-
399
- // let mint_operation = 0;
400
- // let transfer_operation = 0;
401
- // issuerOperations.transactions.forEach((transaction) => {
402
- // if (transaction.transaction?.$case === "spark") {
403
- // if (transaction.transaction.spark.operationType === "ISSUER_MINT") {
404
- // mint_operation++;
405
- // } else if (
406
- // transaction.transaction.spark.operationType === "ISSUER_TRANSFER"
407
- // ) {
408
- // transfer_operation++;
409
- // }
410
- // }
411
- // });
412
- // expect(mint_operation).toBeGreaterThanOrEqual(1);
413
- // expect(transfer_operation).toBeGreaterThanOrEqual(1);
414
- // });
415
-
416
- it("it should mint token with 1 max supply without issue", async () => {
282
+ it("should track token operations in monitoring", async () => {
283
+ const tokenAmount: bigint = 1000n;
284
+
285
+ const { wallet: issuerWallet } =
286
+ await IssuerSparkWalletTesting.initialize({
287
+ options: config,
288
+ });
289
+
290
+ const { wallet: userWallet } = await SparkWalletTesting.initialize({
291
+ options: config,
292
+ });
293
+
294
+ await issuerWallet.createToken({
295
+ tokenName: `${name}FRZ`,
296
+ tokenTicker: "FRZ",
297
+ decimals: 0,
298
+ isFreezable: true,
299
+ maxSupply: 100000n,
300
+ });
301
+ await issuerWallet.mintTokens(tokenAmount);
302
+ const tokenIdentifier = await issuerWallet.getIssuerTokenIdentifier();
303
+ const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
304
+
305
+ await issuerWallet.transferTokens({
306
+ tokenAmount,
307
+ tokenIdentifier: tokenIdentifier!,
308
+ receiverSparkAddress: await userWallet.getSparkAddress(),
309
+ });
310
+
311
+ const userBalanceObj = await userWallet.getBalance();
312
+ const userBalance = filterTokenBalanceForTokenIdentifier(
313
+ userBalanceObj?.tokenBalances,
314
+ tokenIdentifier!,
315
+ );
316
+ expect(userBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
317
+
318
+ const transactions = await issuerWallet.queryTokenTransactions({
319
+ tokenIdentifiers: [tokenIdentifier!],
320
+ ownerPublicKeys: [issuerPublicKey],
321
+ });
322
+ expect(transactions.length).toBeGreaterThanOrEqual(2);
323
+
324
+ let mint_operation = 0;
325
+ let transfer_operation = 0;
326
+ transactions.forEach((transaction) => {
327
+ if (transaction.tokenTransaction?.tokenInputs?.$case === "mintInput") {
328
+ mint_operation++;
329
+ } else if (
330
+ transaction.tokenTransaction?.tokenInputs?.$case === "transferInput"
331
+ ) {
332
+ transfer_operation++;
333
+ }
334
+ });
335
+ expect(mint_operation).toBeGreaterThanOrEqual(1);
336
+ expect(transfer_operation).toBeGreaterThanOrEqual(1);
337
+ });
338
+
339
+ it("should correctly assign operation types for complete token lifecycle operations", async () => {
340
+ const tokenAmount = 1000n;
341
+
342
+ const { wallet: issuerWallet } =
343
+ await IssuerSparkWalletTesting.initialize({
344
+ options: config,
345
+ });
346
+
347
+ const { wallet: userWallet } = await SparkWalletTesting.initialize({
348
+ options: config,
349
+ });
350
+
351
+ await issuerWallet.createToken({
352
+ tokenName: `${name}LFC`,
353
+ tokenTicker: "LFC",
354
+ decimals: 0,
355
+ isFreezable: false,
356
+ maxSupply: 1_000_000n,
357
+ });
358
+
359
+ await issuerWallet.mintTokens(tokenAmount);
360
+
361
+ const tokenIdentifier = await issuerWallet.getIssuerTokenIdentifier();
362
+ const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
363
+
364
+ await issuerWallet.transferTokens({
365
+ tokenAmount: 500n,
366
+ tokenIdentifier: tokenIdentifier!,
367
+ receiverSparkAddress: await userWallet.getSparkAddress(),
368
+ });
369
+
370
+ await userWallet.transferTokens({
371
+ tokenAmount: 250n,
372
+ tokenIdentifier: tokenIdentifier!,
373
+ receiverSparkAddress: await issuerWallet.getSparkAddress(),
374
+ });
375
+
376
+ const BURN_ADDRESS = "02".repeat(33);
377
+
378
+ await issuerWallet.burnTokens(250n);
379
+
380
+ const transactions = await issuerWallet.queryTokenTransactions({
381
+ tokenIdentifiers: [tokenIdentifier!],
382
+ ownerPublicKeys: [issuerPublicKey],
383
+ });
384
+
385
+ const mintTransaction = transactions.find(
386
+ (tx) => tx.tokenTransaction?.tokenInputs?.$case === "mintInput",
387
+ );
388
+
389
+ const transferTransaction = transactions.find(
390
+ (tx) => tx.tokenTransaction?.tokenInputs?.$case === "transferInput",
391
+ );
392
+
393
+ const burnTransaction = transactions.find(
394
+ (tx) =>
395
+ tx.tokenTransaction?.tokenInputs?.$case === "transferInput" &&
396
+ bytesToHex(tx.tokenTransaction?.tokenOutputs?.[0]?.ownerPublicKey) ===
397
+ BURN_ADDRESS,
398
+ );
399
+
400
+ expect(mintTransaction).toBeDefined();
401
+ expect(transferTransaction).toBeDefined();
402
+ expect(burnTransaction).toBeDefined();
403
+ });
404
+
405
+ it("should create, mint, get all transactions, transfer tokens multiple times, get all transactions again, and check difference", async () => {
406
+ const tokenAmount: bigint = 100n;
407
+
408
+ const { wallet: issuerWallet } =
409
+ await IssuerSparkWalletTesting.initialize({
410
+ options: config,
411
+ });
412
+
413
+ const { wallet: userWallet } = await SparkWalletTesting.initialize({
414
+ options: config,
415
+ });
416
+
417
+ await issuerWallet.createToken({
418
+ tokenName: `${name}Transfer`,
419
+ tokenTicker: "TTO",
420
+ decimals: 0,
421
+ isFreezable: false,
422
+ maxSupply: 100000n,
423
+ });
424
+
425
+ const tokenIdentifier = await issuerWallet.getIssuerTokenIdentifier();
426
+
427
+ await issuerWallet.mintTokens(tokenAmount);
428
+
429
+ {
430
+ const transactions = await issuerWallet.queryTokenTransactions({
431
+ tokenIdentifiers: [tokenIdentifier!],
432
+ });
433
+ const amount_of_transactions = transactions.length;
434
+ expect(amount_of_transactions).toEqual(1);
435
+ }
436
+
437
+ await issuerWallet.transferTokens({
438
+ tokenAmount,
439
+ tokenIdentifier: tokenIdentifier!,
440
+ receiverSparkAddress: await userWallet.getSparkAddress(),
441
+ });
442
+
443
+ {
444
+ const transactions = await issuerWallet.queryTokenTransactions({
445
+ tokenIdentifiers: [tokenIdentifier!],
446
+ });
447
+ const amount_of_transactions = transactions.length;
448
+ expect(amount_of_transactions).toEqual(2);
449
+ }
450
+
451
+ for (let index = 0; index < 100; ++index) {
452
+ await issuerWallet.mintTokens(tokenAmount);
453
+ await issuerWallet.transferTokens({
454
+ tokenAmount,
455
+ tokenIdentifier: tokenIdentifier!,
456
+ receiverSparkAddress: await userWallet.getSparkAddress(),
457
+ });
458
+ } // 202 in total
459
+
460
+ {
461
+ const transactions = await issuerWallet.queryTokenTransactions({
462
+ tokenIdentifiers: [tokenIdentifier!],
463
+ pageSize: 10,
464
+ });
465
+ const amount_of_transactions = transactions.length;
466
+ expect(amount_of_transactions).toEqual(10);
467
+ }
468
+
469
+ {
470
+ let hashset_of_all_transactions: Set<String> = new Set();
471
+
472
+ let pageSize = 10;
473
+ let offset = 0;
474
+ let page_num = 0;
475
+
476
+ while (true) {
477
+ const transactionsPage = await issuerWallet.queryTokenTransactions({
478
+ tokenIdentifiers: [tokenIdentifier!],
479
+ pageSize,
480
+ offset,
481
+ });
482
+
483
+ if (transactionsPage.length === 0) {
484
+ break;
485
+ }
486
+
487
+ if (offset === 0) {
488
+ expect(transactionsPage.length).toEqual(pageSize);
489
+ }
490
+
491
+ for (let index = 0; index < transactionsPage.length; ++index) {
492
+ const element = transactionsPage[index];
493
+ if (element.tokenTransaction !== undefined) {
494
+ const hash: String = bytesToHex(element.tokenTransactionHash);
495
+ if (hashset_of_all_transactions.has(hash)) {
496
+ expect(
497
+ `Duplicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: ${pageSize} ; hash_duplicate: ${hash}`,
498
+ ).toEqual("");
499
+ } else {
500
+ hashset_of_all_transactions.add(hash);
501
+ }
502
+ } else {
503
+ expect(
504
+ `Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: ${pageSize}`,
505
+ ).toEqual("");
506
+ }
507
+ }
508
+
509
+ // Prepare for next iteration.
510
+ offset += transactionsPage.length;
511
+ page_num += 1;
512
+ }
513
+
514
+ expect(hashset_of_all_transactions.size).toEqual(202);
515
+ }
516
+ });
517
+
518
+ it("should mint token with 1 max supply without issue", async () => {
417
519
  const tokenAmount: bigint = 1n;
418
520
  const { wallet: issuerWallet } =
419
521
  await IssuerSparkWalletTesting.initialize({
@@ -433,7 +535,7 @@ describe.each(TEST_CONFIGS)(
433
535
  expect(tokenBalance.balance).toEqual(tokenAmount);
434
536
  });
435
537
 
436
- it("it should be able to create a token with name of size equal to MAX_SYMBOL_SIZE", async () => {
538
+ it("should be able to create a token with name of size equal to MAX_SYMBOL_SIZE", async () => {
437
539
  const { wallet: issuerWallet } =
438
540
  await IssuerSparkWalletTesting.initialize({
439
541
  options: config,
@@ -448,7 +550,7 @@ describe.each(TEST_CONFIGS)(
448
550
  });
449
551
  });
450
552
 
451
- it("it should be able to create a token with symbol of size equal to MAX_NAME_SIZE", async () => {
553
+ it("should be able to create a token with symbol of size equal to MAX_NAME_SIZE", async () => {
452
554
  const { wallet: issuerWallet } =
453
555
  await IssuerSparkWalletTesting.initialize({
454
556
  options: config,
@@ -463,7 +565,7 @@ describe.each(TEST_CONFIGS)(
463
565
  });
464
566
  });
465
567
 
466
- it("should create, mint, freeze and unfreeze tokens", async () => {
568
+ it("should create, mint, freeze, and unfreeze tokens", async () => {
467
569
  const tokenAmount: bigint = 1000n;
468
570
  const { wallet: issuerWallet } =
469
571
  await IssuerSparkWalletTesting.initialize({
@@ -505,11 +607,10 @@ describe.each(TEST_CONFIGS)(
505
607
  ).balance;
506
608
  expect(issuerBalanceAfterTransfer).toEqual(0n);
507
609
 
508
- const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
509
610
  const userBalanceObj = await userWallet.getBalance();
510
- const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
611
+ const userBalanceAfterTransfer = filterTokenBalanceForTokenIdentifier(
511
612
  userBalanceObj?.tokenBalances,
512
- tokenPublicKey,
613
+ tokenIdentifier!,
513
614
  );
514
615
  expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
515
616
 
@@ -525,7 +626,7 @@ describe.each(TEST_CONFIGS)(
525
626
  expect(unfreezeResponse.impactedTokenAmount).toEqual(tokenAmount);
526
627
  });
527
628
 
528
- it("should mint and burn tokens", async () => {
629
+ it("should create, mint and burn tokens", async () => {
529
630
  const tokenAmount: bigint = 200n;
530
631
 
531
632
  const { wallet: issuerWallet } =
@@ -555,7 +656,7 @@ describe.each(TEST_CONFIGS)(
555
656
  );
556
657
  });
557
658
 
558
- it("should complete full token lifecycle: create, mint, transfer, return, burn", async () => {
659
+ it("should complete a full token lifecycle - create, mint, transfer, return, burn", async () => {
559
660
  const tokenAmount: bigint = 1000n;
560
661
 
561
662
  const { wallet: issuerWallet } =
@@ -569,7 +670,6 @@ describe.each(TEST_CONFIGS)(
569
670
  isFreezable: false,
570
671
  maxSupply: 1_000_000n,
571
672
  });
572
- const issuerPublicKey = await issuerWallet.getIdentityPublicKey();
573
673
 
574
674
  const { wallet: userWallet } = await SparkWalletTesting.initialize({
575
675
  options: config,
@@ -600,9 +700,9 @@ describe.each(TEST_CONFIGS)(
600
700
  expect(issuerBalanceAfterTransfer).toEqual(initialBalance);
601
701
 
602
702
  const userBalanceObj = await userWallet.getBalance();
603
- const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
703
+ const userBalanceAfterTransfer = filterTokenBalanceForTokenIdentifier(
604
704
  userBalanceObj?.tokenBalances,
605
- issuerPublicKey,
705
+ tokenIdentifier!,
606
706
  );
607
707
  expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
608
708
 
@@ -613,9 +713,9 @@ describe.each(TEST_CONFIGS)(
613
713
  });
614
714
 
615
715
  const userBalanceObjAfterTransferBack = await userWallet.getBalance();
616
- const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
716
+ const userBalanceAfterTransferBack = filterTokenBalanceForTokenIdentifier(
617
717
  userBalanceObjAfterTransferBack?.tokenBalances,
618
- issuerPublicKey,
718
+ tokenIdentifier!,
619
719
  );
620
720
 
621
721
  expect(userBalanceAfterTransferBack.balance).toEqual(0n);
@@ -631,111 +731,5 @@ describe.each(TEST_CONFIGS)(
631
731
  ).balance;
632
732
  expect(issuerTokenBalanceAfterBurn).toEqual(initialBalance);
633
733
  });
634
-
635
- // it("should correctly assign operation types for complete token lifecycle operations", async () => {
636
- // const { wallet: userWallet } = await SparkWalletTesting.initialize({
637
- // options: config,
638
- // });
639
-
640
- // const tokenAmount = 1000n;
641
-
642
- // await sharedIssuerWallet.mintTokens(tokenAmount);
643
-
644
- // await sharedIssuerWallet.transferTokens({
645
- // tokenAmount: 500n,
646
- // tokenPublicKey: sharedTokenPublicKey,
647
- // receiverSparkAddress: await userWallet.getSparkAddress(),
648
- // });
649
-
650
- // await userWallet.transferTokens({
651
- // tokenPublicKey: sharedTokenPublicKey,
652
- // tokenAmount: 250n,
653
- // receiverSparkAddress: await sharedIssuerWallet.getSparkAddress(),
654
- // });
655
-
656
- // // as in userWallet we didn't have burnTokens method, we need to transfer tokens to burn address manually
657
- // const BURN_ADDRESS = "02".repeat(33);
658
- // const burnAddress = encodeSparkAddress({
659
- // identityPublicKey: BURN_ADDRESS,
660
- // network: "LOCAL",
661
- // });
662
-
663
- // await userWallet.transferTokens({
664
- // tokenPublicKey: sharedTokenPublicKey,
665
- // tokenAmount: 250n,
666
- // receiverSparkAddress: burnAddress,
667
- // });
668
-
669
- // await sharedIssuerWallet.burnTokens(250n);
670
-
671
- // const activity = await sharedIssuerWallet.getIssuerTokenActivity();
672
-
673
- // const mintTransaction = activity.transactions.find(
674
- // (tx) =>
675
- // tx.transaction?.$case === "spark" &&
676
- // tx.transaction.spark.operationType === "ISSUER_MINT",
677
- // );
678
-
679
- // const transferTransaction = activity.transactions.find(
680
- // (tx) =>
681
- // tx.transaction?.$case === "spark" &&
682
- // tx.transaction.spark.operationType === "ISSUER_TRANSFER",
683
- // );
684
-
685
- // const burnTransaction = activity.transactions.find(
686
- // (tx) =>
687
- // tx.transaction?.$case === "spark" &&
688
- // tx.transaction.spark.operationType === "ISSUER_BURN",
689
- // );
690
-
691
- // const transferBackTransaction = activity.transactions.find(
692
- // (tx) =>
693
- // tx.transaction?.$case === "spark" &&
694
- // tx.transaction.spark.operationType === "USER_TRANSFER",
695
- // );
696
-
697
- // const userBurnTransaction = activity.transactions.find(
698
- // (tx) =>
699
- // tx.transaction?.$case === "spark" &&
700
- // tx.transaction.spark.operationType === "USER_BURN",
701
- // );
702
-
703
- // expect(mintTransaction).toBeDefined();
704
- // expect(transferTransaction).toBeDefined();
705
- // expect(burnTransaction).toBeDefined();
706
- // expect(transferBackTransaction).toBeDefined();
707
- // expect(userBurnTransaction).toBeDefined();
708
- // });
709
-
710
- (config.tokenTransactionVersion === "V0" ? it.skip : it)(
711
- "should create a token using createToken API",
712
- async () => {
713
- const { wallet: issuerWallet } =
714
- await IssuerSparkWalletTesting.initialize({
715
- options: config,
716
- });
717
-
718
- const tokenName = `${name}Creatable`;
719
- const tokenTicker = "CRT";
720
- const maxSupply = 5000n;
721
- const decimals = 0;
722
- const txId = await issuerWallet.createToken({
723
- tokenName,
724
- tokenTicker,
725
- decimals,
726
- isFreezable: false,
727
- maxSupply,
728
- });
729
-
730
- expect(typeof txId).toBe("string");
731
- expect(txId.length).toBeGreaterThan(0);
732
-
733
- const metadata = await issuerWallet.getIssuerTokenMetadata();
734
- expect(metadata.tokenName).toEqual(tokenName);
735
- expect(metadata.tokenTicker).toEqual(tokenTicker);
736
- expect(metadata.maxSupply).toEqual(maxSupply);
737
- expect(metadata.decimals).toEqual(decimals);
738
- },
739
- );
740
734
  },
741
735
  );