1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Further e2e fixes in wake of #6364 and #6367 (#6374)

* getMethodData() default to abi decoded method if registry lookup errors

* Update e2e tests to work with getMethodData() fallback changes

* Remove indeterminency in gas input key entering in send token e2e test.
This commit is contained in:
Dan J Miller 2019-03-29 12:18:08 -02:30 committed by GitHub
parent 125a95ba71
commit 19c2b298f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 39 deletions

View File

@ -512,14 +512,22 @@ describe('MetaMask', function () {
await assertElementNotPresent(webdriver, driver, By.xpath(`//li[contains(text(), 'Data')]`)) await assertElementNotPresent(webdriver, driver, By.xpath(`//li[contains(text(), 'Data')]`))
const [gasPriceInput, gasLimitInput] = await findElements(driver, By.css('.advanced-gas-inputs__gas-edit-row__input')) const [gasPriceInput, gasLimitInput] = await findElements(driver, By.css('.advanced-gas-inputs__gas-edit-row__input'))
await gasPriceInput.clear() await gasPriceInput.sendKeys(Key.chord(Key.CONTROL, 'a'))
await delay(tinyDelayMs) await delay(50)
await gasPriceInput.sendKeys(Key.BACK_SPACE) await gasPriceInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasPriceInput.sendKeys(Key.BACK_SPACE) await gasPriceInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasPriceInput.sendKeys('10') await gasPriceInput.sendKeys('10')
await delay(50)
await delay(tinyDelayMs) await delay(tinyDelayMs)
await gasLimitInput.sendKeys('5') await delay(50)
await gasLimitInput.sendKeys(Key.chord(Key.CONTROL, 'a'))
await delay(50)
await gasLimitInput.sendKeys('25000')
await delay(tinyDelayMs) await delay(tinyDelayMs)
const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`), 10000) const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`), 10000)
@ -534,8 +542,10 @@ describe('MetaMask', function () {
let txValues let txValues
it('finds the transaction in the transactions list', async function () { it('finds the transaction in the transactions list', async function () {
const transactions = await findElements(driver, By.css('.transaction-list-item')) await driver.wait(async () => {
assert.equal(transactions.length, 4) const confirmedTxes = await findElements(driver, By.css('.transaction-list__completed-transactions .transaction-list-item'))
return confirmedTxes.length === 4
}, 10000)
txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary')) txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary'))
await driver.wait(until.elementTextMatches(txValues[0], /-3\s*ETH/), 10000) await driver.wait(until.elementTextMatches(txValues[0], /-3\s*ETH/), 10000)
@ -1003,7 +1013,7 @@ describe('MetaMask', function () {
const functionType = await findElement(driver, By.css('.confirm-page-container-content__function-type')) const functionType = await findElement(driver, By.css('.confirm-page-container-content__function-type'))
const functionTypeText = await functionType.getText() const functionTypeText = await functionType.getText()
assert.equal(functionTypeText, 'Not Found') assert.equal(functionTypeText, 'Transfer')
const confirmDataDiv = await findElement(driver, By.css('.confirm-page-container-content__data-box')) const confirmDataDiv = await findElement(driver, By.css('.confirm-page-container-content__data-box'))
const confirmDataText = await confirmDataDiv.getText() const confirmDataText = await confirmDataDiv.getText()
@ -1040,7 +1050,7 @@ describe('MetaMask', function () {
return confirmedTxes.length === 1 return confirmedTxes.length === 1
}, 10000) }, 10000)
const txStatuses = await findElements(driver, By.css('.transaction-list-item__action')) const txStatuses = await findElements(driver, By.css('.transaction-list-item__action'))
await driver.wait(until.elementTextMatches(txStatuses[0], /Contract\sInteraction/i), 10000) await driver.wait(until.elementTextMatches(txStatuses[0], /Sent\sToken/i), 10000)
}) })
}) })
@ -1081,23 +1091,31 @@ describe('MetaMask', function () {
await delay(regularDelayMs) await delay(regularDelayMs)
const [gasPriceInput, gasLimitInput] = await findElements(driver, By.css('.advanced-tab__gas-edit-row__input')) const [gasPriceInput, gasLimitInput] = await findElements(driver, By.css('.advanced-tab__gas-edit-row__input'))
await gasPriceInput.clear() await gasPriceInput.sendKeys(Key.chord(Key.CONTROL, 'a'))
await delay(tinyDelayMs) await delay(50)
await gasPriceInput.sendKeys(Key.BACK_SPACE) await gasPriceInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasPriceInput.sendKeys(Key.BACK_SPACE) await gasPriceInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasPriceInput.sendKeys('10') await gasPriceInput.sendKeys('10')
await delay(tinyDelayMs) await delay(50)
await gasLimitInput.clear()
await delay(tinyDelayMs)
await gasLimitInput.sendKeys(Key.chord(Key.CONTROL, 'a')) await gasLimitInput.sendKeys(Key.chord(Key.CONTROL, 'a'))
await delay(50)
await gasLimitInput.sendKeys(Key.BACK_SPACE) await gasLimitInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasLimitInput.sendKeys(Key.BACK_SPACE) await gasLimitInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasLimitInput.sendKeys(Key.BACK_SPACE) await gasLimitInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasLimitInput.sendKeys(Key.BACK_SPACE) await gasLimitInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasLimitInput.sendKeys(Key.BACK_SPACE) await gasLimitInput.sendKeys(Key.BACK_SPACE)
await delay(50)
await gasLimitInput.sendKeys('60000') await gasLimitInput.sendKeys('60000')
await delay(50)
await gasLimitInput.sendKeys(Key.chord(Key.CONTROL, 'e')) await gasLimitInput.sendKeys(Key.chord(Key.CONTROL, 'e'))
await delay(50)
const save = await findElement(driver, By.css('.page-container__footer-button')) const save = await findElement(driver, By.css('.page-container__footer-button'))
await save.click() await save.click()
@ -1124,7 +1142,7 @@ describe('MetaMask', function () {
const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary')) const txValues = await findElements(driver, By.css('.transaction-list-item__amount--primary'))
await driver.wait(until.elementTextMatches(txValues[0], /-7\s*TST/)) await driver.wait(until.elementTextMatches(txValues[0], /-7\s*TST/))
const txStatuses = await findElements(driver, By.css('.transaction-list-item__action')) const txStatuses = await findElements(driver, By.css('.transaction-list-item__action'))
await driver.wait(until.elementTextMatches(txStatuses[0], /Contract\sInteraction/), 10000) await driver.wait(until.elementTextMatches(txStatuses[0], /Sent\sToken/), 10000)
const walletBalance = await findElement(driver, By.css('.wallet-balance')) const walletBalance = await findElement(driver, By.css('.wallet-balance'))
await walletBalance.click() await walletBalance.click()
@ -1142,7 +1160,7 @@ describe('MetaMask', function () {
}) })
}) })
describe.skip('Approves a custom token from dapp', () => { describe('Approves a custom token from dapp', () => {
let gasModal let gasModal
it('approves an already created token', async () => { it('approves an already created token', async () => {
const windowHandles = await driver.getAllWindowHandles() const windowHandles = await driver.getAllWindowHandles()
@ -1180,11 +1198,11 @@ describe('MetaMask', function () {
const functionType = await findElement(driver, By.css('.confirm-page-container-content__function-type')) const functionType = await findElement(driver, By.css('.confirm-page-container-content__function-type'))
const functionTypeText = await functionType.getText() const functionTypeText = await functionType.getText()
assert.equal(functionTypeText, 'Not Found') assert.equal(functionTypeText, 'Approve')
const confirmDataDiv = await findElement(driver, By.css('.confirm-page-container-content__data-box')) const confirmDataDiv = await findElement(driver, By.css('.confirm-page-container-content__data-box'))
const confirmDataText = await confirmDataDiv.getText() const confirmDataText = await confirmDataDiv.getText()
assert.equal(confirmDataText.match(/0x095ea7b30000000000000000000000002f318c334780961fb129d2a6c30d0763d9a5c97/)) assert(confirmDataText.match(/0x095ea7b30000000000000000000000002f318c334780961fb129d2a6c30d0763d9a5c97/))
const detailsTab = await findElement(driver, By.xpath(`//li[contains(text(), 'Details')]`)) const detailsTab = await findElement(driver, By.xpath(`//li[contains(text(), 'Details')]`))
detailsTab.click() detailsTab.click()

View File

@ -1,3 +1,4 @@
import log from 'loglevel'
import { import {
conversionRateSelector, conversionRateSelector,
currentCurrencySelector, currentCurrencySelector,
@ -369,23 +370,17 @@ export function setTransactionToConfirm (transactionId) {
const { tokens: existingTokens } = state const { tokens: existingTokens } = state
const { data, to: tokenAddress } = txParams const { data, to: tokenAddress } = txParams
try { dispatch(setFetchingData(true))
dispatch(setFetchingData(true)) const methodData = await getMethodData(data)
const methodData = await getMethodData(data) dispatch(updateMethodData(methodData))
dispatch(updateMethodData(methodData))
} catch (error) {
dispatch(updateMethodData({}))
dispatch(setFetchingData(false))
}
try { try {
const toSmartContract = await isSmartContractAddress(to) const toSmartContract = await isSmartContractAddress(to)
dispatch(updateToSmartContract(toSmartContract)) dispatch(updateToSmartContract(toSmartContract))
dispatch(setFetchingData(false))
} catch (error) { } catch (error) {
dispatch(setFetchingData(false)) log.error(error)
} }
dispatch(setFetchingData(false))
const tokenData = getTokenData(data) const tokenData = getTokenData(data)
dispatch(updateTokenData(tokenData)) dispatch(updateTokenData(tokenData))

View File

@ -21,6 +21,7 @@ import {
CANCEL_ATTEMPT_ACTION_KEY, CANCEL_ATTEMPT_ACTION_KEY,
} from '../constants/transactions' } from '../constants/transactions'
import log from 'loglevel'
import { addCurrencies } from './conversion-util' import { addCurrencies } from './conversion-util'
abiDecoder.addABI(abi) abiDecoder.addABI(abi)
@ -37,21 +38,31 @@ const registry = new MethodRegistry({ provider: global.ethereumProvider })
* @param {string} data - The hex data (@code txParams.data) of a transaction * @param {string} data - The hex data (@code txParams.data) of a transaction
* @returns {Object} * @returns {Object}
*/ */
export async function getMethodData (data = '') { export async function getMethodData (data = '') {
const prefixedData = ethUtil.addHexPrefix(data) const prefixedData = ethUtil.addHexPrefix(data)
const fourBytePrefix = prefixedData.slice(0, 10) const fourBytePrefix = prefixedData.slice(0, 10)
const sig = await registry.lookup(fourBytePrefix)
if (!sig) { try {
return {} const sig = await registry.lookup(fourBytePrefix)
}
if (!sig) {
return {}
}
const parsedResult = registry.parse(sig)
return {
name: parsedResult.name,
params: parsedResult.args,
}
} catch (error) {
log.error(error)
const contractData = getTokenData(data)
const { name } = contractData || {}
return { name }
}
const parsedResult = registry.parse(sig)
return {
name: parsedResult.name,
params: parsedResult.args,
}
} }
export function isConfirmDeployContract (txData = {}) { export function isConfirmDeployContract (txData = {}) {