@fedimint/core 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dts/FedimintWallet.d.ts +2 -1
- package/dist/dts/FedimintWallet.d.ts.map +1 -1
- package/dist/dts/WalletDirector.d.ts +16 -0
- package/dist/dts/WalletDirector.d.ts.map +1 -1
- package/dist/dts/services/BalanceService.d.ts +2 -1
- package/dist/dts/services/BalanceService.d.ts.map +1 -1
- package/dist/dts/services/FederationService.d.ts +2 -1
- package/dist/dts/services/FederationService.d.ts.map +1 -1
- package/dist/dts/services/LightningService.d.ts +6 -5
- package/dist/dts/services/LightningService.d.ts.map +1 -1
- package/dist/dts/services/MintService.d.ts +4 -3
- package/dist/dts/services/MintService.d.ts.map +1 -1
- package/dist/dts/services/RecoveryService.d.ts +3 -2
- package/dist/dts/services/RecoveryService.d.ts.map +1 -1
- package/dist/dts/services/WalletService.d.ts +3 -2
- package/dist/dts/services/WalletService.d.ts.map +1 -1
- package/dist/dts/testing.d.ts +2 -0
- package/dist/dts/testing.d.ts.map +1 -0
- package/dist/dts/transport/TransportClient.d.ts +3 -2
- package/dist/dts/transport/TransportClient.d.ts.map +1 -1
- package/dist/index.d.ts +20 -501
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/testing.d-CJcyXM5Q.d.ts +510 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +2 -0
- package/dist/testing.js.map +1 -0
- package/package.json +17 -6
- package/src/FedimintWallet.ts +30 -22
- package/src/WalletDirector.ts +38 -3
- package/src/services/BalanceService.ts +11 -2
- package/src/services/FederationService.ts +21 -6
- package/src/services/LightningService.ts +20 -2
- package/src/services/MintService.ts +34 -10
- package/src/services/RecoveryService.ts +19 -3
- package/src/services/WalletService.ts +22 -7
- package/src/testing.ts +3 -0
- package/src/transport/TransportClient.ts +57 -17
- package/src/utils/logger.ts +2 -2
- package/src/services/BalanceService.test.ts +0 -26
- package/src/services/FederationService.test.ts +0 -58
- package/src/services/LightningService.test.ts +0 -265
- package/src/services/MintService.test.ts +0 -74
- package/src/services/WalletService.test.ts +0 -59
|
@@ -38,36 +38,58 @@ export class TransportClient {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Idempotent setup - Loads the wasm module
|
|
41
|
-
initialize()
|
|
41
|
+
initialize(): Promise<boolean>
|
|
42
|
+
initialize(testFilename: string): Promise<boolean>
|
|
43
|
+
initialize(testFilename?: string): Promise<boolean> {
|
|
42
44
|
if (this.initPromise) return this.initPromise
|
|
43
|
-
|
|
45
|
+
if (testFilename) {
|
|
46
|
+
this.initPromise = this.sendSingleMessage('init', {
|
|
47
|
+
filename: testFilename,
|
|
48
|
+
})
|
|
49
|
+
} else {
|
|
50
|
+
this.initPromise = this.sendSingleMessage('init')
|
|
51
|
+
}
|
|
44
52
|
return this.initPromise
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
private handleLogMessage(message: TransportMessage) {
|
|
48
|
-
const { type, level, message: logMessage, ...data } = message
|
|
49
|
-
this.logger.
|
|
56
|
+
const { type, level = 'debug', message: logMessage, ...data } = message
|
|
57
|
+
this.logger.log(String(level), `Transport Log: ${String(logMessage)}`, data)
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
private handleTransportError = (error: unknown) => {
|
|
53
|
-
this.logger.
|
|
61
|
+
this.logger.warn(
|
|
62
|
+
'TransportClient error',
|
|
63
|
+
JSON.stringify(error, [
|
|
64
|
+
'message',
|
|
65
|
+
'arguments',
|
|
66
|
+
'type',
|
|
67
|
+
'name',
|
|
68
|
+
'request_id',
|
|
69
|
+
]),
|
|
70
|
+
)
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
private handleTransportMessage = (message: TransportMessage) => {
|
|
57
|
-
const { type,
|
|
74
|
+
const { type, request_id, ...data } = message
|
|
58
75
|
if (type === 'log') {
|
|
59
76
|
this.handleLogMessage(message)
|
|
60
77
|
}
|
|
78
|
+
|
|
61
79
|
const streamCallback =
|
|
62
|
-
|
|
80
|
+
request_id !== undefined
|
|
81
|
+
? this.requestCallbacks.get(request_id)
|
|
82
|
+
: undefined
|
|
63
83
|
// TODO: Handle errors... maybe have another callbacks list for errors?
|
|
64
|
-
this.logger.debug('TransportClient - handleTransportMessage', message)
|
|
65
84
|
if (streamCallback) {
|
|
85
|
+
this.logger.debug(
|
|
86
|
+
'TransportClient - handleTransportMessage - callback',
|
|
87
|
+
message,
|
|
88
|
+
)
|
|
66
89
|
streamCallback(data) // {data: something} OR {error: something}
|
|
67
|
-
} else if (
|
|
90
|
+
} else if (request_id !== undefined && type !== 'end') {
|
|
68
91
|
this.logger.warn(
|
|
69
92
|
'TransportClient - handleTransportMessage - received message with no callback',
|
|
70
|
-
requestId,
|
|
71
93
|
message,
|
|
72
94
|
)
|
|
73
95
|
}
|
|
@@ -98,7 +120,7 @@ export class TransportClient {
|
|
|
98
120
|
requestId,
|
|
99
121
|
response,
|
|
100
122
|
)
|
|
101
|
-
if (response.data) resolve(response.data)
|
|
123
|
+
if (response.data !== undefined) resolve(response.data)
|
|
102
124
|
else if (response.error) reject(response.error)
|
|
103
125
|
else
|
|
104
126
|
this.logger.warn(
|
|
@@ -143,6 +165,7 @@ export class TransportClient {
|
|
|
143
165
|
module: ModuleKind,
|
|
144
166
|
method: string,
|
|
145
167
|
body: Body,
|
|
168
|
+
clientName: string,
|
|
146
169
|
onSuccess: (res: Response) => void,
|
|
147
170
|
onError: (res: StreamError['error']) => void,
|
|
148
171
|
onEnd: () => void = () => {},
|
|
@@ -154,6 +177,7 @@ export class TransportClient {
|
|
|
154
177
|
module,
|
|
155
178
|
method,
|
|
156
179
|
body,
|
|
180
|
+
clientName,
|
|
157
181
|
)
|
|
158
182
|
let unsubscribe: (value: void) => void = () => {}
|
|
159
183
|
let isSubscribed = false
|
|
@@ -177,6 +201,7 @@ export class TransportClient {
|
|
|
177
201
|
module,
|
|
178
202
|
method,
|
|
179
203
|
body,
|
|
204
|
+
clientName,
|
|
180
205
|
onSuccess,
|
|
181
206
|
onError,
|
|
182
207
|
onEnd,
|
|
@@ -196,6 +221,7 @@ export class TransportClient {
|
|
|
196
221
|
module: ModuleKind,
|
|
197
222
|
method: string,
|
|
198
223
|
body: Body,
|
|
224
|
+
clientName: string,
|
|
199
225
|
onSuccess: (res: Response) => void,
|
|
200
226
|
onError: (res: StreamError['error']) => void,
|
|
201
227
|
onEnd: () => void = () => {},
|
|
@@ -213,14 +239,15 @@ export class TransportClient {
|
|
|
213
239
|
}
|
|
214
240
|
})
|
|
215
241
|
this.transport.postMessage({
|
|
216
|
-
type: '
|
|
217
|
-
payload: { module, method, body },
|
|
242
|
+
type: 'client_rpc',
|
|
243
|
+
payload: { client_name: clientName, module, method, payload: body },
|
|
218
244
|
requestId,
|
|
219
245
|
})
|
|
220
246
|
|
|
221
247
|
unsubscribePromise.then(() => {
|
|
222
248
|
this.transport.postMessage({
|
|
223
|
-
type: '
|
|
249
|
+
type: 'cancel_rpc',
|
|
250
|
+
payload: { cancel_request_id: requestId },
|
|
224
251
|
requestId,
|
|
225
252
|
})
|
|
226
253
|
this.requestCallbacks.delete(requestId)
|
|
@@ -230,15 +257,28 @@ export class TransportClient {
|
|
|
230
257
|
rpcSingle<
|
|
231
258
|
Response extends JSONValue = JSONValue,
|
|
232
259
|
Error extends string = string,
|
|
233
|
-
>(
|
|
260
|
+
>(
|
|
261
|
+
module: ModuleKind,
|
|
262
|
+
method: string,
|
|
263
|
+
body: JSONValue,
|
|
264
|
+
clientName: string,
|
|
265
|
+
): Promise<Response> {
|
|
234
266
|
this.logger.debug('TransportClient - rpcSingle', module, method, body)
|
|
235
267
|
return new Promise<Response>((resolve, reject) => {
|
|
236
|
-
this.rpcStream<Response>(
|
|
268
|
+
this.rpcStream<Response>(
|
|
269
|
+
module,
|
|
270
|
+
method,
|
|
271
|
+
body,
|
|
272
|
+
clientName,
|
|
273
|
+
resolve,
|
|
274
|
+
reject,
|
|
275
|
+
)
|
|
237
276
|
})
|
|
238
277
|
}
|
|
239
278
|
|
|
240
279
|
async cleanup() {
|
|
241
|
-
await this.sendSingleMessage('cleanup')
|
|
280
|
+
const res = await this.sendSingleMessage('cleanup')
|
|
281
|
+
this.logger.info('TransportClient - cleanup', res)
|
|
242
282
|
this.requestCounter = 0
|
|
243
283
|
this.initPromise = undefined
|
|
244
284
|
this.requestCallbacks.clear()
|
package/src/utils/logger.ts
CHANGED
|
@@ -23,8 +23,8 @@ export class Logger {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
private coerceLevel(level: string): LogLevel {
|
|
26
|
-
if (logLevels.includes(level.
|
|
27
|
-
return level.
|
|
26
|
+
if (logLevels.includes(level.toLowerCase() as LogLevel)) {
|
|
27
|
+
return level.toLowerCase() as LogLevel
|
|
28
28
|
}
|
|
29
29
|
return 'info'
|
|
30
30
|
}
|
|
@@ -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
|
-
)
|