Skip to content

Commit a4e14d3

Browse files
committed
fix: sync with master
2 parents e6e6ce0 + 70b747c commit a4e14d3

File tree

21 files changed

+700
-253
lines changed

21 files changed

+700
-253
lines changed

.github/workflows/e2e-ios.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
- name: Restart docker before last attempt
107107
if: steps.test1.outcome != 'success' && steps.test2.outcome != 'success' && steps.test3.outcome != 'success'
108108
run: |
109-
cd docker && docker-compose down && docker-compose up -d && cd ..
109+
cd docker && docker-compose down -t 60 && docker-compose up -d && cd ..
110110
while ! nc -z '127.0.0.1' 60001; do sleep 1; done
111111
112112
- name: Test attempt 4

__tests__/reselect.ts

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
import assert from 'node:assert';
2+
import cloneDeep from 'lodash/cloneDeep';
3+
import { TChannel } from '@synonymdev/react-native-ldk';
4+
5+
import '../src/utils/i18n';
6+
import store from '../src/store';
7+
import Store from '../src/store/types';
8+
import { createNewWallet } from '../src/utils/startup';
9+
import { updateWallet } from '../src/store/actions/wallet';
10+
import {
11+
balanceSelector,
12+
lnSetupSelector,
13+
} from '../src/store/reselect/aggregations';
14+
15+
describe('Reselect', () => {
16+
let s: Store;
17+
18+
beforeAll(async () => {
19+
require('../nodejs-assets/nodejs-project/main.js');
20+
let res = await createNewWallet();
21+
if (res.isErr()) {
22+
throw res.error;
23+
}
24+
updateWallet({ selectedNetwork: 'bitcoinRegtest' });
25+
s = store.getState();
26+
});
27+
28+
describe('balanceSelector', () => {
29+
it('should return zeros by default', () => {
30+
const state = cloneDeep(s);
31+
assert.deepEqual(balanceSelector(state), {
32+
lightningBalance: 0,
33+
lightningClaimableBalance: 0,
34+
lightningReserveBalance: 0,
35+
lightningSpendingBalance: 0,
36+
onchainBalance: 0,
37+
totalBalance: 0,
38+
totalSpendableBalance: 0,
39+
});
40+
});
41+
42+
it('should return onchain balance for current wallet', () => {
43+
const state = cloneDeep(s);
44+
state.wallet.wallets.wallet0.balance.bitcoinRegtest = 1;
45+
assert.deepEqual(balanceSelector(state), {
46+
lightningBalance: 0,
47+
lightningClaimableBalance: 0,
48+
lightningReserveBalance: 0,
49+
lightningSpendingBalance: 0,
50+
onchainBalance: 1,
51+
totalBalance: 1,
52+
totalSpendableBalance: 1,
53+
});
54+
});
55+
56+
it('should calculate balance for LN wallet', () => {
57+
const state = cloneDeep(s);
58+
state.wallet.wallets.wallet0.balance.bitcoinRegtest = 1;
59+
60+
const channel1 = {
61+
channel_id: 'channel1',
62+
is_channel_ready: true,
63+
outbound_capacity_sat: 1,
64+
balance_sat: 2,
65+
} as TChannel;
66+
const channel2 = {
67+
channel_id: 'channel2',
68+
is_channel_ready: true,
69+
outbound_capacity_sat: 1,
70+
balance_sat: 2,
71+
} as TChannel;
72+
const channel3 = {
73+
channel_id: 'channel3',
74+
is_channel_ready: false,
75+
outbound_capacity_sat: 1,
76+
balance_sat: 2,
77+
} as TChannel;
78+
79+
const lnWallet = state.lightning.nodes.wallet0;
80+
lnWallet.channels.bitcoinRegtest = { channel1, channel2, channel3 };
81+
lnWallet.openChannelIds.bitcoinRegtest = [
82+
'channel1',
83+
'channel2',
84+
'channel3',
85+
];
86+
lnWallet.claimableBalance.bitcoinRegtest = 3;
87+
88+
assert.deepEqual(balanceSelector(state), {
89+
lightningBalance: 7,
90+
lightningClaimableBalance: 3,
91+
lightningReserveBalance: 2,
92+
lightningSpendingBalance: 2,
93+
onchainBalance: 1,
94+
totalBalance: 8,
95+
totalSpendableBalance: 3,
96+
});
97+
});
98+
});
99+
100+
describe('lnSetupSelector', () => {
101+
it('should throw if onchain balance is 0', () => {
102+
const state = cloneDeep(s);
103+
expect(() => lnSetupSelector(state, 0)).toThrow(TypeError);
104+
});
105+
106+
it('should calculate percentage corectly', () => {
107+
const state = cloneDeep(s);
108+
// balance under maxChannelSizeSat
109+
state.wallet.wallets.wallet0.balance.bitcoinRegtest = 20000;
110+
111+
expect(lnSetupSelector(state, 0)).toMatchObject({
112+
percentage: {
113+
savings: 100,
114+
spendings: 0,
115+
},
116+
canContinue: false,
117+
});
118+
119+
expect(lnSetupSelector(state, 10000)).toMatchObject({
120+
percentage: {
121+
savings: 50,
122+
spendings: 50,
123+
},
124+
canContinue: true,
125+
});
126+
127+
expect(lnSetupSelector(state, 16000)).toMatchObject({
128+
percentage: {
129+
savings: 20,
130+
spendings: 80,
131+
},
132+
canContinue: true,
133+
});
134+
});
135+
136+
it('should calculate btSpendingLimitBalanced without LN channels', () => {
137+
// max value is limited by btMaxChannelSizeSat / 2 - btMaxChannelSizeSat * DIFF
138+
const s1 = cloneDeep(s);
139+
s1.wallet.wallets.wallet0.balance.bitcoinRegtest = 1000;
140+
s1.blocktank.info.options = {
141+
...s1.blocktank.info.options,
142+
minChannelSizeSat: 10,
143+
maxChannelSizeSat: 200,
144+
maxClientBalanceSat: 100,
145+
};
146+
147+
expect(lnSetupSelector(s1, 0)).toMatchObject({
148+
slider: {
149+
startValue: 0,
150+
maxValue: 98,
151+
endValue: 1000,
152+
},
153+
btSpendingLimitBalanced: 98,
154+
spendableBalance: 800,
155+
defaultClientBalance: 98,
156+
});
157+
158+
// max value is limited by btMaxClientBalanceSat
159+
const s2 = cloneDeep(s);
160+
s2.wallet.wallets.wallet0.balance.bitcoinRegtest = 1000;
161+
s2.blocktank.info.options = {
162+
...s2.blocktank.info.options,
163+
minChannelSizeSat: 10,
164+
maxChannelSizeSat: 200,
165+
maxClientBalanceSat: 50,
166+
};
167+
168+
expect(lnSetupSelector(s2, 0)).toMatchObject({
169+
slider: {
170+
startValue: 0,
171+
maxValue: 50,
172+
endValue: 1000,
173+
},
174+
btSpendingLimitBalanced: 50,
175+
spendableBalance: 800,
176+
defaultClientBalance: 50,
177+
});
178+
179+
// max value is limited by onchain balance
180+
const s3 = cloneDeep(s);
181+
s3.wallet.wallets.wallet0.balance.bitcoinRegtest = 50;
182+
s3.blocktank.info.options = {
183+
...s3.blocktank.info.options,
184+
minChannelSizeSat: 10,
185+
maxChannelSizeSat: 200,
186+
maxClientBalanceSat: 100,
187+
};
188+
189+
expect(lnSetupSelector(s3, 0)).toMatchObject({
190+
slider: {
191+
startValue: 0,
192+
maxValue: 40,
193+
endValue: 50,
194+
},
195+
btSpendingLimitBalanced: 98,
196+
spendableBalance: 40,
197+
defaultClientBalance: 10,
198+
});
199+
});
200+
201+
it('should calculate btSpendingLimitBalanced with LN channels', () => {
202+
// max value is limited by btMaxChannelSizeSat / 2 - btMaxChannelSizeSat * DIFF
203+
const s1 = cloneDeep(s);
204+
s1.wallet.wallets.wallet0.balance.bitcoinRegtest = 1000;
205+
s1.blocktank.info.options = {
206+
...s1.blocktank.info.options,
207+
minChannelSizeSat: 10,
208+
maxChannelSizeSat: 200,
209+
maxClientBalanceSat: 100,
210+
};
211+
const channel1 = {
212+
channel_id: 'channel1',
213+
is_channel_ready: true,
214+
outbound_capacity_sat: 1,
215+
balance_sat: 2,
216+
} as TChannel;
217+
const lnWallet = s1.lightning.nodes.wallet0;
218+
lnWallet.channels.bitcoinRegtest = { channel1 };
219+
lnWallet.openChannelIds.bitcoinRegtest = ['channel1'];
220+
lnWallet.claimableBalance.bitcoinRegtest = 3;
221+
222+
expect(lnSetupSelector(s1, 20)).toMatchObject({
223+
slider: {
224+
startValue: 0,
225+
maxValue: 98,
226+
endValue: 1005,
227+
},
228+
btSpendingLimitBalanced: 98,
229+
spendableBalance: 804,
230+
defaultClientBalance: 5,
231+
canContinue: true,
232+
});
233+
});
234+
});
235+
});

