@fedimint/core 0.1.0 → 0.1.1

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.
@@ -1,26 +0,0 @@
1
- import { expect } from 'vitest'
2
- import { walletTest } from '../test/fixtures'
3
-
4
- walletTest('getBalance should be initially zero', async ({ wallet }) => {
5
- expect(wallet).toBeDefined()
6
- expect(wallet.isOpen()).toBe(true)
7
- const beforeGetBalance = wallet.testing.getRequestCounter()
8
- await expect(wallet.balance.getBalance()).resolves.toEqual(0)
9
- expect(wallet.testing.getRequestCounter()).toBe(beforeGetBalance + 1)
10
- })
11
-
12
- walletTest('subscribe balance', async ({ wallet }) => {
13
- expect(wallet).toBeDefined()
14
- expect(wallet.isOpen()).toBe(true)
15
-
16
- const counterBefore = wallet.testing.getRequestCounter()
17
- const callbacksBefore = wallet.testing.getRequestCallbackMap().size
18
- const unsubscribe = await wallet.balance.subscribeBalance((balance) => {
19
- expect(balance).toEqual(0)
20
- })
21
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
22
- expect(wallet.testing.getRequestCallbackMap().size).toBe(callbacksBefore + 1)
23
-
24
- await expect(wallet.balance.getBalance()).resolves.toEqual(0)
25
- expect(unsubscribe()).toBeUndefined()
26
- })
@@ -1,58 +0,0 @@
1
- import { expect } from 'vitest'
2
- import { walletTest } from '../test/fixtures'
3
-
4
- walletTest(
5
- 'getConfig should return the federation config',
6
- async ({ wallet }) => {
7
- expect(wallet).toBeDefined()
8
- expect(wallet.isOpen()).toBe(true)
9
- const counterBefore = wallet.testing.getRequestCounter()
10
- await expect(wallet.federation.getConfig()).resolves.toMatchObject({
11
- api_endpoints: expect.any(Object),
12
- broadcast_public_keys: expect.any(Object),
13
- consensus_version: expect.any(Object),
14
- meta: expect.any(Object),
15
- modules: expect.any(Object),
16
- })
17
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
18
- },
19
- )
20
-
21
- walletTest(
22
- 'getFederationId should return the federation id',
23
- async ({ wallet }) => {
24
- expect(wallet).toBeDefined()
25
- expect(wallet.isOpen()).toBe(true)
26
-
27
- const counterBefore = wallet.testing.getRequestCounter()
28
- const federationId = await wallet.federation.getFederationId()
29
- expect(federationId).toBeTypeOf('string')
30
- expect(federationId).toHaveLength(64)
31
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
32
- },
33
- )
34
-
35
- walletTest(
36
- 'getInviteCode should return the invite code',
37
- async ({ wallet }) => {
38
- expect(wallet).toBeDefined()
39
- expect(wallet.isOpen()).toBe(true)
40
-
41
- const counterBefore = wallet.testing.getRequestCounter()
42
- const inviteCode = await wallet.federation.getInviteCode(0)
43
- expect(inviteCode).toBeTypeOf('string')
44
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
45
- },
46
- )
47
-
48
- walletTest(
49
- 'listOperations should return the list of operations',
50
- async ({ wallet }) => {
51
- expect(wallet).toBeDefined()
52
- expect(wallet.isOpen()).toBe(true)
53
-
54
- const counterBefore = wallet.testing.getRequestCounter()
55
- await expect(wallet.federation.listOperations()).resolves.toMatchObject([])
56
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
57
- },
58
- )
@@ -1,265 +0,0 @@
1
- import { expect } from 'vitest'
2
- import { keyPair } from '../test/crypto'
3
- import { walletTest } from '../test/fixtures'
4
-
5
- walletTest(
6
- 'createInvoice should create a bolt11 invoice',
7
- async ({ wallet }) => {
8
- expect(wallet).toBeDefined()
9
- expect(wallet.isOpen()).toBe(true)
10
-
11
- const counterBefore = wallet.testing.getRequestCounter()
12
- const invoice = await wallet.lightning.createInvoice(100, 'test')
13
- expect(invoice).toBeDefined()
14
- expect(invoice).toMatchObject({
15
- invoice: expect.any(String),
16
- operation_id: expect.any(String),
17
- })
18
- // 3 requests were made, one for the invoice, one for refreshing the
19
- // gateway cache, one for getting the gateway info
20
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 3)
21
-
22
- // Test with expiry time
23
- await expect(
24
- wallet.lightning.createInvoice(100, 'test', 1000),
25
- ).resolves.toBeDefined()
26
- },
27
- )
28
-
29
- walletTest('createInvoice with expiry', async ({ wallet }) => {
30
- expect(wallet).toBeDefined()
31
- expect(wallet.isOpen()).toBe(true)
32
-
33
- const invoice = await wallet.lightning.createInvoice(100, 'test', 1000)
34
- expect(invoice).toBeDefined()
35
- expect(invoice).toMatchObject({
36
- invoice: expect.any(String),
37
- operation_id: expect.any(String),
38
- })
39
- })
40
-
41
- walletTest(
42
- 'listGateways should return a list of gateways',
43
- async ({ wallet }) => {
44
- expect(wallet).toBeDefined()
45
- expect(wallet.isOpen()).toBe(true)
46
-
47
- const counterBefore = wallet.testing.getRequestCounter()
48
- const gateways = await wallet.lightning.listGateways()
49
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
50
- expect(gateways).toBeDefined()
51
- expect(gateways).toMatchObject(expect.any(Array))
52
- },
53
- )
54
-
55
- walletTest(
56
- 'updateGatewayCache should update the gateway cache',
57
- async ({ wallet }) => {
58
- expect(wallet).toBeDefined()
59
- expect(wallet.isOpen()).toBe(true)
60
-
61
- const counterBefore = wallet.testing.getRequestCounter()
62
- await expect(wallet.lightning.updateGatewayCache()).resolves.toBeDefined()
63
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
64
- },
65
- )
66
-
67
- walletTest('getGateway should return a gateway', async ({ wallet }) => {
68
- expect(wallet).toBeDefined()
69
- expect(wallet.isOpen()).toBe(true)
70
-
71
- const counterBefore = wallet.testing.getRequestCounter()
72
- const gateway = await wallet.lightning.getGateway()
73
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 1)
74
- expect(gateway).toMatchObject({
75
- api: expect.any(String),
76
- fees: expect.any(Object),
77
- gateway_id: expect.any(String),
78
- gateway_redeem_key: expect.any(String),
79
- lightning_alias: expect.any(String),
80
- mint_channel_id: expect.any(Number),
81
- node_pub_key: expect.any(String),
82
- route_hints: expect.any(Array),
83
- })
84
- })
85
-
86
- walletTest(
87
- 'payInvoice should throw on insufficient funds',
88
- async ({ wallet }) => {
89
- expect(wallet).toBeDefined()
90
- expect(wallet.isOpen()).toBe(true)
91
-
92
- const invoice = await wallet.lightning.createInvoice(100, 'test')
93
- expect(invoice).toBeDefined()
94
- expect(invoice).toMatchObject({
95
- invoice: expect.any(String),
96
- operation_id: expect.any(String),
97
- })
98
-
99
- const counterBefore = wallet.testing.getRequestCounter()
100
- // Insufficient funds
101
- try {
102
- await wallet.lightning.payInvoice(invoice.invoice)
103
- expect.unreachable('Should throw error')
104
- } catch (error) {
105
- expect(error).toBeDefined()
106
- }
107
- // 3 requests were made, one for paying the invoice, one for refreshing the
108
- // gateway cache, one for getting the gateway info
109
- expect(wallet.testing.getRequestCounter()).toBe(counterBefore + 3)
110
- },
111
- )
112
-
113
- walletTest(
114
- 'payInvoice should pay a bolt11 invoice',
115
- { timeout: 20_000 },
116
- async ({ fundedWallet }) => {
117
- expect(fundedWallet).toBeDefined()
118
- expect(fundedWallet.isOpen()).toBe(true)
119
- const initialBalance = await fundedWallet.balance.getBalance()
120
- expect(initialBalance).toBeGreaterThan(0)
121
- const externalInvoice = await fundedWallet.testing.createFaucetInvoice(1)
122
- const gatewayInfo = await fundedWallet.testing.getFaucetGatewayInfo()
123
- const payment = await fundedWallet.lightning.payInvoice(
124
- externalInvoice,
125
- gatewayInfo,
126
- )
127
- expect(payment).toMatchObject({
128
- contract_id: expect.any(String),
129
- fee: expect.any(Number),
130
- payment_type: expect.any(Object),
131
- })
132
- const finalBalance = await fundedWallet.balance.getBalance()
133
- expect(finalBalance).toBeLessThan(initialBalance)
134
- },
135
- )
136
-
137
- walletTest(
138
- 'createInvoiceTweaked should create a bolt11 invoice with a tweaked public key',
139
- async ({ wallet }) => {
140
- expect(wallet).toBeDefined()
141
- expect(wallet.isOpen()).toBe(true)
142
-
143
- // Make an ephemeral key pair
144
- const { publicKey, secretKey } = keyPair()
145
- const tweak = 1
146
-
147
- // Create an invoice paying to the tweaked public key
148
- const invoice = await wallet.lightning.createInvoiceTweaked(
149
- 1000,
150
- 'test tweaked',
151
- publicKey,
152
- tweak,
153
- )
154
- expect(invoice).toBeDefined()
155
- expect(invoice).toMatchObject({
156
- invoice: expect.any(String),
157
- operation_id: expect.any(String),
158
- })
159
- },
160
- )
161
-
162
- walletTest(
163
- 'scanReceivesForTweaks should return the operation id',
164
- async ({ wallet }) => {
165
- expect(wallet).toBeDefined()
166
- expect(wallet.isOpen()).toBe(true)
167
-
168
- // Make an ephemeral key pair
169
- const { publicKey, secretKey } = keyPair()
170
- const tweak = 1
171
-
172
- const gatewayInfo = await wallet.testing.getFaucetGatewayInfo()
173
-
174
- // Create an invoice paying to the tweaked public key
175
- const invoice = await wallet.lightning.createInvoiceTweaked(
176
- 1000,
177
- 'test tweaked',
178
- publicKey,
179
- tweak,
180
- undefined,
181
- gatewayInfo,
182
- )
183
- await expect(
184
- wallet.testing.payFaucetInvoice(invoice.invoice),
185
- ).resolves.toBeDefined()
186
-
187
- // Scan for the receive
188
- const operationIds = await wallet.lightning.scanReceivesForTweaks(
189
- secretKey,
190
- [tweak],
191
- {},
192
- )
193
- expect(operationIds).toBeDefined()
194
- expect(operationIds).toHaveLength(1)
195
-
196
- // Subscribe to claiming the receive
197
- const subscription = await wallet.lightning.subscribeLnClaim(
198
- operationIds[0],
199
- (state) => {
200
- expect(state).toBeDefined()
201
- expect(state).toMatchObject({
202
- state: 'claimed',
203
- })
204
- },
205
- )
206
- expect(subscription).toBeDefined()
207
- },
208
- )
209
-
210
- walletTest(
211
- 'subscribe_internal_pay should return state',
212
- async ({ fundedWallet }) => {
213
- expect(fundedWallet).toBeDefined()
214
- expect(fundedWallet.isOpen()).toBe(true)
215
- const initialBalance = await fundedWallet.balance.getBalance()
216
- expect(initialBalance).toBeGreaterThan(0)
217
- const externalInvoice = (
218
- await fundedWallet.lightning.createInvoice(1, 'test invoice')
219
- ).invoice
220
- const payment = await fundedWallet.lightning.payInvoice(externalInvoice)
221
- expect(payment).toMatchObject({
222
- contract_id: expect.any(String),
223
- fee: expect.any(Number),
224
- payment_type: expect.any(Object),
225
- })
226
- const finalBalance = await fundedWallet.balance.getBalance()
227
- expect(finalBalance).toBeLessThan(initialBalance)
228
- expect(payment.payment_type).toHaveProperty('internal')
229
- if ('internal' in payment.payment_type) {
230
- const id = payment.payment_type.internal
231
- await new Promise<void>((resolve, reject) => {
232
- const unsubscribe = fundedWallet.lightning.subscribeInternalPayment(
233
- id,
234
- (state) => {
235
- try {
236
- expect(state).toBeDefined()
237
- expect(state).toBe('funding')
238
- unsubscribe()
239
- resolve()
240
- } catch (err) {
241
- reject(err)
242
- }
243
- },
244
- )
245
- })
246
- } else {
247
- const id = payment.payment_type.lightning
248
- await new Promise<void>((resolve, reject) => {
249
- const unsubscribe = fundedWallet.lightning.subscribeLnPay(
250
- id,
251
- (state) => {
252
- try {
253
- expect(state).toBeDefined()
254
- expect(state).toBe('created')
255
- unsubscribe()
256
- resolve()
257
- } catch (err) {
258
- reject(err)
259
- }
260
- },
261
- )
262
- })
263
- }
264
- },
265
- )
@@ -1,74 +0,0 @@
1
- import { expect } from 'vitest'
2
- import { walletTest } from '../test/fixtures'
3
-
4
- walletTest('redeemEcash should error on invalid ecash', async ({ wallet }) => {
5
- expect(wallet).toBeDefined()
6
- expect(wallet.isOpen()).toBe(true)
7
-
8
- await expect(wallet.mint.redeemEcash('test')).rejects.toThrow()
9
- })
10
-
11
- walletTest(
12
- 'reissueExternalNotes should throw if wallet is empty',
13
- async ({ wallet }) => {
14
- expect(wallet).toBeDefined()
15
- expect(wallet.isOpen()).toBe(true)
16
-
17
- await expect(wallet.mint.reissueExternalNotes('test')).rejects.toThrow()
18
- },
19
- )
20
-
21
- walletTest('spendNotes should throw if wallet is empty', async ({ wallet }) => {
22
- expect(wallet).toBeDefined()
23
- expect(wallet.isOpen()).toBe(true)
24
-
25
- await expect(wallet.mint.spendNotes(100)).rejects.toThrow()
26
- })
27
-
28
- walletTest('parseNotes should parse notes', async ({ wallet }) => {
29
- expect(wallet).toBeDefined()
30
- expect(wallet.isOpen()).toBe(true)
31
-
32
- await expect(wallet.mint.reissueExternalNotes('test')).rejects.toThrow()
33
- })
34
-
35
- walletTest(
36
- 'getNotesByDenomination should return empty object if wallet is empty',
37
- async ({ wallet }) => {
38
- expect(wallet).toBeDefined()
39
- expect(wallet.isOpen()).toBe(true)
40
-
41
- const notes = await wallet.mint.getNotesByDenomination()
42
- const balance = await wallet.balance.getBalance()
43
- expect(balance).toEqual(0)
44
- expect(notes).toBeDefined()
45
- expect(notes).toEqual({})
46
- },
47
- )
48
-
49
- walletTest(
50
- 'getNotesByDenomination should get notes by denomination',
51
- async ({ fundedWallet }) => {
52
- expect(fundedWallet).toBeDefined()
53
- expect(fundedWallet.isOpen()).toBe(true)
54
-
55
- const notes = await fundedWallet.mint.getNotesByDenomination()
56
- const balance = await fundedWallet.balance.getBalance()
57
- expect(balance).toEqual(10000)
58
- expect(notes).toBeDefined()
59
- expect(notes).toEqual({
60
- '1': 2,
61
- '1024': 3,
62
- '128': 2,
63
- '16': 3,
64
- '2': 3,
65
- '2048': 2,
66
- '256': 3,
67
- '32': 2,
68
- '4': 2,
69
- '512': 3,
70
- '64': 2,
71
- '8': 2,
72
- })
73
- },
74
- )
@@ -1,59 +0,0 @@
1
- import { expect } from 'vitest'
2
- import { walletTest } from '../test/fixtures'
3
- import { TxOutputSummary, WalletSummary } from '../types'
4
-
5
- walletTest(
6
- 'getWalletSummary should return empty object if wallet is empty',
7
- async ({ wallet }) => {
8
- expect(wallet).toBeDefined()
9
- expect(wallet.isOpen()).toBe(true)
10
-
11
- const balance = await wallet.balance.getBalance()
12
- expect(balance).toEqual(0)
13
-
14
- const summary = await wallet.wallet.getWalletSummary()
15
- const expectedSummary = {
16
- spendable_utxos: expect.any(Array<TxOutputSummary>),
17
- unsigned_peg_out_txos: expect.any(Array<TxOutputSummary>),
18
- unsigned_change_utxos: expect.any(Array<TxOutputSummary>),
19
- unconfirmed_peg_out_txos: expect.any(Array<TxOutputSummary>),
20
- unconfirmed_change_utxos: expect.any(Array<TxOutputSummary>),
21
- } satisfies WalletSummary
22
- expect(summary).toEqual(expect.objectContaining(expectedSummary))
23
- },
24
- )
25
-
26
- walletTest(
27
- 'generateAddress should always return an address',
28
- async ({ wallet }) => {
29
- expect(wallet).toBeDefined()
30
- expect(wallet.isOpen()).toBe(true)
31
- const response = await wallet.wallet.generateAddress()
32
-
33
- expect(response, 'generateAddress').toEqual({
34
- deposit_address: expect.any(String),
35
- operation_id: expect.any(String),
36
- })
37
- },
38
- )
39
-
40
- walletTest(
41
- 'sendOnchain should return an operation ID after sending funds',
42
- async ({ fundedWalletBeefy }) => {
43
- expect(fundedWalletBeefy).toBeDefined()
44
- expect(fundedWalletBeefy.isOpen()).toBe(true)
45
-
46
- const amountSat = 100
47
- const address =
48
- 'bcrt1qphk8q2v8he2autevdcefnnwjl4yc2hm74uuvhaa6nhrnkd3gfrwq6mnr76'
49
-
50
- const response = await fundedWalletBeefy.wallet.sendOnchain(
51
- amountSat,
52
- address,
53
- )
54
-
55
- expect(response, 'send onchain').toEqual({
56
- operation_id: expect.any(String),
57
- })
58
- },
59
- )