Skip to content

Commit 5124260

Browse files
authored
fix(backup): add boosts & transfers to backup (#2128)
* fix(backup): add boosts & transfers to backup * test(backup): add e2e tests
1 parent 50ef930 commit 5124260

File tree

24 files changed

+510
-355
lines changed

24 files changed

+510
-355
lines changed

__tests__/helpers.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
reduceValue,
44
timeAgo,
55
isObjPartialMatch,
6+
deepCompareStructure,
67
ellipsis,
78
generateCalendar,
89
getDurationForBlocks,
@@ -160,6 +161,77 @@ describe('isObjPartialMatch', () => {
160161
});
161162
});
162163

164+
describe('deepCompareStructure', () => {
165+
it('can perform match', () => {
166+
const f = deepCompareStructure;
167+
expect(f({}, {})).toEqual(true);
168+
expect(f({}, [])).toEqual(false);
169+
expect(f({ a: 1 }, {})).toEqual(false);
170+
expect(f({ a: 1 }, { a: 2 })).toEqual(true);
171+
expect(f({ a: 1 }, { b: 1 })).toEqual(false);
172+
expect(f({ a: { b: 1 } }, { a: { b: 2 } })).toEqual(true);
173+
expect(f({ a: { b: 1 } }, { a: { c: 1 } })).toEqual(false);
174+
expect(f({ a: 1 }, { a: [] })).toEqual(false);
175+
expect(f({ a: { b: [] } }, { a: { b: [] } })).toEqual(true);
176+
expect(f({ a: { b: 1 } }, { a: { b: [] } })).toEqual(false);
177+
178+
const received = {
179+
boostedTransactions: {
180+
bitcoin: {},
181+
bitcoinTestnet: {},
182+
bitcoinRegtest: {
183+
fff9398e30329ab0d4ae227c017b9c11537d6fadede4df402d3ae9bb854816f5: {
184+
parentTransactions: [
185+
'fff9398e30329ab0d4ae227c017b9c11537d6fadede4df402d3ae9bb854816f5',
186+
],
187+
childTransaction:
188+
'ee459c02101cad9dbab8d0fc2fe55026130e7db4d88ca8892b9003167c787fa1',
189+
type: 'cpfp',
190+
fee: 664,
191+
},
192+
'415098a69d7b1c93b31b14625c4b7663a4bdeee5f15c5982083ac1c4ec14717b': {
193+
parentTransactions: [
194+
'415098a69d7b1c93b31b14625c4b7663a4bdeee5f15c5982083ac1c4ec14717b',
195+
],
196+
childTransaction:
197+
'f7f0d6184818a9588633be608dc4d8f3510708c5946bea330c663a0bf8c334a2',
198+
type: 'cpfp',
199+
fee: 664,
200+
},
201+
},
202+
},
203+
transfers: {
204+
bitcoin: [],
205+
bitcoinTestnet: [],
206+
bitcoinRegtest: [
207+
{
208+
txId: '67a7108cd434d8580a0295517df0c740b59e84e875284ac139717e4dda4da0f8',
209+
type: 'open',
210+
status: 'pending',
211+
orderId: '5f95e1f5-26f9-4fb2-82e6-9ae602764d3b',
212+
amount: 17602,
213+
},
214+
],
215+
},
216+
};
217+
218+
const expected = {
219+
boostedTransactions: {
220+
bitcoin: {},
221+
bitcoinTestnet: {},
222+
bitcoinRegtest: {},
223+
},
224+
transfers: {
225+
bitcoin: [],
226+
bitcoinTestnet: [],
227+
bitcoinRegtest: [],
228+
},
229+
};
230+
231+
expect(f(received, expected, 1)).toEqual(true);
232+
});
233+
});
234+
163235
describe('calendar', () => {
164236
it('can generate calendar', () => {
165237
const date = new Date(Date.UTC(2020, 11, 31, 23, 59, 59));

e2e/backup.e2e.js

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
bitcoinURL,
1010
electrumHost,
1111
electrumPort,
12+
getSeed,
13+
restoreWallet,
1214
} from './helpers';
1315
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
1416

@@ -103,54 +105,9 @@ d('Backup', () => {
103105
await element(by.id('WidgetsEdit')).tap();
104106
await expect(element(by.id('PriceWidget'))).toBeVisible();
105107

106-
// get seed
107-
await element(by.id('Settings')).tap();
108-
await element(by.id('BackupSettings')).tap();
109-
await element(by.id('BackupWallet')).tap();
110-
await sleep(200); // animation
111-
await element(by.id('TapToReveal')).tap();
112-
113-
// get the seed from SeedContaider
114-
const { label: seed } = await element(
115-
by.id('SeedContaider'),
116-
).getAttributes();
117-
118-
await element(by.id('SeedContaider')).swipe('down');
119-
await sleep(200); // animation
120-
await element(by.id('NavigationClose')).atIndex(0).tap();
121-
122-
await sleep(5000); // make sure everything is saved to cloud storage TODO: improve this
123-
124-
console.info('seed: ', seed);
125-
126108
// restore wallet
127-
await device.launchApp({ delete: true });
128-
129-
await waitFor(element(by.id('Check1'))).toBeVisible();
130-
await element(by.id('Check1')).tap();
131-
await element(by.id('Check2')).tap();
132-
await element(by.id('Continue')).tap();
133-
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
134-
await element(by.id('SkipIntro')).tap();
135-
await element(by.id('RestoreWallet')).tap();
136-
await element(by.id('MultipleDevices-button')).tap();
137-
await element(by.id('Word-0')).replaceText(seed);
138-
await element(by.id('WordIndex-4')).swipe('up');
139-
await element(by.id('RestoreButton')).tap();
140-
141-
await waitFor(element(by.id('GetStartedButton')))
142-
.toBeVisible()
143-
.withTimeout(300000); // 5 min
144-
await element(by.id('GetStartedButton')).tap();
145-
146-
// wait for SuggestionsLabel to appear and be accessible
147-
for (let i = 0; i < 60; i++) {
148-
await sleep(200);
149-
try {
150-
await element(by.id('SuggestionsLabel')).tap();
151-
break;
152-
} catch (e) {}
153-
}
109+
const seed = await getSeed();
110+
await restoreWallet(seed);
154111

155112
// check settings
156113
await expect(

e2e/boost.e2e.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
bitcoinURL,
1212
electrumHost,
1313
electrumPort,
14+
getSeed,
15+
restoreWallet,
1416
} from './helpers';
1517
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
1618

@@ -267,10 +269,23 @@ d('Boost', () => {
267269
assert(Number(oldFee.replace(' ', '')) < Number(newFee.replace(' ', '')));
268270
assert(oldTxid !== newTxid);
269271
await expect(element(by.id('RBFBoosted'))).toBeVisible();
272+
await element(by.id('NavigationClose')).atIndex(0).tap();
273+
274+
// wipe & restore
275+
const seed = await getSeed();
276+
await restoreWallet(seed);
277+
278+
// check activity after restore
279+
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
280+
await expect(element(by.id('BoostingIcon'))).toBeVisible();
281+
await element(by.id('ActivityShort-1')).tap();
282+
await expect(element(by.id('BoostedButton'))).toBeVisible();
283+
await expect(element(by.id('StatusBoosting'))).toBeVisible();
270284

271285
// mine new block
272-
await element(by.id('NavigationBack')).atIndex(0).tap();
273286
await rpc.generateToAddress(1, await rpc.getNewAddress());
287+
288+
// check activity item after mine
274289
await waitFor(element(by.id('StatusConfirmed')))
275290
.toBeVisible()
276291
.withTimeout(30000);

e2e/channels.e2e.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
sleep,
1717
waitForActiveChannel,
1818
waitForPeerConnection,
19+
getSeed,
20+
restoreWallet,
1921
} from './helpers';
2022

2123
d = checkComplete(['transfer-1', 'transfer-2']) ? describe.skip : describe;
@@ -186,6 +188,18 @@ d('Transfer', () => {
186188
await expect(
187189
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
188190
).toHaveText('250 000');
191+
await element(by.id('NavigationClose')).tap();
192+
193+
const seed = await getSeed();
194+
await restoreWallet(seed);
195+
196+
// check transfer card
197+
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();
198+
199+
// check activity after restore
200+
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
201+
await element(by.id('ActivityShort-1')).tap();
202+
await expect(element(by.id('StatusTransfer'))).toBeVisible();
189203

190204
markComplete('transfer-1');
191205
});

e2e/helpers.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,65 @@ export const waitForActiveChannel = async (lnd, nodeId, maxRetries = 20) => {
187187
throw new Error('Channel not active');
188188
}
189189
};
190+
191+
export const getSeed = async () => {
192+
await element(by.id('Settings')).tap();
193+
await element(by.id('BackupSettings')).tap();
194+
await element(by.id('BackupWallet')).tap();
195+
// animation
196+
await sleep(200);
197+
await element(by.id('TapToReveal')).tap();
198+
199+
// get the seed from SeedContaider
200+
const { label: seed } = await element(by.id('SeedContaider')).getAttributes();
201+
202+
await element(by.id('SeedContaider')).swipe('down');
203+
// animation
204+
await sleep(200);
205+
await element(by.id('NavigationClose')).atIndex(0).tap();
206+
207+
console.info({ seed });
208+
209+
return seed;
210+
};
211+
212+
export const restoreWallet = async (seed, passphrase) => {
213+
// make sure everything is saved to cloud storage
214+
// TODO: improve this
215+
await sleep(5000);
216+
217+
await device.launchApp({ delete: true });
218+
219+
await waitFor(element(by.id('Check1'))).toBeVisible();
220+
await element(by.id('Check1')).tap();
221+
await element(by.id('Check2')).tap();
222+
await element(by.id('Continue')).tap();
223+
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
224+
await element(by.id('SkipIntro')).tap();
225+
await element(by.id('RestoreWallet')).tap();
226+
await element(by.id('MultipleDevices-button')).tap();
227+
await element(by.id('Word-0')).replaceText(seed);
228+
await element(by.id('WordIndex-4')).swipe('up');
229+
230+
if (passphrase) {
231+
await element(by.id('AdvancedButton')).tap();
232+
await element(by.id('PassphraseInput')).typeText(passphrase);
233+
await element(by.id('PassphraseInput')).tapReturnKey();
234+
}
235+
236+
await element(by.id('RestoreButton')).tap();
237+
238+
await waitFor(element(by.id('GetStartedButton')))
239+
.toBeVisible()
240+
.withTimeout(300000); // 5 min
241+
await element(by.id('GetStartedButton')).tap();
242+
243+
// wait for SuggestionsLabel to appear and be accessible
244+
for (let i = 0; i < 60; i++) {
245+
await sleep(200);
246+
try {
247+
await element(by.id('SuggestionsLabel')).tap();
248+
break;
249+
} catch (e) {}
250+
}
251+
};

e2e/lightning.e2e.js

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
sleep,
1616
waitForActiveChannel,
1717
waitForPeerConnection,
18+
restoreWallet,
19+
getSeed,
1820
} from './helpers';
1921

2022
d = checkComplete('lighting-1') ? describe.skip : describe;
@@ -311,52 +313,9 @@ d('Lightning', () => {
311313
await element(by.id('Tag-stag-delete')).tap();
312314
await element(by.id('NavigationClose')).tap();
313315

314-
// get seed
315-
await element(by.id('Settings')).tap();
316-
await element(by.id('BackupSettings')).tap();
317-
await element(by.id('BackupWallet')).tap();
318-
await sleep(1000); // animation
319-
await element(by.id('TapToReveal')).tap();
320-
321-
// get the seed from SeedContaider
322-
const { label: seed } = await element(
323-
by.id('SeedContaider'),
324-
).getAttributes();
325-
await element(by.id('SeedContaider')).swipe('down');
326-
await sleep(1000); // animation
327-
await element(by.id('NavigationClose')).atIndex(0).tap();
328-
329-
await sleep(5000); // make sure everything is saved to cloud storage TODO: improve this
330-
console.info('seed: ', seed);
331-
332-
// restore wallet
333-
await device.launchApp({ delete: true });
334-
335-
await waitFor(element(by.id('Check1'))).toBeVisible();
336-
await element(by.id('Check1')).tap();
337-
await element(by.id('Check2')).tap();
338-
await element(by.id('Continue')).tap();
339-
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
340-
await element(by.id('SkipIntro')).tap();
341-
await element(by.id('RestoreWallet')).tap();
342-
await element(by.id('MultipleDevices-button')).tap();
343-
await element(by.id('Word-0')).replaceText(seed);
344-
await element(by.id('WordIndex-4')).swipe('up');
345-
await element(by.id('RestoreButton')).tap();
346-
347-
await waitFor(element(by.id('GetStartedButton')))
348-
.toBeVisible()
349-
.withTimeout(300000); // 5 min
350-
await element(by.id('GetStartedButton')).tap();
351-
352-
// wait for SuggestionsLabel to appear and be accessible
353-
for (let i = 0; i < 60; i++) {
354-
await sleep(1000);
355-
try {
356-
await element(by.id('SuggestionsLabel')).tap();
357-
break;
358-
} catch (e) {}
359-
}
316+
// wipe and restore wallet
317+
const seed = await getSeed();
318+
await restoreWallet(seed);
360319

361320
// check balance
362321
await waitFor(

0 commit comments

Comments
 (0)