__tests__/todos.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import assert from 'node:assert';
22
import cloneDeep from 'lodash/cloneDeep';
3+
import { TChannel } from '@synonymdev/react-native-ldk';
4+
import { IBtOrder } from '@synonymdev/blocktank-lsp-http-client';
35

46
import '../src/utils/i18n';
57
import { todosFullSelector } from '../src/store/reselect/todos';
68
import store from '../src/store';
79
import Store from '../src/store/types';
8-
import { createNewWallet } from '../src/utils/startup';
910
import { updateWallet } from '../src/store/actions/wallet';
1011
import {
1112
backupSeedPhraseTodo,
@@ -20,8 +21,7 @@ import {
2021
transferToSavingsTodo,
2122
transferToSpendingTodo,
2223
} from '../src/store/shapes/todos';
23-
import { IBtOrder } from '@synonymdev/blocktank-lsp-http-client';
24-
import { TChannel } from '@synonymdev/react-native-ldk';
24+
import { createNewWallet } from '../src/utils/startup';
2525

2626
describe('Todos selector', () => {
2727
let s: Store;

e2e/slashtags.e2e.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ d('Profile and Contacts', () => {
134134

135135
// self
136136
await element(by.id('AddContact')).tap();
137-
await element(by.id('ContactURLInput')).replaceText(slashtagsUrl);
138-
await element(by.id('ContactURLInput')).tapReturnKey();
139-
await waitFor(element(by.id('ContactError')))
140-
.toBeVisible()
141-
.withTimeout(30000);
137+
await element(by.id('ContactURLInput')).typeText(slashtagsUrl);
138+
await element(by.id('AddContactButton')).tap();
139+
await expect(element(by.id('ContactURLInput-error'))).toBeVisible();
142140

143141
// Satoshi
144142
await element(by.id('ContactURLInput')).replaceText(satoshi.url);
143+
await element(by.id('AddContactButton')).tap();
145144
await waitFor(element(by.id('NameInput')))
146145
.toBeVisible()
147146
.withTimeout(30000);
@@ -157,6 +156,7 @@ d('Profile and Contacts', () => {
157156
// Hal
158157
await element(by.id('AddContact')).tap();
159158
await element(by.id('ContactURLInput')).replaceText(hal.url);
159+
await element(by.id('AddContactButton')).tap();
160160
await waitFor(element(by.id('NameInput')))
161161
.toBeVisible()
162162
.withTimeout(30000);

ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ PODS:
392392
- React-Core
393393
- react-native-keep-awake (1.2.2):
394394
- React-Core
395-
- react-native-ldk (0.0.122):
395+
- react-native-ldk (0.0.123):
396396
- React
397397
- react-native-mmkv (2.10.2):
398398
- MMKV (>= 1.2.13)
@@ -915,7 +915,7 @@ SPEC CHECKSUMS:
915915
react-native-flipper: 9c1957af24b76493ba74f46d000a5c1d485e7731
916916
react-native-image-picker: 2e2e82aba9b6a91a7c78f7d9afde341a2659c7b8
917917
react-native-keep-awake: ad1d67f617756b139536977a0bf06b27cec0714a
918-
react-native-ldk: 3fd5d959c60676bbb5f414a4c5e8a2cd3a4fb227
918+
react-native-ldk: e242bbc0c8ca5356409e2e065b80364dadb270b6
919919
react-native-mmkv: 9ae7ca3977e8ef48dbf7f066974eb844c20b5fd7
920920
react-native-netinfo: 5ddbf20865bcffab6b43d0e4e1fd8b3896beb898
921921
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@sayem314/react-native-keep-awake": "1.2.2",
5454
"@shopify/react-native-skia": "0.1.216",
5555
"@synonymdev/blocktank-client": "0.0.50",
56-
"@synonymdev/blocktank-lsp-http-client": "0.6.0",
56+
"@synonymdev/blocktank-lsp-http-client": "0.9.0",
5757
"@synonymdev/feeds": "2.1.1",
5858
"@synonymdev/react-native-ldk": "0.0.123",
5959
"@synonymdev/react-native-lnurl": "0.0.5",
@@ -62,7 +62,7 @@
6262
"@synonymdev/slashtags-keychain": "1.0.0",
6363
"@synonymdev/slashtags-profile": "1.0.2",
6464
"@synonymdev/slashtags-sdk": "1.0.0-alpha.38",
65-
"@synonymdev/slashtags-url": "1.0.0-alpha.4",
65+
"@synonymdev/slashtags-url": "1.0.1",
6666
"@synonymdev/slashtags-widget-bitcoin-feed": "1.0.0",
6767
"@synonymdev/slashtags-widget-facts-feed": "1.1.0",
6868
"@synonymdev/slashtags-widget-news-feed": "1.1.0",

0 commit comments

Comments
 (0)