|
| 1 | +import { exec } from 'child_process'; |
| 2 | +// `expect` keyword is already used by jest. |
| 3 | +import { expect as detoxExpect } from 'detox'; |
| 4 | + |
| 5 | +import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link'; |
| 6 | +import TrezorConnect from '@trezor/connect-deeplink'; |
| 7 | + |
| 8 | +import { openApp } from '../utils'; |
| 9 | +import { onOnboarding } from '../pageObjects/onboardingActions'; |
| 10 | +import { onCoinEnablingInit } from '../pageObjects/coinEnablingActions'; |
| 11 | + |
| 12 | +const TREZOR_DEVICE_LABEL = 'Trezor T - Tester'; |
| 13 | +// Contains only one BTC account with a single transaction to make the discovery as fast as possible. |
| 14 | +const SIMPLE_SEED = 'immune enlist rule measure fan swarm mandate track point menu security fan'; |
| 15 | +const platform = device.getPlatform(); |
| 16 | + |
| 17 | +function openUriScheme(url, platform) { |
| 18 | + const command = `npx uri-scheme open '${url.replace(/'/g, '')}' --${platform}`; |
| 19 | + |
| 20 | + exec(command, (err, stdout, stderr) => { |
| 21 | + if (err) { |
| 22 | + console.error('Error:'); |
| 23 | + console.error(err); |
| 24 | + console.error(); |
| 25 | + return; |
| 26 | + } |
| 27 | + console.log(stdout); |
| 28 | + console.error(stderr); |
| 29 | + }); |
| 30 | +} |
| 31 | + |
| 32 | +describe('Deeplink connect popup.', () => { |
| 33 | + beforeAll(async () => { |
| 34 | + if (platform === 'android') { |
| 35 | + // Prepare Trezor device for test scenario and turn it off. |
| 36 | + await TrezorUserEnvLink.disconnect(); |
| 37 | + await TrezorUserEnvLink.connect(); |
| 38 | + await TrezorUserEnvLink.startEmu({ wipe: true }); |
| 39 | + await TrezorUserEnvLink.setupEmu({ |
| 40 | + label: TREZOR_DEVICE_LABEL, |
| 41 | + mnemonic: SIMPLE_SEED, |
| 42 | + }); |
| 43 | + await TrezorUserEnvLink.startBridge(); |
| 44 | + await TrezorUserEnvLink.stopEmu(); |
| 45 | + } |
| 46 | + |
| 47 | + await openApp({ newInstance: true }); |
| 48 | + |
| 49 | + await TrezorConnect.init({ |
| 50 | + manifest: { |
| 51 | + |
| 52 | + appUrl: 'http://your.application.com', |
| 53 | + }, |
| 54 | + deeplinkOpen: url => { |
| 55 | + // eslint-disable-next-line no-console |
| 56 | + console.log('deeplinkOpen', url); |
| 57 | + openUriScheme(url, 'android'); |
| 58 | + }, |
| 59 | + deeplinkCallbackUrl: 'https://test.com/connect', |
| 60 | + // deeplinkUrl: 'https://dev.suite.sldev.cz/connect/develop/deeplink/', |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + afterAll(async () => { |
| 65 | + if (platform === 'android') { |
| 66 | + await TrezorUserEnvLink.stopEmu(); |
| 67 | + } |
| 68 | + await device.terminateApp(); |
| 69 | + }); |
| 70 | + |
| 71 | + it('Navigate to dashboard', async () => { |
| 72 | + await onOnboarding.finishOnboarding(); |
| 73 | + console.log('after onboarding'); |
| 74 | + |
| 75 | + if (platform === 'android') { |
| 76 | + console.log('platform is android'); |
| 77 | + await TrezorUserEnvLink.startEmu(); |
| 78 | + |
| 79 | + await waitFor(element(by.id('@screen/CoinEnablingInit'))) |
| 80 | + .toBeVisible() |
| 81 | + .withTimeout(10000); |
| 82 | + |
| 83 | + console.log('before waitForBtcToBeVisible'); |
| 84 | + await onCoinEnablingInit.waitForBtcToBeVisible(); |
| 85 | + |
| 86 | + console.log('before enableNetwork'); |
| 87 | + await onCoinEnablingInit.enableNetwork('btc'); |
| 88 | + // TODO: I don't understand why without eth the part after does not complete. |
| 89 | + await onCoinEnablingInit.enableNetwork('eth'); |
| 90 | + |
| 91 | + console.log('before onCoinEnablingInit.save'); |
| 92 | + await onCoinEnablingInit.save(); |
| 93 | + |
| 94 | + console.log('before waitFor skip-view-only-mode'); |
| 95 | + await waitFor(element(by.id('skip-view-only-mode'))) |
| 96 | + .toBeVisible() |
| 97 | + .withTimeout(60000); // communication between connected Trezor and app takes some time. |
| 98 | + |
| 99 | + console.log('before skip-view-only-mode tap()'); |
| 100 | + await element(by.id('skip-view-only-mode')).tap(); |
| 101 | + |
| 102 | + console.log('before @home/portfolio/graph'); |
| 103 | + await detoxExpect(element(by.id('@home/portfolio/graph'))); // discovery finished and graph is visible |
| 104 | + |
| 105 | + // TODO: At this point we should be able to call a TrezorConnect from the deeplink package, |
| 106 | + // TODO: and check that the app opens it!! |
| 107 | + const response = await TrezorConnect.getAddress({ |
| 108 | + path: "m/49'/0'/0'/0/0", |
| 109 | + coin: 'btc', |
| 110 | + }); |
| 111 | + |
| 112 | + console.log('response', response); |
| 113 | + } |
| 114 | + }); |
| 115 | +}); |
0 commit comments