mainnet-js 2.2.6 → 2.2.8

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.
@@ -704,6 +704,86 @@ describe(`Test cashtokens`, () => {
704
704
  expect(tokenUtxos2.length).toBe(1);
705
705
  });
706
706
 
707
+ test("Test sending tokens should not burn tokens", async () => {
708
+ const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
709
+ const bob = await RegTestWallet.newRandom();
710
+ const charlie = await RegTestWallet.newRandom();
711
+ // prepare inputs for two token geneses
712
+ await alice.send([
713
+ { cashaddr: bob.cashaddr!, value: 10000, unit: "sat" },
714
+ { cashaddr: charlie.cashaddr!, value: 10000, unit: "sat" },
715
+ ]);
716
+
717
+ const genesisResponse = await bob.tokenGenesis({
718
+ amount: 1001,
719
+ });
720
+
721
+ const tokenId = genesisResponse.tokenIds![0];
722
+
723
+ const tokenBalance = await bob.getTokenBalance(tokenId);
724
+ expect(tokenBalance).toBe(1001);
725
+ const tokenUtxos = await bob.getTokenUtxos(tokenId);
726
+ expect(tokenUtxos.length).toBe(1);
727
+
728
+ await bob.send({ cashaddr: alice.cashaddr!, value: 1000, unit: "sat" });
729
+
730
+ await bob.send([
731
+ {
732
+ cashaddr: charlie.cashaddr!,
733
+ tokenId: tokenId,
734
+ amount: 5,
735
+ },
736
+ {
737
+ cashaddr: charlie.cashaddr!,
738
+ tokenId: tokenId,
739
+ amount: 501,
740
+ },
741
+ {
742
+ cashaddr: charlie.cashaddr!,
743
+ tokenId: tokenId,
744
+ amount: 95,
745
+ },
746
+ {
747
+ cashaddr: charlie.cashaddr!,
748
+ tokenId: tokenId,
749
+ amount: 100,
750
+ },
751
+ {
752
+ cashaddr: charlie.cashaddr!,
753
+ tokenId: tokenId,
754
+ amount: 300,
755
+ },
756
+ ]);
757
+
758
+ const tokenBalance2 = await bob.getTokenBalance(tokenId);
759
+ expect(tokenBalance2).toBe(0);
760
+ const tokenUtxos2 = await bob.getTokenUtxos(tokenId);
761
+ expect(tokenUtxos2.length).toBe(0);
762
+
763
+ const tokenBalance3 = await charlie.getTokenBalance(tokenId);
764
+ expect(tokenBalance3).toBe(1001);
765
+ const tokenUtxos3 = await charlie.getTokenUtxos(tokenId);
766
+ expect(tokenUtxos3.length).toBe(5);
767
+
768
+ // charlie sends some from one of this utxos
769
+ await charlie.send([
770
+ {
771
+ cashaddr: bob.cashaddr!,
772
+ tokenId: tokenId,
773
+ amount: 50,
774
+ },
775
+ ]);
776
+ const tokenBalance4 = await charlie.getTokenBalance(tokenId);
777
+ expect(tokenBalance4).toBe(951);
778
+ const tokenUtxos4 = await charlie.getTokenUtxos(tokenId);
779
+ expect(tokenUtxos4.length).toBe(1);
780
+
781
+ const tokenBalance5 = await bob.getTokenBalance(tokenId);
782
+ expect(tokenBalance5).toBe(50);
783
+ const tokenUtxos5 = await bob.getTokenUtxos(tokenId);
784
+ expect(tokenUtxos5.length).toBe(1);
785
+ });
786
+
707
787
  test("Test minting NFTs not burn tokens", async () => {
708
788
  const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
709
789
  const bob = await RegTestWallet.newRandom();
package/src/wallet/Wif.ts CHANGED
@@ -1107,7 +1107,7 @@ export class Wallet extends BaseWallet {
1107
1107
  inputs: UtxoI[],
1108
1108
  outputs: SendRequestType[]
1109
1109
  ) => {
1110
- // allow for implicit token burn if the total amount sent is less than user had
1110
+ // Do NOT allow for implicit token burn if the total amount sent is less than user had
1111
1111
  // allow for token genesis, creating more tokens than we had before (0)
1112
1112
  if (!checkTokenQuantities) {
1113
1113
  return;
@@ -1148,7 +1148,7 @@ export class Wallet extends BaseWallet {
1148
1148
  available += token.token?.amount!;
1149
1149
  if (available >= outputAmountSum) {
1150
1150
  change = available - outputAmountSum;
1151
- break;
1151
+ //break;
1152
1152
  }
1153
1153
  }
1154
1154
  if (ensureUtxos.length) {