@buildonspark/issuer-sdk 0.0.34 → 0.0.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/dist/index.cjs +2 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -6
- package/package.json +3 -3
- package/src/issuer-spark-wallet.ts +6 -8
- package/src/proto/spark.ts +1673 -768
- package/src/tests/integration/spark.test.ts +216 -192
- package/src/tests/utils/issuer-test-wallet.ts +31 -0
- package/src/tests/utils/spark-testing-wallet.ts +64 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filterTokenBalanceForTokenPublicKey } from "@buildonspark/spark-sdk/utils";
|
|
2
2
|
import { jest } from "@jest/globals";
|
|
3
3
|
import { hexToBytes } from "@noble/curves/abstract/utils";
|
|
4
4
|
import {
|
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
LOCAL_WALLET_CONFIG_SCHNORR,
|
|
7
7
|
} from "../../../../spark-sdk/src/services/wallet-config.js";
|
|
8
8
|
import { BitcoinFaucet } from "../../../../spark-sdk/src/tests/utils/test-faucet.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
|
|
10
|
+
import { SparkWalletTesting } from "../utils/spark-testing-wallet.js";
|
|
11
11
|
|
|
12
12
|
const brokenTestFn = process.env.GITHUB_ACTIONS ? it.skip : it;
|
|
13
13
|
describe("token integration test", () => {
|
|
14
14
|
jest.setTimeout(80000);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
brokenTestFn("should issue a single token with ECDSA", async () => {
|
|
17
17
|
const tokenAmount: bigint = 1000n;
|
|
18
|
-
const { wallet } = await
|
|
18
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
19
19
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -25,9 +25,9 @@ describe("token integration test", () => {
|
|
|
25
25
|
expect(tokenBalance).toEqual(tokenAmount);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
brokenTestFn("should issue a single token with Schnorr", async () => {
|
|
29
29
|
const tokenAmount: bigint = 1000n;
|
|
30
|
-
const { wallet } = await
|
|
30
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
31
31
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -39,15 +39,15 @@ describe("token integration test", () => {
|
|
|
39
39
|
|
|
40
40
|
brokenTestFn("should announce and issue a single token", async () => {
|
|
41
41
|
const tokenAmount: bigint = 1000n;
|
|
42
|
-
const { wallet } = await
|
|
42
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
43
43
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
// Faucet funds to the Issuer wallet because announcing a token
|
|
47
47
|
// requires ownership of an L1 UTXO.
|
|
48
|
-
const faucet =
|
|
49
|
-
const l1WalletPubKey = await wallet.
|
|
50
|
-
await faucet.
|
|
48
|
+
const faucet = BitcoinFaucet.getInstance();
|
|
49
|
+
const l1WalletPubKey = await wallet.getTokenL1Address();
|
|
50
|
+
await faucet.sendToAddress(l1WalletPubKey, 100_000n);
|
|
51
51
|
await faucet.mineBlocks(6);
|
|
52
52
|
|
|
53
53
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
@@ -57,7 +57,7 @@ describe("token integration test", () => {
|
|
|
57
57
|
tokenName: "TestToken1",
|
|
58
58
|
tokenTicker: "TT1",
|
|
59
59
|
decimals: 0,
|
|
60
|
-
maxSupply:
|
|
60
|
+
maxSupply: 0n,
|
|
61
61
|
isFreezable: false,
|
|
62
62
|
});
|
|
63
63
|
console.log("Announce token response:", response);
|
|
@@ -96,43 +96,50 @@ describe("token integration test", () => {
|
|
|
96
96
|
expect(tokenInfo[0].maxSupply).toEqual(tokenAmount);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
99
|
+
brokenTestFn(
|
|
100
|
+
"should issue a single token and transfer it with ECDSA",
|
|
101
|
+
async () => {
|
|
102
|
+
const tokenAmount: bigint = 1000n;
|
|
103
|
+
|
|
104
|
+
const { wallet: issuerWallet } =
|
|
105
|
+
await IssuerSparkWalletTesting.initialize({
|
|
106
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize(
|
|
110
|
+
{
|
|
111
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
116
|
+
await issuerWallet.transferTokens({
|
|
117
|
+
tokenAmount,
|
|
118
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
119
|
+
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
120
|
+
});
|
|
121
|
+
const sourceBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
122
|
+
.balance;
|
|
123
|
+
expect(sourceBalance).toEqual(0n);
|
|
124
|
+
|
|
125
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
126
|
+
const balanceObj = await destinationWallet.getBalance();
|
|
127
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
128
|
+
balanceObj?.tokenBalances,
|
|
129
|
+
tokenPublicKey,
|
|
130
|
+
);
|
|
131
|
+
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
brokenTestFn("monitoring operations", async () => {
|
|
129
136
|
const tokenAmount: bigint = 1000n;
|
|
130
137
|
|
|
131
|
-
const { wallet: issuerWallet } = await
|
|
138
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
132
139
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
133
140
|
});
|
|
134
141
|
|
|
135
|
-
const { wallet: destinationWallet } = await
|
|
142
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize({
|
|
136
143
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
137
144
|
});
|
|
138
145
|
|
|
@@ -162,37 +169,44 @@ describe("token integration test", () => {
|
|
|
162
169
|
}
|
|
163
170
|
});
|
|
164
171
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
172
|
+
brokenTestFn(
|
|
173
|
+
"should issue a single token and transfer it with Schnorr",
|
|
174
|
+
async () => {
|
|
175
|
+
const tokenAmount: bigint = 1000n;
|
|
176
|
+
|
|
177
|
+
const { wallet: issuerWallet } =
|
|
178
|
+
await IssuerSparkWalletTesting.initialize({
|
|
179
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize(
|
|
183
|
+
{
|
|
184
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
189
|
+
await issuerWallet.transferTokens({
|
|
190
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
191
|
+
tokenAmount,
|
|
192
|
+
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
193
|
+
});
|
|
194
|
+
const sourceBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
195
|
+
.balance;
|
|
196
|
+
expect(sourceBalance).toEqual(0n);
|
|
197
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
198
|
+
const balanceObj = await destinationWallet.getBalance();
|
|
199
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
200
|
+
balanceObj?.tokenBalances,
|
|
201
|
+
tokenPublicKey,
|
|
202
|
+
);
|
|
203
|
+
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
brokenTestFn("should freeze tokens with ECDSA", async () => {
|
|
194
208
|
const tokenAmount: bigint = 1000n;
|
|
195
|
-
const { wallet: issuerWallet } = await
|
|
209
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
196
210
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
197
211
|
});
|
|
198
212
|
|
|
@@ -203,7 +217,7 @@ describe("token integration test", () => {
|
|
|
203
217
|
.balance;
|
|
204
218
|
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
205
219
|
|
|
206
|
-
const { wallet: userWallet } = await
|
|
220
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
207
221
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
208
222
|
});
|
|
209
223
|
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
@@ -237,9 +251,9 @@ describe("token integration test", () => {
|
|
|
237
251
|
expect(unfreezeResponse.impactedTokenAmount).toEqual(tokenAmount);
|
|
238
252
|
});
|
|
239
253
|
|
|
240
|
-
|
|
254
|
+
brokenTestFn("should freeze tokens with Schnorr", async () => {
|
|
241
255
|
const tokenAmount: bigint = 1000n;
|
|
242
|
-
const { wallet: issuerWallet } = await
|
|
256
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
243
257
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
244
258
|
});
|
|
245
259
|
|
|
@@ -250,7 +264,7 @@ describe("token integration test", () => {
|
|
|
250
264
|
.balance;
|
|
251
265
|
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
252
266
|
|
|
253
|
-
const { wallet: userWallet } = await
|
|
267
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
254
268
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
255
269
|
});
|
|
256
270
|
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
@@ -284,9 +298,9 @@ describe("token integration test", () => {
|
|
|
284
298
|
expect(unfreezeResult.impactedTokenAmount).toBe(1000n);
|
|
285
299
|
});
|
|
286
300
|
|
|
287
|
-
|
|
301
|
+
brokenTestFn("should burn tokens with ECDSA", async () => {
|
|
288
302
|
const tokenAmount: bigint = 200n;
|
|
289
|
-
const { wallet: issuerWallet } = await
|
|
303
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
290
304
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
291
305
|
});
|
|
292
306
|
await issuerWallet.mintTokens(tokenAmount);
|
|
@@ -303,9 +317,9 @@ describe("token integration test", () => {
|
|
|
303
317
|
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
304
318
|
});
|
|
305
319
|
|
|
306
|
-
|
|
320
|
+
brokenTestFn("should burn tokens with Schnorr", async () => {
|
|
307
321
|
const tokenAmount: bigint = 200n;
|
|
308
|
-
const { wallet: issuerWallet } = await
|
|
322
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
309
323
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
310
324
|
});
|
|
311
325
|
await issuerWallet.mintTokens(tokenAmount);
|
|
@@ -322,128 +336,138 @@ describe("token integration test", () => {
|
|
|
322
336
|
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
323
337
|
});
|
|
324
338
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
const { wallet: userWallet } = await SparkWallet.initialize({
|
|
333
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
337
|
-
|
|
338
|
-
const issuerBalanceAfterMint = (await issuerWallet.getIssuerTokenBalance())
|
|
339
|
-
.balance;
|
|
340
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
341
|
-
|
|
342
|
-
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
343
|
-
|
|
344
|
-
await issuerWallet.transferTokens({
|
|
345
|
-
tokenAmount,
|
|
346
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
347
|
-
receiverSparkAddress: userWalletPublicKey,
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
const issuerBalanceAfterTransfer = (
|
|
351
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
352
|
-
).balance;
|
|
353
|
-
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
354
|
-
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
355
|
-
const userWalletPublicKeyHex = await userWallet.getSparkAddress();
|
|
356
|
-
const userBalanceObj = await userWallet.getBalance();
|
|
357
|
-
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
358
|
-
userBalanceObj?.tokenBalances,
|
|
359
|
-
tokenPublicKeyHex,
|
|
360
|
-
);
|
|
361
|
-
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
362
|
-
await userWallet.transferTokens({
|
|
363
|
-
tokenPublicKey: tokenPublicKeyHex,
|
|
364
|
-
tokenAmount,
|
|
365
|
-
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
369
|
-
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
370
|
-
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
371
|
-
tokenPublicKeyHex,
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
375
|
-
|
|
376
|
-
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
377
|
-
.balance;
|
|
378
|
-
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
379
|
-
await issuerWallet.burnTokens(tokenAmount);
|
|
380
|
-
const issuerTokenBalanceAfterBurn = (
|
|
381
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
382
|
-
).balance;
|
|
383
|
-
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
384
|
-
});
|
|
339
|
+
brokenTestFn(
|
|
340
|
+
"mint, transfer to user, user transfer to issuer, burn with ECDSA",
|
|
341
|
+
async () => {
|
|
342
|
+
const tokenAmount: bigint = 1000n;
|
|
385
343
|
|
|
386
|
-
|
|
387
|
-
|
|
344
|
+
const { wallet: issuerWallet } =
|
|
345
|
+
await IssuerSparkWalletTesting.initialize({
|
|
346
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
347
|
+
});
|
|
388
348
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
349
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
350
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
351
|
+
});
|
|
392
352
|
|
|
393
|
-
|
|
394
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
395
|
-
});
|
|
353
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
396
354
|
|
|
397
|
-
|
|
398
|
-
|
|
355
|
+
const issuerBalanceAfterMint = (
|
|
356
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
357
|
+
).balance;
|
|
358
|
+
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
399
359
|
|
|
400
|
-
|
|
401
|
-
.balance;
|
|
402
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
360
|
+
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
403
361
|
|
|
404
|
-
|
|
362
|
+
await issuerWallet.transferTokens({
|
|
363
|
+
tokenAmount,
|
|
364
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
365
|
+
receiverSparkAddress: userWalletPublicKey,
|
|
366
|
+
});
|
|
405
367
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
368
|
+
const issuerBalanceAfterTransfer = (
|
|
369
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
370
|
+
).balance;
|
|
371
|
+
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
372
|
+
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
373
|
+
const userWalletPublicKeyHex = await userWallet.getSparkAddress();
|
|
374
|
+
const userBalanceObj = await userWallet.getBalance();
|
|
375
|
+
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
376
|
+
userBalanceObj?.tokenBalances,
|
|
377
|
+
tokenPublicKeyHex,
|
|
378
|
+
);
|
|
379
|
+
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
380
|
+
await userWallet.transferTokens({
|
|
381
|
+
tokenPublicKey: tokenPublicKeyHex,
|
|
382
|
+
tokenAmount,
|
|
383
|
+
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
384
|
+
});
|
|
411
385
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
386
|
+
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
387
|
+
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
388
|
+
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
389
|
+
tokenPublicKeyHex,
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
393
|
+
|
|
394
|
+
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
395
|
+
.balance;
|
|
396
|
+
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
397
|
+
await issuerWallet.burnTokens(tokenAmount);
|
|
398
|
+
const issuerTokenBalanceAfterBurn = (
|
|
399
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
400
|
+
).balance;
|
|
401
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
402
|
+
},
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
brokenTestFn(
|
|
406
|
+
"mint, transfer to user, user transfer to issuer, burn with Schnorr",
|
|
407
|
+
async () => {
|
|
408
|
+
const tokenAmount: bigint = 1000n;
|
|
409
|
+
|
|
410
|
+
const { wallet: issuerWallet } =
|
|
411
|
+
await IssuerSparkWalletTesting.initialize({
|
|
412
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
416
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
417
|
+
});
|
|
416
418
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
420
|
-
userBalanceObj?.tokenBalances,
|
|
421
|
-
tokenPublicKeyHex,
|
|
422
|
-
);
|
|
423
|
-
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
419
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
420
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
424
421
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
});
|
|
422
|
+
const issuerBalanceAfterMint = (
|
|
423
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
424
|
+
).balance;
|
|
425
|
+
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
430
426
|
|
|
431
|
-
|
|
432
|
-
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
433
|
-
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
434
|
-
tokenPublicKeyHex,
|
|
435
|
-
);
|
|
436
|
-
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
427
|
+
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
437
428
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
429
|
+
await issuerWallet.transferTokens({
|
|
430
|
+
tokenAmount,
|
|
431
|
+
tokenPublicKey,
|
|
432
|
+
receiverSparkAddress: userWalletPublicKey,
|
|
433
|
+
});
|
|
441
434
|
|
|
442
|
-
|
|
435
|
+
const issuerBalanceAfterTransfer = (
|
|
436
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
437
|
+
).balance;
|
|
438
|
+
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
439
|
+
|
|
440
|
+
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
441
|
+
const userBalanceObj = await userWallet.getBalance();
|
|
442
|
+
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
443
|
+
userBalanceObj?.tokenBalances,
|
|
444
|
+
tokenPublicKeyHex,
|
|
445
|
+
);
|
|
446
|
+
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
447
|
+
|
|
448
|
+
await userWallet.transferTokens({
|
|
449
|
+
tokenPublicKey: tokenPublicKeyHex,
|
|
450
|
+
tokenAmount,
|
|
451
|
+
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
452
|
+
});
|
|
443
453
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
454
|
+
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
455
|
+
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
456
|
+
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
457
|
+
tokenPublicKeyHex,
|
|
458
|
+
);
|
|
459
|
+
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
460
|
+
|
|
461
|
+
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
462
|
+
.balance;
|
|
463
|
+
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
464
|
+
|
|
465
|
+
await issuerWallet.burnTokens(tokenAmount);
|
|
466
|
+
|
|
467
|
+
const issuerTokenBalanceAfterBurn = (
|
|
468
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
469
|
+
).balance;
|
|
470
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
471
|
+
},
|
|
472
|
+
);
|
|
449
473
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SparkWalletProps } from "@buildonspark/spark-sdk";
|
|
2
|
+
import { IssuerSparkWallet } from "../../issuer-spark-wallet.js";
|
|
3
|
+
|
|
4
|
+
export class IssuerSparkWalletTesting extends IssuerSparkWallet {
|
|
5
|
+
private disableEvents: boolean;
|
|
6
|
+
|
|
7
|
+
constructor(props: SparkWalletProps, disableEvents = true) {
|
|
8
|
+
super(props.options);
|
|
9
|
+
this.disableEvents = disableEvents;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static async initialize(props: SparkWalletProps): Promise<{
|
|
13
|
+
mnemonic?: string;
|
|
14
|
+
wallet: IssuerSparkWalletTesting;
|
|
15
|
+
}> {
|
|
16
|
+
const wallet = new IssuerSparkWalletTesting(props, true);
|
|
17
|
+
|
|
18
|
+
const result = await wallet.initWallet(props.mnemonicOrSeed);
|
|
19
|
+
return {
|
|
20
|
+
wallet,
|
|
21
|
+
mnemonic: result?.mnemonic,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected override async setupBackgroundStream() {
|
|
26
|
+
if (!this.disableEvents) {
|
|
27
|
+
return super.setupBackgroundStream();
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SparkWallet, SparkWalletProps } from "@buildonspark/spark-sdk";
|
|
2
|
+
import {
|
|
3
|
+
QueryTransfersResponse,
|
|
4
|
+
Transfer,
|
|
5
|
+
} from "@buildonspark/spark-sdk/proto/spark";
|
|
6
|
+
import { ConfigOptions } from "@buildonspark/spark-sdk/services/wallet-config";
|
|
7
|
+
import { SparkSigner } from "@buildonspark/spark-sdk/signer";
|
|
8
|
+
|
|
9
|
+
interface ISparkWalletTesting extends SparkWallet {
|
|
10
|
+
getSigner(): SparkSigner;
|
|
11
|
+
queryPendingTransfers(): Promise<QueryTransfersResponse>;
|
|
12
|
+
verifyPendingTransfer(transfer: Transfer): Promise<Map<string, Uint8Array>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class SparkWalletTesting
|
|
16
|
+
extends SparkWallet
|
|
17
|
+
implements ISparkWalletTesting
|
|
18
|
+
{
|
|
19
|
+
private disableEvents: boolean;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
options?: ConfigOptions,
|
|
23
|
+
signer?: SparkSigner,
|
|
24
|
+
disableEvents = true,
|
|
25
|
+
) {
|
|
26
|
+
super(options, signer);
|
|
27
|
+
this.disableEvents = disableEvents;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async initialize(props: SparkWalletProps, disableEvents = true) {
|
|
31
|
+
const wallet = new SparkWalletTesting(
|
|
32
|
+
props.options,
|
|
33
|
+
props.signer,
|
|
34
|
+
disableEvents,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const initResponse = await wallet.initWallet(props.mnemonicOrSeed);
|
|
38
|
+
return {
|
|
39
|
+
wallet,
|
|
40
|
+
mnemonic: initResponse?.mnemonic,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected override async setupBackgroundStream() {
|
|
45
|
+
if (!this.disableEvents) {
|
|
46
|
+
await super.setupBackgroundStream();
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public getSigner(): SparkSigner {
|
|
52
|
+
return this.config.signer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async queryPendingTransfers(): Promise<QueryTransfersResponse> {
|
|
56
|
+
return await this.transferService.queryPendingTransfers();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async verifyPendingTransfer(
|
|
60
|
+
transfer: Transfer,
|
|
61
|
+
): Promise<Map<string, Uint8Array>> {
|
|
62
|
+
return await this.transferService.verifyPendingTransfer(transfer);
|
|
63
|
+
}
|
|
64
|
+
}
|