@buildonspark/spark-sdk 0.2.5 → 0.2.6

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/chunk-AVI5E5VT.js +66 -0
  3. package/dist/{chunk-U7LRIWTF.js → chunk-GUZ3WCB4.js} +313 -143
  4. package/dist/{client-C88GCTPB.d.cts → client-CusuvuCe.d.cts} +2 -2
  5. package/dist/{client-Dg6vS_2I.d.ts → client-Dn4Ld8pD.d.ts} +2 -2
  6. package/dist/debug.cjs +452 -286
  7. package/dist/debug.d.cts +8 -6
  8. package/dist/debug.d.ts +8 -6
  9. package/dist/debug.js +1 -1
  10. package/dist/graphql/objects/index.d.cts +3 -3
  11. package/dist/graphql/objects/index.d.ts +3 -3
  12. package/dist/index.cjs +526 -303
  13. package/dist/index.d.cts +19 -187
  14. package/dist/index.d.ts +19 -187
  15. package/dist/index.js +11 -6
  16. package/dist/index.node.cjs +451 -328
  17. package/dist/index.node.d.cts +7 -6
  18. package/dist/index.node.d.ts +7 -6
  19. package/dist/index.node.js +55 -98
  20. package/dist/native/index.cjs +468 -301
  21. package/dist/native/index.d.cts +37 -18
  22. package/dist/native/index.d.ts +37 -18
  23. package/dist/native/index.js +317 -148
  24. package/dist/proto/lrc20.d.cts +1 -1
  25. package/dist/proto/lrc20.d.ts +1 -1
  26. package/dist/proto/spark.d.cts +1 -1
  27. package/dist/proto/spark.d.ts +1 -1
  28. package/dist/proto/spark_token.d.cts +1 -1
  29. package/dist/proto/spark_token.d.ts +1 -1
  30. package/dist/{spark-ESAfZARg.d.cts → spark-Cj4brrP5.d.cts} +1 -1
  31. package/dist/{spark-ESAfZARg.d.ts → spark-Cj4brrP5.d.ts} +1 -1
  32. package/dist/{spark-wallet-B2WwKN8W.d.ts → spark-wallet-B6YthxDI.d.ts} +36 -17
  33. package/dist/{spark-wallet-Di65w0Us.d.cts → spark-wallet-BbOf2P2l.d.cts} +36 -17
  34. package/dist/spark-wallet.node-BBk1sGS2.d.cts +12 -0
  35. package/dist/spark-wallet.node-Bffethig.d.ts +12 -0
  36. package/dist/tests/test-utils.cjs +78 -50
  37. package/dist/tests/test-utils.d.cts +24 -23
  38. package/dist/tests/test-utils.d.ts +24 -23
  39. package/dist/tests/test-utils.js +2 -2
  40. package/dist/token-transactions-0_5XMWjs.d.ts +184 -0
  41. package/dist/token-transactions-CD-Adb5y.d.cts +184 -0
  42. package/dist/types/index.d.cts +2 -2
  43. package/dist/types/index.d.ts +2 -2
  44. package/dist/{xchain-address-CqRu3F21.d.cts → xchain-address-BnKZ0-dY.d.cts} +5 -5
  45. package/dist/{xchain-address-BsveIy5l.d.ts → xchain-address-Di3lu4Wy.d.ts} +5 -5
  46. package/package.json +7 -2
  47. package/src/index.node.ts +5 -1
  48. package/src/index.ts +4 -1
  49. package/src/services/config.ts +13 -2
  50. package/src/services/token-transactions.ts +22 -8
  51. package/src/services/wallet-config.ts +22 -13
  52. package/src/spark-wallet/spark-wallet.browser.ts +72 -0
  53. package/src/spark-wallet/spark-wallet.node.ts +60 -118
  54. package/src/spark-wallet/spark-wallet.ts +273 -146
  55. package/src/tests/integration/ssp/coop-exit-validation.test.ts +233 -0
  56. package/src/tests/integration/ssp/coop-exit.test.ts +112 -93
  57. package/src/tests/integration/ssp/static-deposit-validation.test.ts +145 -0
  58. package/src/tests/integration/ssp/static_deposit.test.ts +439 -132
  59. package/src/tests/integration/ssp/transfers.test.ts +7 -2
  60. package/src/tests/integration/static_deposit.test.ts +92 -0
  61. package/src/tests/integration/transfer.test.ts +1 -1
  62. package/src/tests/utils/regtest-test-faucet.ts +8 -0
  63. package/src/tests/utils/spark-testing-wallet.ts +42 -0
  64. package/src/tests/utils/test-faucet.ts +6 -2
  65. package/src/utils/token-identifier.ts +47 -4
  66. package/src/utils/token-transactions.ts +13 -9
  67. package/dist/chunk-LQZL2D3Y.js +0 -7
  68. package/dist/spark-wallet.node-7R0Rxyj9.d.cts +0 -13
  69. package/dist/spark-wallet.node-CSPWOWRu.d.ts +0 -13
