BlueWallet/tests/e2e/bluewallet.spec.js

438 lines
18 KiB
JavaScript
Raw Normal View History

/* global it, describe, expect, element, by, waitFor, device */
2020-03-16 14:51:08 +01:00
const bitcoin = require('bitcoinjs-lib');
const assert = require('assert');
2020-03-16 14:51:08 +01:00
describe('BlueWallet UI Tests', () => {
2020-04-20 14:29:37 +02:00
it('selftest passes', async () => {
await waitFor(element(by.id('WalletsList')))
.toBeVisible()
.withTimeout(300 * 1000);
// go to settings, press SelfTest and wait for OK
await element(by.id('SettingsButton')).tap();
await element(by.id('AboutButton')).tap();
await element(by.id('AboutScrollView')).swipe('up', 'fast', 1); // in case emu screen is small and it doesnt fit
await element(by.id('RunSelfTestButton')).tap();
await waitFor(element(by.id('SelfTestOk')))
.toBeVisible()
.withTimeout(300 * 1000);
});
2020-03-19 16:51:35 +01:00
it('can encrypt storage, with plausible deniability', async () => {
await yo('WalletsList');
// lets create a wallet
await helperCreateWallet();
2020-03-19 16:51:35 +01:00
// go to settings
await expect(element(by.id('SettingsButton'))).toBeVisible();
await element(by.id('SettingsButton')).tap();
await expect(element(by.id('SecurityButton'))).toBeVisible();
2020-03-19 16:51:35 +01:00
// go to Security page where we will enable encryption
await element(by.id('SecurityButton')).tap();
await expect(element(by.id('EncyptedAndPasswordProtected'))).toBeVisible();
2020-03-19 16:51:35 +01:00
await expect(element(by.id('PlausibleDeniabilityButton'))).toBeNotVisible();
if (device.getPlatform() === 'ios') {
console.warn('Android only test skipped');
return;
}
2020-03-19 16:51:35 +01:00
// lets encrypt the storage.
// first, trying to mistype second password:
2020-03-19 16:51:35 +01:00
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol. lets tap it
await element(by.type('android.widget.EditText')).typeText('08902');
await element(by.text('OK')).tap();
2020-03-19 16:51:35 +01:00
await element(by.type('android.widget.EditText')).typeText('666');
await element(by.text('OK')).tap();
await expect(element(by.text('Passwords do not match'))).toBeVisible();
await element(by.text('OK')).tap();
2020-03-19 16:51:35 +01:00
// now, lets put correct passwords and encrypt the storage
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.type('android.widget.EditText')).typeText('qqq');
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('qqq');
await element(by.text('OK')).tap();
2020-03-16 14:51:08 +01:00
2020-03-19 16:51:35 +01:00
// relaunch app
await device.launchApp({ newInstance: true });
await waitFor(element(by.text('OK')))
.toBeVisible()
2020-03-19 17:55:35 +01:00
.withTimeout(33000);
2020-03-19 16:51:35 +01:00
// trying to decrypt with wrong password
await expect(element(by.text('Your storage is encrypted. Password is required to decrypt it'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('wrong');
await element(by.text('OK')).tap();
await expect(element(by.text('Wrong password, please try again.'))).toBeVisible();
2020-03-19 16:51:35 +01:00
// correct password
await element(by.type('android.widget.EditText')).typeText('qqq');
await element(by.text('OK')).tap();
await yo('WalletsList');
2020-03-19 16:51:35 +01:00
// previously created wallet should be visible
await expect(element(by.id('cr34t3d'))).toBeVisible();
2020-03-19 16:51:35 +01:00
// now lets enable plausible deniability feature
// go to settings -> security screen -> plausible deniability screen
await element(by.id('SettingsButton')).tap();
await expect(element(by.id('SecurityButton'))).toBeVisible();
await element(by.id('SecurityButton')).tap();
2020-03-19 16:51:35 +01:00
await expect(element(by.id('EncyptedAndPasswordProtected'))).toBeVisible();
await expect(element(by.id('PlausibleDeniabilityButton'))).toBeVisible();
await element(by.id('PlausibleDeniabilityButton')).tap();
// trying to enable plausible denability
await element(by.id('CreateFakeStorageButton')).tap();
2020-03-23 19:18:45 +01:00
await expect(element(by.text('Password for fake storage should not match the password for your main storage'))).toBeVisible();
2020-03-19 16:51:35 +01:00
// trying MAIN password: should fail, obviously
await element(by.type('android.widget.EditText')).typeText('qqq');
await element(by.text('OK')).tap();
await expect(element(by.text('Password is currently in use. Please, try a different password.'))).toBeVisible();
await element(by.text('OK')).tap();
// trying new password, but will mistype
await element(by.id('CreateFakeStorageButton')).tap();
await element(by.type('android.widget.EditText')).typeText('passwordForFakeStorage');
await element(by.text('OK')).tap();
await expect(element(by.text('Retype password'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('passwordForFakeStorageWithTypo'); // retyping with typo
await element(by.text('OK')).tap();
await expect(element(by.text('Passwords do not match, try again'))).toBeVisible();
await element(by.text('OK')).tap();
// trying new password
await element(by.id('CreateFakeStorageButton')).tap();
await element(by.type('android.widget.EditText')).typeText('passwordForFakeStorage');
await element(by.text('OK')).tap();
await expect(element(by.text('Retype password'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('passwordForFakeStorage'); // retyping
await element(by.text('OK')).tap();
await expect(element(by.text('Success'))).toBeVisible();
await element(by.text('OK')).tap();
// created fake storage.
// creating a wallet inside this fake storage
await helperCreateWallet('fake_wallet');
// relaunch the app, unlock with fake password, expect to see fake wallet
// relaunch app
await device.launchApp({ newInstance: true });
2020-03-19 16:51:35 +01:00
await waitFor(element(by.text('OK')))
.toBeVisible()
2020-03-19 17:55:35 +01:00
.withTimeout(33000);
2020-03-19 16:51:35 +01:00
//
await expect(element(by.text('Your storage is encrypted. Password is required to decrypt it'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('qqq');
await element(by.text('OK')).tap();
await yo('WalletsList');
// previously created wallet IN MAIN STORAGE should be visible
await expect(element(by.id('cr34t3d'))).toBeVisible();
// relaunch app
await device.launchApp({ newInstance: true });
await sleep(3000);
//
await expect(element(by.text('Your storage is encrypted. Password is required to decrypt it'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('passwordForFakeStorage');
await element(by.text('OK')).tap();
await yo('WalletsList');
// previously created wallet in FAKE storage should be visible
await expect(element(by.id('fake_wallet'))).toBeVisible();
});
2020-03-20 12:46:45 +01:00
it('can encrypt storage, and decrypt storage works', async () => {
await yo('WalletsList');
await helperCreateWallet();
await element(by.id('SettingsButton')).tap();
await element(by.id('SecurityButton')).tap();
2020-03-20 12:46:45 +01:00
if (device.getPlatform() === 'ios') {
console.warn('Android only test skipped');
return;
}
// lets encrypt the storage.
// lets put correct passwords and encrypt the storage
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
await element(by.id('PlausibleDeniabilityButton')).tap();
// trying to enable plausible denability
await element(by.id('CreateFakeStorageButton')).tap();
await element(by.type('android.widget.EditText')).typeText('fake');
await element(by.text('OK')).tap();
await expect(element(by.text('Retype password'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('fake'); // retyping
await element(by.text('OK')).tap();
await expect(element(by.text('Success'))).toBeVisible();
await element(by.text('OK')).tap();
// created fake storage.
// creating a wallet inside this fake storage
await helperCreateWallet('fake_wallet');
// relaunch app
await device.launchApp({ newInstance: true });
await waitFor(element(by.text('OK')))
.toBeVisible()
.withTimeout(33000);
//
await expect(element(by.text('Your storage is encrypted. Password is required to decrypt it'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
await yo('WalletsList');
// previously created wallet IN MAIN STORAGE should be visible
await expect(element(by.id('cr34t3d'))).toBeVisible();
// now go to settings, and decrypt
await element(by.id('SettingsButton')).tap();
await element(by.id('SecurityButton')).tap();
2020-03-20 12:46:45 +01:00
// putting FAKE storage password. should not succeed
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('fake');
await element(by.text('OK')).tap();
await expect(element(by.text('Wrong password, please try again.'))).toBeVisible();
await element(by.text('OK')).tap();
// correct password
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
// relaunch app
await device.launchApp({ newInstance: true });
await yo('cr34t3d'); // success
});
2020-04-01 17:34:40 +02:00
it.skip('can encrypt storage, and decrypt storage, but this time the fake one', async () => {
2020-03-20 12:46:45 +01:00
// this test mostly repeats previous one, except in the end it logins with FAKE password to unlock FAKE
// storage bucket, and then decrypts it. effectively, everything from MAIN storage bucket is lost
2020-03-26 21:03:27 +01:00
if (process.env.TRAVIS) return; // skipping on CI to not take time (plus it randomly fails)
2020-03-20 12:46:45 +01:00
await yo('WalletsList');
await helperCreateWallet();
await element(by.id('SettingsButton')).tap();
await element(by.id('SecurityButton')).tap();
2020-03-20 12:46:45 +01:00
if (device.getPlatform() === 'ios') {
console.warn('Android only test skipped');
return;
}
// lets encrypt the storage.
// lets put correct passwords and encrypt the storage
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
await element(by.id('PlausibleDeniabilityButton')).tap();
// trying to enable plausible denability
await element(by.id('CreateFakeStorageButton')).tap();
await element(by.type('android.widget.EditText')).typeText('fake');
await element(by.text('OK')).tap();
await expect(element(by.text('Retype password'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('fake'); // retyping
await element(by.text('OK')).tap();
await expect(element(by.text('Success'))).toBeVisible();
await element(by.text('OK')).tap();
// created fake storage.
// creating a wallet inside this fake storage
await helperCreateWallet('fake_wallet');
// relaunch app
await device.launchApp({ newInstance: true });
await waitFor(element(by.text('OK')))
.toBeVisible()
.withTimeout(33000);
//
await expect(element(by.text('Your storage is encrypted. Password is required to decrypt it'))).toBeVisible();
await element(by.type('android.widget.EditText')).typeText('fake');
await element(by.text('OK')).tap();
await yo('WalletsList');
// previously created wallet IN FAKE STORAGE should be visible
await expect(element(by.id('fake_wallet'))).toBeVisible();
// now go to settings, and decrypt
await element(by.id('SettingsButton')).tap();
await element(by.id('SecurityButton')).tap();
2020-03-20 12:46:45 +01:00
// putting MAIN storage password. should not succeed
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('pass');
await element(by.text('OK')).tap();
await expect(element(by.text('Wrong password, please try again.'))).toBeVisible();
await element(by.text('OK')).tap();
// correct password
await element(by.type('android.widget.CompoundButton')).tap(); // thats a switch lol
await element(by.text('OK')).tap();
await element(by.type('android.widget.EditText')).typeText('fake');
await element(by.text('OK')).tap();
// relaunch app
await device.launchApp({ newInstance: true });
await yo('fake_wallet'); // success, we are observing wallet in FAKE storage. wallet from main storage is lost
});
2020-03-19 16:51:35 +01:00
it('can create wallet, reload app and it persists', async () => {
await yo('WalletsList');
await helperCreateWallet();
await device.launchApp({ newInstance: true });
await yo('WalletsList');
await expect(element(by.id('cr34t3d'))).toBeVisible();
2020-03-16 14:51:08 +01:00
});
it('can import BIP84 mnemonic, fetch balance & transactions, then create a transaction', async () => {
if (!process.env.HD_MNEMONIC_BIP84) {
console.error('process.env.HD_MNEMONIC_BIP84 not set, skipped');
return;
}
await helperImportWallet(process.env.HD_MNEMONIC_BIP84, 'Imported HD SegWit (BIP84 Bech32 Native)', '0.00105526 BTC');
// lets create real transaction:
await element(by.id('SendButton')).tap();
await element(by.id('AddressInput')).typeText('bc1q063ctu6jhe5k4v8ka99qac8rcm2tzjjnuktyrl');
await element(by.id('BitcoinAmountInput')).typeText('0.0005\n');
if (process.env.TRAVIS) await sleep(5000);
try {
await element(by.id('CreateTransactionButton')).tap();
} catch (_) {}
// created. verifying:
await yo('TransactionValue');
expect(element(by.id('TransactionValue'))).toHaveText('0.0005');
await element(by.id('TransactionDetailsButton')).tap();
// now, a hack to extract element text. warning, this might break in future
// @see https://github.com/wix/detox/issues/445
let txhex = '';
try {
await expect(element(by.id('TxhexInput'))).toHaveText('_unfoundable_text');
} catch (error) {
if (device.getPlatform() === 'ios') {
const start = `accessibilityLabel was "`;
const end = '" on ';
const errorMessage = error.message.toString();
const [, restMessage] = errorMessage.split(start);
const [label] = restMessage.split(end);
txhex = label;
} else {
const start = 'Got:';
const end = '}"';
const errorMessage = error.message.toString();
const [, restMessage] = errorMessage.split(start);
const [label] = restMessage.split(end);
const value = label.split(',');
var combineText = value.find(i => i.includes('text=')).trim();
const [, elementText] = combineText.split('=');
txhex = elementText;
}
}
let transaction = bitcoin.Transaction.fromHex(txhex);
assert.ok(transaction.ins.length === 1 || transaction.ins.length === 2); // depending on current fees gona use either 1 or 2 inputs
assert.strictEqual(transaction.outs.length, 2);
assert.strictEqual(bitcoin.address.fromOutputScript(transaction.outs[0].script), 'bc1q063ctu6jhe5k4v8ka99qac8rcm2tzjjnuktyrl'); // to address
assert.strictEqual(transaction.outs[0].value, 50000);
});
it('can import zpub as watch-only and create PSBT', async () => {
await helperImportWallet(
'zpub6r7jhKKm7BAVx3b3nSnuadY1WnshZYkhK8gKFoRLwK9rF3Mzv28BrGcCGA3ugGtawi1WLb2vyjQAX9ZTDGU5gNk2bLdTc3iEXr6tzR1ipNP',
'Imported Watch-only',
'0.002 BTC',
);
await element(by.id('SendButton')).tap();
await element(by.text('OK')).tap();
await element(by.id('AddressInput')).typeText('bc1q063ctu6jhe5k4v8ka99qac8rcm2tzjjnuktyrl');
await element(by.id('BitcoinAmountInput')).typeText('0.0005\n');
if (process.env.TRAVIS) await sleep(5000);
try {
await element(by.id('CreateTransactionButton')).tap();
} catch (_) {}
await yo('TextHelperForPSBT');
});
2020-03-16 14:51:08 +01:00
});
2020-03-19 16:51:35 +01:00
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
2020-03-19 17:55:35 +01:00
async function yo(id, timeout = 33000) {
2020-03-19 16:51:35 +01:00
return waitFor(element(by.id(id)))
.toBeVisible()
.withTimeout(timeout);
}
async function sup(text, timeout = 33000) {
return waitFor(element(by.text(text)))
.toBeVisible()
.withTimeout(timeout);
}
2020-03-19 16:51:35 +01:00
async function helperCreateWallet(walletName) {
await element(by.id('CreateAWallet')).tap();
await element(by.id('WalletNameInput')).typeText(walletName || 'cr34t3d');
2020-03-19 17:55:35 +01:00
await yo('ActivateBitcoinButton');
2020-03-19 16:51:35 +01:00
await element(by.id('ActivateBitcoinButton')).tap();
await element(by.id('ActivateBitcoinButton')).tap();
// why tf we need 2 taps for it to work..? mystery
await element(by.id('Create')).tap();
2020-03-19 17:55:35 +01:00
await yo('PleaseBackupScrollView');
2020-03-19 16:51:35 +01:00
await element(by.id('PleaseBackupScrollView')).swipe('up', 'fast', 1); // in case emu screen is small and it doesnt fit
2020-03-19 17:55:35 +01:00
await yo('PleasebackupOk');
2020-03-19 16:51:35 +01:00
await element(by.id('PleasebackupOk')).tap();
await expect(element(by.id('WalletsList'))).toBeVisible();
await expect(element(by.id(walletName || 'cr34t3d'))).toBeVisible();
}
async function helperImportWallet(importText, expectedWalletLabel, expectedBalance) {
await yo('WalletsList');
// going to Import Wallet screen and importing mnemonic
await element(by.id('CreateAWallet')).tap();
await element(by.id('ImportWallet')).tap();
await element(by.id('MnemonicInput')).typeText(importText);
try {
await element(by.id('DoImport')).tap();
} catch (_) {}
if (process.env.TRAVIS) await sleep(60000);
await sup('OK', 3 * 61000); // waiting for wallet import
await element(by.text('OK')).tap();
// ok, wallet imported
// lets go inside wallet
await element(by.text(expectedWalletLabel)).tap();
// label might change in the future
expect(element(by.id('WalletBalance'))).toHaveText(expectedBalance);
}