Skip to content

Commit

Permalink
fix(backup): add boosts & transfers to backup (#2128)
Browse files Browse the repository at this point in the history
* fix(backup): add boosts & transfers to backup

* test(backup): add e2e tests
  • Loading branch information
pwltr authored Nov 27, 2024
1 parent 50ef930 commit 5124260
Show file tree
Hide file tree
Showing 24 changed files with 510 additions and 355 deletions.
72 changes: 72 additions & 0 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
reduceValue,
timeAgo,
isObjPartialMatch,
deepCompareStructure,
ellipsis,
generateCalendar,
getDurationForBlocks,
Expand Down Expand Up @@ -160,6 +161,77 @@ describe('isObjPartialMatch', () => {
});
});

describe('deepCompareStructure', () => {
it('can perform match', () => {
const f = deepCompareStructure;
expect(f({}, {})).toEqual(true);
expect(f({}, [])).toEqual(false);
expect(f({ a: 1 }, {})).toEqual(false);
expect(f({ a: 1 }, { a: 2 })).toEqual(true);
expect(f({ a: 1 }, { b: 1 })).toEqual(false);
expect(f({ a: { b: 1 } }, { a: { b: 2 } })).toEqual(true);
expect(f({ a: { b: 1 } }, { a: { c: 1 } })).toEqual(false);
expect(f({ a: 1 }, { a: [] })).toEqual(false);
expect(f({ a: { b: [] } }, { a: { b: [] } })).toEqual(true);
expect(f({ a: { b: 1 } }, { a: { b: [] } })).toEqual(false);

const received = {
boostedTransactions: {
bitcoin: {},
bitcoinTestnet: {},
bitcoinRegtest: {
fff9398e30329ab0d4ae227c017b9c11537d6fadede4df402d3ae9bb854816f5: {
parentTransactions: [
'fff9398e30329ab0d4ae227c017b9c11537d6fadede4df402d3ae9bb854816f5',
],
childTransaction:
'ee459c02101cad9dbab8d0fc2fe55026130e7db4d88ca8892b9003167c787fa1',
type: 'cpfp',
fee: 664,
},
'415098a69d7b1c93b31b14625c4b7663a4bdeee5f15c5982083ac1c4ec14717b': {
parentTransactions: [
'415098a69d7b1c93b31b14625c4b7663a4bdeee5f15c5982083ac1c4ec14717b',
],
childTransaction:
'f7f0d6184818a9588633be608dc4d8f3510708c5946bea330c663a0bf8c334a2',
type: 'cpfp',
fee: 664,
},
},
},
transfers: {
bitcoin: [],
bitcoinTestnet: [],
bitcoinRegtest: [
{
txId: '67a7108cd434d8580a0295517df0c740b59e84e875284ac139717e4dda4da0f8',
type: 'open',
status: 'pending',
orderId: '5f95e1f5-26f9-4fb2-82e6-9ae602764d3b',
amount: 17602,
},
],
},
};

const expected = {
boostedTransactions: {
bitcoin: {},
bitcoinTestnet: {},
bitcoinRegtest: {},
},
transfers: {
bitcoin: [],
bitcoinTestnet: [],
bitcoinRegtest: [],
},
};

expect(f(received, expected, 1)).toEqual(true);
});
});

