@buildonspark/issuer-sdk 0.0.75 → 0.0.77
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/CHANGELOG.md +20 -0
- package/dist/index.cjs +21 -211
- package/dist/index.d.cts +1 -17
- package/dist/index.d.ts +1 -17
- package/dist/index.js +15 -213
- package/package.json +3 -3
- package/src/issuer-wallet/issuer-spark-wallet.ts +5 -118
- package/src/services/token-transactions.ts +1 -1
- package/src/tests/integration/spark.test.ts +578 -826
- package/src/tests/stress/transfers.test.ts +5 -5
|
@@ -1,935 +1,687 @@
|
|
|
1
1
|
import { filterTokenBalanceForTokenPublicKey } from "@buildonspark/spark-sdk/utils";
|
|
2
2
|
import { jest } from "@jest/globals";
|
|
3
3
|
import { encodeSparkAddress } from "@buildonspark/spark-sdk/address";
|
|
4
|
-
import {
|
|
5
|
-
LOCAL_WALLET_CONFIG_ECDSA,
|
|
6
|
-
LOCAL_WALLET_CONFIG_SCHNORR,
|
|
7
|
-
} from "../../../../spark-sdk/src/services/wallet-config.js";
|
|
8
4
|
import { BitcoinFaucet } from "../../../../spark-sdk/src/tests/utils/test-faucet.js";
|
|
9
5
|
import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
|
|
6
|
+
import { hexToBytes } from "@noble/curves/abstract/utils";
|
|
10
7
|
import { SparkWalletTesting } from "../utils/spark-testing-wallet.js";
|
|
11
8
|
import { IssuerSparkWallet } from "../../index.js";
|
|
12
|
-
import {
|
|
9
|
+
import { LOCAL_WALLET_CONFIG } from "@buildonspark/spark-sdk/services/wallet-config";
|
|
10
|
+
import { ConfigOptions } from "@buildonspark/spark-sdk/services/wallet-config";
|
|
11
|
+
|
|
12
|
+
export const TOKENS_V0_SCHNORR_CONFIG: Required<ConfigOptions> = {
|
|
13
|
+
...LOCAL_WALLET_CONFIG,
|
|
14
|
+
tokenTransactionVersion: "V0",
|
|
15
|
+
tokenSignatures: "SCHNORR",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const TOKENS_V1_SCHNORR_CONFIG: Required<ConfigOptions> = {
|
|
19
|
+
...LOCAL_WALLET_CONFIG,
|
|
20
|
+
tokenTransactionVersion: "V1",
|
|
21
|
+
tokenSignatures: "SCHNORR",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const TOKENS_V0_ECDSA_CONFIG: Required<ConfigOptions> = {
|
|
25
|
+
...LOCAL_WALLET_CONFIG,
|
|
26
|
+
tokenSignatures: "ECDSA",
|
|
27
|
+
tokenTransactionVersion: "V0",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const TOKENS_V1_ECDSA_CONFIG: Required<ConfigOptions> = {
|
|
31
|
+
...LOCAL_WALLET_CONFIG,
|
|
32
|
+
tokenSignatures: "ECDSA",
|
|
33
|
+
tokenTransactionVersion: "V1",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const TEST_CONFIGS = [
|
|
37
|
+
{ name: "TV0E", config: TOKENS_V0_ECDSA_CONFIG },
|
|
38
|
+
{ name: "TV0S", config: TOKENS_V0_SCHNORR_CONFIG },
|
|
39
|
+
{ name: "TV1E", config: TOKENS_V1_ECDSA_CONFIG },
|
|
40
|
+
{ name: "TV1S", config: TOKENS_V1_SCHNORR_CONFIG },
|
|
41
|
+
];
|
|
13
42
|
|
|
14
|
-
|
|
15
|
-
if (hexString.length % 2 !== 0) {
|
|
16
|
-
throw new Error("Hex string must have an even number of characters.");
|
|
17
|
-
}
|
|
43
|
+
const brokenTestFn = process.env.GITHUB_ACTIONS ? it.skip : it;
|
|
18
44
|
|
|
19
|
-
|
|
45
|
+
describe.each(TEST_CONFIGS)(
|
|
46
|
+
"token integration tests - $name",
|
|
47
|
+
({ name, config }) => {
|
|
48
|
+
jest.setTimeout(80000);
|
|
20
49
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
50
|
+
let sharedIssuerWallet: IssuerSparkWallet;
|
|
51
|
+
let sharedUserWallet: any;
|
|
52
|
+
let sharedTokenPublicKey: string;
|
|
25
53
|
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
jest.setTimeout(80000);
|
|
54
|
+
beforeAll(async () => {
|
|
55
|
+
const { wallet: issuerWallet } =
|
|
56
|
+
await IssuerSparkWalletTesting.initialize({
|
|
57
|
+
options: config,
|
|
58
|
+
});
|
|
32
59
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
37
|
-
});
|
|
60
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
61
|
+
options: config,
|
|
62
|
+
});
|
|
38
63
|
|
|
39
|
-
|
|
40
|
-
|
|
64
|
+
// Announce a shared token for this configuration
|
|
65
|
+
await fundAndAnnounce(issuerWallet, 1000000n, 0, `${name}Shared`, "SHR");
|
|
41
66
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
67
|
+
sharedIssuerWallet = issuerWallet;
|
|
68
|
+
sharedUserWallet = userWallet;
|
|
69
|
+
sharedTokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
46
70
|
});
|
|
47
71
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
wallet,
|
|
51
|
-
tokenAmount,
|
|
52
|
-
2 ** 53,
|
|
53
|
-
"2Pow53Decimal",
|
|
54
|
-
"2P53D",
|
|
55
|
-
false,
|
|
56
|
-
),
|
|
57
|
-
).rejects.toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should fail when minting more than max supply", async () => {
|
|
61
|
-
const tokenAmount: bigint = 1000n;
|
|
62
|
-
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
63
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
72
|
+
afterEach(async () => {
|
|
73
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
64
74
|
});
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
it("should fail when minting tokens without announcement", async () => {
|
|
77
|
+
const tokenAmount: bigint = 1000n;
|
|
78
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
79
|
+
options: config,
|
|
80
|
+
});
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
const tokenAmount: bigint = 1000n;
|
|
72
|
-
const tokenName = "AnnounceIssue";
|
|
73
|
-
const tokenSymbol = "AIT";
|
|
74
|
-
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
75
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
82
|
+
await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
|
|
76
83
|
});
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const identityPublicKey = await wallet.getIdentityPublicKey();
|
|
84
|
-
expect(publicKeyInfo?.tokenName).toEqual(tokenName);
|
|
85
|
-
expect(publicKeyInfo?.tokenSymbol).toEqual(tokenSymbol);
|
|
86
|
-
expect(publicKeyInfo?.tokenDecimals).toEqual(0);
|
|
87
|
-
expect(publicKeyInfo?.maxSupply).toEqual(100000n);
|
|
88
|
-
expect(publicKeyInfo?.isFreezable).toEqual(false);
|
|
89
|
-
|
|
90
|
-
// Compare the public key using bytesToHex
|
|
91
|
-
const pubKeyHex = publicKeyInfo?.tokenPublicKey;
|
|
92
|
-
expect(pubKeyHex).toEqual(identityPublicKey);
|
|
93
|
-
|
|
94
|
-
await wallet.mintTokens(tokenAmount);
|
|
95
|
-
|
|
96
|
-
const tokenBalance = await wallet.getIssuerTokenBalance();
|
|
97
|
-
expect(tokenBalance.balance).toEqual(tokenAmount);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should announce, mint, and transfer tokens with ECDSA", async () => {
|
|
101
|
-
const tokenAmount: bigint = 1000n;
|
|
102
|
-
|
|
103
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
104
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
105
|
-
});
|
|
85
|
+
it("should fail when announce decimal is greater than js MAX_SAFE_INTEGER", async () => {
|
|
86
|
+
const tokenAmount: bigint = 1000n;
|
|
87
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
88
|
+
options: config,
|
|
89
|
+
});
|
|
106
90
|
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
await expect(
|
|
92
|
+
fundAndAnnounce(
|
|
93
|
+
wallet,
|
|
94
|
+
tokenAmount,
|
|
95
|
+
2 ** 53,
|
|
96
|
+
"2Pow53Decimal",
|
|
97
|
+
"2P53D",
|
|
98
|
+
false,
|
|
99
|
+
),
|
|
100
|
+
).rejects.toThrow();
|
|
109
101
|
});
|
|
110
102
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
117
|
-
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
118
|
-
});
|
|
119
|
-
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
120
|
-
expect(sourceBalance).toEqual(0n);
|
|
121
|
-
|
|
122
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
123
|
-
const balanceObj = await destinationWallet.getBalance();
|
|
124
|
-
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
125
|
-
balanceObj?.tokenBalances,
|
|
126
|
-
tokenPublicKey,
|
|
127
|
-
);
|
|
128
|
-
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should announce, mint, get list all transactions, and transfer tokens with ECDSA multiple times, get list all transactions again and check difference", async () => {
|
|
132
|
-
const tokenAmount: bigint = 100n;
|
|
103
|
+
it("should fail when minting more than max supply", async () => {
|
|
104
|
+
const tokenAmount: bigint = 1000n;
|
|
105
|
+
const { wallet } = await IssuerSparkWalletTesting.initialize({
|
|
106
|
+
options: config,
|
|
107
|
+
});
|
|
133
108
|
|
|
134
|
-
|
|
135
|
-
|
|
109
|
+
await fundAndAnnounce(wallet, 2n, 0, "MST", "MST");
|
|
110
|
+
await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
|
|
136
111
|
});
|
|
137
112
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
113
|
+
it("should mint tokens successfully", async () => {
|
|
114
|
+
const tokenAmount: bigint = 1000n;
|
|
141
115
|
|
|
142
|
-
|
|
116
|
+
const publicKeyInfo = await sharedIssuerWallet.getIssuerTokenInfo();
|
|
143
117
|
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
expect(
|
|
148
|
-
|
|
118
|
+
// Assert token public key info values
|
|
119
|
+
const identityPublicKey = await sharedIssuerWallet.getIdentityPublicKey();
|
|
120
|
+
expect(publicKeyInfo?.tokenName).toEqual(`${name}Shared`);
|
|
121
|
+
expect(publicKeyInfo?.tokenSymbol).toEqual("SHR");
|
|
122
|
+
expect(publicKeyInfo?.tokenDecimals).toEqual(0);
|
|
123
|
+
expect(publicKeyInfo?.maxSupply).toEqual(1000000n);
|
|
124
|
+
expect(publicKeyInfo?.isFreezable).toEqual(false);
|
|
149
125
|
|
|
150
|
-
|
|
126
|
+
// Compare the public key using bytesToHex
|
|
127
|
+
const pubKeyHex = publicKeyInfo?.tokenPublicKey;
|
|
128
|
+
expect(pubKeyHex).toEqual(identityPublicKey);
|
|
151
129
|
|
|
152
|
-
|
|
153
|
-
const transactions = await issuerWallet.getIssuerTokenActivity();
|
|
154
|
-
const amount_of_transactions = transactions.transactions.length;
|
|
155
|
-
expect(amount_of_transactions).toEqual(1);
|
|
156
|
-
}
|
|
130
|
+
await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
157
131
|
|
|
158
|
-
|
|
159
|
-
tokenAmount
|
|
160
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
161
|
-
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
132
|
+
const tokenBalance = await sharedIssuerWallet.getIssuerTokenBalance();
|
|
133
|
+
expect(tokenBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
|
|
162
134
|
});
|
|
163
135
|
|
|
164
|
-
{
|
|
165
|
-
const
|
|
166
|
-
const amount_of_transactions = transactions.transactions.length;
|
|
167
|
-
expect(amount_of_transactions).toEqual(2);
|
|
168
|
-
}
|
|
136
|
+
it("should mint and transfer tokens", async () => {
|
|
137
|
+
const tokenAmount: bigint = 1000n;
|
|
169
138
|
|
|
170
|
-
|
|
171
|
-
await
|
|
172
|
-
await issuerWallet.transferTokens({
|
|
139
|
+
await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
140
|
+
await sharedIssuerWallet.transferTokens({
|
|
173
141
|
tokenAmount,
|
|
174
|
-
tokenPublicKey:
|
|
175
|
-
receiverSparkAddress: await
|
|
142
|
+
tokenPublicKey: sharedTokenPublicKey,
|
|
143
|
+
receiverSparkAddress: await sharedUserWallet.getSparkAddress(),
|
|
176
144
|
});
|
|
177
|
-
} // 202 in total
|
|
178
|
-
|
|
179
|
-
let all_transactions = await issuerWallet.getIssuerTokenActivity(250);
|
|
180
|
-
const amount_of_transactions = all_transactions.transactions.length;
|
|
181
|
-
expect(amount_of_transactions).toEqual(202);
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
const transactions = await issuerWallet.getIssuerTokenActivity(10);
|
|
185
|
-
const amount_of_transactions = transactions.transactions.length;
|
|
186
|
-
expect(amount_of_transactions).toEqual(10);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
{
|
|
190
|
-
let hashset_of_all_transactions: Set<String> = new Set();
|
|
191
|
-
|
|
192
|
-
let transactions = await issuerWallet.getIssuerTokenActivity(10);
|
|
193
|
-
let amount_of_transactions = transactions.transactions.length;
|
|
194
|
-
expect(amount_of_transactions).toEqual(10);
|
|
195
|
-
let page_num = 0;
|
|
196
|
-
for (let index = 0; index < transactions.transactions.length; ++index) {
|
|
197
|
-
const element = transactions.transactions[index];
|
|
198
|
-
if (!(element.transaction === undefined)) {
|
|
199
|
-
let hash: String = "";
|
|
200
|
-
if (element.transaction.$case === "spark") {
|
|
201
|
-
hash = element.transaction.spark.transactionHash;
|
|
202
|
-
} else if (element.transaction.$case === "onChain") {
|
|
203
|
-
hash = element.transaction.onChain.transactionHash;
|
|
204
|
-
}
|
|
205
|
-
if (hashset_of_all_transactions.has(hash)) {
|
|
206
|
-
expect(
|
|
207
|
-
`Dublicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: 10 ; hash_dublicate: ${hash}`,
|
|
208
|
-
).toEqual("");
|
|
209
|
-
} else {
|
|
210
|
-
hashset_of_all_transactions.add(hash);
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
expect(
|
|
214
|
-
`Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: 10`,
|
|
215
|
-
).toEqual("");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
while (!(undefined === transactions.nextCursor)) {
|
|
220
|
-
let transactions_2 = await issuerWallet.getIssuerTokenActivity(10, {
|
|
221
|
-
lastTransactionHash: hexStringToUint8Array(
|
|
222
|
-
transactions.nextCursor.lastTransactionHash,
|
|
223
|
-
),
|
|
224
|
-
layer: transactions.nextCursor.layer,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
++page_num;
|
|
228
|
-
|
|
229
|
-
for (
|
|
230
|
-
let index = 0;
|
|
231
|
-
index < transactions_2.transactions.length;
|
|
232
|
-
++index
|
|
233
|
-
) {
|
|
234
|
-
const element = transactions_2.transactions[index];
|
|
235
|
-
if (!(element.transaction === undefined)) {
|
|
236
|
-
let hash: String = "";
|
|
237
|
-
if (element.transaction.$case === "spark") {
|
|
238
|
-
hash = element.transaction.spark.transactionHash;
|
|
239
|
-
} else if (element.transaction.$case === "onChain") {
|
|
240
|
-
hash = element.transaction.onChain.transactionHash;
|
|
241
|
-
}
|
|
242
|
-
if (hashset_of_all_transactions.has(hash)) {
|
|
243
|
-
expect(
|
|
244
|
-
`Dublicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: 10 ; hash_dublicate: ${hash}`,
|
|
245
|
-
).toEqual("");
|
|
246
|
-
} else {
|
|
247
|
-
hashset_of_all_transactions.add(hash);
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
expect(
|
|
251
|
-
`Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: 10`,
|
|
252
|
-
).toEqual("");
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
transactions = transactions_2;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
expect(hashset_of_all_transactions.size == 202);
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("should announce, mint, and batchtransfer tokens with ECDSA", async () => {
|
|
264
|
-
const tokenAmount: bigint = 999n;
|
|
265
|
-
|
|
266
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
267
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const { wallet: destinationWallet } = await SparkWalletTesting.initialize({
|
|
271
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
const { wallet: destinationWallet2 } = await SparkWalletTesting.initialize({
|
|
275
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
276
|
-
});
|
|
277
145
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
146
|
+
const balanceObj = await sharedUserWallet.getBalance();
|
|
147
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
148
|
+
balanceObj?.tokenBalances,
|
|
149
|
+
sharedTokenPublicKey,
|
|
150
|
+
);
|
|
151
|
+
expect(destinationBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// it("should announce, mint, get list all transactions, and transfer tokens multiple times, get list all transactions again and check difference", async () => {
|
|
155
|
+
// const tokenAmount: bigint = 100n;
|
|
156
|
+
|
|
157
|
+
// const { wallet: issuerWallet } =
|
|
158
|
+
// await IssuerSparkWalletTesting.initialize({
|
|
159
|
+
// options: config,
|
|
160
|
+
// });
|
|
161
|
+
|
|
162
|
+
// const { wallet: destinationWallet } = await SparkWalletTesting.initialize(
|
|
163
|
+
// {
|
|
164
|
+
// options: config,
|
|
165
|
+
// },
|
|
166
|
+
// );
|
|
167
|
+
|
|
168
|
+
// await fundAndAnnounce(issuerWallet, 100000n, 0, `${name}Transfer`, "TTO");
|
|
169
|
+
|
|
170
|
+
// {
|
|
171
|
+
// const transactions = await issuerWallet.getIssuerTokenActivity();
|
|
172
|
+
// const amount_of_transactions = transactions.transactions.length;
|
|
173
|
+
// expect(amount_of_transactions).toEqual(0);
|
|
174
|
+
// }
|
|
175
|
+
|
|
176
|
+
// await issuerWallet.mintTokens(tokenAmount);
|
|
177
|
+
|
|
178
|
+
// {
|
|
179
|
+
// const transactions = await issuerWallet.getIssuerTokenActivity();
|
|
180
|
+
// const amount_of_transactions = transactions.transactions.length;
|
|
181
|
+
// expect(amount_of_transactions).toEqual(1);
|
|
182
|
+
// }
|
|
183
|
+
|
|
184
|
+
// await issuerWallet.transferTokens({
|
|
185
|
+
// tokenAmount,
|
|
186
|
+
// tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
187
|
+
// receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
188
|
+
// });
|
|
189
|
+
|
|
190
|
+
// {
|
|
191
|
+
// const transactions = await issuerWallet.getIssuerTokenActivity();
|
|
192
|
+
// const amount_of_transactions = transactions.transactions.length;
|
|
193
|
+
// expect(amount_of_transactions).toEqual(2);
|
|
194
|
+
// }
|
|
195
|
+
|
|
196
|
+
// for (let index = 0; index < 100; ++index) {
|
|
197
|
+
// await issuerWallet.mintTokens(tokenAmount);
|
|
198
|
+
// await issuerWallet.transferTokens({
|
|
199
|
+
// tokenAmount,
|
|
200
|
+
// tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
201
|
+
// receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
202
|
+
// });
|
|
203
|
+
// } // 202 in total
|
|
204
|
+
|
|
205
|
+
// let all_transactions = await issuerWallet.getIssuerTokenActivity(250);
|
|
206
|
+
// const amount_of_transactions = all_transactions.transactions.length;
|
|
207
|
+
// expect(amount_of_transactions).toEqual(202);
|
|
208
|
+
|
|
209
|
+
// {
|
|
210
|
+
// const transactions = await issuerWallet.getIssuerTokenActivity(10);
|
|
211
|
+
// const amount_of_transactions = transactions.transactions.length;
|
|
212
|
+
// expect(amount_of_transactions).toEqual(10);
|
|
213
|
+
// }
|
|
214
|
+
|
|
215
|
+
// {
|
|
216
|
+
// let hashset_of_all_transactions: Set<String> = new Set();
|
|
217
|
+
|
|
218
|
+
// let transactions = await issuerWallet.getIssuerTokenActivity(10);
|
|
219
|
+
// let amount_of_transactions = transactions.transactions.length;
|
|
220
|
+
// expect(amount_of_transactions).toEqual(10);
|
|
221
|
+
// let page_num = 0;
|
|
222
|
+
// for (let index = 0; index < transactions.transactions.length; ++index) {
|
|
223
|
+
// const element = transactions.transactions[index];
|
|
224
|
+
// if (!(element.transaction === undefined)) {
|
|
225
|
+
// let hash: String = "";
|
|
226
|
+
// if (element.transaction.$case === "spark") {
|
|
227
|
+
// hash = element.transaction.spark.transactionHash;
|
|
228
|
+
// } else if (element.transaction.$case === "onChain") {
|
|
229
|
+
// hash = element.transaction.onChain.transactionHash;
|
|
230
|
+
// }
|
|
231
|
+
// if (hashset_of_all_transactions.has(hash)) {
|
|
232
|
+
// expect(
|
|
233
|
+
// `Dublicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: 10 ; hash_dublicate: ${hash}`,
|
|
234
|
+
// ).toEqual("");
|
|
235
|
+
// } else {
|
|
236
|
+
// hashset_of_all_transactions.add(hash);
|
|
237
|
+
// }
|
|
238
|
+
// } else {
|
|
239
|
+
// expect(
|
|
240
|
+
// `Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: 10`,
|
|
241
|
+
// ).toEqual("");
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
244
|
+
|
|
245
|
+
// while (!(undefined === transactions.nextCursor)) {
|
|
246
|
+
// let transactions_2 = await issuerWallet.getIssuerTokenActivity(10, {
|
|
247
|
+
// lastTransactionHash: hexToBytes(
|
|
248
|
+
// transactions.nextCursor.lastTransactionHash,
|
|
249
|
+
// ),
|
|
250
|
+
// layer: transactions.nextCursor.layer,
|
|
251
|
+
// });
|
|
252
|
+
|
|
253
|
+
// ++page_num;
|
|
254
|
+
|
|
255
|
+
// for (
|
|
256
|
+
// let index = 0;
|
|
257
|
+
// index < transactions_2.transactions.length;
|
|
258
|
+
// ++index
|
|
259
|
+
// ) {
|
|
260
|
+
// const element = transactions_2.transactions[index];
|
|
261
|
+
// if (!(element.transaction === undefined)) {
|
|
262
|
+
// let hash: String = "";
|
|
263
|
+
// if (element.transaction.$case === "spark") {
|
|
264
|
+
// hash = element.transaction.spark.transactionHash;
|
|
265
|
+
// } else if (element.transaction.$case === "onChain") {
|
|
266
|
+
// hash = element.transaction.onChain.transactionHash;
|
|
267
|
+
// }
|
|
268
|
+
// if (hashset_of_all_transactions.has(hash)) {
|
|
269
|
+
// expect(
|
|
270
|
+
// `Dublicate found. Pagination is broken? Index of transaction: ${index} ; page №: ${page_num} ; page size: 10 ; hash_dublicate: ${hash}`,
|
|
271
|
+
// ).toEqual("");
|
|
272
|
+
// } else {
|
|
273
|
+
// hashset_of_all_transactions.add(hash);
|
|
274
|
+
// }
|
|
275
|
+
// } else {
|
|
276
|
+
// expect(
|
|
277
|
+
// `Transaction is undefined. Something is really wrong. Index of transaction: ${index} ; page №: ${page_num} ; page size: 10`,
|
|
278
|
+
// ).toEqual("");
|
|
279
|
+
// }
|
|
280
|
+
// }
|
|
281
|
+
|
|
282
|
+
// transactions = transactions_2;
|
|
283
|
+
// }
|
|
284
|
+
|
|
285
|
+
// expect(hashset_of_all_transactions.size == 202);
|
|
286
|
+
// }
|
|
287
|
+
// });
|
|
288
|
+
|
|
289
|
+
it("should mint and batchtransfer tokens", async () => {
|
|
290
|
+
const tokenAmount: bigint = 999n;
|
|
291
|
+
|
|
292
|
+
const { wallet: destinationWallet } = await SparkWalletTesting.initialize(
|
|
293
|
+
{
|
|
294
|
+
options: config,
|
|
295
|
+
},
|
|
296
|
+
);
|
|
281
297
|
|
|
282
|
-
|
|
298
|
+
const { wallet: destinationWallet2 } =
|
|
299
|
+
await SparkWalletTesting.initialize({
|
|
300
|
+
options: config,
|
|
301
|
+
});
|
|
283
302
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
289
|
-
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
tokenAmount: tokenAmount / 3n,
|
|
293
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
294
|
-
receiverSparkAddress: await destinationWallet2.getSparkAddress(),
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
tokenAmount: tokenAmount / 3n,
|
|
298
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
299
|
-
receiverSparkAddress: await destinationWallet3.getSparkAddress(),
|
|
300
|
-
},
|
|
301
|
-
]);
|
|
302
|
-
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
303
|
-
expect(sourceBalance).toEqual(0n);
|
|
304
|
-
|
|
305
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
306
|
-
const balanceObj = await destinationWallet.getBalance();
|
|
307
|
-
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
308
|
-
balanceObj?.tokenBalances,
|
|
309
|
-
tokenPublicKey,
|
|
310
|
-
);
|
|
311
|
-
expect(destinationBalance.balance).toEqual(tokenAmount / 3n);
|
|
312
|
-
const balanceObj2 = await destinationWallet2.getBalance();
|
|
313
|
-
const destinationBalance2 = filterTokenBalanceForTokenPublicKey(
|
|
314
|
-
balanceObj2?.tokenBalances,
|
|
315
|
-
tokenPublicKey,
|
|
316
|
-
);
|
|
317
|
-
expect(destinationBalance2.balance).toEqual(tokenAmount / 3n);
|
|
318
|
-
const balanceObj3 = await destinationWallet3.getBalance();
|
|
319
|
-
const destinationBalance3 = filterTokenBalanceForTokenPublicKey(
|
|
320
|
-
balanceObj3?.tokenBalances,
|
|
321
|
-
tokenPublicKey,
|
|
322
|
-
);
|
|
323
|
-
expect(destinationBalance3.balance).toEqual(tokenAmount / 3n);
|
|
324
|
-
});
|
|
303
|
+
const { wallet: destinationWallet3 } =
|
|
304
|
+
await SparkWalletTesting.initialize({
|
|
305
|
+
options: config,
|
|
306
|
+
});
|
|
325
307
|
|
|
326
|
-
|
|
327
|
-
|
|
308
|
+
await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
309
|
+
const sourceBalanceBefore = (
|
|
310
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
311
|
+
).balance;
|
|
328
312
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
313
|
+
await sharedIssuerWallet.batchTransferTokens([
|
|
314
|
+
{
|
|
315
|
+
tokenAmount: tokenAmount / 3n,
|
|
316
|
+
tokenPublicKey: sharedTokenPublicKey,
|
|
317
|
+
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
tokenAmount: tokenAmount / 3n,
|
|
321
|
+
tokenPublicKey: sharedTokenPublicKey,
|
|
322
|
+
receiverSparkAddress: await destinationWallet2.getSparkAddress(),
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
tokenAmount: tokenAmount / 3n,
|
|
326
|
+
tokenPublicKey: sharedTokenPublicKey,
|
|
327
|
+
receiverSparkAddress: await destinationWallet3.getSparkAddress(),
|
|
328
|
+
},
|
|
329
|
+
]);
|
|
330
|
+
|
|
331
|
+
const sourceBalanceAfter = (
|
|
332
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
333
|
+
).balance;
|
|
334
|
+
expect(sourceBalanceAfter).toEqual(sourceBalanceBefore - tokenAmount);
|
|
332
335
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
+
const balanceObj = await destinationWallet.getBalance();
|
|
337
|
+
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
338
|
+
balanceObj?.tokenBalances,
|
|
339
|
+
sharedTokenPublicKey,
|
|
340
|
+
);
|
|
341
|
+
expect(destinationBalance.balance).toEqual(tokenAmount / 3n);
|
|
342
|
+
const balanceObj2 = await destinationWallet2.getBalance();
|
|
343
|
+
const destinationBalance2 = filterTokenBalanceForTokenPublicKey(
|
|
344
|
+
balanceObj2?.tokenBalances,
|
|
345
|
+
sharedTokenPublicKey,
|
|
346
|
+
);
|
|
347
|
+
expect(destinationBalance2.balance).toEqual(tokenAmount / 3n);
|
|
348
|
+
const balanceObj3 = await destinationWallet3.getBalance();
|
|
349
|
+
const destinationBalance3 = filterTokenBalanceForTokenPublicKey(
|
|
350
|
+
balanceObj3?.tokenBalances,
|
|
351
|
+
sharedTokenPublicKey,
|
|
352
|
+
);
|
|
353
|
+
expect(destinationBalance3.balance).toEqual(tokenAmount / 3n);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// it("should track token operations in monitoring", async () => {
|
|
357
|
+
// const tokenAmount: bigint = 1000n;
|
|
358
|
+
|
|
359
|
+
// await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
360
|
+
// await sharedIssuerWallet.transferTokens({
|
|
361
|
+
// tokenAmount,
|
|
362
|
+
// tokenPublicKey: sharedTokenPublicKey,
|
|
363
|
+
// receiverSparkAddress: await sharedUserWallet.getSparkAddress(),
|
|
364
|
+
// });
|
|
365
|
+
|
|
366
|
+
// const balanceObj = await sharedUserWallet.getBalance();
|
|
367
|
+
// const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
368
|
+
// balanceObj?.tokenBalances,
|
|
369
|
+
// sharedTokenPublicKey,
|
|
370
|
+
// );
|
|
371
|
+
// expect(destinationBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
|
|
372
|
+
|
|
373
|
+
// const issuerOperations =
|
|
374
|
+
// await sharedIssuerWallet.getIssuerTokenActivity();
|
|
375
|
+
// expect(issuerOperations.transactions.length).toBeGreaterThanOrEqual(2);
|
|
376
|
+
|
|
377
|
+
// let mint_operation = 0;
|
|
378
|
+
// let transfer_operation = 0;
|
|
379
|
+
// issuerOperations.transactions.forEach((transaction) => {
|
|
380
|
+
// if (transaction.transaction?.$case === "spark") {
|
|
381
|
+
// if (transaction.transaction.spark.operationType === "ISSUER_MINT") {
|
|
382
|
+
// mint_operation++;
|
|
383
|
+
// } else if (
|
|
384
|
+
// transaction.transaction.spark.operationType === "ISSUER_TRANSFER"
|
|
385
|
+
// ) {
|
|
386
|
+
// transfer_operation++;
|
|
387
|
+
// }
|
|
388
|
+
// }
|
|
389
|
+
// });
|
|
390
|
+
// expect(mint_operation).toBeGreaterThanOrEqual(1);
|
|
391
|
+
// expect(transfer_operation).toBeGreaterThanOrEqual(1);
|
|
392
|
+
// });
|
|
393
|
+
|
|
394
|
+
it("it should mint token with 1 max supply without issue", async () => {
|
|
395
|
+
const tokenAmount: bigint = 1n;
|
|
396
|
+
const { wallet: issuerWallet } =
|
|
397
|
+
await IssuerSparkWalletTesting.initialize({
|
|
398
|
+
options: config,
|
|
399
|
+
});
|
|
336
400
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
});
|
|
401
|
+
await fundAndAnnounce(issuerWallet, 1n, 0, "MST", "MST");
|
|
402
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
340
403
|
|
|
341
|
-
|
|
342
|
-
|
|
404
|
+
const tokenBalance = await issuerWallet.getIssuerTokenBalance();
|
|
405
|
+
expect(tokenBalance.balance).toEqual(tokenAmount);
|
|
343
406
|
});
|
|
344
407
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
tokenAmount: tokenAmount / 3n,
|
|
351
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
352
|
-
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
tokenAmount: tokenAmount / 3n,
|
|
356
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
357
|
-
receiverSparkAddress: await destinationWallet2.getSparkAddress(),
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
tokenAmount: tokenAmount / 3n,
|
|
361
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
362
|
-
receiverSparkAddress: await destinationWallet3.getSparkAddress(),
|
|
363
|
-
},
|
|
364
|
-
]);
|
|
365
|
-
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
366
|
-
expect(sourceBalance).toEqual(0n);
|
|
367
|
-
|
|
368
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
369
|
-
const balanceObj = await destinationWallet.getBalance();
|
|
370
|
-
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
371
|
-
balanceObj?.tokenBalances,
|
|
372
|
-
tokenPublicKey,
|
|
373
|
-
);
|
|
374
|
-
expect(destinationBalance.balance).toEqual(tokenAmount / 3n);
|
|
375
|
-
const balanceObj2 = await destinationWallet2.getBalance();
|
|
376
|
-
const destinationBalance2 = filterTokenBalanceForTokenPublicKey(
|
|
377
|
-
balanceObj2?.tokenBalances,
|
|
378
|
-
tokenPublicKey,
|
|
379
|
-
);
|
|
380
|
-
expect(destinationBalance2.balance).toEqual(tokenAmount / 3n);
|
|
381
|
-
const balanceObj3 = await destinationWallet3.getBalance();
|
|
382
|
-
const destinationBalance3 = filterTokenBalanceForTokenPublicKey(
|
|
383
|
-
balanceObj3?.tokenBalances,
|
|
384
|
-
tokenPublicKey,
|
|
385
|
-
);
|
|
386
|
-
expect(destinationBalance3.balance).toEqual(tokenAmount / 3n);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it("should track token operations in monitoring", async () => {
|
|
390
|
-
const tokenAmount: bigint = 1000n;
|
|
391
|
-
|
|
392
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
393
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
394
|
-
});
|
|
408
|
+
it("it should be able to announce a token with name of size equal to MAX_SYMBOL_SIZE", async () => {
|
|
409
|
+
const { wallet: issuerWallet } =
|
|
410
|
+
await IssuerSparkWalletTesting.initialize({
|
|
411
|
+
options: config,
|
|
412
|
+
});
|
|
395
413
|
|
|
396
|
-
|
|
397
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
414
|
+
await fundAndAnnounce(issuerWallet, 1n, 0, "MST", "TESTAA");
|
|
398
415
|
});
|
|
399
416
|
|
|
400
|
-
|
|
417
|
+
it("it should be able to announce a token with symbol of size equal to MAX_NAME_SIZE", async () => {
|
|
418
|
+
const { wallet: issuerWallet } =
|
|
419
|
+
await IssuerSparkWalletTesting.initialize({
|
|
420
|
+
options: config,
|
|
421
|
+
});
|
|
401
422
|
|
|
402
|
-
|
|
403
|
-
await issuerWallet.transferTokens({
|
|
404
|
-
tokenAmount,
|
|
405
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
406
|
-
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
423
|
+
await fundAndAnnounce(issuerWallet, 1n, 0, "ABCDEFGHIJKLMNOPQ", "MQS");
|
|
407
424
|
});
|
|
408
|
-
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
409
|
-
expect(sourceBalance).toEqual(0n);
|
|
410
|
-
|
|
411
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
412
|
-
const balanceObj = await destinationWallet.getBalance();
|
|
413
|
-
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
414
|
-
balanceObj?.tokenBalances,
|
|
415
|
-
tokenPublicKey,
|
|
416
|
-
);
|
|
417
|
-
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
418
|
-
});
|
|
419
425
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
});
|
|
426
|
+
it("it should NOT be able to announce a token with ( symbol size + name size ) > MAX_NAME_AND_SYMBOL_SIZE", async () => {
|
|
427
|
+
const { wallet: issuerWallet } =
|
|
428
|
+
await IssuerSparkWalletTesting.initialize({
|
|
429
|
+
options: config,
|
|
430
|
+
});
|
|
426
431
|
|
|
427
|
-
|
|
428
|
-
|
|
432
|
+
await expect(
|
|
433
|
+
fundAndAnnounce(issuerWallet, 1n, 0, "ABCDEFGHIJKLMNOPQ", "TESTAB"),
|
|
434
|
+
).rejects.toThrow();
|
|
429
435
|
});
|
|
430
436
|
|
|
431
|
-
|
|
437
|
+
it("it should NOT be able to announce a token with ( symbol size + name size ) > MAX_NAME_AND_SYMBOL_SIZE, and size is calculated in bytes", async () => {
|
|
438
|
+
const { wallet: issuerWallet } =
|
|
439
|
+
await IssuerSparkWalletTesting.initialize({
|
|
440
|
+
options: config,
|
|
441
|
+
});
|
|
432
442
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
437
|
-
receiverSparkAddress: await destinationWallet.getSparkAddress(),
|
|
438
|
-
});
|
|
439
|
-
const sourceBalance = (await issuerWallet.getIssuerTokenBalance()).balance;
|
|
440
|
-
expect(sourceBalance).toEqual(0n);
|
|
441
|
-
|
|
442
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
443
|
-
const balanceObj = await destinationWallet.getBalance();
|
|
444
|
-
const destinationBalance = filterTokenBalanceForTokenPublicKey(
|
|
445
|
-
balanceObj?.tokenBalances,
|
|
446
|
-
tokenPublicKey,
|
|
447
|
-
);
|
|
448
|
-
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
449
|
-
|
|
450
|
-
const issuerOperations = await issuerWallet.getIssuerTokenActivity();
|
|
451
|
-
expect(issuerOperations.transactions.length).toBe(2);
|
|
452
|
-
const issuerOperationTx = issuerOperations.transactions[0].transaction;
|
|
453
|
-
expect(issuerOperationTx?.$case).toBe("spark");
|
|
454
|
-
let mint_operation = 0;
|
|
455
|
-
let transfer_operation = 0;
|
|
456
|
-
issuerOperations.transactions.forEach((transaction) => {
|
|
457
|
-
if (transaction.transaction?.$case === "spark") {
|
|
458
|
-
if (transaction.transaction.spark.operationType === "ISSUER_MINT") {
|
|
459
|
-
mint_operation++;
|
|
460
|
-
} else if (
|
|
461
|
-
transaction.transaction.spark.operationType === "ISSUER_TRANSFER"
|
|
462
|
-
) {
|
|
463
|
-
transfer_operation++;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
443
|
+
await expect(
|
|
444
|
+
fundAndAnnounce(issuerWallet, 1n, 0, "ABCDEFGHIJKLMNOPQ", "🥸🥸"),
|
|
445
|
+
).rejects.toThrow();
|
|
466
446
|
});
|
|
467
|
-
expect(mint_operation).toBe(1);
|
|
468
|
-
expect(transfer_operation).toBe(1);
|
|
469
|
-
});
|
|
470
447
|
|
|
471
|
-
|
|
472
|
-
|
|
448
|
+
// freeze is hardcoded to mainnet
|
|
449
|
+
brokenTestFn(
|
|
450
|
+
"should announce, mint, freeze and unfreeze tokens",
|
|
451
|
+
async () => {
|
|
452
|
+
const tokenAmount: bigint = 1000n;
|
|
453
|
+
const { wallet: issuerWallet } =
|
|
454
|
+
await IssuerSparkWalletTesting.initialize({
|
|
455
|
+
options: config,
|
|
456
|
+
});
|
|
473
457
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
});
|
|
458
|
+
await fundAndAnnounce(issuerWallet, 100000n, 0, `${name}FR`, "FRT");
|
|
459
|
+
await issuerWallet.mintTokens(tokenAmount);
|
|
477
460
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
461
|
+
// Check issuer balance after minting
|
|
462
|
+
const issuerBalanceAfterMint = (
|
|
463
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
464
|
+
).balance;
|
|
465
|
+
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
481
466
|
|
|
482
|
-
|
|
467
|
+
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
468
|
+
options: config,
|
|
469
|
+
});
|
|
470
|
+
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
483
471
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
472
|
+
await issuerWallet.transferTokens({
|
|
473
|
+
tokenAmount,
|
|
474
|
+
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
475
|
+
receiverSparkAddress: userWalletPublicKey,
|
|
476
|
+
});
|
|
477
|
+
const issuerBalanceAfterTransfer = (
|
|
478
|
+
await issuerWallet.getIssuerTokenBalance()
|
|
479
|
+
).balance;
|
|
480
|
+
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
481
|
+
|
|
482
|
+
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
483
|
+
const userBalanceObj = await userWallet.getBalance();
|
|
484
|
+
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
485
|
+
userBalanceObj?.tokenBalances,
|
|
486
|
+
tokenPublicKey,
|
|
487
|
+
);
|
|
488
|
+
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
489
|
+
|
|
490
|
+
// Freeze tokens
|
|
491
|
+
const freezeResponse =
|
|
492
|
+
await issuerWallet.freezeTokens(userWalletPublicKey);
|
|
493
|
+
expect(freezeResponse.impactedOutputIds.length).toBeGreaterThan(0);
|
|
494
|
+
expect(freezeResponse.impactedTokenAmount).toEqual(tokenAmount);
|
|
495
|
+
|
|
496
|
+
// Unfreeze tokens
|
|
497
|
+
const unfreezeResponse =
|
|
498
|
+
await issuerWallet.unfreezeTokens(userWalletPublicKey);
|
|
499
|
+
expect(unfreezeResponse.impactedOutputIds.length).toBeGreaterThan(0);
|
|
500
|
+
expect(unfreezeResponse.impactedTokenAmount).toEqual(tokenAmount);
|
|
501
|
+
},
|
|
497
502
|
);
|
|
498
|
-
expect(destinationBalance.balance).toEqual(tokenAmount);
|
|
499
|
-
});
|
|
500
503
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
504
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
505
|
-
});
|
|
504
|
+
it("should mint and burn tokens", async () => {
|
|
505
|
+
const tokenAmount: bigint = 200n;
|
|
506
506
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
507
|
+
await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
508
|
+
const issuerTokenBalance = (
|
|
509
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
510
|
+
).balance;
|
|
511
|
+
expect(issuerTokenBalance).toBeGreaterThanOrEqual(tokenAmount);
|
|
513
512
|
|
|
514
|
-
|
|
515
|
-
expect(tokenBalance.balance).toEqual(tokenAmount);
|
|
516
|
-
});
|
|
513
|
+
await sharedIssuerWallet.burnTokens(tokenAmount);
|
|
517
514
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
515
|
+
const issuerTokenBalanceAfterBurn = (
|
|
516
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
517
|
+
).balance;
|
|
518
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(
|
|
519
|
+
issuerTokenBalance - tokenAmount,
|
|
520
|
+
);
|
|
521
521
|
});
|
|
522
522
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
529
|
-
});
|
|
523
|
+
brokenTestFn(
|
|
524
|
+
"should mint and burn tokens and totalSupply has to be equal amount of token minted minus burned tokens",
|
|
525
|
+
async () => {
|
|
526
|
+
const tokenAmount_init: bigint = 2000n;
|
|
527
|
+
const tokenAmount_burn: bigint = 1000n;
|
|
530
528
|
|
|
531
|
-
|
|
532
|
-
|
|
529
|
+
const existingTotalSupply =
|
|
530
|
+
(await sharedIssuerWallet.getIssuerTokenInfo())?.totalSupply || 0n;
|
|
533
531
|
|
|
534
|
-
|
|
535
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
536
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
537
|
-
});
|
|
532
|
+
await sharedIssuerWallet.mintTokens(tokenAmount_init);
|
|
538
533
|
|
|
539
|
-
|
|
540
|
-
fundAndAnnounce(issuerWallet, 1n, 0, "ABCDEFGHIJKLMNOPQ", "TESTAB"),
|
|
541
|
-
).rejects.toThrow();
|
|
542
|
-
});
|
|
534
|
+
await sharedIssuerWallet.burnTokens(tokenAmount_burn);
|
|
543
535
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
547
|
-
});
|
|
536
|
+
const newTotalSupply =
|
|
537
|
+
(await sharedIssuerWallet.getIssuerTokenInfo())?.totalSupply || 0n;
|
|
548
538
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
539
|
+
expect(newTotalSupply).toEqual(
|
|
540
|
+
existingTotalSupply + tokenAmount_init - tokenAmount_burn,
|
|
541
|
+
);
|
|
542
|
+
},
|
|
543
|
+
);
|
|
553
544
|
|
|
554
|
-
|
|
555
|
-
brokenTestFn(
|
|
556
|
-
"should announce, mint, freeze and unfreeze tokens with ECDSA",
|
|
557
|
-
async () => {
|
|
545
|
+
it("should complete full token lifecycle: announce, mint, transfer, return, burn", async () => {
|
|
558
546
|
const tokenAmount: bigint = 1000n;
|
|
559
|
-
const { wallet: issuerWallet } =
|
|
560
|
-
await IssuerSparkWalletTesting.initialize({
|
|
561
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSAFreeze", "EFT");
|
|
565
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
566
|
-
|
|
567
|
-
// Check issuer balance after minting
|
|
568
|
-
const issuerBalanceAfterMint = (
|
|
569
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
570
|
-
).balance;
|
|
571
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
572
547
|
|
|
573
548
|
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
574
|
-
options:
|
|
575
|
-
});
|
|
576
|
-
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
577
|
-
|
|
578
|
-
await issuerWallet.transferTokens({
|
|
579
|
-
tokenAmount,
|
|
580
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
581
|
-
receiverSparkAddress: userWalletPublicKey,
|
|
549
|
+
options: config,
|
|
582
550
|
});
|
|
583
|
-
const issuerBalanceAfterTransfer = (
|
|
584
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
585
|
-
).balance;
|
|
586
|
-
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
587
|
-
|
|
588
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
589
|
-
const userBalanceObj = await userWallet.getBalance();
|
|
590
|
-
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
591
|
-
userBalanceObj?.tokenBalances,
|
|
592
|
-
tokenPublicKey,
|
|
593
|
-
);
|
|
594
|
-
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
595
|
-
// Freeze tokens
|
|
596
|
-
const freezeResponse =
|
|
597
|
-
await issuerWallet.freezeTokens(userWalletPublicKey);
|
|
598
|
-
expect(freezeResponse.impactedOutputIds.length).toBeGreaterThan(0);
|
|
599
|
-
expect(freezeResponse.impactedTokenAmount).toEqual(tokenAmount);
|
|
600
|
-
|
|
601
|
-
// Unfreeze tokens
|
|
602
|
-
const unfreezeResponse =
|
|
603
|
-
await issuerWallet.unfreezeTokens(userWalletPublicKey);
|
|
604
|
-
expect(unfreezeResponse.impactedOutputIds.length).toBeGreaterThan(0);
|
|
605
|
-
expect(unfreezeResponse.impactedTokenAmount).toEqual(tokenAmount);
|
|
606
|
-
},
|
|
607
|
-
);
|
|
608
|
-
|
|
609
|
-
// freeze is hardcoded to mainnet
|
|
610
|
-
brokenTestFn(
|
|
611
|
-
"should announce, mint, freeze and unfreeze tokens with Schnorr",
|
|
612
|
-
async () => {
|
|
613
|
-
const tokenAmount: bigint = 1000n;
|
|
614
|
-
const { wallet: issuerWallet } =
|
|
615
|
-
await IssuerSparkWalletTesting.initialize({
|
|
616
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
617
|
-
});
|
|
618
551
|
|
|
619
|
-
|
|
552
|
+
const initialBalance = (await sharedIssuerWallet.getIssuerTokenBalance())
|
|
553
|
+
.balance;
|
|
620
554
|
|
|
621
|
-
await
|
|
555
|
+
await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
622
556
|
|
|
623
|
-
// Check issuer balance after minting
|
|
624
557
|
const issuerBalanceAfterMint = (
|
|
625
|
-
await
|
|
558
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
626
559
|
).balance;
|
|
627
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
560
|
+
expect(issuerBalanceAfterMint).toEqual(initialBalance + tokenAmount);
|
|
628
561
|
|
|
629
|
-
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
630
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
631
|
-
});
|
|
632
562
|
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
633
563
|
|
|
634
|
-
await
|
|
564
|
+
await sharedIssuerWallet.transferTokens({
|
|
635
565
|
tokenAmount,
|
|
636
|
-
tokenPublicKey:
|
|
566
|
+
tokenPublicKey: sharedTokenPublicKey,
|
|
637
567
|
receiverSparkAddress: userWalletPublicKey,
|
|
638
568
|
});
|
|
639
569
|
|
|
640
570
|
const issuerBalanceAfterTransfer = (
|
|
641
|
-
await
|
|
571
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
642
572
|
).balance;
|
|
643
|
-
expect(issuerBalanceAfterTransfer).toEqual(
|
|
573
|
+
expect(issuerBalanceAfterTransfer).toEqual(initialBalance);
|
|
644
574
|
|
|
645
|
-
const tokenPublicKey = await issuerWallet.getIdentityPublicKey();
|
|
646
575
|
const userBalanceObj = await userWallet.getBalance();
|
|
647
576
|
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
648
577
|
userBalanceObj?.tokenBalances,
|
|
649
|
-
|
|
578
|
+
sharedTokenPublicKey,
|
|
650
579
|
);
|
|
651
580
|
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
652
581
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
await issuerWallet.unfreezeTokens(userWalletPublicKey);
|
|
659
|
-
expect(unfreezeResult.impactedOutputIds.length).toBe(1);
|
|
660
|
-
expect(unfreezeResult.impactedTokenAmount).toBe(1000n);
|
|
661
|
-
},
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
it("should announce, mint, and burn tokens with ECDSA", async () => {
|
|
665
|
-
const tokenAmount: bigint = 200n;
|
|
666
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
667
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSABurn", "EBT");
|
|
671
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
672
|
-
|
|
673
|
-
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
674
|
-
.balance;
|
|
675
|
-
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
676
|
-
|
|
677
|
-
await issuerWallet.burnTokens(tokenAmount);
|
|
678
|
-
|
|
679
|
-
const issuerTokenBalanceAfterBurn = (
|
|
680
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
681
|
-
).balance;
|
|
682
|
-
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
it("should announce, mint, and burn tokens with ECDSA and totalSupply has to be equal amount of token minted minus burned tokens", async () => {
|
|
686
|
-
const tokenAmount_init: bigint = 2000n;
|
|
687
|
-
const tokenAmount_burn: bigint = 1000n;
|
|
688
|
-
|
|
689
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
690
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSATotalSupply", "ETS");
|
|
694
|
-
await issuerWallet.mintTokens(tokenAmount_init);
|
|
695
|
-
|
|
696
|
-
await issuerWallet.burnTokens(tokenAmount_burn);
|
|
697
|
-
|
|
698
|
-
const smth_with_total_supply = await issuerWallet.getIssuerTokenInfo();
|
|
699
|
-
|
|
700
|
-
expect(smth_with_total_supply?.totalSupply).toEqual(
|
|
701
|
-
tokenAmount_init - tokenAmount_burn,
|
|
702
|
-
);
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
it("should announce, mint, and burn tokens with Schnorr", async () => {
|
|
706
|
-
const tokenAmount: bigint = 200n;
|
|
707
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
708
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "SchnorrBurn", "SBT");
|
|
712
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
713
|
-
|
|
714
|
-
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
715
|
-
.balance;
|
|
716
|
-
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
717
|
-
|
|
718
|
-
await issuerWallet.burnTokens(tokenAmount);
|
|
719
|
-
|
|
720
|
-
const issuerTokenBalanceAfterBurn = (
|
|
721
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
722
|
-
).balance;
|
|
723
|
-
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
it("should complete full token lifecycle with ECDSA: announce, mint, transfer, return, burn", async () => {
|
|
727
|
-
const tokenAmount: bigint = 1000n;
|
|
728
|
-
|
|
729
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
730
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
734
|
-
options: LOCAL_WALLET_CONFIG_ECDSA,
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSAFullCycle", "EFCT");
|
|
738
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
739
|
-
|
|
740
|
-
const issuerBalanceAfterMint = (await issuerWallet.getIssuerTokenBalance())
|
|
741
|
-
.balance;
|
|
742
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
743
|
-
|
|
744
|
-
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
745
|
-
|
|
746
|
-
await issuerWallet.transferTokens({
|
|
747
|
-
tokenAmount,
|
|
748
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
749
|
-
receiverSparkAddress: userWalletPublicKey,
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
const issuerBalanceAfterTransfer = (
|
|
753
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
754
|
-
).balance;
|
|
755
|
-
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
756
|
-
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
757
|
-
const userWalletPublicKeyHex = await userWallet.getSparkAddress();
|
|
758
|
-
const userBalanceObj = await userWallet.getBalance();
|
|
759
|
-
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
760
|
-
userBalanceObj?.tokenBalances,
|
|
761
|
-
tokenPublicKeyHex,
|
|
762
|
-
);
|
|
763
|
-
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
764
|
-
await userWallet.transferTokens({
|
|
765
|
-
tokenPublicKey: tokenPublicKeyHex,
|
|
766
|
-
tokenAmount,
|
|
767
|
-
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
768
|
-
});
|
|
769
|
-
|
|
770
|
-
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
771
|
-
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
772
|
-
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
773
|
-
tokenPublicKeyHex,
|
|
774
|
-
);
|
|
775
|
-
|
|
776
|
-
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
777
|
-
|
|
778
|
-
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
779
|
-
.balance;
|
|
780
|
-
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
781
|
-
await issuerWallet.burnTokens(tokenAmount);
|
|
782
|
-
const issuerTokenBalanceAfterBurn = (
|
|
783
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
784
|
-
).balance;
|
|
785
|
-
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
786
|
-
});
|
|
787
|
-
|
|
788
|
-
it("should complete full token lifecycle with Schnorr: announce, mint, transfer, return, burn", async () => {
|
|
789
|
-
const tokenAmount: bigint = 1000n;
|
|
790
|
-
|
|
791
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
792
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
793
|
-
});
|
|
794
|
-
|
|
795
|
-
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
796
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
797
|
-
});
|
|
798
|
-
|
|
799
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "SchnorrFullCycle", "SFCT");
|
|
800
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
801
|
-
|
|
802
|
-
const issuerBalanceAfterMint = (await issuerWallet.getIssuerTokenBalance())
|
|
803
|
-
.balance;
|
|
804
|
-
expect(issuerBalanceAfterMint).toEqual(tokenAmount);
|
|
805
|
-
|
|
806
|
-
const userWalletPublicKey = await userWallet.getSparkAddress();
|
|
807
|
-
|
|
808
|
-
await issuerWallet.transferTokens({
|
|
809
|
-
tokenAmount,
|
|
810
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
811
|
-
receiverSparkAddress: userWalletPublicKey,
|
|
812
|
-
});
|
|
813
|
-
|
|
814
|
-
const issuerBalanceAfterTransfer = (
|
|
815
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
816
|
-
).balance;
|
|
817
|
-
expect(issuerBalanceAfterTransfer).toEqual(0n);
|
|
818
|
-
|
|
819
|
-
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
820
|
-
const userBalanceObj = await userWallet.getBalance();
|
|
821
|
-
const userBalanceAfterTransfer = filterTokenBalanceForTokenPublicKey(
|
|
822
|
-
userBalanceObj?.tokenBalances,
|
|
823
|
-
tokenPublicKeyHex,
|
|
824
|
-
);
|
|
825
|
-
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
826
|
-
|
|
827
|
-
await userWallet.transferTokens({
|
|
828
|
-
tokenPublicKey: tokenPublicKeyHex,
|
|
829
|
-
tokenAmount,
|
|
830
|
-
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
834
|
-
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
835
|
-
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
836
|
-
tokenPublicKeyHex,
|
|
837
|
-
);
|
|
838
|
-
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
839
|
-
|
|
840
|
-
const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
|
|
841
|
-
.balance;
|
|
842
|
-
expect(issuerTokenBalance).toEqual(tokenAmount);
|
|
843
|
-
|
|
844
|
-
await issuerWallet.burnTokens(tokenAmount);
|
|
845
|
-
|
|
846
|
-
const issuerTokenBalanceAfterBurn = (
|
|
847
|
-
await issuerWallet.getIssuerTokenBalance()
|
|
848
|
-
).balance;
|
|
849
|
-
expect(issuerTokenBalanceAfterBurn).toEqual(0n);
|
|
850
|
-
});
|
|
851
|
-
it("should correctly assign operation types for complete token lifecycle operations", async () => {
|
|
852
|
-
const { wallet: issuerWallet } = await IssuerSparkWalletTesting.initialize({
|
|
853
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
854
|
-
});
|
|
855
|
-
|
|
856
|
-
const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
857
|
-
options: LOCAL_WALLET_CONFIG_SCHNORR,
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
const tokenAmount = 1000n;
|
|
861
|
-
|
|
862
|
-
await fundAndAnnounce(issuerWallet, 100000n, 0, "OperationTypeTest", "OTT");
|
|
863
|
-
await issuerWallet.mintTokens(tokenAmount);
|
|
864
|
-
|
|
865
|
-
await issuerWallet.transferTokens({
|
|
866
|
-
tokenAmount: 500n,
|
|
867
|
-
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
868
|
-
receiverSparkAddress: await userWallet.getSparkAddress(),
|
|
869
|
-
});
|
|
870
|
-
|
|
871
|
-
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
872
|
-
|
|
873
|
-
await userWallet.transferTokens({
|
|
874
|
-
tokenPublicKey: tokenPublicKeyHex,
|
|
875
|
-
tokenAmount: 250n,
|
|
876
|
-
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
// as in userWallet we didn't have burnTokens method, we need to transfer tokens to burn address manually
|
|
880
|
-
const BURN_ADDRESS = "02".repeat(33);
|
|
881
|
-
const burnAddress = encodeSparkAddress({
|
|
882
|
-
identityPublicKey: BURN_ADDRESS,
|
|
883
|
-
network: "LOCAL",
|
|
884
|
-
});
|
|
885
|
-
|
|
886
|
-
await userWallet.transferTokens({
|
|
887
|
-
tokenPublicKey: tokenPublicKeyHex,
|
|
888
|
-
tokenAmount: 250n,
|
|
889
|
-
receiverSparkAddress: burnAddress,
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
await issuerWallet.burnTokens(250n);
|
|
893
|
-
|
|
894
|
-
const activity = await issuerWallet.getIssuerTokenActivity();
|
|
895
|
-
|
|
896
|
-
const mintTransaction = activity.transactions.find(
|
|
897
|
-
(tx) =>
|
|
898
|
-
tx.transaction?.$case === "spark" &&
|
|
899
|
-
tx.transaction.spark.operationType === "ISSUER_MINT",
|
|
900
|
-
);
|
|
582
|
+
await userWallet.transferTokens({
|
|
583
|
+
tokenPublicKey: sharedTokenPublicKey,
|
|
584
|
+
tokenAmount,
|
|
585
|
+
receiverSparkAddress: await sharedIssuerWallet.getSparkAddress(),
|
|
586
|
+
});
|
|
901
587
|
|
|
902
|
-
|
|
903
|
-
(
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
588
|
+
const userBalanceObjAfterTransferBack = await userWallet.getBalance();
|
|
589
|
+
const userBalanceAfterTransferBack = filterTokenBalanceForTokenPublicKey(
|
|
590
|
+
userBalanceObjAfterTransferBack?.tokenBalances,
|
|
591
|
+
sharedTokenPublicKey,
|
|
592
|
+
);
|
|
907
593
|
|
|
908
|
-
|
|
909
|
-
(tx) =>
|
|
910
|
-
tx.transaction?.$case === "spark" &&
|
|
911
|
-
tx.transaction.spark.operationType === "ISSUER_BURN",
|
|
912
|
-
);
|
|
594
|
+
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
913
595
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
);
|
|
596
|
+
const issuerTokenBalance = (
|
|
597
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
598
|
+
).balance;
|
|
599
|
+
expect(issuerTokenBalance).toEqual(initialBalance + tokenAmount);
|
|
919
600
|
|
|
920
|
-
|
|
921
|
-
(tx) =>
|
|
922
|
-
tx.transaction?.$case === "spark" &&
|
|
923
|
-
tx.transaction.spark.operationType === "USER_BURN",
|
|
924
|
-
);
|
|
601
|
+
await sharedIssuerWallet.burnTokens(tokenAmount);
|
|
925
602
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
603
|
+
const issuerTokenBalanceAfterBurn = (
|
|
604
|
+
await sharedIssuerWallet.getIssuerTokenBalance()
|
|
605
|
+
).balance;
|
|
606
|
+
expect(issuerTokenBalanceAfterBurn).toEqual(initialBalance);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
// it("should correctly assign operation types for complete token lifecycle operations", async () => {
|
|
610
|
+
// const { wallet: userWallet } = await SparkWalletTesting.initialize({
|
|
611
|
+
// options: config,
|
|
612
|
+
// });
|
|
613
|
+
|
|
614
|
+
// const tokenAmount = 1000n;
|
|
615
|
+
|
|
616
|
+
// await sharedIssuerWallet.mintTokens(tokenAmount);
|
|
617
|
+
|
|
618
|
+
// await sharedIssuerWallet.transferTokens({
|
|
619
|
+
// tokenAmount: 500n,
|
|
620
|
+
// tokenPublicKey: sharedTokenPublicKey,
|
|
621
|
+
// receiverSparkAddress: await userWallet.getSparkAddress(),
|
|
622
|
+
// });
|
|
623
|
+
|
|
624
|
+
// await userWallet.transferTokens({
|
|
625
|
+
// tokenPublicKey: sharedTokenPublicKey,
|
|
626
|
+
// tokenAmount: 250n,
|
|
627
|
+
// receiverSparkAddress: await sharedIssuerWallet.getSparkAddress(),
|
|
628
|
+
// });
|
|
629
|
+
|
|
630
|
+
// // as in userWallet we didn't have burnTokens method, we need to transfer tokens to burn address manually
|
|
631
|
+
// const BURN_ADDRESS = "02".repeat(33);
|
|
632
|
+
// const burnAddress = encodeSparkAddress({
|
|
633
|
+
// identityPublicKey: BURN_ADDRESS,
|
|
634
|
+
// network: "LOCAL",
|
|
635
|
+
// });
|
|
636
|
+
|
|
637
|
+
// await userWallet.transferTokens({
|
|
638
|
+
// tokenPublicKey: sharedTokenPublicKey,
|
|
639
|
+
// tokenAmount: 250n,
|
|
640
|
+
// receiverSparkAddress: burnAddress,
|
|
641
|
+
// });
|
|
642
|
+
|
|
643
|
+
// await sharedIssuerWallet.burnTokens(250n);
|
|
644
|
+
|
|
645
|
+
// const activity = await sharedIssuerWallet.getIssuerTokenActivity();
|
|
646
|
+
|
|
647
|
+
// const mintTransaction = activity.transactions.find(
|
|
648
|
+
// (tx) =>
|
|
649
|
+
// tx.transaction?.$case === "spark" &&
|
|
650
|
+
// tx.transaction.spark.operationType === "ISSUER_MINT",
|
|
651
|
+
// );
|
|
652
|
+
|
|
653
|
+
// const transferTransaction = activity.transactions.find(
|
|
654
|
+
// (tx) =>
|
|
655
|
+
// tx.transaction?.$case === "spark" &&
|
|
656
|
+
// tx.transaction.spark.operationType === "ISSUER_TRANSFER",
|
|
657
|
+
// );
|
|
658
|
+
|
|
659
|
+
// const burnTransaction = activity.transactions.find(
|
|
660
|
+
// (tx) =>
|
|
661
|
+
// tx.transaction?.$case === "spark" &&
|
|
662
|
+
// tx.transaction.spark.operationType === "ISSUER_BURN",
|
|
663
|
+
// );
|
|
664
|
+
|
|
665
|
+
// const transferBackTransaction = activity.transactions.find(
|
|
666
|
+
// (tx) =>
|
|
667
|
+
// tx.transaction?.$case === "spark" &&
|
|
668
|
+
// tx.transaction.spark.operationType === "USER_TRANSFER",
|
|
669
|
+
// );
|
|
670
|
+
|
|
671
|
+
// const userBurnTransaction = activity.transactions.find(
|
|
672
|
+
// (tx) =>
|
|
673
|
+
// tx.transaction?.$case === "spark" &&
|
|
674
|
+
// tx.transaction.spark.operationType === "USER_BURN",
|
|
675
|
+
// );
|
|
676
|
+
|
|
677
|
+
// expect(mintTransaction).toBeDefined();
|
|
678
|
+
// expect(transferTransaction).toBeDefined();
|
|
679
|
+
// expect(burnTransaction).toBeDefined();
|
|
680
|
+
// expect(transferBackTransaction).toBeDefined();
|
|
681
|
+
// expect(userBurnTransaction).toBeDefined();
|
|
682
|
+
// });
|
|
683
|
+
},
|
|
684
|
+
);
|
|
933
685
|
|
|
934
686
|
async function fundAndAnnounce(
|
|
935
687
|
wallet: IssuerSparkWallet,
|