@@ -1,175 +1,482 @@
1
- import { describe, expect, it } from "@jest/globals";
2
- import { SparkWalletTesting } from "../../utils/spark-testing-wallet.js";
1
+ import {
2
+ SparkWalletTesting,
3
+ initWallet,
4
+ } from "../../utils/spark-testing-wallet.js";
5
+ import { bytesToHex } from "@noble/hashes/utils";
3
6
  import { BitcoinFaucet } from "../../utils/test-faucet.js";
7
+ import { ValidationError } from "../../../errors/types.js";
4
8
 
5
- const DEPOSIT_AMOUNT = 10000n;
9
+ const SMALL_DEPOSIT_AMOUNT = 10n;
10
+ export const DEPOSIT_AMOUNT = 10000n;
6
11
  const SECOND_DEPOSIT_AMOUNT = 20000n;
7
12
  const THIRD_DEPOSIT_AMOUNT = 30000n;
8
13
 
9
14
  describe("SSP static deposit address integration", () => {
10
- it("should claim deposits to a static deposit address", async () => {
11
- const faucet = BitcoinFaucet.getInstance();
15
+ describe("Happy path testing", () => {
16
+ it("should claim deposits to a static deposit address", async () => {
17
+ const faucet = BitcoinFaucet.getInstance();
18
+ const { wallet: userWallet } = await SparkWalletTesting.initialize(
19
+ {
20
+ options: {
21
+ network: "LOCAL",
22
+ },
23
+ },
24
+ false,
25
+ );
26
+
27
+ const depositAddress = await userWallet.getStaticDepositAddress();
28
+ expect(depositAddress).toBeDefined();
29
+ const signedTx = await faucet.sendToAddress(
30
+ depositAddress,
31
+ DEPOSIT_AMOUNT,
32
+ );
33
+
34
+ // Wait for the transaction to be mined
35
+ await faucet.mineBlocks(6);
36
+ expect(signedTx).toBeDefined();
37
+ const transactionId = signedTx.id;
38
+ let vout;
39
+ for (let i = 0; i < signedTx.outputsLength; i++) {
40
+ const output = signedTx.getOutput(i);
41
+ if (output.amount === DEPOSIT_AMOUNT) {
42
+ vout = i;
43
+ break;
44
+ }
45
+ }
12
46
 
13
- const { wallet: userWallet } = await SparkWalletTesting.initialize(
14
- {
15
- options: {
16
- network: "LOCAL",
47
+ const quote = await userWallet.getClaimStaticDepositQuote(
48
+ transactionId,
49
+ vout!,
50
+ );
51
+
52
+ await new Promise((resolve) => setTimeout(resolve, 1000));
53
+
54
+ const quoteAmount = quote!.creditAmountSats;
55
+ const sspSignature = quote!.signature;
56
+
57
+ await userWallet.claimStaticDeposit({
58
+ transactionId,
59
+ creditAmountSats: quoteAmount,
60
+ sspSignature,
61
+ outputIndex: vout!,
62
+ });
63
+ await new Promise((resolve) => setTimeout(resolve, 1000));
64
+ const { balance } = await userWallet.getBalance();
65
+ expect(balance).toBe(BigInt(quoteAmount));
66
+
67
+ // Test depositing money to the same address and second time and claiming.
68
+ const signedTx2 = await faucet.sendToAddress(
69
+ depositAddress,
70
+ SECOND_DEPOSIT_AMOUNT,
71
+ );
72
+ const transactionId2 = signedTx2.id;
73
+ // Wait for the transaction to be mined
74
+ await faucet.mineBlocks(6);
75
+ // Test claiming and getting the quote without passing in the output index.
76
+ const quote2 =
77
+ await userWallet.getClaimStaticDepositQuote(transactionId2);
78
+ const quoteAmount2 = quote2!.creditAmountSats;
79
+ const sspSignature2 = quote2!.signature;
80
+ await userWallet.claimStaticDeposit({
81
+ transactionId: transactionId2,
82
+ creditAmountSats: quoteAmount2,
83
+ sspSignature: sspSignature2,
84
+ });
85
+ await new Promise((resolve) => setTimeout(resolve, 1000));
86
+ const { balance: balance2 } = await userWallet.getBalance();
87
+ expect(balance2).toBe(BigInt(quoteAmount + quoteAmount2));
88
+
89
+ // Test depositing money to the same address and test claim with max fee flow.
90
+ const signedTx3 = await faucet.sendToAddress(
91
+ depositAddress,
92
+ THIRD_DEPOSIT_AMOUNT,
93
+ );
94
+ const transactionId3 = signedTx3.id;
95
+ // Wait for the transaction to be mined
96
+ await faucet.mineBlocks(6);
97
+ // Get quote so we can calculate the expected balance. Not needed for actual flow.
98
+ const quote3 =
99
+ await userWallet.getClaimStaticDepositQuote(transactionId3);
100
+ const quoteAmount3 = quote3!.creditAmountSats;
101
+ await userWallet.claimStaticDepositWithMaxFee({
102
+ transactionId: transactionId3,
103
+ maxFee: 1000,
104
+ });
105
+ await new Promise((resolve) => setTimeout(resolve, 1000));
106
+ const { balance: balance3 } = await userWallet.getBalance();
107
+ expect(balance3).toBe(BigInt(quoteAmount + quoteAmount2 + quoteAmount3));
108
+ // Get transfers should include static deposit transfers.
109
+ const transfers = await userWallet.getTransfers();
110
+ expect(transfers.transfers.length).toBe(3);
111
+ }, 60000);
112
+
113
+ it("should create a refund transaction", async () => {
114
+ const faucet = BitcoinFaucet.getInstance();
115
+
116
+ const { wallet: userWallet } = await SparkWalletTesting.initialize(
117
+ {
118
+ options: {
119
+ network: "LOCAL",
120
+ },
17
121
  },
18
- },
19
- false,
20
- );
122
+ false,
123
+ );
21
124
 
22
- const depositAddress = await userWallet.getStaticDepositAddress();
23
- expect(depositAddress).toBeDefined();
125
+ const depositAddress = await userWallet.getStaticDepositAddress();
126
+ expect(depositAddress).toBeDefined();
24
127
 
25
- const signedTx = await faucet.sendToAddress(depositAddress, DEPOSIT_AMOUNT);
128
+ const signedTx = await faucet.sendToAddress(
129
+ depositAddress,
130
+ DEPOSIT_AMOUNT,
131
+ );
26
132
 
27
- // Wait for the transaction to be mined
28
- await faucet.mineBlocks(6);
133
+ // Wait for the transaction to be mined
134
+ await faucet.mineBlocks(6);
29
135
 
30
- expect(signedTx).toBeDefined();
136
+ expect(signedTx).toBeDefined();
31
137
 
32
- const transactionId = signedTx.id;
138
+ const transactionId = signedTx.id;
33
139
 
34
- let vout;
140
+ let vout: number | undefined;
35
141
 
36
- for (let i = 0; i < signedTx.outputsLength; i++) {
37
- const output = signedTx.getOutput(i);
38
- if (output.amount === DEPOSIT_AMOUNT) {
39
- vout = i;
40
- break;
142
+ for (let i = 0; i < signedTx.outputsLength; i++) {
143
+ const output = signedTx.getOutput(i);
144
+ if (output.amount === DEPOSIT_AMOUNT) {
145
+ vout = i;
146
+ break;
147
+ }
41
148
  }
42
- }
43
-
44
- const quote = await userWallet.getClaimStaticDepositQuote(
45
- transactionId,
46
- vout!,
47
- );
48
-
49
- const quoteAmount = quote!.creditAmountSats;
50
- const sspSignature = quote!.signature;
51
-
52
- await userWallet.claimStaticDeposit({
53
- transactionId,
54
- creditAmountSats: quoteAmount,
55
- sspSignature,
56
- outputIndex: vout!,
57
- });
58
149
 
59
- await new Promise((resolve) => setTimeout(resolve, 1000));
150
+ const refundAddress = await faucet.getNewAddress();
151
+
152
+ const refundTx = await userWallet.refundStaticDeposit({
153
+ depositTransactionId: transactionId,
154
+ destinationAddress: refundAddress,
155
+ satsPerVbyteFee: 2,
156
+ });
157
+
158
+ expect(refundTx).toBeDefined();
159
+
160
+ // Calling it again should create a new transaction.
161
+ const refundTx2 = await userWallet.refundStaticDeposit({
162
+ depositTransactionId: transactionId,
163
+ destinationAddress: refundAddress,
164
+ outputIndex: vout!,
165
+ satsPerVbyteFee: 2,
166
+ });
167
+
168
+ expect(refundTx2).toBeDefined();
169
+
170
+ expect(refundTx).not.toBe(refundTx2);
171
+ }, 60000);
172
+ });
173
+
174
+ describe("Quote unhappy path testing", () => {
175
+ it("should error claim quote from a different wallet", async () => {
176
+ const { wallet: aliceWallet } = await SparkWalletTesting.initialize(
177
+ {
178
+ options: {
179
+ network: "LOCAL",
180
+ },
181
+ },
182
+ false,
183
+ );
184
+
185
+ const { wallet: bobWallet } = await SparkWalletTesting.initialize(
186
+ {
187
+ options: {
188
+ network: "LOCAL",
189
+ },
190
+ },
191
+ false,
192
+ );
60
193
 
61
- const { balance } = await userWallet.getBalance();
62
- expect(balance).toBe(BigInt(quoteAmount));
194
+ const faucet = BitcoinFaucet.getInstance();
63
195
 
64
- // Test depositing money to the same address and second time and claiming.
65
- const signedTx2 = await faucet.sendToAddress(
66
- depositAddress,
67
- SECOND_DEPOSIT_AMOUNT,
68
- );
69
- const transactionId2 = signedTx2.id;
70
- // Wait for the transaction to be mined
71
- await faucet.mineBlocks(6);
196
+ const depositAddress = await aliceWallet.getStaticDepositAddress();
197
+ expect(depositAddress).toBeDefined();
72
198
 
73
- // Test claiming and getting the quote without passing in the output index.
74
- const quote2 = await userWallet.getClaimStaticDepositQuote(transactionId2);
199
+ const signedTx = await faucet.sendToAddress(
200
+ depositAddress,
201
+ DEPOSIT_AMOUNT,
202
+ );
75
203
 
76
- const quoteAmount2 = quote2!.creditAmountSats;
77
- const sspSignature2 = quote2!.signature;
204
+ // Wait for the transaction to be mined
205
+ await faucet.mineBlocks(6);
78
206
 
79
- await userWallet.claimStaticDeposit({
80
- transactionId: transactionId2,
81
- creditAmountSats: quoteAmount2,
82
- sspSignature: sspSignature2,
83
- });
207
+ expect(signedTx).toBeDefined();
84
208
 
85
- await new Promise((resolve) => setTimeout(resolve, 1000));
209
+ const transactionId = signedTx.id;
86
210
 
87
- const { balance: balance2 } = await userWallet.getBalance();
88
- expect(balance2).toBe(BigInt(quoteAmount + quoteAmount2));
211
+ await expect(
212
+ bobWallet.getClaimStaticDepositQuote(transactionId),
213
+ ).rejects.toThrow();
214
+ }, 60000);
89
215
 
90
- // Test depositing money to the same address and test claim with max fee flow.
91
- const signedTx3 = await faucet.sendToAddress(
92
- depositAddress,
93
- THIRD_DEPOSIT_AMOUNT,
94
- );
95
- const transactionId3 = signedTx3.id;
96
- // Wait for the transaction to be mined
97
- await faucet.mineBlocks(6);
216
+ it("should error if txid does not exist", async () => {
217
+ const { wallet: aliceWallet } = await SparkWalletTesting.initialize(
218
+ {
219
+ options: {
220
+ network: "LOCAL",
221
+ },
222
+ },
223
+ false,
224
+ );
98
225
 
99
- // Get quote so we can calculate the expected balance. Not needed for actual flow.
100
- const quote3 = await userWallet.getClaimStaticDepositQuote(transactionId3);
226
+ const faucet = BitcoinFaucet.getInstance();
101
227
 
102
- const quoteAmount3 = quote3!.creditAmountSats;
228
+ const depositAddress = await aliceWallet.getStaticDepositAddress();
229
+ expect(depositAddress).toBeDefined();
103
230
 
104
- await userWallet.claimStaticDepositWithMaxFee({
105
- transactionId: transactionId3,
106
- maxFee: 1000,
107
- });
231
+ const signedTx = await faucet.sendToAddress(
232
+ depositAddress,
233
+ DEPOSIT_AMOUNT,
234
+ );
108
235
 
109
- await new Promise((resolve) => setTimeout(resolve, 1000));
236
+ // Wait for the transaction to be mined
237
+ await faucet.mineBlocks(6);
110
238
 
111
- const { balance: balance3 } = await userWallet.getBalance();
112
- expect(balance3).toBe(BigInt(quoteAmount + quoteAmount2 + quoteAmount3));
239
+ expect(signedTx).toBeDefined();
113
240
 
114
- // Get transfers should include static deposit transfers.
115
- const transfers = await userWallet.getTransfers();
116
- expect(transfers.transfers.length).toBe(3);
117
- }, 60000);
241
+ const transactionId = signedTx.id;
118
242
 
119
- it("should create a refund transaction", async () => {
120
- const faucet = BitcoinFaucet.getInstance();
243
+ await expect(
244
+ aliceWallet.getClaimStaticDepositQuote(
245
+ `${transactionId.slice(0, -6)}abcdef`,
246
+ ),
247
+ ).rejects.toThrow();
248
+ });
121
249
 
122
- const { wallet: userWallet } = await SparkWalletTesting.initialize(
123
- {
124
- options: {
125
- network: "LOCAL",
250
+ it("should error if tx amount does not cover fees", async () => {
251
+ const { wallet: aliceWallet } = await SparkWalletTesting.initialize(
252
+ {
253
+ options: {
254
+ network: "LOCAL",
255
+ },
126
256
  },
127
- },
128
- false,
129
- );
130
-
131
- const depositAddress = await userWallet.getStaticDepositAddress();
132
- expect(depositAddress).toBeDefined();
133
-
134
- const signedTx = await faucet.sendToAddress(depositAddress, DEPOSIT_AMOUNT);
135
-
136
- // Wait for the transaction to be mined
137
- await faucet.mineBlocks(6);
138
-
139
- expect(signedTx).toBeDefined();
257
+ false,
258
+ );
140
259
 
141
- const transactionId = signedTx.id;
260
+ const faucet = BitcoinFaucet.getInstance();
142
261
 
143
- let vout: number | undefined;
262
+ const depositAddress = await aliceWallet.getStaticDepositAddress();
263
+ expect(depositAddress).toBeDefined();
144
264
 
145
- for (let i = 0; i < signedTx.outputsLength; i++) {
146
- const output = signedTx.getOutput(i);
147
- if (output.amount === DEPOSIT_AMOUNT) {
148
- vout = i;
149
- break;
150
- }
151
- }
265
+ const signedTx = await faucet.sendToAddress(
266
+ depositAddress,
267
+ SMALL_DEPOSIT_AMOUNT,
268
+ );
152
269
 
153
- const refundAddress = await faucet.getNewAddress();
270
+ // Wait for the transaction to be mined
271
+ await faucet.mineBlocks(6);
154
272
 
155
- const refundTx = await userWallet.refundStaticDeposit({
156
- depositTransactionId: transactionId,
157
- destinationAddress: refundAddress,
158
- satsPerVbyteFee: 2,
159
- });
273
+ expect(signedTx).toBeDefined();
160
274
 
161
- expect(refundTx).toBeDefined();
275
+ const transactionId = signedTx.id;
162
276
 
163
- // Calling it again should create a new transaction.
164
- const refundTx2 = await userWallet.refundStaticDeposit({
165
- depositTransactionId: transactionId,
166
- destinationAddress: refundAddress,
167
- outputIndex: vout!,
168
- satsPerVbyteFee: 2,
169
- });
277
+ await expect(
278
+ aliceWallet.getClaimStaticDepositQuote(transactionId),
279
+ ).rejects.toThrow();
280
+ }, 60000);
170
281
 
171
- expect(refundTx2).toBeDefined();
172
-
173
- expect(refundTx).not.toBe(refundTx2);
174
- }, 60000);
282
+ it("should error claim quote if tx already claimed", async () => {
283
+ const { wallet: aliceWallet } = await SparkWalletTesting.initialize(
284
+ {
285
+ options: {
286
+ network: "LOCAL",
287
+ },
288
+ },
289
+ false,
290
+ );
291
+
292
+ const faucet = BitcoinFaucet.getInstance();
293
+
294
+ const depositAddress = await aliceWallet.getStaticDepositAddress();
295
+ expect(depositAddress).toBeDefined();
296
+
297
+ const signedTx = await faucet.sendToAddress(
298
+ depositAddress,
299
+ DEPOSIT_AMOUNT,
300
+ );
301
+
302
+ // Wait for the transaction to be mined
303
+ await faucet.mineBlocks(6);
304
+
305
+ expect(signedTx).toBeDefined();
306
+
307
+ const transactionId = signedTx.id;
308
+
309
+ const quote = await aliceWallet.getClaimStaticDepositQuote(transactionId);
310
+
311
+ await aliceWallet.claimStaticDeposit({
312
+ transactionId: transactionId,
313
+ creditAmountSats: quote.creditAmountSats,
314
+ sspSignature: quote.signature,
315
+ });
316
+ await new Promise((resolve) => setTimeout(resolve, 40000));
317
+
318
+ const { balance } = await aliceWallet.getBalance();
319
+
320
+ expect(balance).toBe(BigInt(quote.creditAmountSats));
321
+
322
+ await expect(
323
+ aliceWallet.getClaimStaticDepositQuote(transactionId),
324
+ ).rejects.toThrow();
325
+ }, 60000);
326
+ });
327
+
328
+ describe("Claim unhappy path testing", () => {
329
+ it("should reject claim with fake SSP signature", async () => {
330
+ console.log("Initializing wallet for fake SSP signature test...");
331
+ const {
332
+ wallet: userWallet,
333
+ signedTx,
334
+ vout,
335
+ faucet,
336
+ } = await initWallet(DEPOSIT_AMOUNT, "LOCAL");
337
+
338
+ // Wait for the transaction to be mined
339
+ await faucet.mineBlocks(6);
340
+
341
+ const transactionId = signedTx.id;
342
+
343
+ console.log("Fetching claim quote for static deposit...");
344
+ const quote = await userWallet.getClaimStaticDepositQuote(
345
+ transactionId,
346
+ vout!,
347
+ );
348
+
349
+ await new Promise((resolve) => setTimeout(resolve, 10000));
350
+
351
+ const quoteAmount = quote!.creditAmountSats;
352
+
353
+ // Generate a fake signature (64 bytes of random data to simulate a signature)
354
+ const fakeSignature = new Uint8Array(64);
355
+ crypto.getRandomValues(fakeSignature);
356
+ console.log("Expecting error when claiming with fake signature...");
357
+ await expect(
358
+ userWallet.claimStaticDeposit({
359
+ transactionId,
360
+ creditAmountSats: quoteAmount,
361
+ sspSignature: bytesToHex(fakeSignature),
362
+ outputIndex: vout!,
363
+ }),
364
+ ).rejects.toThrow(
365
+ 'Request ClaimStaticDeposit failed. [{"message":"Something went wrong."',
366
+ );
367
+ }, 600000);
368
+
369
+ it("should reject claiming the same deposit twice", async () => {
370
+ console.log("Initializing wallet for double-claim test...");
371
+ const {
372
+ wallet: userWallet,
373
+ signedTx,
374
+ vout,
375
+ faucet,
376
+ } = await initWallet(DEPOSIT_AMOUNT, "LOCAL");
377
+
378
+ // Wait for the transaction to be mined
379
+ await faucet.mineBlocks(6);
380
+
381
+ const transactionId = signedTx.id;
382
+
383
+ console.log("Fetching claim quote for static deposit...");
384
+ const quote = await userWallet.getClaimStaticDepositQuote(
385
+ transactionId,
386
+ vout!,
387
+ );
388
+
389
+ await new Promise((resolve) => setTimeout(resolve, 10000));
390
+
391
+ const quoteAmount = quote!.creditAmountSats;
392
+ const sspSignature = quote!.signature;
393
+
394
+ console.log("Attempting to claim static deposit for the first time...");
395
+ const outputs = await userWallet.claimStaticDeposit({
396
+ transactionId,
397
+ creditAmountSats: quoteAmount,
398
+ sspSignature,
399
+ outputIndex: vout!,
400
+ });
401
+
402
+ await new Promise((resolve) => setTimeout(resolve, 30000));
403
+
404
+ expect(outputs).toBeDefined();
405
+
406
+ console.log(
407
+ "Expecting error when attempting to claim the same deposit twice...",
408
+ );
409
+ await expect(
410
+ userWallet.claimStaticDeposit({
411
+ transactionId,
412
+ creditAmountSats: quoteAmount,
413
+ sspSignature,
414
+ outputIndex: vout!,
415
+ }),
416
+ ).rejects.toThrow("UTXO is spent or not found.");
417
+ }, 600000);
418
+
419
+ it("Claim, then try to refund.", async () => {
420
+ console.log("Initializing wallet for claim and refund test...");
421
+ const {
422
+ wallet: userWallet,
423
+ depositAddress,
424
+ signedTx,
425
+ vout,
426
+ faucet,
427
+ } = await initWallet(DEPOSIT_AMOUNT, "LOCAL");
428
+
429
+ // Wait for the transaction to be mined
430
+ await faucet.mineBlocks(6);
431
+
432
+ expect(signedTx).toBeDefined();
433
+
434
+ const transactionId = signedTx.id;
435
+
436
+ const quote = await userWallet.getClaimStaticDepositQuote(
437
+ transactionId,
438
+ vout!,
439
+ );
440
+
441
+ const quoteAmount = quote!.creditAmountSats;
442
+ const sspSignature = quote!.signature;
443
+
444
+ console.log("Attempting to claim static deposit...");
445
+ await userWallet.claimStaticDeposit({
446
+ transactionId,
447
+ creditAmountSats: quoteAmount,
448
+ sspSignature,
449
+ outputIndex: vout!,
450
+ });
451
+
452
+ await new Promise((resolve) => setTimeout(resolve, 30000));
453
+
454
+ console.log("Fetching wallet balance after claim...");
455
+ const { balance } = await userWallet.getBalance();
456
+ expect(balance).toBe(BigInt(quoteAmount));
457
+
458
+ console.log(`Alice balance: ${balance}`);
459
+
460
+ console.log("Initiating transfer to Spark address...");
461
+ const sparkAddress = await userWallet.getSparkAddress();
462
+ const transfer = await userWallet.transfer({
463
+ amountSats: Number(balance),
464
+ receiverSparkAddress: sparkAddress,
465
+ });
466
+
467
+ expect(transfer).toBeDefined();
468
+
469
+ await new Promise((resolve) => setTimeout(resolve, 1000));
470
+
471
+ // Try to refund the deposit after claiming and transfer
472
+ console.log("Attempting refund of claimed deposit...");
473
+ await expect(
474
+ userWallet.refundStaticDeposit({
475
+ depositTransactionId: transactionId,
476
+ destinationAddress: depositAddress,
477
+ fee: 301,
478
+ }),
479
+ ).rejects.toThrow();
480
+ }, 600000);
481
+ });
175
482
  });
@@ -7,7 +7,7 @@ const DEPOSIT_AMOUNT = 10000n;
7
7
  const SECOND_DEPOSIT_AMOUNT = 20000n;
8
8
 
9
9
  describe("SSP Transfers Test", () => {
10
- it("getTransfers should return the corresponding ssp request if it exists", async () => {
10
+ it("getTransfers and getTransfer should return the corresponding ssp request if it exists", async () => {
11
11
  const faucet = BitcoinFaucet.getInstance();
12
12
 
13
13
  const { wallet: userWallet } = await SparkWalletTesting.initialize(
@@ -75,7 +75,6 @@ describe("SSP Transfers Test", () => {
75
75
  receiverSparkAddress: await userWallet2.getSparkAddress(),
76
76
  });
77
77
 
78
- // Get transfers should include static deposit transfers.
79
78
  const transfers = await userWallet.getTransfers();
80
79
  expect(transfers.transfers.length).toBe(2);
81
80
 
@@ -86,6 +85,9 @@ describe("SSP Transfers Test", () => {
86
85
  transferTypeToJSON(TransferType.TRANSFER),
87
86
  );
88
87
 
88
+ const sparkTransfer = await userWallet.getTransfer(firstTransfer!.id);
89
+ expect(sparkTransfer?.userRequest).not.toBeDefined();
90
+
89
91
  const secondTransfer = transfers.transfers[1];
90
92
  expect(secondTransfer).toBeDefined();
91
93
  expect(secondTransfer?.userRequest).toBeDefined();
@@ -93,5 +95,8 @@ describe("SSP Transfers Test", () => {
93
95
  transferTypeToJSON(TransferType.UTXO_SWAP),
94
96
  );
95
97
  expect(secondTransfer?.userRequest?.typename).toBe("ClaimStaticDeposit");
98
+
99
+ const utxoSwapTransfer = await userWallet.getTransfer(secondTransfer!.id);
100
+ expect(utxoSwapTransfer?.userRequest).toBeDefined();
96
101
  }, 60000);
97
102
  });