describe('calendar', () => {
it('can generate calendar', () => {
const date = new Date(Date.UTC(2020, 11, 31, 23, 59, 59));
Expand Down
51 changes: 4 additions & 47 deletions e2e/backup.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
bitcoinURL,
electrumHost,
electrumPort,
getSeed,
restoreWallet,
} from './helpers';
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';

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

// get seed
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
await sleep(200); // animation
await element(by.id('TapToReveal')).tap();

// get the seed from SeedContaider
const { label: seed } = await element(
by.id('SeedContaider'),
).getAttributes();

await element(by.id('SeedContaider')).swipe('down');
await sleep(200); // animation
await element(by.id('NavigationClose')).atIndex(0).tap();

await sleep(5000); // make sure everything is saved to cloud storage TODO: improve this

console.info('seed: ', seed);

// restore wallet
await device.launchApp({ delete: true });

await waitFor(element(by.id('Check1'))).toBeVisible();
await element(by.id('Check1')).tap();
await element(by.id('Check2')).tap();
await element(by.id('Continue')).tap();
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
await element(by.id('SkipIntro')).tap();
await element(by.id('RestoreWallet')).tap();
await element(by.id('MultipleDevices-button')).tap();
await element(by.id('Word-0')).replaceText(seed);
await element(by.id('WordIndex-4')).swipe('up');
await element(by.id('RestoreButton')).tap();

await waitFor(element(by.id('GetStartedButton')))
.toBeVisible()
.withTimeout(300000); // 5 min
await element(by.id('GetStartedButton')).tap();

// wait for SuggestionsLabel to appear and be accessible
for (let i = 0; i < 60; i++) {
await sleep(200);
try {
await element(by.id('SuggestionsLabel')).tap();
break;
} catch (e) {}
}
const seed = await getSeed();
await restoreWallet(seed);

// check settings
await expect(
Expand Down
17 changes: 16 additions & 1 deletion e2e/boost.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
bitcoinURL,
electrumHost,
electrumPort,
getSeed,
restoreWallet,
} from './helpers';
import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';

Expand Down Expand Up @@ -267,10 +269,23 @@ d('Boost', () => {
assert(Number(oldFee.replace(' ', '')) < Number(newFee.replace(' ', '')));
assert(oldTxid !== newTxid);
await expect(element(by.id('RBFBoosted'))).toBeVisible();
await element(by.id('NavigationClose')).atIndex(0).tap();

// wipe & restore
const seed = await getSeed();
await restoreWallet(seed);

// check activity after restore
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
await expect(element(by.id('BoostingIcon'))).toBeVisible();
await element(by.id('ActivityShort-1')).tap();
await expect(element(by.id('BoostedButton'))).toBeVisible();
await expect(element(by.id('StatusBoosting'))).toBeVisible();

// mine new block
await element(by.id('NavigationBack')).atIndex(0).tap();
await rpc.generateToAddress(1, await rpc.getNewAddress());

// check activity item after mine
await waitFor(element(by.id('StatusConfirmed')))
.toBeVisible()
.withTimeout(30000);
Expand Down
14 changes: 14 additions & 0 deletions e2e/channels.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
sleep,
waitForActiveChannel,
waitForPeerConnection,
getSeed,
restoreWallet,
} from './helpers';

d = checkComplete(['transfer-1', 'transfer-2']) ? describe.skip : describe;
Expand Down Expand Up @@ -186,6 +188,18 @@ d('Transfer', () => {
await expect(
element(by.id('MoneyText').withAncestor(by.id('TotalSize'))),
).toHaveText('250 000');
await element(by.id('NavigationClose')).tap();

const seed = await getSeed();
await restoreWallet(seed);

// check transfer card
await expect(element(by.id('Suggestion-lightningSettingUp'))).toBeVisible();

// check activity after restore
await element(by.id('WalletsScrollView')).scrollTo('bottom', NaN, 0.85);
await element(by.id('ActivityShort-1')).tap();
await expect(element(by.id('StatusTransfer'))).toBeVisible();

markComplete('transfer-1');
});
Expand Down
62 changes: 62 additions & 0 deletions e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,65 @@ export const waitForActiveChannel = async (lnd, nodeId, maxRetries = 20) => {
throw new Error('Channel not active');
}
};

export const getSeed = async () => {
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
// animation
await sleep(200);
await element(by.id('TapToReveal')).tap();

// get the seed from SeedContaider
const { label: seed } = await element(by.id('SeedContaider')).getAttributes();

await element(by.id('SeedContaider')).swipe('down');
// animation
await sleep(200);
await element(by.id('NavigationClose')).atIndex(0).tap();

console.info({ seed });

return seed;
};

export const restoreWallet = async (seed, passphrase) => {
// make sure everything is saved to cloud storage
// TODO: improve this
await sleep(5000);

await device.launchApp({ delete: true });

await waitFor(element(by.id('Check1'))).toBeVisible();
await element(by.id('Check1')).tap();
await element(by.id('Check2')).tap();
await element(by.id('Continue')).tap();
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
await element(by.id('SkipIntro')).tap();
await element(by.id('RestoreWallet')).tap();
await element(by.id('MultipleDevices-button')).tap();
await element(by.id('Word-0')).replaceText(seed);
await element(by.id('WordIndex-4')).swipe('up');

if (passphrase) {
await element(by.id('AdvancedButton')).tap();
await element(by.id('PassphraseInput')).typeText(passphrase);
await element(by.id('PassphraseInput')).tapReturnKey();
}

await element(by.id('RestoreButton')).tap();

await waitFor(element(by.id('GetStartedButton')))
.toBeVisible()
.withTimeout(300000); // 5 min
await element(by.id('GetStartedButton')).tap();

// wait for SuggestionsLabel to appear and be accessible
for (let i = 0; i < 60; i++) {
await sleep(200);
try {
await element(by.id('SuggestionsLabel')).tap();
break;
} catch (e) {}
}
};
51 changes: 5 additions & 46 deletions e2e/lightning.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
sleep,
waitForActiveChannel,
waitForPeerConnection,
restoreWallet,
getSeed,
} from './helpers';

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

// get seed
await element(by.id('Settings')).tap();
await element(by.id('BackupSettings')).tap();
await element(by.id('BackupWallet')).tap();
await sleep(1000); // animation
await element(by.id('TapToReveal')).tap();

// get the seed from SeedContaider
const { label: seed } = await element(
by.id('SeedContaider'),
).getAttributes();
await element(by.id('SeedContaider')).swipe('down');
await sleep(1000); // animation
await element(by.id('NavigationClose')).atIndex(0).tap();

await sleep(5000); // make sure everything is saved to cloud storage TODO: improve this
console.info('seed: ', seed);

// restore wallet
await device.launchApp({ delete: true });

await waitFor(element(by.id('Check1'))).toBeVisible();
await element(by.id('Check1')).tap();
await element(by.id('Check2')).tap();
await element(by.id('Continue')).tap();
await waitFor(element(by.id('SkipIntro'))).toBeVisible();
await element(by.id('SkipIntro')).tap();
await element(by.id('RestoreWallet')).tap();
await element(by.id('MultipleDevices-button')).tap();
await element(by.id('Word-0')).replaceText(seed);
await element(by.id('WordIndex-4')).swipe('up');
await element(by.id('RestoreButton')).tap();

await waitFor(element(by.id('GetStartedButton')))
.toBeVisible()
.withTimeout(300000); // 5 min
await element(by.id('GetStartedButton')).tap();

// wait for SuggestionsLabel to appear and be accessible
for (let i = 0; i < 60; i++) {
await sleep(1000);
try {
await element(by.id('SuggestionsLabel')).tap();
break;
} catch (e) {}
}
// wipe and restore wallet
const seed = await getSeed();
await restoreWallet(seed);

// check balance
await waitFor(
Expand Down
Loading

0 comments on commit 5124260

Please sign in to comment.