mainnet-js 2.2.9 → 2.3.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.
@@ -31,30 +31,30 @@ describe(`Wallet should function in the browser`, () => {
31
31
  const alice = await RegTestWallet.fromId(id);
32
32
  const bob = await RegTestWallet.newRandom();
33
33
  const genesisResponse = await alice.tokenGenesis({
34
- amount: 100,
34
+ amount: 100n,
35
35
  });
36
36
 
37
37
  const tokenId = genesisResponse.tokenIds[0];
38
38
  const tokenBalance = await alice.getTokenBalance(tokenId);
39
- expect(tokenBalance).toBe(100);
39
+ expect(tokenBalance).toBe(100n);
40
40
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
41
41
  expect(tokenUtxos.length).toBe(1);
42
42
  const response = await alice.send([
43
43
  new TokenSendRequest({
44
44
  cashaddr: bob.cashaddr,
45
- amount: 25,
45
+ amount: 25n,
46
46
  tokenId: tokenId,
47
47
  }),
48
48
  new TokenSendRequest({
49
49
  cashaddr: alice.cashaddr,
50
- amount: 25,
50
+ amount: 25n,
51
51
  tokenId: tokenId,
52
52
  }),
53
53
  ]);
54
54
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
55
55
  expect(newTokenUtxos.length).toBe(2);
56
- expect(await alice.getTokenBalance(tokenId)).toBe(75);
57
- expect(await bob.getTokenBalance(tokenId)).toBe(25);
56
+ expect(await alice.getTokenBalance(tokenId)).toBe(75n);
57
+ expect(await bob.getTokenBalance(tokenId)).toBe(25n);
58
58
  }, process.env.ALICE_ID);
59
59
  });
60
60
 
