@buildonspark/issuer-sdk 0.0.44 → 0.0.46
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/services/freeze.ts +1 -1
- package/src/tests/integration/spark.test.ts +303 -332
package/dist/index.cjs
CHANGED
|
@@ -133,7 +133,7 @@ var TokenFreezeService = class {
|
|
|
133
133
|
};
|
|
134
134
|
} catch (error) {
|
|
135
135
|
throw new import_spark_sdk2.NetworkError(
|
|
136
|
-
|
|
136
|
+
`Failed to send a freeze/unfreeze operation for token: ${tokenPublicKey.toString()} at operator: ${operator.address}`,
|
|
137
137
|
{
|
|
138
138
|
operation: "freeze_tokens",
|
|
139
139
|
errorCount: 1,
|
package/dist/index.js
CHANGED
|
@@ -111,7 +111,7 @@ var TokenFreezeService = class {
|
|
|
111
111
|
};
|
|
112
112
|
} catch (error) {
|
|
113
113
|
throw new NetworkError(
|
|
114
|
-
|
|
114
|
+
`Failed to send a freeze/unfreeze operation for token: ${tokenPublicKey.toString()} at operator: ${operator.address}`,
|
|
115
115
|
{
|
|
116
116
|
operation: "freeze_tokens",
|
|
117
117
|
errorCount: 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/issuer-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"description": "Spark Issuer SDK for token issuance",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@bufbuild/protobuf": "^2.2.5",
|
|
57
|
-
"@buildonspark/lrc20-sdk": "0.0.
|
|
58
|
-
"@buildonspark/spark-sdk": "0.1.
|
|
57
|
+
"@buildonspark/lrc20-sdk": "0.0.42",
|
|
58
|
+
"@buildonspark/spark-sdk": "0.1.15",
|
|
59
59
|
"@noble/curves": "^1.8.0",
|
|
60
60
|
"@scure/btc-signer": "^1.5.0",
|
|
61
61
|
"bitcoinjs-lib": "^6.1.5",
|
package/src/services/freeze.ts
CHANGED
|
@@ -75,7 +75,7 @@ export class TokenFreezeService {
|
|
|
75
75
|
};
|
|
76
76
|
} catch (error) {
|
|
77
77
|
throw new NetworkError(
|
|
78
|
-
|
|
78
|
+
`Failed to send a freeze/unfreeze operation for token: ${tokenPublicKey.toString()} at operator: ${operator.address}`,
|
|
79
79
|
{
|
|
80
80
|
operation: "freeze_tokens",
|
|
81
81
|
errorCount: 1,
|
|
@@ -15,135 +15,136 @@ const brokenTestFn = process.env.GITHUB_ACTIONS ? it.skip : it;
|
|
|
15
15
|
describe("token integration tests", () => {
|
|
16
16
|
jest.setTimeout(80000);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await wallet.mintTokens(tokenAmount);
|
|
18
|
+
it("should fail when minting tokens without announcement", async () => {
|
|
19
|
+
const tokenAmount: bigint = 1000n;
|
|
20
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
21
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
22
|
+
});
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
);
|
|
24
|
+
await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
|
|
25
|
+
});
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
39
|
-
});
|
|
27
|
+
it("should fail when announce decimal is greater than js MAX_SAFE_INTEGER", async () => {
|
|
28
|
+
const tokenAmount: bigint = 1000n;
|
|
29
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
30
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
31
|
+
});
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
33
|
+
await expect(
|
|
34
|
+
fundAndAnnounce(
|
|
35
|
+
wallet,
|
|
36
|
+
tokenAmount,
|
|
37
|
+
2 ** 53,
|
|
38
|
+
"2Pow53Decimal",
|
|
39
|
+
"2P53D",
|
|
40
|
+
false,
|
|
41
|
+
),
|
|
42
|
+
).rejects.toThrow();
|
|
43
|
+
});
|
|
53
44
|
|
|
54
|
-
|
|
45
|
+
it("should fail when minting more than max supply", async () => {
|
|
55
46
|
const tokenAmount: bigint = 1000n;
|
|
56
47
|
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
57
48
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
58
49
|
});
|
|
59
50
|
|
|
60
|
-
await fundAndAnnounce(wallet, 2n, 0, "
|
|
51
|
+
await fundAndAnnounce(wallet, 2n, 0, "MaxSupply", "MST");
|
|
61
52
|
await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
|
|
62
53
|
});
|
|
63
54
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
72
|
-
});
|
|
55
|
+
it("should announce token and issue tokens successfully", async () => {
|
|
56
|
+
const tokenAmount: bigint = 1000n;
|
|
57
|
+
const tokenName = "AnnounceIssue";
|
|
58
|
+
const tokenSymbol = "AIT";
|
|
59
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
60
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
61
|
+
});
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
await fundAndAnnounce(wallet, 100000n, 0, tokenName, tokenSymbol);
|
|
75
64
|
|
|
76
|
-
|
|
65
|
+
const publicKeyInfo = await wallet.getIssuerTokenInfo();
|
|
77
66
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
// Assert token public key info values
|
|
68
|
+
const identityPublicKey = await wallet.getIdentityPublicKey();
|
|
69
|
+
expect(publicKeyInfo?.tokenName).toEqual(tokenName);
|
|
70
|
+
expect(publicKeyInfo?.tokenSymbol).toEqual(tokenSymbol);
|
|
71
|
+
expect(publicKeyInfo?.tokenDecimals).toEqual(0);
|
|
72
|
+
expect(publicKeyInfo?.maxSupply).toEqual(100000n);
|
|
73
|
+
expect(publicKeyInfo?.isFreezable).toEqual(false);
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
// Compare the public key using bytesToHex
|
|
76
|
+
const pubKeyHex = publicKeyInfo?.tokenPublicKey;
|
|
77
|
+
expect(pubKeyHex).toEqual(identityPublicKey);
|
|
89
78
|
|
|
90
|
-
|
|
79
|
+
await wallet.mintTokens(tokenAmount);
|
|
91
80
|
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
const tokenBalance = await wallet.getIssuerTokenBalance();
|
|
82
|
+
expect(tokenBalance.balance).toEqual(tokenAmount);
|
|
83
|
+
});
|
|
94
84
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
expect(tokenInfo[0].tokenSymbol).toEqual(tokenSymbol);
|
|
98
|
-
expect(tokenInfo[0].tokenDecimals).toEqual(0);
|
|
99
|
-
expect(tokenInfo[0].maxSupply).toEqual(tokenAmount);
|
|
100
|
-
},
|
|
101
|
-
);
|
|
85
|
+
it("should announce, mint, and transfer tokens with ECDSA", async () => {
|
|
86
|
+
const tokenAmount: bigint = 1000n;
|
|
102
87
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const tokenAmount: bigint = 1000n;
|
|
88
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
89
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
90
|
+
});
|
|
107
91
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
92
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize({
|
|
93
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
94
|
+
});
|
|
112
95
|
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
116
|
-
},
|
|
117
|
-
);
|
|
96
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSATransfer", "ETT");
|
|
118
97
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
98
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
99
|
+
await issuerWallet.transferTokens({
|
|
100
|
+
tokenAmount,
|
|
101
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
102
|
+
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
103
|
+
});
|
|
104
|
+
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
105
|
+
expect(sourceBalance).toEqual(0n);
|
|
126
106
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
expect(sourceBalance).toEqual(0n);
|
|
107
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
108
|
+
const balanceObj = await destinationWallet.getBalance();
|
|
109
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
110
|
+
balanceObj?.tokenBalances,
|
|
111
|
+
tokenPublicKey,
|
|
112
|
+
);
|
|
113
|
+
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
114
|
+
});
|
|
136
115
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
144
|
-
},
|
|
145
|
-
);
|
|
116
|
+
it("should track token operations in monitoring", async () => {
|
|
117
|
+
const tokenAmount: bigint = 1000n;
|
|
118
|
+
|
|
119
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
120
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
121
|
+
});
|
|
146
122
|
|
|
123
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize({
|
|
124
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSATransfer", "ETT");
|
|
128
|
+
|
|
129
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
130
|
+
await issuerWallet.transferTokens({
|
|
131
|
+
tokenAmount,
|
|
132
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
133
|
+
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
134
|
+
});
|
|
135
|
+
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
136
|
+
expect(sourceBalance).toEqual(0n);
|
|
137
|
+
|
|
138
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
139
|
+
const balanceObj = await destinationWallet.getBalance();
|
|
140
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
141
|
+
balanceObj?.tokenBalances,
|
|
142
|
+
tokenPublicKey,
|
|
143
|
+
);
|
|
144
|
+
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// broken because LRC20 does not yet have ISSUER operation types.
|
|
147
148
|
brokenTestFn("should track token operations in monitoring", async () => {
|
|
148
149
|
const tokenAmount: bigint = 1000n;
|
|
149
150
|
|
|
@@ -155,7 +156,7 @@ describe("token integration tests", () => {
|
|
|
155
156
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
156
157
|
});
|
|
157
158
|
|
|
158
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "
|
|
159
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "Monitoring", "MOT");
|
|
159
160
|
|
|
160
161
|
await issuerWallet.mintTokens(tokenAmount);
|
|
161
162
|
await issuerWallet.transferTokens({
|
|
@@ -178,54 +179,71 @@ describe("token integration tests", () => {
|
|
|
178
179
|
expect(issuerOperations.transactions.length).toBe(2);
|
|
179
180
|
const issuerOperationTx = issuerOperations.transactions[0].transaction;
|
|
180
181
|
expect(issuerOperationTx?.$case).toBe("spark");
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
let mint_operation = 0;
|
|
183
|
+
let transfer_operation = 0;
|
|
184
|
+
issuerOperations.transactions.forEach((transaction) => {
|
|
185
|
+
if (transaction.transaction?.$case === "spark") {
|
|
186
|
+
if (transaction.transaction.spark.operationType === "ISSUER_MINT") {
|
|
187
|
+
mint_operation++;
|
|
188
|
+
} else if (
|
|
189
|
+
transaction.transaction.spark.operationType === "ISSUER_TRANSFER"
|
|
190
|
+
) {
|
|
191
|
+
transfer_operation++;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
expect(mint_operation).toBe(1);
|
|
196
|
+
expect(transfer_operation).toBe(1);
|
|
184
197
|
});
|
|
185
198
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
async () => {
|
|
189
|
-
const tokenAmount: bigint = 1000n;
|
|
199
|
+
it("should announce, mint, and transfer tokens with Schnorr", async () => {
|
|
200
|
+
const tokenAmount: bigint = 1000n;
|
|
190
201
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
202
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
203
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
204
|
+
});
|
|
195
205
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
);
|
|
206
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize({
|
|
207
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
208
|
+
});
|
|
201
209
|
|
|
202
|
-
|
|
203
|
-
issuerWallet,
|
|
204
|
-
100000n,
|
|
205
|
-
0,
|
|
206
|
-
"SchnorrTransferToken",
|
|
207
|
-
"STT",
|
|
208
|
-
);
|
|
210
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "SchnorrTransfer", "STT");
|
|
209
211
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
);
|
|
212
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
213
|
+
await issuerWallet.transferTokens({
|
|
214
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
215
|
+
tokenAmount,
|
|
216
|
+
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
217
|
+
});
|
|
218
|
+
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
219
|
+
expect(sourceBalance).toEqual(0n);
|
|
220
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
221
|
+
const balanceObj = await destinationWallet.getBalance();
|
|
222
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
223
|
+
balanceObj?.tokenBalances,
|
|
224
|
+
tokenPublicKey,
|
|
225
|
+
);
|
|
226
|
+
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
227
|
+
});
|
|
228
228
|
|
|
229
|
+
it("it should mint token with 1 max supply without issue", async () => {
|
|
230
|
+
const tokenAmount: bigint = 1n;
|
|
231
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
232
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize({
|
|
236
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
await fundAndAnnounce(issuerWallet, 1n, 0, "MaxSupply", "MST");
|
|
240
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
241
|
+
|
|
242
|
+
const tokenBalance = await issuerWallet.getIssuerTokenBalance();
|
|
243
|
+
expect(tokenBalance.balance).toEqual(tokenAmount);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// freeze is hardcoded to mainnet
|
|
229
247
|
brokenTestFn(
|
|
230
248
|
"should announce, mint, freeze and unfreeze tokens with ECDSA",
|
|
231
249
|
async () => {
|
|
@@ -235,13 +253,7 @@ describe("token integration tests", () => {
|
|
|
235
253
|
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
236
254
|
});
|
|
237
255
|
|
|
238
|
-
await fundAndAnnounce(
|
|
239
|
-
issuerWallet,
|
|
240
|
-
100000n,
|
|
241
|
-
0,
|
|
242
|
-
"ECDSAFreezeToken",
|
|
243
|
-
"EFT",
|
|
244
|
-
);
|
|
256
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSAFreeze", "EFT");
|
|
245
257
|
await issuerWallet.mintTokens(tokenAmount);
|
|
246
258
|
|
|
247
259
|
// Check issuer balance after minting
|
|
@@ -286,6 +298,7 @@ describe("token integration tests", () => {
|
|
|
286
298
|
},
|
|
287
299
|
);
|
|
288
300
|
|
|
301
|
+
// freeze is hardcoded to mainnet
|
|
289
302
|
brokenTestFn(
|
|
290
303
|
"should announce, mint, freeze and unfreeze tokens with Schnorr",
|
|
291
304
|
async () => {
|
|
@@ -295,13 +308,7 @@ describe("token integration tests", () => {
|
|
|
295
308
|
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
296
309
|
});
|
|
297
310
|
|
|
298
|
-
await fundAndAnnounce(
|
|
299
|
-
issuerWallet,
|
|
300
|
-
100000n,
|
|
301
|
-
0,
|
|
302
|
-
"SchnorrFreezeToken",
|
|
303
|
-
"SFT",
|
|
304
|
-
);
|
|
311
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "SchnorrFreeze", "SFT");
|
|
305
312
|
|
|
306
313
|
await issuerWallet.mintTokens(tokenAmount);
|
|
307
314
|
|
|
@@ -346,210 +353,173 @@ describe("token integration tests", () => {
|
|
|
346
353
|
},
|
|
347
354
|
);
|
|
348
355
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
await IssuerSparkWalletTesting.initialize({
|
|
355
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
356
|
-
});
|
|
356
|
+
it("should announce, mint, and burn tokens with ECDSA", async () => {
|
|
357
|
+
const tokenAmount: bigint = 200n;
|
|
358
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
359
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
360
|
+
});
|
|
357
361
|
|
|
358
|
-
|
|
359
|
-
|
|
362
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSABurn", "EBT");
|
|
363
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
360
364
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
365
|
+
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
366
|
+
.balance;
|
|
367
|
+
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
364
368
|
|
|
365
|
-
|
|
369
|
+
await issuerWallet.burnTokens(tokenAmount);
|
|
366
370
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
);
|
|
371
|
+
const issuerTokenBalanceAfterBurn = (
|
|
372
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
373
|
+
).balance;
|
|
374
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
375
|
+
});
|
|
373
376
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
await IssuerSparkWalletTesting.initialize({
|
|
380
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
381
|
-
});
|
|
377
|
+
it("should announce, mint, and burn tokens with Schnorr", async () => {
|
|
378
|
+
const tokenAmount: bigint = 200n;
|
|
379
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
380
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
381
|
+
});
|
|
382
382
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
100000n,
|
|
386
|
-
0,
|
|
387
|
-
"SchnorrBurnToken",
|
|
388
|
-
"SBT",
|
|
389
|
-
);
|
|
390
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
383
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "SchnorrBurn", "SBT");
|
|
384
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
391
385
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
386
|
+
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
387
|
+
.balance;
|
|
388
|
+
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
395
389
|
|
|
396
|
-
|
|
390
|
+
await issuerWallet.burnTokens(tokenAmount);
|
|
397
391
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
);
|
|
392
|
+
const issuerTokenBalanceAfterBurn = (
|
|
393
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
394
|
+
).balance;
|
|
395
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
396
|
+
});
|
|
404
397
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
async () => {
|
|
408
|
-
const tokenAmount: bigint = 1000n;
|
|
398
|
+
it("should complete full token lifecycle with ECDSA: announce, mint, transfer, return, burn", async () => {
|
|
399
|
+
const tokenAmount: bigint = 1000n;
|
|
409
400
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
});
|
|
401
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
402
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
403
|
+
});
|
|
414
404
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
405
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
406
|
+
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
407
|
+
});
|
|
418
408
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
100000n,
|
|
422
|
-
0,
|
|
423
|
-
"ECDSAFullCycleToken",
|
|
424
|
-
"EFCT",
|
|
425
|
-
false,
|
|
426
|
-
);
|
|
427
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
409
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSAFullCycle", "EFCT");
|
|
410
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
428
411
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
412
|
+
const issuerBalanceAfterMint = (await issuerWallet.getIssuerTokenBalance())
|
|
413
|
+
.balance;
|
|
414
|
+
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
433
415
|
|
|
434
|
-
|
|
416
|
+
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
435
417
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
418
|
+
await issuerWallet.transferTokens({
|
|
419
|
+
tokenAmount,
|
|
420
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
421
|
+
receiverSparkAddress: userWalletPublicKey,
|
|
422
|
+
});
|
|
441
423
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
424
|
+
const issuerBalanceAfterTransfer = (
|
|
425
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
426
|
+
).balance;
|
|
427
|
+
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
428
|
+
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
429
|
+
const userWalletPublicKeyHex = await userWallet.getSparkAddress();
|
|
430
|
+
const userBalanceObj = await userWallet.getBalance();
|
|
431
|
+
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
432
|
+
userBalanceObj?.tokenBalances,
|
|
433
|
+
tokenPublicKeyHex,
|
|
434
|
+
);
|
|
435
|
+
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
436
|
+
await userWallet.transferTokens({
|
|
437
|
+
tokenPublicKey: tokenPublicKeyHex,
|
|
438
|
+
tokenAmount,
|
|
439
|
+
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
440
|
+
});
|
|
459
441
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
442
|
+
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
443
|
+
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
444
|
+
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
445
|
+
tokenPublicKeyHex,
|
|
446
|
+
);
|
|
465
447
|
|
|
466
|
-
|
|
448
|
+
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
467
449
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
);
|
|
450
|
+
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
451
|
+
.balance;
|
|
452
|
+
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
453
|
+
await issuerWallet.burnTokens(tokenAmount);
|
|
454
|
+
const issuerTokenBalanceAfterBurn = (
|
|
455
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
456
|
+
).balance;
|
|
457
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
458
|
+
});
|
|
478
459
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
async () => {
|
|
482
|
-
const tokenAmount: bigint = 1000n;
|
|
460
|
+
it("should complete full token lifecycle with Schnorr: announce, mint, transfer, return, burn", async () => {
|
|
461
|
+
const tokenAmount: bigint = 1000n;
|
|
483
462
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
});
|
|
463
|
+
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
464
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
465
|
+
});
|
|
488
466
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
467
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
468
|
+
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
469
|
+
});
|
|
492
470
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
100000n,
|
|
496
|
-
0,
|
|
497
|
-
"SchnorrFullCycleToken",
|
|
498
|
-
"SFCT",
|
|
499
|
-
);
|
|
500
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
471
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, "SchnorrFullCycle", "SFCT");
|
|
472
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
501
473
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
474
|
+
const issuerBalanceAfterMint = (await issuerWallet.getIssuerTokenBalance())
|
|
475
|
+
.balance;
|
|
476
|
+
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
506
477
|
|
|
507
|
-
|
|
478
|
+
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
508
479
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
480
|
+
await issuerWallet.transferTokens({
|
|
481
|
+
tokenAmount,
|
|
482
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
483
|
+
receiverSparkAddress: userWalletPublicKey,
|
|
484
|
+
});
|
|
514
485
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
486
|
+
const issuerBalanceAfterTransfer = (
|
|
487
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
488
|
+
).balance;
|
|
489
|
+
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
519
490
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
491
|
+
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
492
|
+
const userBalanceObj = await userWallet.getBalance();
|
|
493
|
+
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
494
|
+
userBalanceObj?.tokenBalances,
|
|
495
|
+
tokenPublicKeyHex,
|
|
496
|
+
);
|
|
497
|
+
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
527
498
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
499
|
+
await userWallet.transferTokens({
|
|
500
|
+
tokenPublicKey: tokenPublicKeyHex,
|
|
501
|
+
tokenAmount,
|
|
502
|
+
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
503
|
+
});
|
|
533
504
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
505
|
+
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
506
|
+
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
507
|
+
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
508
|
+
tokenPublicKeyHex,
|
|
509
|
+
);
|
|
510
|
+
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
540
511
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
512
|
+
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
513
|
+
.balance;
|
|
514
|
+
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
544
515
|
|
|
545
|
-
|
|
516
|
+
await issuerWallet.burnTokens(tokenAmount);
|
|
546
517
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
);
|
|
518
|
+
const issuerTokenBalanceAfterBurn = (
|
|
519
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
520
|
+
).balance;
|
|
521
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
522
|
+
});
|
|
553
523
|
});
|
|
554
524
|
|
|
555
525
|
async function fundAndAnnounce(
|
|
@@ -580,10 +550,11 @@ async function fundAndAnnounce(
|
|
|
580
550
|
console.log("Announce token response:", response);
|
|
581
551
|
} catch (error: any) {
|
|
582
552
|
console.error("Error when announcing token on L1:", error);
|
|
583
|
-
|
|
553
|
+
throw error;
|
|
584
554
|
}
|
|
585
|
-
await faucet.mineBlocks(
|
|
555
|
+
await faucet.mineBlocks(2);
|
|
586
556
|
|
|
587
557
|
// Wait for LRC20 processing.
|
|
588
|
-
|
|
558
|
+
const SECONDS = 1000;
|
|
559
|
+
await new Promise((resolve) => setTimeout(resolve, 3 * SECONDS));
|
|
589
560
|
}
|