2021-06-24 16:19:31 +02:00
const { strict : assert } = require ( 'assert' ) ;
2022-02-23 18:27:13 +01:00
const {
2023-05-26 15:05:34 +02:00
TEST _SEED _PHRASE ,
2022-02-23 18:27:13 +01:00
withFixtures ,
completeImportSRPOnboardingFlow ,
2023-05-24 19:50:31 +02:00
sendTransaction ,
findAnotherAccountFromAccountList ,
2023-06-08 15:21:21 +02:00
waitForAccountRendered ,
convertToHexValue ,
regularDelayMs ,
2023-06-20 17:33:24 +02:00
unlockWallet ,
2022-02-23 18:27:13 +01:00
} = require ( '../helpers' ) ;
2023-06-08 15:21:21 +02:00
2022-10-28 10:42:12 +02:00
const FixtureBuilder = require ( '../fixture-builder' ) ;
2023-06-08 15:21:21 +02:00
const { shortenAddress } = require ( '../../../ui/helpers/utils/util' ) ;
2021-06-24 16:19:31 +02:00
describe ( 'Add account' , function ( ) {
2022-02-23 18:27:13 +01:00
const testPassword = 'correct horse battery staple' ;
2023-06-08 15:21:21 +02:00
const firstAccount = '0x0Cc5261AB8cE458dc977078A3623E2BaDD27afD3' ;
const secondAccount = '0x3ED0eE22E0685Ebbf07b2360A8331693c413CC59' ;
2021-06-24 16:19:31 +02:00
const ganacheOptions = {
accounts : [
{
secretKey :
2022-02-23 18:27:13 +01:00
'0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9' ,
2022-01-19 00:08:41 +01:00
balance : convertToHexValue ( 25000000000000000000 ) ,
2021-06-24 16:19:31 +02:00
} ,
] ,
} ;
2022-02-23 18:27:13 +01:00
2021-06-24 16:19:31 +02:00
it ( 'should display correct new account name after create' , async function ( ) {
await withFixtures (
{
2022-10-28 10:42:12 +02:00
fixtures : new FixtureBuilder ( ) . build ( ) ,
2021-06-24 16:19:31 +02:00
ganacheOptions ,
title : this . test . title ,
} ,
async ( { driver } ) => {
await driver . navigate ( ) ;
2023-06-20 17:33:24 +02:00
await unlockWallet ( driver ) ;
2021-06-24 16:19:31 +02:00
2023-06-01 23:14:38 +02:00
await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
await driver . clickElement (
2023-06-20 15:38:24 +02:00
'[data-testid="multichain-account-menu-popover-add-account"]' ,
2023-06-01 23:14:38 +02:00
) ;
2023-06-13 17:07:01 +02:00
await driver . fill ( '[placeholder="Account 2"]' , '2nd account' ) ;
2021-06-24 16:19:31 +02:00
await driver . clickElement ( { text : 'Create' , tag : 'button' } ) ;
2023-06-20 15:45:40 +02:00
await driver . findElement ( {
2023-06-01 23:14:38 +02:00
css : '[data-testid="account-menu-icon"]' ,
2023-06-20 15:45:40 +02:00
text : '2nd account' ,
2021-06-24 16:19:31 +02:00
} ) ;
} ,
) ;
} ) ;
2022-02-23 18:27:13 +01:00
2023-05-24 19:50:31 +02:00
it ( 'should not affect public address when using secret recovery phrase to recover account with non-zero balance' , async function ( ) {
2022-02-23 18:27:13 +01:00
await withFixtures (
{
2022-10-28 10:42:12 +02:00
fixtures : new FixtureBuilder ( { onboarding : true } ) . build ( ) ,
2022-02-23 18:27:13 +01:00
ganacheOptions ,
title : this . test . title ,
failOnConsoleError : false ,
} ,
async ( { driver } ) => {
await driver . navigate ( ) ;
2023-05-24 19:50:31 +02:00
// On boarding with 1st account
2022-02-23 18:27:13 +01:00
await completeImportSRPOnboardingFlow (
driver ,
2023-05-26 15:05:34 +02:00
TEST _SEED _PHRASE ,
2022-02-23 18:27:13 +01:00
testPassword ,
) ;
2023-05-24 19:50:31 +02:00
// Check address of 1st account
2023-06-08 15:21:21 +02:00
await waitForAccountRendered ( driver ) ;
2023-06-20 15:45:40 +02:00
await driver . findElement ( {
css : '.multichain-address-copy-button' ,
text : shortenAddress ( firstAccount ) ,
} ) ;
2022-02-23 18:27:13 +01:00
2023-06-08 15:21:21 +02:00
// Create 2nd account
2023-05-24 19:50:31 +02:00
await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
2023-06-01 23:14:38 +02:00
await driver . clickElement (
2023-06-20 15:38:24 +02:00
'[data-testid="multichain-account-menu-popover-add-account"]' ,
2023-06-01 23:14:38 +02:00
) ;
2023-06-13 17:07:01 +02:00
await driver . fill ( '[placeholder="Account 2"]' , '2nd account' ) ;
2022-02-23 18:27:13 +01:00
await driver . clickElement ( { text : 'Create' , tag : 'button' } ) ;
2023-06-08 15:21:21 +02:00
await waitForAccountRendered ( driver ) ;
2022-02-23 18:27:13 +01:00
2023-05-24 19:50:31 +02:00
// Check address of 2nd account
2023-06-20 15:45:40 +02:00
await waitForAccountRendered ( driver ) ;
await driver . findElement ( {
css : '.multichain-address-copy-button' ,
text : shortenAddress ( secondAccount ) ,
} ) ;
2022-02-23 18:27:13 +01:00
2023-06-08 15:21:21 +02:00
// Log into the account with balance(account 1)
// and transfer some balance to 2nd account
// so they will not be removed after recovering SRP
2023-05-24 19:50:31 +02:00
const accountOneSelector = await findAnotherAccountFromAccountList (
driver ,
1 ,
'Account 1' ,
2022-02-23 18:27:13 +01:00
) ;
2023-06-08 15:21:21 +02:00
await waitForAccountRendered ( driver ) ;
2023-05-24 19:50:31 +02:00
await driver . clickElement ( accountOneSelector ) ;
await sendTransaction ( driver , secondAccount , '2.8' ) ;
2022-02-23 18:27:13 +01:00
2023-05-24 19:50:31 +02:00
// Lock the account
2023-06-01 23:14:38 +02:00
await driver . clickElement (
'[data-testid="account-options-menu-button"]' ,
) ;
2022-02-23 18:27:13 +01:00
await driver . delay ( regularDelayMs ) ;
2023-06-08 15:21:21 +02:00
await driver . waitForSelector ( '[data-testid="global-menu-lock"]' ) ;
await driver . clickElement ( '[data-testid="global-menu-lock"]' ) ;
await driver . waitForSelector ( '[data-testid="unlock-page"]' ) ;
2022-02-23 18:27:13 +01:00
2023-05-24 19:50:31 +02:00
// Recover via SRP in "forget password" option
2022-02-23 18:27:13 +01:00
const restoreSeedLink = await driver . findClickableElement (
2022-02-23 20:05:55 +01:00
'.unlock-page__link' ,
2022-02-23 18:27:13 +01:00
) ;
await restoreSeedLink . click ( ) ;
2022-03-16 22:43:21 +01:00
await driver . pasteIntoField (
2022-03-21 20:09:26 +01:00
'[data-testid="import-srp__srp-word-0"]' ,
2023-05-26 15:05:34 +02:00
TEST _SEED _PHRASE ,
2022-02-23 18:27:13 +01:00
) ;
await driver . fill ( '#password' , 'correct horse battery staple' ) ;
await driver . fill ( '#confirm-password' , 'correct horse battery staple' ) ;
2023-06-08 15:21:21 +02:00
await driver . delay ( regularDelayMs ) ;
await driver . clickElement (
'[data-testid="create-new-vault-submit-button"]' ,
) ;
2022-02-23 18:27:13 +01:00
2023-05-24 19:50:31 +02:00
// Land in 1st account home page
await driver . findElement ( '.home__main-view' ) ;
2023-06-08 15:21:21 +02:00
await waitForAccountRendered ( driver ) ;
2022-02-23 18:27:13 +01:00
2023-05-24 19:50:31 +02:00
// Check address of 1st account
2023-06-20 15:45:40 +02:00
await driver . findElement ( {
css : '.multichain-address-copy-button' ,
text : shortenAddress ( firstAccount ) ,
} ) ;
2023-06-08 15:21:21 +02:00
2023-05-24 19:50:31 +02:00
// Check address of 2nd account
const accountTwoSelector = await findAnotherAccountFromAccountList (
driver ,
2 ,
'Account 2' ,
2022-02-23 18:27:13 +01:00
) ;
2023-05-24 19:50:31 +02:00
await driver . clickElement ( accountTwoSelector ) ;
2023-06-08 15:21:21 +02:00
2023-06-20 15:45:40 +02:00
await driver . findElement ( {
css : '.multichain-address-copy-button' ,
text : shortenAddress ( secondAccount ) ,
} ) ;
2022-02-23 18:27:13 +01:00
} ,
) ;
} ) ;
2022-02-24 17:37:37 +01:00
2023-06-20 15:45:40 +02:00
it ( 'should be possible to remove an account imported with a private key, but should not be possible to remove an account generated from the SRP imported in onboarding' , async function ( ) {
2022-02-24 17:37:37 +01:00
const testPrivateKey =
'14abe6f4aab7f9f626fe981c864d0adeb5685f289ac9270c27b8fd790b4235d6' ;
await withFixtures (
{
2022-10-28 10:42:12 +02:00
fixtures : new FixtureBuilder ( ) . build ( ) ,
2022-02-24 17:37:37 +01:00
ganacheOptions ,
title : this . test . title ,
} ,
async ( { driver } ) => {
await driver . navigate ( ) ;
2023-06-20 17:33:24 +02:00
await unlockWallet ( driver ) ;
2022-02-24 17:37:37 +01:00
2023-06-01 23:14:38 +02:00
await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
await driver . clickElement (
2023-06-20 15:38:24 +02:00
'[data-testid="multichain-account-menu-popover-add-account"]' ,
2023-06-01 23:14:38 +02:00
) ;
2023-06-13 17:07:01 +02:00
await driver . fill ( '[placeholder="Account 2"]' , '2nd account' ) ;
2022-02-24 17:37:37 +01:00
await driver . clickElement ( { text : 'Create' , tag : 'button' } ) ;
2023-06-08 15:21:21 +02:00
// Wait for 2nd account to be created
await waitForAccountRendered ( driver ) ;
2023-06-20 15:45:40 +02:00
await driver . findElement ( {
css : '[data-testid="account-menu-icon"]' ,
text : '2nd account' ,
} ) ;
2023-06-08 15:21:21 +02:00
2023-06-01 23:14:38 +02:00
await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
2023-06-08 15:21:21 +02:00
const menuItems = await driver . findElements (
'.multichain-account-list-item' ,
) ;
assert . equal ( menuItems . length , 2 ) ;
// User cannot delete 2nd account generated from the SRP imported in onboarding
2022-02-24 17:37:37 +01:00
await driver . clickElement (
2023-06-01 23:14:38 +02:00
'.multichain-account-list-item--selected [data-testid="account-list-item-menu-button"]' ,
2022-02-24 17:37:37 +01:00
) ;
2023-06-08 15:21:21 +02:00
await driver . waitForElementNotPresent (
'[data-testid="account-list-menu-remove"]' ,
) ;
2022-02-24 17:37:37 +01:00
2023-06-08 15:21:21 +02:00
// Create 3rd account with private key
2023-06-16 18:25:13 +02:00
await driver . clickElement ( '.mm-text-field' ) ;
2023-06-01 23:14:38 +02:00
await driver . clickElement ( { text : 'Import account' , tag : 'button' } ) ;
2022-02-24 17:37:37 +01:00
await driver . fill ( '#private-key-box' , testPrivateKey ) ;
2023-06-13 17:07:01 +02:00
await driver . clickElement (
'[data-testid="import-account-confirm-button"]' ,
) ;
2022-02-24 17:37:37 +01:00
2023-06-08 15:21:21 +02:00
// Wait for 3rd account to be created
await waitForAccountRendered ( driver ) ;
2023-06-20 15:45:40 +02:00
await driver . findElement ( {
css : '[data-testid="account-menu-icon"]' ,
text : 'Account 3' ,
} ) ;
2022-02-24 17:37:37 +01:00
2023-06-08 15:21:21 +02:00
// User can delete 3rd account imported with a private key
2023-06-01 23:14:38 +02:00
await driver . clickElement ( '[data-testid="account-menu-icon"]' ) ;
2023-06-08 15:21:21 +02:00
const importedMenuItems = await driver . findElements (
'.multichain-account-list-item' ,
) ;
assert . equal ( importedMenuItems . length , 3 ) ;
2022-02-24 17:37:37 +01:00
await driver . clickElement (
2023-06-01 23:14:38 +02:00
'.multichain-account-list-item--selected [data-testid="account-list-item-menu-button"]' ,
2022-02-24 17:37:37 +01:00
) ;
2023-06-01 23:14:38 +02:00
await driver . findElement ( '[data-testid="account-list-menu-remove"]' ) ;
2022-02-24 17:37:37 +01:00
} ,
) ;
} ) ;
2021-06-24 16:19:31 +02:00
} ) ;