Refactoring send-edit.spec.js to use fixtures (#10792)

feature/default_network_editable
Niranjana Binoy 4 years ago committed by GitHub
parent 044949f8e1
commit 966b2dcb43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 172
      test/e2e/fixtures/send-edit/state.json
  2. 6
      test/e2e/run-all.sh
  3. 254
      test/e2e/send-edit.spec.js
  4. 111
      test/e2e/tests/send-edit.spec.js

@ -0,0 +1,172 @@
{
"data": {
"AppStateController": {
"mkrMigrationReminderTimestamp": null,
"swapsWelcomeMessageHasBeenShown": true
},
"CachedBalancesController": {
"cachedBalances": {
"4": {}
}
},
"CurrencyController": {
"conversionDate": 1575697244.188,
"conversionRate": 149.61,
"currentCurrency": "usd",
"nativeCurrency": "ETH"
},
"IncomingTransactionsController": {
"incomingTransactions": {},
"incomingTxLastFetchedBlocksByNetwork": {
"goerli": null,
"kovan": null,
"mainnet": null,
"rinkeby": 5570536
}
},
"KeyringController": {
"vault": "{\"data\":\"s6TpYjlUNsn7ifhEFTkuDGBUM1GyOlPrim7JSjtfIxgTt8/6MiXgiR/CtFfR4dWW2xhq85/NGIBYEeWrZThGdKGarBzeIqBfLFhw9n509jprzJ0zc2Rf+9HVFGLw+xxC4xPxgCS0IIWeAJQ+XtGcHmn0UZXriXm8Ja4kdlow6SWinB7sr/WM3R0+frYs4WgllkwggDf2/Tv6VHygvLnhtzp6hIJFyTjh+l/KnyJTyZW1TkZhDaNDzX3SCOHT\",\"iv\":\"FbeHDAW5afeWNORfNJBR0Q==\",\"salt\":\"TxZ+WbCW6891C9LK/hbMAoUsSEW1E8pyGLVBU6x5KR8=\"}"
},
"NetworkController": {
"network": "1337",
"provider": {
"nickname": "Localhost 8545",
"rpcUrl": "http://localhost:8545",
"chainId": "0x539",
"ticker": "ETH",
"type": "rpc"
}
},
"OnboardingController": {
"onboardingTabs": {},
"seedPhraseBackedUp": false
},
"PermissionsMetadata": {
"domainMetadata": {
"metamask.github.io": {
"icon": null,
"name": "M E T A M A S K M E S H T E S T"
}
},
"permissionsHistory": {},
"permissionsLog": [
{
"id": 746677923,
"method": "eth_accounts",
"methodType": "restricted",
"origin": "metamask.github.io",
"request": {
"id": 746677923,
"jsonrpc": "2.0",
"method": "eth_accounts",
"origin": "metamask.github.io",
"params": []
},
"requestTime": 1575697241368,
"response": {
"id": 746677923,
"jsonrpc": "2.0",
"result": []
},
"responseTime": 1575697241370,
"success": true
}
]
},
"PreferencesController": {
"accountTokens": {
"0x5cfe73b6021e818b776b421b1c4db2474086a7e1": {
"rinkeby": [],
"ropsten": []
}
},
"assetImages": {},
"completedOnboarding": true,
"currentLocale": "en",
"featureFlags": {
"showIncomingTransactions": true,
"transactionTime": false
},
"firstTimeFlowType": "create",
"forgottenPassword": false,
"frequentRpcListDetail": [],
"identities": {
"0x5cfe73b6021e818b776b421b1c4db2474086a7e1": {
"address": "0x5cfe73b6021e818b776b421b1c4db2474086a7e1",
"name": "Account 1"
}
},
"knownMethodData": {},
"lostIdentities": {},
"metaMetricsId": null,
"metaMetricsSendCount": 0,
"participateInMetaMetrics": false,
"preferences": {
"useNativeCurrencyAsPrimaryCurrency": true
},
"selectedAddress": "0x5cfe73b6021e818b776b421b1c4db2474086a7e1",
"suggestedTokens": {},
"tokens": [],
"useBlockie": false,
"useNonceField": false,
"usePhishDetect": true
},
"TransactionController": {
"transactions": {
"4046084157914634": {
"chainId": "0x539",
"history": [
{
"chainId": "0x539",
"id": 4046084157914634,
"loadingDefaults": true,
"metamaskNetworkId": "1337",
"origin": "metamask",
"status": "unapproved",
"time": 1617228030067,
"txParams": {
"from": "0x5cfe73b6021e818b776b421b1c4db2474086a7e1",
"gas": "0x61a8",
"gasPrice": "0x2540be400",
"to": "0x2f318C334780961FB129D2a6c30D0763d9a5C970",
"value": "0xde0b6b3a7640000"
},
"type": "sentEther"
},
[
{
"note": "Added new unapproved transaction.",
"op": "replace",
"path": "/loadingDefaults",
"timestamp": 1617228030069,
"value": false
}
]
],
"id": 4046084157914634,
"loadingDefaults": false,
"metamaskNetworkId": "1337",
"origin": "metamask",
"status": "unapproved",
"time": 1617228030067,
"txParams": {
"from": "0x5cfe73b6021e818b776b421b1c4db2474086a7e1",
"gas": "0x61a8",
"gasPrice": "0x2540be400",
"to": "0x2f318C334780961FB129D2a6c30D0763d9a5C970",
"value": "0xde0b6b3a7640000"
},
"type": "sentEther"
}
}
},
"config": {},
"firstTimeInfo": {
"date": 1575697234195,
"version": "7.7.0"
}
},
"meta": {
"version": 40
}
}

@ -55,12 +55,6 @@ retry concurrently --kill-others \
--success first \ --success first \
'mocha test/e2e/from-import-ui.spec' 'mocha test/e2e/from-import-ui.spec'
retry concurrently --kill-others \
--names 'e2e' \
--prefix '[{time}][{name}]' \
--success first \
'mocha test/e2e/send-edit.spec'
retry concurrently --kill-others \ retry concurrently --kill-others \
--names 'dapp,e2e' \ --names 'dapp,e2e' \
--prefix '[{time}][{name}]' \ --prefix '[{time}][{name}]' \

@ -1,254 +0,0 @@
const assert = require('assert');
const webdriver = require('selenium-webdriver');
const { By, until } = webdriver;
const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');
const { buildWebDriver } = require('./webdriver');
const Ganache = require('./ganache');
const ganacheServer = new Ganache();
describe('Using MetaMask with an existing account', function () {
let driver;
const testSeedPhrase =
'forum vessel pink push lonely enact gentle tail admit parrot grunt dress';
this.timeout(0);
this.bail(true);
before(async function () {
await ganacheServer.start({
accounts: [
{
secretKey:
'0x53CB0AB5226EEBF4D872113D98332C1555DC304443BEE1CF759D15798D3C55A9',
balance: 25000000000000000000,
},
],
});
const result = await buildWebDriver();
driver = result.driver;
await driver.navigate();
});
afterEach(async function () {
if (process.env.SELENIUM_BROWSER === 'chrome') {
const errors = await driver.checkBrowserForConsoleErrors(driver);
if (errors.length) {
const errorReports = errors.map((err) => err.message);
const errorMessage = `Errors found in browser console:\n${errorReports.join(
'\n',
)}`;
console.error(new Error(errorMessage));
}
}
if (this.currentTest.state === 'failed') {
await driver.verboseReportOnFailure(this.currentTest.title);
}
});
after(async function () {
await ganacheServer.quit();
await driver.quit();
});
describe('First time flow starting from an existing seed phrase', function () {
it('clicks the continue button on the welcome screen', async function () {
await driver.findElement(By.css('.welcome-page__header'));
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.getStarted.message}')]`,
),
);
await driver.delay(largeDelayMs);
});
it('clicks the "Import Wallet" option', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import wallet')]`),
);
await driver.delay(largeDelayMs);
});
it('clicks the "No thanks" option on the metametrics opt-in screen', async function () {
await driver.clickElement(By.css('.btn-default'));
await driver.delay(largeDelayMs);
});
it('imports a seed phrase', async function () {
const [seedTextArea] = await driver.findElements(
By.css('input[placeholder="Paste seed phrase from clipboard"]'),
);
await seedTextArea.sendKeys(testSeedPhrase);
await driver.delay(regularDelayMs);
const [password] = await driver.findElements(By.id('password'));
await password.sendKeys('correct horse battery staple');
const [confirmPassword] = await driver.findElements(
By.id('confirm-password'),
);
confirmPassword.sendKeys('correct horse battery staple');
await driver.clickElement(By.css('.first-time-flow__terms'));
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Import')]`),
);
await driver.delay(regularDelayMs);
});
it('clicks through the success screen', async function () {
await driver.findElement(
By.xpath(`//div[contains(text(), 'Congratulations')]`),
);
await driver.clickElement(
By.xpath(
`//button[contains(text(), '${enLocaleMessages.endOfFlowMessage10.message}')]`,
),
);
await driver.delay(regularDelayMs);
});
});
describe('Send ETH from inside MetaMask', function () {
it('starts a send transaction', async function () {
await driver.clickElement(By.css('[data-testid="eth-overview-send"]'));
await driver.delay(regularDelayMs);
const inputAddress = await driver.findElement(
By.css('input[placeholder="Search, public address (0x), or ENS"]'),
);
await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970');
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
await inputAmount.sendKeys('1');
// Set the gas limit
await driver.clickElement(By.css('.advanced-gas-options-btn'));
await driver.delay(regularDelayMs);
const gasModal = await driver.findElement(By.css('span .modal'));
const [gasPriceInput, gasLimitInput] = await driver.findElements(
By.css('.advanced-gas-inputs__gas-edit-row__input'),
);
await gasPriceInput.clear();
await driver.delay(50);
await gasPriceInput.sendKeys('10');
await driver.delay(50);
await driver.delay(tinyDelayMs);
await driver.delay(50);
await gasLimitInput.clear();
await driver.delay(50);
await gasLimitInput.sendKeys('25000');
await driver.delay(1000);
await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`));
await driver.wait(until.stalenessOf(gasModal));
await driver.delay(regularDelayMs);
// Continue to next screen
await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`));
await driver.delay(regularDelayMs);
});
it('has correct value and fee on the confirm screen the transaction', async function () {
const transactionAmounts = await driver.findElements(
By.css('.currency-display-component__text'),
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '1');
const transactionFee = transactionAmounts[1];
assert.equal(await transactionFee.getText(), '0.00025');
});
it('edits the transaction', async function () {
await driver.clickElement(
By.css('.confirm-page-container-header__back-button'),
);
await driver.delay(regularDelayMs);
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
await inputAmount.clear();
await driver.delay(50);
await inputAmount.sendKeys('2.2');
await driver.clickElement(By.css('.advanced-gas-options-btn'));
await driver.delay(regularDelayMs);
const gasModal = await driver.findElement(By.css('span .modal'));
const [gasPriceInput, gasLimitInput] = await driver.findElements(
By.css('.advanced-gas-inputs__gas-edit-row__input'),
);
await gasPriceInput.clear();
await driver.delay(50);
await gasPriceInput.sendKeys('8');
await driver.delay(50);
await driver.delay(tinyDelayMs);
await driver.delay(50);
await gasLimitInput.clear();
await driver.delay(50);
await gasLimitInput.sendKeys('100000');
await driver.delay(1000);
await driver.clickElement(By.xpath(`//button[contains(text(), 'Save')]`));
await driver.wait(until.stalenessOf(gasModal));
await driver.delay(regularDelayMs);
await driver.clickElement(By.xpath(`//button[contains(text(), 'Next')]`));
await driver.delay(regularDelayMs);
});
it('has correct updated value on the confirm screen the transaction', async function () {
const transactionAmounts = await driver.findElements(
By.css('.currency-display-component__text'),
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '2.2');
const transactionFee = transactionAmounts[1];
assert.equal(await transactionFee.getText(), '0.0008');
});
it('confirms the transaction', async function () {
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.delay(regularDelayMs);
});
it('finds the transaction in the transactions list', async function () {
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElements(
By.css('.transaction-list-item__primary-currency'),
);
assert.equal(txValues.length, 1);
assert.ok(/-2.2\s*ETH/u.test(await txValues[0].getText()));
});
});
});

