@lightsparkdev/lightspark-sdk 1.2.1 → 1.2.2
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 +6 -0
- package/dist/{chunk-VTPDR6P4.js → chunk-GLL4KTUT.js} +353 -15
- package/dist/{index-5acc6526.d.ts → index-eb604025.d.ts} +662 -3
- package/dist/index.cjs +654 -76
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +265 -17
- package/dist/objects/index.cjs +345 -5
- package/dist/objects/index.d.cts +1 -1
- package/dist/objects/index.d.ts +1 -1
- package/dist/objects/index.js +9 -1
- package/package.json +1 -1
- package/src/client.ts +194 -1
- package/src/graphql/ClaimUmaInvitation.ts +21 -0
- package/src/graphql/ClaimUmaInvitationWithIncentives.ts +25 -0
- package/src/graphql/CreateUmaInvitation.ts +19 -0
- package/src/graphql/CreateUmaInvitationWithIncentives.ts +23 -0
- package/src/graphql/FetchUmaInvitation.ts +15 -0
- package/src/objects/ClaimUmaInvitationInput.ts +26 -0
- package/src/objects/ClaimUmaInvitationOutput.ts +30 -0
- package/src/objects/ClaimUmaInvitationWithIncentivesInput.ts +44 -0
- package/src/objects/ClaimUmaInvitationWithIncentivesOutput.ts +33 -0
- package/src/objects/CreateInvitationWithIncentivesInput.ts +37 -0
- package/src/objects/CreateInvitationWithIncentivesOutput.ts +32 -0
- package/src/objects/CreateUmaInvitationInput.ts +22 -0
- package/src/objects/CreateUmaInvitationOutput.ts +30 -0
- package/src/objects/Entity.ts +13 -0
- package/src/objects/IncentivesIneligibilityReason.ts +24 -0
- package/src/objects/IncentivesStatus.ts +18 -0
- package/src/objects/OutgoingPayment.ts +1 -0
- package/src/objects/OutgoingPaymentAttempt.ts +6 -1
- package/src/objects/RegionCode.ts +510 -0
- package/src/objects/UmaInvitation.ts +113 -0
- package/src/objects/WebhookEventType.ts +4 -0
- package/src/objects/index.ts +15 -0
- package/src/tests/integration/constants.ts +0 -3
- package/src/tests/integration/general-regtest.test.ts +177 -196
package/src/objects/index.ts
CHANGED
|
@@ -22,10 +22,16 @@ export {
|
|
|
22
22
|
export { default as ChannelSnapshot } from "./ChannelSnapshot.js";
|
|
23
23
|
export { default as ChannelStatus } from "./ChannelStatus.js";
|
|
24
24
|
export { default as ChannelToTransactionsConnection } from "./ChannelToTransactionsConnection.js";
|
|
25
|
+
export { default as ClaimUmaInvitationInput } from "./ClaimUmaInvitationInput.js";
|
|
26
|
+
export { default as ClaimUmaInvitationOutput } from "./ClaimUmaInvitationOutput.js";
|
|
27
|
+
export { default as ClaimUmaInvitationWithIncentivesInput } from "./ClaimUmaInvitationWithIncentivesInput.js";
|
|
28
|
+
export { default as ClaimUmaInvitationWithIncentivesOutput } from "./ClaimUmaInvitationWithIncentivesOutput.js";
|
|
25
29
|
export { default as ComplianceProvider } from "./ComplianceProvider.js";
|
|
26
30
|
export { default as Connection } from "./Connection.js";
|
|
27
31
|
export { default as CreateApiTokenInput } from "./CreateApiTokenInput.js";
|
|
28
32
|
export { default as CreateApiTokenOutput } from "./CreateApiTokenOutput.js";
|
|
33
|
+
export { default as CreateInvitationWithIncentivesInput } from "./CreateInvitationWithIncentivesInput.js";
|
|
34
|
+
export { default as CreateInvitationWithIncentivesOutput } from "./CreateInvitationWithIncentivesOutput.js";
|
|
29
35
|
export { default as CreateInvoiceInput } from "./CreateInvoiceInput.js";
|
|
30
36
|
export { default as CreateInvoiceOutput } from "./CreateInvoiceOutput.js";
|
|
31
37
|
export { default as CreateLnurlInvoiceInput } from "./CreateLnurlInvoiceInput.js";
|
|
@@ -35,6 +41,8 @@ export { default as CreateTestModeInvoiceInput } from "./CreateTestModeInvoiceIn
|
|
|
35
41
|
export { default as CreateTestModeInvoiceOutput } from "./CreateTestModeInvoiceOutput.js";
|
|
36
42
|
export { default as CreateTestModePaymentInput } from "./CreateTestModePaymentInput.js";
|
|
37
43
|
export { default as CreateTestModePaymentoutput } from "./CreateTestModePaymentoutput.js";
|
|
44
|
+
export { default as CreateUmaInvitationInput } from "./CreateUmaInvitationInput.js";
|
|
45
|
+
export { default as CreateUmaInvitationOutput } from "./CreateUmaInvitationOutput.js";
|
|
38
46
|
export { default as CreateUmaInvoiceInput } from "./CreateUmaInvoiceInput.js";
|
|
39
47
|
export { default as CurrencyAmount } from "./CurrencyAmount.js";
|
|
40
48
|
export { default as CurrencyUnit } from "./CurrencyUnit.js";
|
|
@@ -51,6 +59,8 @@ export { default as GraphNode } from "./GraphNode.js";
|
|
|
51
59
|
export { default as Hop, getHopQuery } from "./Hop.js";
|
|
52
60
|
export { default as HtlcAttemptFailureCode } from "./HtlcAttemptFailureCode.js";
|
|
53
61
|
export { default as IdAndSignature } from "./IdAndSignature.js";
|
|
62
|
+
export { default as IncentivesIneligibilityReason } from "./IncentivesIneligibilityReason.js";
|
|
63
|
+
export { default as IncentivesStatus } from "./IncentivesStatus.js";
|
|
54
64
|
export { default as IncomingPayment } from "./IncomingPayment.js";
|
|
55
65
|
export {
|
|
56
66
|
default as IncomingPaymentAttempt,
|
|
@@ -109,6 +119,7 @@ export { default as PaymentRequestStatus } from "./PaymentRequestStatus.js";
|
|
|
109
119
|
export { default as PayUmaInvoiceInput } from "./PayUmaInvoiceInput.js";
|
|
110
120
|
export { default as Permission } from "./Permission.js";
|
|
111
121
|
export { default as PostTransactionData } from "./PostTransactionData.js";
|
|
122
|
+
export { default as RegionCode } from "./RegionCode.js";
|
|
112
123
|
export { default as RegisterPaymentInput } from "./RegisterPaymentInput.js";
|
|
113
124
|
export { default as RegisterPaymentOutput } from "./RegisterPaymentOutput.js";
|
|
114
125
|
export { default as ReleaseChannelPerCommitmentSecretInput } from "./ReleaseChannelPerCommitmentSecretInput.js";
|
|
@@ -148,6 +159,10 @@ export { default as TransactionFailures } from "./TransactionFailures.js";
|
|
|
148
159
|
export { default as TransactionStatus } from "./TransactionStatus.js";
|
|
149
160
|
export { default as TransactionType } from "./TransactionType.js";
|
|
150
161
|
export { default as TransactionUpdate } from "./TransactionUpdate.js";
|
|
162
|
+
export {
|
|
163
|
+
default as UmaInvitation,
|
|
164
|
+
getUmaInvitationQuery,
|
|
165
|
+
} from "./UmaInvitation.js";
|
|
151
166
|
export { default as UpdateChannelPerCommitmentPointInput } from "./UpdateChannelPerCommitmentPointInput.js";
|
|
152
167
|
export { default as UpdateChannelPerCommitmentPointOutput } from "./UpdateChannelPerCommitmentPointOutput.js";
|
|
153
168
|
export { default as UpdateNodeSharedSecretInput } from "./UpdateNodeSharedSecretInput.js";
|
|
@@ -5,9 +5,6 @@ export const INVOICE_EXPIRY = 172800; //ms
|
|
|
5
5
|
export const TRANSACTION_WAIT_TIME = TESTS_TIMEOUT / 1000; //seconds
|
|
6
6
|
export const PAGINATION_STEP = 3;
|
|
7
7
|
|
|
8
|
-
export const PAY_AMOUNT = 1_000; //msats
|
|
9
|
-
export const MAX_FEE = 10000000; //msats
|
|
10
|
-
|
|
11
8
|
export const REGTEST_SIGNING_KEY_PASSWORD = "1234!@#$";
|
|
12
9
|
export const ENCODED_REGTEST_REQUEST_FOR_TESTS =
|
|
13
10
|
"lnbcrt1pjj6zu2pp50qr2p79v65u9l8w3859259yj9fe5nt79hfw5k2am424440tlj09qdq0dp5jqargv4ex2ggcqzpgxqyz5vqsp5v0z0fu99jf37xcasu88evuphx9kdrpvtupdvhu329kx7k7un59zs9qyyssqegzx986rszy96te2kmxl7prlz0p8avthpwzhsz5v220uek7xxrz54svdsjpzwn04m6utj5ua9tmtktygc5xmjmjaqey9dadt33r8gxspvcg8wv";
|
|
@@ -18,35 +18,42 @@ import {
|
|
|
18
18
|
OutgoingPayment,
|
|
19
19
|
PaymentRequestStatus,
|
|
20
20
|
TransactionStatus,
|
|
21
|
+
WithdrawalMode,
|
|
22
|
+
WithdrawalRequestStatus,
|
|
21
23
|
type AccountToNodesConnection,
|
|
22
24
|
} from "../../index.js";
|
|
23
25
|
import { logger } from "../../logger.js";
|
|
26
|
+
import WithdrawalRequest from "../../objects/WithdrawalRequest.js";
|
|
24
27
|
import {
|
|
25
28
|
DAY_IN_MS,
|
|
26
29
|
ENCODED_REGTEST_REQUEST_FOR_TESTS,
|
|
27
30
|
INVOICE_EXPIRY,
|
|
28
31
|
LONG_TEST_TIMEOUT,
|
|
29
|
-
MAX_FEE,
|
|
30
32
|
PAGINATION_STEP,
|
|
31
|
-
PAY_AMOUNT,
|
|
32
33
|
REGTEST_SIGNING_KEY_PASSWORD,
|
|
33
34
|
TESTS_TIMEOUT,
|
|
34
35
|
TRANSACTION_WAIT_TIME,
|
|
35
36
|
} from "./constants.js";
|
|
36
37
|
|
|
38
|
+
const TEST_MODE_L1_WITHDRAWAL_ADDRESS =
|
|
39
|
+
"bcrt1qnuyejmm2l4kavspq0jqaw0fv07lg6zv3z9z3te";
|
|
40
|
+
|
|
37
41
|
const unauthorizedLightsparkClient = new LightsparkClient();
|
|
38
42
|
|
|
39
43
|
const { apiTokenClientId, apiTokenClientSecret, baseUrl } =
|
|
40
44
|
getCredentialsFromEnvOrThrow();
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
const accountAuthProvider = new AccountTokenAuthProvider(
|
|
47
|
+
apiTokenClientId,
|
|
48
|
+
apiTokenClientSecret,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
|
|
52
|
+
|
|
43
53
|
let paymentInvoice: string | undefined;
|
|
44
54
|
let regtestNodeId: string | undefined;
|
|
45
55
|
let invoicePayment: OutgoingPayment | undefined;
|
|
46
56
|
|
|
47
|
-
const pollIntervalMs = 750;
|
|
48
|
-
const pollTimeoutSecs = 20;
|
|
49
|
-
const pollMaxTimeouts = (pollTimeoutSecs * 1000) / pollIntervalMs;
|
|
50
57
|
const pollIgnoreErrors = false;
|
|
51
58
|
|
|
52
59
|
let nodesConnection: AccountToNodesConnection | undefined;
|
|
@@ -56,28 +63,6 @@ const testModeInvoices: Record<string, string | null> = {
|
|
|
56
63
|
withoutMemo: null,
|
|
57
64
|
};
|
|
58
65
|
|
|
59
|
-
const createTestModePayment = async () => {
|
|
60
|
-
const regtestNodeId = getRegtestNodeId();
|
|
61
|
-
const testInvoice = await lightsparkClient.createInvoice(
|
|
62
|
-
regtestNodeId,
|
|
63
|
-
PAY_AMOUNT,
|
|
64
|
-
"hi there!",
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
if (!testInvoice) {
|
|
68
|
-
throw new TypeError("Test invoice wasn't created");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const payment = await lightsparkClient.createTestModePayment(
|
|
72
|
-
regtestNodeId,
|
|
73
|
-
testInvoice,
|
|
74
|
-
);
|
|
75
|
-
if (!payment) {
|
|
76
|
-
throw new TypeError("Test mode payment wasn't created");
|
|
77
|
-
}
|
|
78
|
-
return payment;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
66
|
const initSuiteName = "initialization";
|
|
82
67
|
const p0SuiteName = "p0";
|
|
83
68
|
const p1SuiteName = "p1";
|
|
@@ -126,18 +111,98 @@ async function getRegtestNode() {
|
|
|
126
111
|
return regtestNode;
|
|
127
112
|
}
|
|
128
113
|
|
|
114
|
+
const createTestModePayment = async () => {
|
|
115
|
+
const regtestNodeId = getRegtestNodeId();
|
|
116
|
+
const testInvoice = await lightsparkClient.createInvoice(
|
|
117
|
+
regtestNodeId,
|
|
118
|
+
10_000,
|
|
119
|
+
"hi there!",
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if (!testInvoice) {
|
|
123
|
+
throw new TypeError("Test invoice wasn't created");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const payment = await lightsparkClient.createTestModePayment(
|
|
127
|
+
regtestNodeId,
|
|
128
|
+
testInvoice,
|
|
129
|
+
);
|
|
130
|
+
if (!payment) {
|
|
131
|
+
throw new TypeError("Test mode payment wasn't created");
|
|
132
|
+
}
|
|
133
|
+
return payment;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
async function fundNode(satsToFund: number) {
|
|
137
|
+
let regtestNode = await getRegtestNode();
|
|
138
|
+
|
|
139
|
+
const initialSendBalance = mapCurrencyAmount(
|
|
140
|
+
regtestNode?.balances?.availableToSendBalance,
|
|
141
|
+
);
|
|
142
|
+
log("initialSendBalance.sats", initialSendBalance.sats);
|
|
143
|
+
|
|
144
|
+
const nodeId = getRegtestNodeId();
|
|
145
|
+
|
|
146
|
+
log(`Funding node ${nodeId} with ${satsToFund} sats`);
|
|
147
|
+
await lightsparkClient.fundNode(nodeId, satsToFund);
|
|
148
|
+
|
|
149
|
+
regtestNode = await pollUntil(
|
|
150
|
+
() => {
|
|
151
|
+
return getRegtestNode();
|
|
152
|
+
},
|
|
153
|
+
(current, response) => {
|
|
154
|
+
if (
|
|
155
|
+
current &&
|
|
156
|
+
!mapCurrencyAmount(current.balances?.availableToSendBalance).isEqualTo(
|
|
157
|
+
initialSendBalance,
|
|
158
|
+
)
|
|
159
|
+
) {
|
|
160
|
+
return {
|
|
161
|
+
stopPolling: true,
|
|
162
|
+
value: current,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return response;
|
|
166
|
+
},
|
|
167
|
+
(10 * 60 * 1000) / 3000 /* can take several minutes */,
|
|
168
|
+
3000,
|
|
169
|
+
pollIgnoreErrors,
|
|
170
|
+
() => new Error("Timeout waiting for node to be funded"),
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const balances = regtestNode?.balances;
|
|
174
|
+
if (!balances) {
|
|
175
|
+
throw new Error("No balances property on node");
|
|
176
|
+
}
|
|
177
|
+
log(
|
|
178
|
+
"regtestNode.balances.availableToSend sats",
|
|
179
|
+
mapCurrencyAmount(balances.availableToSendBalance).sats,
|
|
180
|
+
);
|
|
181
|
+
log(
|
|
182
|
+
"regtestNode.balances.ownedBalance sats",
|
|
183
|
+
mapCurrencyAmount(balances.ownedBalance).sats,
|
|
184
|
+
);
|
|
185
|
+
log(
|
|
186
|
+
"regtestNode.balances.withdrawableBalance sats",
|
|
187
|
+
mapCurrencyAmount(balances.availableToWithdrawBalance).sats,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
expect(
|
|
191
|
+
mapCurrencyAmount(regtestNode.balances?.availableToSendBalance).isEqualTo(
|
|
192
|
+
initialSendBalance,
|
|
193
|
+
),
|
|
194
|
+
).toBe(false);
|
|
195
|
+
|
|
196
|
+
return regtestNode;
|
|
197
|
+
}
|
|
198
|
+
|
|
129
199
|
describe(initSuiteName, () => {
|
|
130
|
-
test("
|
|
131
|
-
const accountAuthProvider = new AccountTokenAuthProvider(
|
|
132
|
-
apiTokenClientId,
|
|
133
|
-
apiTokenClientSecret,
|
|
134
|
-
);
|
|
135
|
-
lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl);
|
|
200
|
+
test("Should get env vars and construct the client successfully", () => {
|
|
136
201
|
expect(lightsparkClient).toBeDefined();
|
|
137
202
|
});
|
|
138
203
|
|
|
139
204
|
test(
|
|
140
|
-
"Should successfully get the current account regtest node and
|
|
205
|
+
"Should successfully get the current account regtest node and use it for the current test suite",
|
|
141
206
|
async () => {
|
|
142
207
|
const account = await getAccount();
|
|
143
208
|
nodesConnection = await account.getNodes(lightsparkClient, 1, [
|
|
@@ -166,7 +231,7 @@ describe(p0SuiteName, () => {
|
|
|
166
231
|
test("Should create a normal payment invoice", async () => {
|
|
167
232
|
paymentInvoice = await lightsparkClient.createInvoice(
|
|
168
233
|
getRegtestNodeId(),
|
|
169
|
-
|
|
234
|
+
10_000,
|
|
170
235
|
"hi there!",
|
|
171
236
|
);
|
|
172
237
|
expect(paymentInvoice).toBeDefined();
|
|
@@ -175,7 +240,7 @@ describe(p0SuiteName, () => {
|
|
|
175
240
|
test("Should create a AMP type invoice", async () => {
|
|
176
241
|
const AmpPaymentInvoice = await lightsparkClient.createInvoice(
|
|
177
242
|
getRegtestNodeId(),
|
|
178
|
-
|
|
243
|
+
10_000,
|
|
179
244
|
"hi there!",
|
|
180
245
|
InvoiceType.AMP,
|
|
181
246
|
);
|
|
@@ -186,7 +251,7 @@ describe(p0SuiteName, () => {
|
|
|
186
251
|
const AmpPaymentInvoiceWithExpiration =
|
|
187
252
|
await lightsparkClient.createInvoice(
|
|
188
253
|
getRegtestNodeId(),
|
|
189
|
-
|
|
254
|
+
10_000,
|
|
190
255
|
"hi there!",
|
|
191
256
|
InvoiceType.STANDARD,
|
|
192
257
|
INVOICE_EXPIRY,
|
|
@@ -205,7 +270,7 @@ describe(p0SuiteName, () => {
|
|
|
205
270
|
expect(AnyPaymentAmountInvoice).toBeDefined();
|
|
206
271
|
});
|
|
207
272
|
|
|
208
|
-
test("
|
|
273
|
+
test("Should throw an error on create an unauthorized invoice", async () => {
|
|
209
274
|
await expect(
|
|
210
275
|
unauthorizedLightsparkClient.createInvoice(
|
|
211
276
|
getRegtestNodeId(),
|
|
@@ -215,114 +280,68 @@ describe(p0SuiteName, () => {
|
|
|
215
280
|
).rejects.toThrowError();
|
|
216
281
|
});
|
|
217
282
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
regtestNode?.balances?.ownedBalance,
|
|
224
|
-
);
|
|
225
|
-
const initialSendBalance = mapCurrencyAmount(
|
|
226
|
-
regtestNode?.balances?.availableToSendBalance,
|
|
227
|
-
);
|
|
228
|
-
log("initialOwnedBalance.sats", initialOwnedBalance.sats);
|
|
229
|
-
log("initialSendBalance.sats", initialSendBalance.sats);
|
|
230
|
-
|
|
231
|
-
const nodeId = getRegtestNodeId();
|
|
232
|
-
|
|
233
|
-
const targetBalanceSats = 40_000_000;
|
|
234
|
-
/* Backend will error on fund_node if total balance is greater than 100,000,000 sats, so we should
|
|
235
|
-
adjust to a target balance less than that: */
|
|
236
|
-
if (initialOwnedBalance.sats > targetBalanceSats) {
|
|
237
|
-
const invoiceAmount = initialOwnedBalance.sats - targetBalanceSats;
|
|
238
|
-
log("adjusting balance: invoiceAmount sats", invoiceAmount);
|
|
239
|
-
|
|
240
|
-
await lightsparkClient.loadNodeSigningKey(getRegtestNodeId(), {
|
|
241
|
-
password: REGTEST_SIGNING_KEY_PASSWORD,
|
|
242
|
-
});
|
|
283
|
+
test(
|
|
284
|
+
"Should withdraw all funds from the node, also causing all channels to be closed",
|
|
285
|
+
async () => {
|
|
286
|
+
// first make sure we have a balance to withdraw
|
|
287
|
+
let regtestNode = await getRegtestNode();
|
|
243
288
|
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
round((initialOwnedBalance.sats - targetBalanceSats) * 1000), // convert to msats
|
|
289
|
+
const initialSendBalance = mapCurrencyAmount(
|
|
290
|
+
regtestNode?.balances?.availableToSendBalance,
|
|
247
291
|
);
|
|
292
|
+
log("initialSendBalance.sats", initialSendBalance.sats);
|
|
248
293
|
|
|
249
|
-
if (
|
|
250
|
-
|
|
294
|
+
if (initialSendBalance.sats < 100_000) {
|
|
295
|
+
regtestNode = await fundNode(100_000);
|
|
251
296
|
}
|
|
252
297
|
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
298
|
+
const withdrawalRequest = await lightsparkClient.requestWithdrawal(
|
|
299
|
+
getRegtestNodeId(),
|
|
300
|
+
-1,
|
|
301
|
+
TEST_MODE_L1_WITHDRAWAL_ADDRESS,
|
|
302
|
+
WithdrawalMode.WALLET_THEN_CHANNELS,
|
|
258
303
|
);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
304
|
+
expect(withdrawalRequest).toBeDefined();
|
|
305
|
+
const completedWithdrawalRequest: WithdrawalRequest = await pollUntil(
|
|
306
|
+
() =>
|
|
307
|
+
lightsparkClient.executeRawQuery(
|
|
308
|
+
WithdrawalRequest.getWithdrawalRequestQuery(withdrawalRequest.id),
|
|
309
|
+
),
|
|
310
|
+
(current, response) => {
|
|
311
|
+
if (
|
|
312
|
+
current &&
|
|
313
|
+
![
|
|
314
|
+
WithdrawalRequestStatus.IN_PROGRESS,
|
|
315
|
+
WithdrawalRequestStatus.CREATED,
|
|
316
|
+
].includes(current.status)
|
|
317
|
+
) {
|
|
318
|
+
return {
|
|
319
|
+
stopPolling: true,
|
|
320
|
+
value: current,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return response;
|
|
324
|
+
},
|
|
325
|
+
(10 * 60 * 1000) / 3000 /* can take several minutes */,
|
|
326
|
+
3000,
|
|
327
|
+
pollIgnoreErrors,
|
|
328
|
+
() => new Error("Timeout waiting for payment to be received"),
|
|
267
329
|
);
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
log(`Funding node ${nodeId} with ${satsToFund} sats`);
|
|
277
|
-
await lightsparkClient.fundNode(nodeId, satsToFund);
|
|
278
|
-
|
|
279
|
-
regtestNode = await pollUntil(
|
|
280
|
-
() => {
|
|
281
|
-
return getRegtestNode();
|
|
282
|
-
},
|
|
283
|
-
(current, response) => {
|
|
284
|
-
if (
|
|
285
|
-
current &&
|
|
286
|
-
!mapCurrencyAmount(
|
|
287
|
-
current.balances?.availableToSendBalance,
|
|
288
|
-
).isEqualTo(initialSendBalance)
|
|
289
|
-
) {
|
|
290
|
-
return {
|
|
291
|
-
stopPolling: true,
|
|
292
|
-
value: current,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
return response;
|
|
296
|
-
},
|
|
297
|
-
pollIntervalMs,
|
|
298
|
-
pollMaxTimeouts,
|
|
299
|
-
pollIgnoreErrors,
|
|
300
|
-
() => new Error("Timeout waiting for payment to be received"),
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
const balances = regtestNode?.balances;
|
|
304
|
-
if (!balances) {
|
|
305
|
-
throw new Error("No balances property on node");
|
|
306
|
-
}
|
|
307
|
-
log(
|
|
308
|
-
"regtestNode.balances.availableToSend sats",
|
|
309
|
-
mapCurrencyAmount(balances.availableToSendBalance).sats,
|
|
310
|
-
);
|
|
311
|
-
log(
|
|
312
|
-
"regtestNode.balances.ownedBalance sats",
|
|
313
|
-
mapCurrencyAmount(balances.ownedBalance).sats,
|
|
314
|
-
);
|
|
315
|
-
log(
|
|
316
|
-
"regtestNode.balances.withdrawableBalance sats",
|
|
317
|
-
mapCurrencyAmount(balances.availableToWithdrawBalance).sats,
|
|
318
|
-
);
|
|
330
|
+
expect(completedWithdrawalRequest.status).toBe(
|
|
331
|
+
WithdrawalRequestStatus.SUCCESSFUL,
|
|
332
|
+
);
|
|
333
|
+
},
|
|
334
|
+
10 * 60 * 1000 /* can take several minutes */,
|
|
335
|
+
);
|
|
319
336
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
337
|
+
const satsToFund = 10_000_000;
|
|
338
|
+
test(
|
|
339
|
+
"Should deposit funds to node with a defined amount of sats",
|
|
340
|
+
async () => {
|
|
341
|
+
await fundNode(10_000_000);
|
|
342
|
+
},
|
|
343
|
+
10 * 60 * 1000 /* can take several minutes */,
|
|
344
|
+
);
|
|
326
345
|
|
|
327
346
|
test("Should pay an invoice", async () => {
|
|
328
347
|
const node = await getRegtestNode();
|
|
@@ -333,7 +352,7 @@ describe(p0SuiteName, () => {
|
|
|
333
352
|
|
|
334
353
|
const testInvoice = await lightsparkClient.createTestModeInvoice(
|
|
335
354
|
getRegtestNodeId(),
|
|
336
|
-
|
|
355
|
+
round(satsToFund / 4), // should be some small fraction of the sats we know we have from earlier funding test
|
|
337
356
|
"hi there!",
|
|
338
357
|
);
|
|
339
358
|
|
|
@@ -344,19 +363,12 @@ describe(p0SuiteName, () => {
|
|
|
344
363
|
invoicePayment = await lightsparkClient.payInvoice(
|
|
345
364
|
getRegtestNodeId(),
|
|
346
365
|
testInvoice,
|
|
347
|
-
|
|
366
|
+
10_000_000,
|
|
348
367
|
TESTS_TIMEOUT,
|
|
349
368
|
);
|
|
350
369
|
expect(invoicePayment).toBeDefined();
|
|
351
370
|
});
|
|
352
371
|
|
|
353
|
-
// TODO: THIS ACTION CAN BE CREATED ONLY IN MAINNET
|
|
354
|
-
// test('Should deposit funds to node with a defined amount of sats', async () => {
|
|
355
|
-
// const fundingResult = await lightsparkClient.requestWithdrawal(getRegtestNodeId(), PAY_AMOUNT, '', WithdrawalMode.WALLET_THEN_CHANNELS)
|
|
356
|
-
// const transaction = await lightsparkClient.waitForTransactionComplete(fundingResult.id, TRANSACTION_WAIT_TIME)
|
|
357
|
-
// expect(transaction.status).toBe(TransactionStatus.SUCCESS)
|
|
358
|
-
// }, TRANSACTION_WAIT_TIME)
|
|
359
|
-
|
|
360
372
|
test(
|
|
361
373
|
"Should open just-in-time channel from inbound payment",
|
|
362
374
|
async () => {
|
|
@@ -373,7 +385,7 @@ describe(p0SuiteName, () => {
|
|
|
373
385
|
|
|
374
386
|
describe(p1SuiteName, () => {
|
|
375
387
|
test(
|
|
376
|
-
"
|
|
388
|
+
"Should fetch the current account",
|
|
377
389
|
async () => {
|
|
378
390
|
const wallet = await lightsparkClient.getCurrentAccount();
|
|
379
391
|
expect(wallet?.id).toBeDefined();
|
|
@@ -382,7 +394,7 @@ describe(p1SuiteName, () => {
|
|
|
382
394
|
);
|
|
383
395
|
|
|
384
396
|
test(
|
|
385
|
-
"
|
|
397
|
+
"Should fetch the current account from unauthorized client",
|
|
386
398
|
async () => {
|
|
387
399
|
await expect(
|
|
388
400
|
unauthorizedLightsparkClient.getCurrentAccount(),
|
|
@@ -392,7 +404,7 @@ describe(p1SuiteName, () => {
|
|
|
392
404
|
);
|
|
393
405
|
|
|
394
406
|
test(
|
|
395
|
-
"
|
|
407
|
+
"Should listen current payment requests",
|
|
396
408
|
async () => {
|
|
397
409
|
for (let i = 0; i < PAGINATION_STEP; i++) {
|
|
398
410
|
await createTestModePayment();
|
|
@@ -408,7 +420,7 @@ describe(p1SuiteName, () => {
|
|
|
408
420
|
);
|
|
409
421
|
|
|
410
422
|
test(
|
|
411
|
-
"
|
|
423
|
+
"Should listen current payment requests after some date",
|
|
412
424
|
async () => {
|
|
413
425
|
const requestsAfterDate = dayjs(Date.now() - DAY_IN_MS).format();
|
|
414
426
|
const requests = await lightsparkClient.getRecentPaymentRequests(
|
|
@@ -423,7 +435,7 @@ describe(p1SuiteName, () => {
|
|
|
423
435
|
);
|
|
424
436
|
|
|
425
437
|
test(
|
|
426
|
-
"
|
|
438
|
+
"Should listen current payment requests from unauthorized client",
|
|
427
439
|
async () => {
|
|
428
440
|
await expect(
|
|
429
441
|
unauthorizedLightsparkClient.getRecentPaymentRequests(
|
|
@@ -437,7 +449,7 @@ describe(p1SuiteName, () => {
|
|
|
437
449
|
);
|
|
438
450
|
|
|
439
451
|
test(
|
|
440
|
-
"
|
|
452
|
+
"Should list recent transactions",
|
|
441
453
|
async () => {
|
|
442
454
|
const transactions = await lightsparkClient.getRecentTransactions(
|
|
443
455
|
getRegtestNodeId(),
|
|
@@ -449,7 +461,7 @@ describe(p1SuiteName, () => {
|
|
|
449
461
|
TESTS_TIMEOUT,
|
|
450
462
|
);
|
|
451
463
|
|
|
452
|
-
test("
|
|
464
|
+
test("Should fetch an invoices payment by IDs", () => {
|
|
453
465
|
if (!invoicePayment?.id) throw new TypeError("invoicePayment is null");
|
|
454
466
|
|
|
455
467
|
const payment = OutgoingPayment.getOutgoingPaymentQuery(invoicePayment?.id);
|
|
@@ -458,7 +470,7 @@ describe(p1SuiteName, () => {
|
|
|
458
470
|
});
|
|
459
471
|
|
|
460
472
|
test(
|
|
461
|
-
"
|
|
473
|
+
"Should decode an invoice",
|
|
462
474
|
async () => {
|
|
463
475
|
const decodedInvoice = await lightsparkClient.decodeInvoice(
|
|
464
476
|
ENCODED_REGTEST_REQUEST_FOR_TESTS,
|
|
@@ -474,11 +486,11 @@ describe(p1SuiteName, () => {
|
|
|
474
486
|
);
|
|
475
487
|
|
|
476
488
|
test(
|
|
477
|
-
"
|
|
489
|
+
"Should create STANDARD a test mode invoice",
|
|
478
490
|
async () => {
|
|
479
491
|
testModeInvoices.withMemo = await lightsparkClient.createTestModeInvoice(
|
|
480
492
|
getRegtestNodeId(),
|
|
481
|
-
|
|
493
|
+
10_000,
|
|
482
494
|
"hi there!",
|
|
483
495
|
);
|
|
484
496
|
expect(testModeInvoices.withMemo).not.toBeNull();
|
|
@@ -487,7 +499,7 @@ describe(p1SuiteName, () => {
|
|
|
487
499
|
);
|
|
488
500
|
|
|
489
501
|
test(
|
|
490
|
-
"
|
|
502
|
+
"Should create an AMP a test mode invoice",
|
|
491
503
|
async () => {
|
|
492
504
|
const testInvoice = await lightsparkClient.createTestModeInvoice(
|
|
493
505
|
getRegtestNodeId(),
|
|
@@ -501,7 +513,7 @@ describe(p1SuiteName, () => {
|
|
|
501
513
|
);
|
|
502
514
|
|
|
503
515
|
test(
|
|
504
|
-
"
|
|
516
|
+
"Should create a clear memo test mode invoice",
|
|
505
517
|
async () => {
|
|
506
518
|
testModeInvoices.withoutMemo =
|
|
507
519
|
await lightsparkClient.createTestModeInvoice(getRegtestNodeId(), 0);
|
|
@@ -511,32 +523,13 @@ describe(p1SuiteName, () => {
|
|
|
511
523
|
);
|
|
512
524
|
|
|
513
525
|
test(
|
|
514
|
-
"
|
|
515
|
-
async () => {
|
|
516
|
-
if (!testModeInvoices.withoutMemo) {
|
|
517
|
-
throw new TypeError("Test mode invoice wasn't created");
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
const invoicePayment = await lightsparkClient.payInvoice(
|
|
521
|
-
getRegtestNodeId(),
|
|
522
|
-
testModeInvoices.withoutMemo,
|
|
523
|
-
MAX_FEE,
|
|
524
|
-
TESTS_TIMEOUT,
|
|
525
|
-
PAY_AMOUNT,
|
|
526
|
-
);
|
|
527
|
-
expect(invoicePayment).toBeDefined();
|
|
528
|
-
},
|
|
529
|
-
TESTS_TIMEOUT,
|
|
530
|
-
);
|
|
531
|
-
|
|
532
|
-
test(
|
|
533
|
-
"should create a test mode payment",
|
|
526
|
+
"Should create a test mode payment",
|
|
534
527
|
async () => {
|
|
535
528
|
const regtestNodeId = getRegtestNodeId();
|
|
536
529
|
|
|
537
530
|
const invoiceForTestPayment = await lightsparkClient.createInvoice(
|
|
538
531
|
regtestNodeId,
|
|
539
|
-
|
|
532
|
+
10_000,
|
|
540
533
|
"hi there!",
|
|
541
534
|
);
|
|
542
535
|
|
|
@@ -564,7 +557,7 @@ describe(p1SuiteName, () => {
|
|
|
564
557
|
);
|
|
565
558
|
|
|
566
559
|
test(
|
|
567
|
-
"
|
|
560
|
+
"Should successfully create an uma invoice",
|
|
568
561
|
async () => {
|
|
569
562
|
const nodeId = getRegtestNodeId();
|
|
570
563
|
|
|
@@ -586,7 +579,7 @@ describe(p1SuiteName, () => {
|
|
|
586
579
|
|
|
587
580
|
describe(p2SuiteName, () => {
|
|
588
581
|
test(
|
|
589
|
-
"
|
|
582
|
+
"Should get a bitcoin fee estimate",
|
|
590
583
|
async () => {
|
|
591
584
|
const fee = await lightsparkClient.getBitcoinFeeEstimate();
|
|
592
585
|
expect(fee).not.toBeNull();
|
|
@@ -594,20 +587,8 @@ describe(p2SuiteName, () => {
|
|
|
594
587
|
TESTS_TIMEOUT,
|
|
595
588
|
);
|
|
596
589
|
|
|
597
|
-
// FIXME: THIS ACTION WORKS ONLY IN MAINNET
|
|
598
|
-
// test('should send a keysend payment', async () => {
|
|
599
|
-
// const payment = await lightsparkClient.sendPayment(
|
|
600
|
-
// getRegtestNodeId(),
|
|
601
|
-
// '018afbd7e2fd4f890000ac5e051e3488',
|
|
602
|
-
// TESTS_TIMEOUT,
|
|
603
|
-
// PAY_AMOUNT,
|
|
604
|
-
// MAX_FEE
|
|
605
|
-
// )
|
|
606
|
-
// expect(payment?.status).not.toBe(TransactionStatus.FAILED)
|
|
607
|
-
// })
|
|
608
|
-
|
|
609
590
|
test(
|
|
610
|
-
"
|
|
591
|
+
"Should execute a raw graphql query",
|
|
611
592
|
async () => {
|
|
612
593
|
type DecodeInvoiceQueryResult = {
|
|
613
594
|
decoded_payment_request: {
|