@@ -70,7 +70,7 @@ describe(`Wallet should function in the browser`, () => {
70
70
 
71
71
  const tokenId = genesisResponse.tokenIds[0];
72
72
  const tokenBalance = await alice.getTokenBalance(tokenId);
73
- expect(tokenBalance).toBe(0);
73
+ expect(tokenBalance).toBe(0n);
74
74
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
75
75
  expect(tokenUtxos.length).toBe(1);
76
76
  const response = await alice.send([
@@ -81,11 +81,11 @@ describe(`Wallet should function in the browser`, () => {
81
81
  commitment: "abcd",
82
82
  }),
83
83
  ]);
84
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
84
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
85
85
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
86
86
  expect(newTokenUtxos.length).toBe(0);
87
87
 
88
- expect(await bob.getTokenBalance(tokenId)).toBe(0);
88
+ expect(await bob.getTokenBalance(tokenId)).toBe(0n);
89
89
  const bobTokenUtxos = await bob.getTokenUtxos(tokenId);
90
90
  expect(bobTokenUtxos.length).toBe(1);
91
91
  expect(tokenId).toEqual(response.tokenIds[0]);
@@ -104,7 +104,7 @@ describe(`Wallet should function in the browser`, () => {
104
104
 
105
105
  const tokenId = genesisResponse.tokenIds[0];
106
106
  const tokenBalance = await alice.getTokenBalance(tokenId);
107
- expect(tokenBalance).toBe(0);
107
+ expect(tokenBalance).toBe(0n);
108
108
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
109
109
  expect(tokenUtxos.length).toBe(1);
110
110
  await expect(
@@ -130,7 +130,7 @@ describe(`Wallet should function in the browser`, () => {
130
130
 
131
131
  const tokenId = genesisResponse.tokenIds[0];
132
132
  const tokenBalance = await alice.getTokenBalance(tokenId);
133
- expect(tokenBalance).toBe(0);
133
+ expect(tokenBalance).toBe(0n);
134
134
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
135
135
  expect(tokenUtxos.length).toBe(1);
136
136
  const response = await alice.send([
@@ -141,7 +141,7 @@ describe(`Wallet should function in the browser`, () => {
141
141
  commitment: "abcd02",
142
142
  }),
143
143
  ]);
144
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
144
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
145
145
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
146
146
  expect(newTokenUtxos.length).toBe(1);
147
147
  expect(tokenId).toEqual(response.tokenIds[0]);
@@ -160,7 +160,7 @@ describe(`Wallet should function in the browser`, () => {
160
160
 
161
161
  const tokenId = genesisResponse.tokenIds[0];
162
162
  const tokenBalance = await alice.getTokenBalance(tokenId);
163
- expect(tokenBalance).toBe(0);
163
+ expect(tokenBalance).toBe(0n);
164
164
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
165
165
  expect(tokenUtxos.length).toBe(1);
166
166
  const response = await alice.tokenMint(tokenId, [
@@ -175,7 +175,7 @@ describe(`Wallet should function in the browser`, () => {
175
175
  capability: NFTCapability.none,
176
176
  }),
177
177
  ]);
178
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
178
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
179
179
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
180
180
  expect(newTokenUtxos.length).toBe(3);
181
181
  expect(tokenId).toEqual(response.tokenIds[0]);
@@ -187,14 +187,14 @@ describe(`Wallet should function in the browser`, () => {
187
187
  const alice = await RegTestWallet.fromId(id);
188
188
  const genesisResponse = await alice.tokenGenesis({
189
189
  cashaddr: alice.cashaddr,
190
- amount: 4,
190
+ amount: 4n,
191
191
  capability: NFTCapability.minting,
192
192
  commitment: "abcd",
193
193
  });
194
194
 
195
195
  const tokenId = genesisResponse.tokenIds[0];
196
196
  const tokenBalance = await alice.getTokenBalance(tokenId);
197
- expect(tokenBalance).toBe(4);
197
+ expect(tokenBalance).toBe(4n);
198
198
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
199
199
  expect(tokenUtxos.length).toBe(1);
200
200
 
@@ -215,7 +215,7 @@ describe(`Wallet should function in the browser`, () => {
215
215
  ],
216
216
  true
217
217
  );
218
- expect(await alice.getTokenBalance(tokenId)).toBe(2);
218
+ expect(await alice.getTokenBalance(tokenId)).toBe(2n);
219
219
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
220
220
  expect(newTokenUtxos.length).toBe(3);
221
221
  expect(tokenId).toEqual(response.tokenIds[0]);
@@ -237,7 +237,7 @@ describe(`Wallet should function in the browser`, () => {
237
237
  ],
238
238
  false
239
239
  );
240
- expect(await alice.getTokenBalance(tokenId)).toBe(2);
240
+ expect(await alice.getTokenBalance(tokenId)).toBe(2n);
241
241
  const ftTokenUtxos = await alice.getTokenUtxos(tokenId);
242
242
  expect(ftTokenUtxos.length).toBe(5);
243
243
  expect(tokenId).toEqual(ftResponse.tokenIds[0]);
@@ -265,7 +265,7 @@ describe(`Wallet should function in the browser`, () => {
265
265
  ],
266
266
  true
267
267
  );
268
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
268
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
269
269
  const ft2TokenUtxos = await alice.getTokenUtxos(tokenId);
270
270
  expect(ft2TokenUtxos.length).toBe(8);
271
271
  expect(tokenId).toEqual(ft2Response.tokenIds[0]);
@@ -277,12 +277,12 @@ describe(`Wallet should function in the browser`, () => {
277
277
  const alice = await RegTestWallet.fromId(id);
278
278
  const genesisResponse = await alice.tokenGenesis({
279
279
  cashaddr: alice.cashaddr,
280
- amount: 4,
280
+ amount: 4n,
281
281
  });
282
282
 
283
283
  const tokenId = genesisResponse.tokenIds[0];
284
284
  const tokenBalance = await alice.getTokenBalance(tokenId);
285
- expect(tokenBalance).toBe(4);
285
+ expect(tokenBalance).toBe(4n);
286
286
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
287
287
  expect(tokenUtxos.length).toBe(1);
288
288
 
@@ -290,7 +290,7 @@ describe(`Wallet should function in the browser`, () => {
290
290
  const response = await alice.tokenBurn(
291
291
  {
292
292
  tokenId: tokenId,
293
- amount: 5,
293
+ amount: 5n,
294
294
  },
295
295
  "burn"
296
296
  );
@@ -301,7 +301,7 @@ describe(`Wallet should function in the browser`, () => {
301
301
  expect(rawTx.vout[0].scriptPubKey.hex).toContain(
302
302
  binToHex(utf8ToBin("burn"))
303
303
  );
304
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
304
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
305
305
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
306
306
  expect(newTokenUtxos.length).toBe(0);
307
307
  expect(tokenId).toEqual(response.tokenIds[0]);
@@ -313,14 +313,14 @@ describe(`Wallet should function in the browser`, () => {
313
313
  const alice = await RegTestWallet.fromId(id);
314
314
  const genesisResponse = await alice.tokenGenesis({
315
315
  cashaddr: alice.cashaddr,
316
- amount: 4,
316
+ amount: 4n,
317
317
  capability: NFTCapability.minting,
318
318
  commitment: "abcd",
319
319
  });
320
320
 
321
321
  const tokenId = genesisResponse.tokenIds[0];
322
322
  const tokenBalance = await alice.getTokenBalance(tokenId);
323
- expect(tokenBalance).toBe(4);
323
+ expect(tokenBalance).toBe(4n);
324
324
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
325
325
  expect(tokenUtxos.length).toBe(1);
326
326
 
@@ -328,7 +328,7 @@ describe(`Wallet should function in the browser`, () => {
328
328
  const response = await alice.tokenBurn(
329
329
  {
330
330
  tokenId: tokenId,
331
- amount: 1,
331
+ amount: 1n,
332
332
  capability: NFTCapability.minting,
333
333
  commitment: "abcd",
334
334
  },
@@ -341,8 +341,8 @@ describe(`Wallet should function in the browser`, () => {
341
341
  expect(rawTx.vout[0].scriptPubKey.hex).toContain(
342
342
  binToHex(utf8ToBin("burn"))
343
343
  );
344
- expect(await alice.getTokenBalance(tokenId)).toBe(3);
345
- expect((await alice.getAllTokenBalances())[tokenId]).toBe(3);
344
+ expect(await alice.getTokenBalance(tokenId)).toBe(3n);
345
+ expect((await alice.getAllTokenBalances())[tokenId]).toBe(3n);
346
346
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
347
347
  expect(newTokenUtxos.length).toBe(1);
348
348
  expect(await alice.getNftTokenBalance(tokenId)).toBe(1);
@@ -353,13 +353,13 @@ describe(`Wallet should function in the browser`, () => {
353
353
  const ftResponse = await alice.tokenBurn(
354
354
  {
355
355
  tokenId: tokenId,
356
- amount: 5,
356
+ amount: 5n,
357
357
  capability: NFTCapability.minting,
358
358
  commitment: "abcd",
359
359
  },
360
360
  "burn"
361
361
  );
362
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
362
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
363
363
  const ftTokenUtxos = await alice.getTokenUtxos(tokenId);
364
364
  expect(ftTokenUtxos.length).toBe(1);
365
365
  expect(tokenId).toEqual(ftResponse.tokenIds[0]);
@@ -373,13 +373,13 @@ describe(`Wallet should function in the browser`, () => {
373
373
  },
374
374
  "burn"
375
375
  );
376
- expect(await alice.getTokenBalance(tokenId)).toBe(0);
377
- expect((await alice.getAllTokenBalances())[tokenId] || 0).toBe(0);
376
+ expect(await alice.getTokenBalance(tokenId)).toBe(0n);
377
+ expect((await alice.getAllTokenBalances())[tokenId] || 0n).toBe(0n);
378
378
  const nftTokenUtxos = await alice.getTokenUtxos(tokenId);
379
379
  expect(nftTokenUtxos.length).toBe(0);
380
380
  expect(tokenId).toEqual(nftResponse.tokenIds[0]);
381
381
  expect(await alice.getNftTokenBalance(tokenId)).toBe(0);
382
- expect((await alice.getAllNftTokenBalances())[tokenId] || 0).toBe(0);
382
+ expect((await alice.getAllNftTokenBalances())[tokenId] || 0n).toBe(0n);
383
383
  }, process.env.ALICE_ID);
384
384
  });
385
385
 
@@ -395,7 +395,7 @@ describe(`Wallet should function in the browser`, () => {
395
395
 
396
396
  const tokenId = genesisResponse.tokenIds[0];
397
397
  const tokenBalance = await bob.getTokenBalance(tokenId);
398
- expect(tokenBalance).toBe(100);
398
+ expect(tokenBalance).toBe(100n);
399
399
  const tokenUtxos = await bob.getTokenUtxos(tokenId);
400
400
  expect(tokenUtxos.length).toBe(1);
401
401
  expect(tokenUtxos[0].satoshis).toBe(7000);
@@ -411,7 +411,7 @@ describe(`Wallet should function in the browser`, () => {
411
411
  ]);
412
412
  let newTokenUtxos = await bob.getTokenUtxos(tokenId);
413
413
  expect(newTokenUtxos.length).toBe(1);
414
- expect(await bob.getTokenBalance(tokenId)).toBe(100);
414
+ expect(await bob.getTokenBalance(tokenId)).toBe(100n);
415
415
 
416
416
  let bobUtxos = await bob.getAddressUtxos(bob.cashaddr);
417
417
  expect(bobUtxos.length).toBe(2);
@@ -429,7 +429,7 @@ describe(`Wallet should function in the browser`, () => {
429
429
  ]);
430
430
  newTokenUtxos = await bob.getTokenUtxos(tokenId);
431
431
  expect(newTokenUtxos.length).toBe(1);
432
- expect(await bob.getTokenBalance(tokenId)).toBe(100);
432
+ expect(await bob.getTokenBalance(tokenId)).toBe(100n);
433
433
 
434
434
  bobUtxos = await bob.getAddressUtxos(bob.cashaddr);
435
435
  expect(bobUtxos.length).toBe(2);
@@ -453,7 +453,7 @@ describe(`Wallet should function in the browser`, () => {
453
453
 
454
454
  const tokenId = genesisResponse.tokenIds[0];
455
455
  const tokenBalance = await alice.getTokenBalance(tokenId);
456
- expect(tokenBalance).toBe(100);
456
+ expect(tokenBalance).toBe(100n);
457
457
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
458
458
  expect(tokenUtxos.length).toBe(1);
459
459
  expect(tokenUtxos[0].satoshis).toBe(5000);
@@ -483,8 +483,8 @@ describe(`Wallet should function in the browser`, () => {
483
483
  delay(1000),
484
484
  ]);
485
485
 
486
- expect(balance).toBe(100);
487
- expect(seenBalance).toBe(100);
486
+ expect(balance).toBe(100n);
487
+ expect(seenBalance).toBe(100n);
488
488
 
489
489
  await Promise.all([cancel(), delay(1000)]);
490
490
  }, process.env.ALICE_ID);
@@ -505,6 +505,11 @@ describe(`Wallet should function in the browser`, () => {
505
505
  return true;
506
506
  };
507
507
 
508
+ BigInt.prototype.toJSON = function () {
509
+ const int = Number.parseInt(this.toString());
510
+ return int ?? this.toString();
511
+ };
512
+
508
513
  const aliceWallet = await RegTestWallet.fromId(id);
509
514
  const aliceWatchWallet = await RegTestWallet.watchOnly(
510
515
  aliceWallet.cashaddr