Skip to content

Commit

Permalink
TW-459: [e2e] Import account by Mnemonic (#852)
Browse files Browse the repository at this point in the history
* [e2e] Import account by Mnemonic

* env fix

* env fix

* env fix

* env fix

* env fix

* env fix

* TW-459: [e2e] Import account by Mnemonic. Refactor

* TW-459: [e2e] Import account by Mnemonic. Refactor

* TW-459: [e2e] Import account by Mnemonic. Refactor + CopyButton selector fix

---------

Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>
  • Loading branch information
tttt24 and alex-tsx committed Feb 3, 2023
1 parent 554d980 commit cbfeda7
Show file tree
Hide file tree
Showing 31 changed files with 301 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
DEFAULT_SEED_PHRASE: ${{ secrets.DEFAULT_SEED_PHRASE }}
DEFAULT_PASSWORD: ${{ secrets.DEFAULT_PASSWORD }}
DEFAULT_HD_ACCOUNT_PRIVATE_KEY: ${{ secrets.DEFAULT_HD_ACCOUNT_PRIVATE_KEY }}
SECOND_SEED_PHRASE: ${{ secrets.SECOND_SEED_PHRASE }}
SECOND_SEED_PHRASE_PRIVATE_KEY: ${{ secrets.SECOND_SEED_PHRASE_PRIVATE_KEY }}

- name: Install dependencies and code quality check
uses: ./.github/workflows/code-quality-check
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/secrets-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ inputs:
required: false
DEFAULT_HD_ACCOUNT_PRIVATE_KEY:
required: false
SECOND_SEED_PHRASE:
required: false
SECOND_SEED_PHRASE_PRIVATE_KEY:
required: false

runs:
using: 'composite'
Expand Down Expand Up @@ -52,4 +56,6 @@ runs:
DEFAULT_SEED_PHRASE=${{ inputs.DEFAULT_SEED_PHRASE }}
DEFAULT_PASSWORD=${{ inputs.DEFAULT_PASSWORD }}
DEFAULT_HD_ACCOUNT_PRIVATE_KEY=${{ inputs.DEFAULT_HD_ACCOUNT_PRIVATE_KEY }}
SECOND_SEED_PHRASE=${{ inputs.SECOND_SEED_PHRASE }}
SECOND_SEED_PHRASE_PRIVATE_KEY=${{ inputs.SECOND_SEED_PHRASE_PRIVATE_KEY }}
EOF
2 changes: 2 additions & 0 deletions e2e/.env.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DEFAULT_SEED_PHRASE=
DEFAULT_PASSWORD=
DEFAULT_HD_ACCOUNT_PRIVATE_KEY=
SECOND_SEED_PHRASE=
SECOND_SEED_PHRASE_PRIVATE_KEY=
6 changes: 6 additions & 0 deletions e2e/src/classes/browser-context.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { getEnv } from '../utils/env.utils';
const defaultSeedPhrase = getEnv('DEFAULT_SEED_PHRASE');
const defaultPassword = getEnv('DEFAULT_PASSWORD');
const defaultPrivateKey = getEnv('DEFAULT_HD_ACCOUNT_PRIVATE_KEY');
const secondSeedPhrase = getEnv('SECOND_SEED_PHRASE');
const privateKeyOfSecondSeedPhrase = getEnv('SECOND_SEED_PHRASE_PRIVATE_KEY');

if (!defaultSeedPhrase) throw new Error('process.env.DEFAULT_SEED_PHRASE not found.');
if (!defaultPassword) throw new Error('process.env.DEFAULT_PASSWORD not found.');
if (!defaultPrivateKey) throw new Error('process.env.DEFAULT_PASSWORD not found.');
if (!secondSeedPhrase) throw new Error('process.env.SECOND_SEED_PHRASE not found.');
if (!privateKeyOfSecondSeedPhrase) throw new Error('process.env.SECOND_SEED_PHRASE_PRIVATE_KEY not found.');

export class BrowserContext {
public static EXTENSION_ID: string;
Expand All @@ -17,6 +21,8 @@ export class BrowserContext {
public static seedPhrase = defaultSeedPhrase;
public static password = defaultPassword;
public static privateKey = defaultPrivateKey;
public static secondSeedPhrase = secondSeedPhrase;
public static privateKeyOfSecondSeedPhrase = privateKeyOfSecondSeedPhrase;
public static resetPrivates = () => {
BrowserContext.seedPhrase = defaultSeedPhrase;
BrowserContext.password = defaultPassword;
Expand Down
3 changes: 1 addition & 2 deletions e2e/src/features/create-new-wallet.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Feature: Create a new wallet
@dev
Scenario: As a user, i'd like to create a new wallet
Given I am on the Welcome page
And I press Create New Wallet button on the Welcome page
Expand All @@ -21,5 +20,5 @@ Feature: Create a new wallet
And I press Accept Terms Checkbox on the Register Form page
And I press Create Button on the Register Form page

Then I am on the Header page
Then I am on the Home page

18 changes: 18 additions & 0 deletions e2e/src/features/import-account-by-mnemonic.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Import Account by Mnemonic
@dev
Scenario: As a user, I'd like to import account by mnemonic
Given I have imported an existing account

And I press AccountIcon on the Header page
And I am on the AccountsDropdown page

And I press ImportAccountButton on the AccountsDropdown page
And I am on the ImportAccountTab page

And I select Mnemonic tab
And I am on the ImportAccountMnemonic page

And I enter second mnemonic
And I press Mnemonic Import Button on the Import Account(Mnemonic) page

Then I reveal a private key and compare with private key of second seed phrase
4 changes: 2 additions & 2 deletions e2e/src/features/import-existing-wallet.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: Import existing wallet
And I press Import Existing Wallet button on the Welcome page

And I am on the ImportExistingWallet page
And I enter my mnemonic
And I enter default mnemonic
And I press Next button on the Import Existing Seed Phrase page

And I am on the SetWallet page
Expand All @@ -14,5 +14,5 @@ Feature: Import existing wallet
And I press Accept Terms Checkbox on the Register Form page
And I press Import Button on the Register Form page

Then I am on the Header page
Then I am on the Home page

3 changes: 2 additions & 1 deletion e2e/src/features/reveal-private-key.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Feature: Reveal private key
And I am on the RevealSecrets page
And I enter password into Reveal Password Field on the RevealSecrets page
And I press Reveal Button on the RevealSecrets page
And I compare my Private Key to Revealed value

Then I compare my Private Key to Revealed value

3 changes: 2 additions & 1 deletion e2e/src/features/reveal-seed-phrase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Feature: Reveal seed phrase
And I am on the RevealSecrets page
And I enter password into Reveal Password Field on the RevealSecrets page
And I press Reveal Button on the RevealSecrets page
And I compare my Seed Phrase to Revealed value

Then I compare my Seed Phrase to Revealed value

12 changes: 11 additions & 1 deletion e2e/src/page-objects/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { AccountsDropdown } from './pages/drop-down-lists/accounts.drop-down';
import { HeaderPage } from './pages/header.page';
import { HomePage } from './pages/home.page';
import { ImportAccountMnemonicTab } from './pages/import-account-tabs/import-account-mnemonic-tab.page';
import { ImportAccountPrivateKeyTab } from './pages/import-account-tabs/import-account-private-key-tab.page';
import { ImportAccountTab } from './pages/import-account-tabs/import-account-tab-switcher.page';
import { ImportAccountWatchOnlyTab } from './pages/import-account-tabs/import-account-watch-only-tab.page';
import { ImportExistingWalletPage } from './pages/importing-existing-wallet.page';
import { NewSeedBackupPage } from './pages/new-seed-backup.page';
import { RevealSecretsPage } from './pages/reveal-secrets.page';
Expand All @@ -17,5 +22,10 @@ export const Pages = {
Settings: new SettingsPage(),
RevealSecrets: new RevealSecretsPage(),
NewSeedBackup: new NewSeedBackupPage(),
VerifyMnemonic: new VerifyMnemonicPage()
VerifyMnemonic: new VerifyMnemonicPage(),
ImportAccountTab: new ImportAccountTab(),
ImportAccountPrivateKey: new ImportAccountPrivateKeyTab(),
ImportAccountMnemonic: new ImportAccountMnemonicTab(),
ImportAccountWatchOnly: new ImportAccountWatchOnlyTab(),
Home: new HomePage()
};
27 changes: 27 additions & 0 deletions e2e/src/page-objects/pages/home.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ExploreSelectors } from '../../../../src/app/pages/Explore.selectors';
import { Page } from '../../classes/page.class';
import { createPageElement } from '../../utils/search.utils';

export class HomePage extends Page {
ReceiveButton = createPageElement(ExploreSelectors.ReceiveButton);
BuyButton = createPageElement(ExploreSelectors.BuyButton);
SendButton = createPageElement(ExploreSelectors.SendButton);
WithdrawButton = createPageElement(ExploreSelectors.WithdrawButton);
SwapButton = createPageElement(ExploreSelectors.SwapButton);
AssetsTab = createPageElement(ExploreSelectors.AssetsTab);
ActivityTab = createPageElement(ExploreSelectors.ActivityTab);
CollectiblesTab = createPageElement(ExploreSelectors.CollectiblesTab);
PublicAddressButton = createPageElement(ExploreSelectors.PublicAddressButton);

async isVisible() {
await this.ReceiveButton.waitForDisplayed();
await this.BuyButton.waitForDisplayed();
await this.SendButton.waitForDisplayed();
await this.WithdrawButton.waitForDisplayed();
await this.SwapButton.waitForDisplayed();
await this.AssetsTab.waitForDisplayed();
await this.ActivityTab.waitForDisplayed();
await this.CollectiblesTab.waitForDisplayed();
await this.PublicAddressButton.waitForDisplayed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ImportAccountTestIds } from '../../../../../src/app/pages/ImportAccount/ImportAccount.test-ids';
import { Page } from '../../../classes/page.class';
import { createPageElement, findElements } from '../../../utils/search.utils';

export class ImportAccountMnemonicTab extends Page {
mnemonicWordInput = createPageElement(ImportAccountTestIds.mnemonicWordInput);
mnemonicPasswordField = createPageElement(ImportAccountTestIds.mnemonicPasswordField);
mnemonicImportButton = createPageElement(ImportAccountTestIds.mnemonicImportButton);

async isVisible() {
await this.mnemonicWordInput.waitForDisplayed();
await this.mnemonicPasswordField.waitForDisplayed();
await this.mnemonicImportButton.waitForDisplayed();
}

async enterSeedPhrase(seedPhrase: string) {
const wordsArray = seedPhrase.split(' ');
const wordsInputs = await findElements(ImportAccountTestIds.mnemonicWordInput);

for (let i = 0; i < wordsArray.length; i++) {
const word = wordsArray[i];
const input = wordsInputs[i];

await input.type(word);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ImportAccountTestIds } from '../../../../../src/app/pages/ImportAccount/ImportAccount.test-ids';
import { Page } from '../../../classes/page.class';
import { createPageElement } from '../../../utils/search.utils';

export class ImportAccountPrivateKeyTab extends Page {
privateKeyInput = createPageElement(ImportAccountTestIds.privateKeyInput);
privateKeyImportButton = createPageElement(ImportAccountTestIds.privateKeyImportButton);

async isVisible() {
await this.privateKeyInput.waitForDisplayed();
await this.privateKeyImportButton.waitForDisplayed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ImportAccountTestIds } from '../../../../../src/app/pages/ImportAccount/ImportAccount.test-ids';
import { Page } from '../../../classes/page.class';
import { createPageElement, findElements, getElementText } from '../../../utils/search.utils';

export class ImportAccountTab extends Page {
tabSwitcher = createPageElement(ImportAccountTestIds.tabSwitcher);

async isVisible() {
await this.tabSwitcher.waitForDisplayed();
}
async selectTab(tabName: string) {
const tabElements = await findElements(ImportAccountTestIds.tabSwitcher);

for (const tabElement of tabElements) {
const getTabValue = await getElementText(tabElement);

if (getTabValue === tabName) {
await tabElement.click();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ImportAccountTestIds } from '../../../../../src/app/pages/ImportAccount/ImportAccount.test-ids';
import { Page } from '../../../classes/page.class';
import { createPageElement } from '../../../utils/search.utils';

export class ImportAccountWatchOnlyTab extends Page {
watchOnlyInput = createPageElement(ImportAccountTestIds.watchOnlyInput);
watchOnlyImportButton = createPageElement(ImportAccountTestIds.watchOnlyImportButton);

async isVisible() {
await this.watchOnlyInput.waitForDisplayed();
await this.watchOnlyImportButton.waitForDisplayed();
}
}
13 changes: 11 additions & 2 deletions e2e/src/page-objects/pages/importing-existing-wallet.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ export class ImportExistingWalletPage extends Page {
await this.nextButton.waitForDisplayed();
await this.wordInput.waitForDisplayed();
}
async getWordsInputs() {
return findElements(ImportFromSeedPhraseTestIds.wordInput);

async enterSeedPhrase(seedPhrase: string) {
const wordsArray = seedPhrase.split(' ');
const wordsInputs = await findElements(ImportFromSeedPhraseTestIds.wordInput);

for (let i = 0; i < wordsArray.length; i++) {
const word = wordsArray[i];
const input = wordsInputs[i];

await input.type(word);
}
}
}
36 changes: 30 additions & 6 deletions e2e/src/page-objects/pages/verify-mnemonic.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NewSeedVerifyTestIds } from '../../../../src/app/pages/NewWallet/create/NewSeedVerify/NewSeedVerify.test-ids';
import { BrowserContext } from '../../classes/browser-context.class';
import { Page } from '../../classes/page.class';
import { createPageElement, findElements } from '../../utils/search.utils';
import { createPageElement, findElements, getElementText } from '../../utils/search.utils';

export class VerifyMnemonicPage extends Page {
nextButton = createPageElement(NewSeedVerifyTestIds.nextButton);
Expand All @@ -10,10 +11,33 @@ export class VerifyMnemonicPage extends Page {
await this.nextButton.waitForDisplayed();
await this.firstMnemonicInput.waitForDisplayed();
}
async getWordNumberSpans() {
return findElements(NewSeedVerifyTestIds.mnemonicWordNumber);
}
async getWordsInputs() {
return findElements(NewSeedVerifyTestIds.firstMnemonicInput);

async enterSeedPhraseVerification() {
const wordNumberSpans = await findElements(NewSeedVerifyTestIds.mnemonicWordNumber);
const wordNumberTexts = await Promise.all(wordNumberSpans.map(item => getElementText(item)));

const wordNumbers = wordNumberTexts.map(fullText => {
const numberText = fullText.split(' ')[1];

return Number(numberText);
});

const wordInputs = await findElements(NewSeedVerifyTestIds.firstMnemonicInput);
const wordInputTexts = await Promise.all(wordInputs.map(item => getElementText(item)));
const emptyWordInputIndexes = wordInputTexts
.map((text, index) => {
if (text) return undefined;
return index;
})
.filter(index => index !== undefined) as number[];

for (const index of emptyWordInputIndexes) {
const input = wordInputs[index];

const wordIndex = wordNumbers[index] - 1;
const word = BrowserContext.seedPhrase.split(' ')[wordIndex];

await input.type(word);
}
}
}
9 changes: 2 additions & 7 deletions e2e/src/step-definitions/common.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BrowserContext } from '../classes/browser-context.class';
import { Pages } from '../page-objects';
import { getInputText } from '../utils/input.utils';
import { createPageElement } from '../utils/search.utils';
import { enterMyMnemonicStep } from '../utils/shared-steps.utils';
import { LONG_TIMEOUT } from '../utils/timing.utils';

Given(/^I am on the (\w+) page$/, async (page: keyof typeof Pages) => {
Expand All @@ -15,10 +14,6 @@ Given(/I press (.*) on the (.*) page/, async (elementName: string, pageName: str
await createPageElement(`${pageName}/${elementName}`).click();
});

Given(/I enter my mnemonic/, async () => {
await enterMyMnemonicStep();
});

Given(
/I enter (seed|password) into (.*) on the (.*) page/,
async (inputType: string, elementName: string, pageName: string) => {
Expand All @@ -33,7 +28,7 @@ Given(/I have imported an existing account/, { timeout: LONG_TIMEOUT }, async ()
await Pages.Welcome.importExistingWalletButton.click();

await Pages.ImportExistingWallet.isVisible();
await enterMyMnemonicStep();
await Pages.ImportExistingWallet.enterSeedPhrase(BrowserContext.seedPhrase);
await Pages.ImportExistingWallet.nextButton.click();

await Pages.SetWallet.isVisible();
Expand All @@ -43,5 +38,5 @@ Given(/I have imported an existing account/, { timeout: LONG_TIMEOUT }, async ()
await Pages.SetWallet.acceptTerms.click();
await Pages.SetWallet.importButton.click();

await Pages.Header.isVisible();
await Pages.Home.isVisible();
});
28 changes: 1 addition & 27 deletions e2e/src/step-definitions/create-new-wallet.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { expect } from 'chai';

import { BrowserContext } from '../classes/browser-context.class';
import { Pages } from '../page-objects';
import { getElementText } from '../utils/search.utils';

Given(/I save my mnemonic/, async () => {
const value = await Pages.NewSeedBackup.seedPhraseValue.getText();
Expand All @@ -12,30 +11,5 @@ Given(/I save my mnemonic/, async () => {
});

Given(/I verify my mnemonic/, async () => {
const wordNumberSpans = await Pages.VerifyMnemonic.getWordNumberSpans();
const wordNumberTexts = await Promise.all(wordNumberSpans.map(item => getElementText(item)));

const wordNumbers = wordNumberTexts.map(fullText => {
const numberText = fullText.split(' ')[1];

return Number(numberText);
});

const wordInputs = await Pages.VerifyMnemonic.getWordsInputs();
const wordInputTexts = await Promise.all(wordInputs.map(item => getElementText(item)));
const emptyWordInputIndexes = wordInputTexts
.map((text, index) => {
if (text) return undefined;
return index;
})
.filter(index => index !== undefined) as number[];

for (const index of emptyWordInputIndexes) {
const input = wordInputs[index];

const wordIndex = wordNumbers[index] - 1;
const word = BrowserContext.seedPhrase.split(' ')[wordIndex];

await input.type(word);
}
await Pages.VerifyMnemonic.enterSeedPhraseVerification();
});
Loading

0 comments on commit cbfeda7

Please sign in to comment.