From 88a6f3787c520e404212c499f683c465727ca736 Mon Sep 17 00:00:00 2001 From: Peter Yinusa <53189696+PeterYinusa@users.noreply.github.com> Date: Mon, 31 Oct 2022 09:48:04 +0000 Subject: [PATCH] [E2E] Restore tests (#16298) * add restore test * rename spec --- test/e2e/restore/MetaMaskUserData.json | 50 +++++++++++++++++++ ...{backup.spec.js => backup-restore.spec.js} | 48 +++++++++++++++++- 2 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 test/e2e/restore/MetaMaskUserData.json rename test/e2e/tests/{backup.spec.js => backup-restore.spec.js} (59%) diff --git a/test/e2e/restore/MetaMaskUserData.json b/test/e2e/restore/MetaMaskUserData.json new file mode 100644 index 000000000..abea11e14 --- /dev/null +++ b/test/e2e/restore/MetaMaskUserData.json @@ -0,0 +1,50 @@ +{ + "addressBook": { + "addressBook": { + "0x539": { + "0x0c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb": { + "address": "0x0c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb", + "chainId": "0x539", + "isEns": false, + "memo": "", + "name": "Test Account" + } + } + } + }, + "preferences": { + "advancedGasFee": null, + "currentLocale": "en", + "dismissSeedBackUpReminder": true, + "featureFlags": { + "showIncomingTransactions": true + }, + "forgottenPassword": false, + "frequentRpcListDetail": [ + { + "chainId": "0x539", + "nickname": "Localhost 8545", + "rpcPrefs": {}, + "rpcUrl": "http://localhost:8545", + "ticker": "ETH" + } + ], + "infuraBlocked": false, + "ipfsGateway": "dweb.link", + "knownMethodData": {}, + "ledgerTransportType": "webhid", + "openSeaEnabled": false, + "preferences": { + "hideZeroBalanceTokens": false, + "showFiatInTestnets": false, + "showTestNetworks": false, + "useNativeCurrencyAsPrimaryCurrency": true + }, + "theme": "light", + "useBlockie": false, + "useCollectibleDetection": false, + "useNonceField": false, + "usePhishDetect": true, + "useTokenDetection": false + } +} diff --git a/test/e2e/tests/backup.spec.js b/test/e2e/tests/backup-restore.spec.js similarity index 59% rename from test/e2e/tests/backup.spec.js rename to test/e2e/tests/backup-restore.spec.js index 90fa400ce..1310abd53 100644 --- a/test/e2e/tests/backup.spec.js +++ b/test/e2e/tests/backup-restore.spec.js @@ -1,5 +1,6 @@ const { strict: assert } = require('assert'); const { promises: fs } = require('fs'); +const path = require('path'); const { convertToHexValue, withFixtures, @@ -36,7 +37,14 @@ const backupExists = async () => { } }; -describe('Backup', function () { +const restoreFile = path.join( + __dirname, + '..', + 'restore', + 'MetaMaskUserData.json', +); + +describe('Backup and Restore', function () { const ganacheOptions = { accounts: [ { @@ -46,7 +54,7 @@ describe('Backup', function () { }, ], }; - it('should create backup for the account', async function () { + it('should backup the account settings', async function () { await withFixtures( { fixtures: new FixtureBuilder().build(), @@ -79,4 +87,40 @@ describe('Backup', function () { }, ); }); + + it('should restore the account settings', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions, + title: this.test.title, + }, + async ({ driver }) => { + await driver.navigate(); + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + + // Restore + await driver.clickElement('.account-menu__icon'); + await driver.clickElement({ text: 'Settings', tag: 'div' }); + await driver.clickElement({ text: 'Advanced', tag: 'div' }); + const restore = await driver.findElement('#restore-file'); + await restore.sendKeys(restoreFile); + + // Dismiss success message + await driver.waitForSelector({ + css: '.actionable-message__message', + text: 'Your data has been restored successfully', + }); + await driver.clickElement({ text: 'Dismiss', tag: 'button' }); + + // Verify restore + await driver.clickElement({ text: 'Contacts', tag: 'div' }); + const recipient = await driver.findElement('[data-testid="recipient"]'); + assert.ok( + /Test\sAccount\s*0x0c54...AaFb/u.test(await recipient.getText()), + ); + }, + ); + }); });