@ -0,0 +1,111 @@
const { strict: assert } = require('assert');
const { By, Key, until } = require('selenium-webdriver');
const {
withFixtures,
tinyDelayMs,
regularDelayMs,
largeDelayMs,
} = require('../helpers');
describe('Editing Confirm Transaction', function () {
it('goes back from confirm page to edit eth value, gas price and gas limit', async function () {
const ganacheOptions = {
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: 25000000000000000000,
},
],
};
await withFixtures(
{
dapp: true,
fixtures: 'send-edit',
ganacheOptions,
title: this.test.title,
},
async ({ driver }) => {
await driver.navigate();
const passwordField = await driver.findElement(By.css('#password'));
await passwordField.sendKeys('correct horse battery staple');
await passwordField.sendKeys(Key.ENTER);
const transactionAmounts = await driver.findElements(
By.css('.currency-display-component__text'),
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '1');
const transactionFee = transactionAmounts[1];
assert.equal(await transactionFee.getText(), '0.00025');
await driver.clickElement(
By.css('.confirm-page-container-header__back-button'),
);
const inputAmount = await driver.findElement(
By.css('.unit-input__input'),
);
await inputAmount.clear();
await inputAmount.sendKeys('2.2');
await driver.clickElement(By.css('.advanced-gas-options-btn'));
await driver.delay(regularDelayMs);
const gasModal = await driver.findElement(By.css('span .modal'));
const [gasPriceInput, gasLimitInput] = await driver.findElements(
By.css('.advanced-gas-inputs__gas-edit-row__input'),
);
await gasPriceInput.clear();
await gasPriceInput.sendKeys('8');
await driver.delay(tinyDelayMs);
await gasLimitInput.clear();
await gasLimitInput.sendKeys('100000');
await driver.delay(largeDelayMs);
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Save')]`),
);
await driver.wait(until.stalenessOf(gasModal));
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Next')]`),
);
// has correct updated value on the confirm screen the transaction
const editedTransactionAmounts = await driver.findElements(
By.css('.currency-display-component__text'),
);
const editedTransactionAmount = editedTransactionAmounts[0];
assert.equal(await editedTransactionAmount.getText(), '2.2');
const editedTransactionFee = editedTransactionAmounts[1];
assert.equal(await editedTransactionFee.getText(), '0.0008');
// confirms the transaction
await driver.clickElement(
By.xpath(`//button[contains(text(), 'Confirm')]`),
);
await driver.delay(regularDelayMs);
await driver.clickElement(By.css('[data-testid="home__activity-tab"]'));
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
By.css(
'.transaction-list__completed-transactions .transaction-list-item',
),
);
return confirmedTxes.length === 1;
}, 10000);
const txValues = await driver.findElements(
By.css('.transaction-list-item__primary-currency'),
);
assert.equal(txValues.length, 1);
assert.ok(/-2.2\s*ETH/u.test(await txValues[0].getText()));
},
);
});
});
Loading…
Cancel
Save