Merge pull request #150 from dennis00010011b/e2e-add-token-validation

e2e add token validation
This commit is contained in:
Victor Baranov 2018-10-01 15:15:18 +03:00 committed by GitHub
commit ad6cccbef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 109 deletions

View File

@ -72,6 +72,7 @@ describe('Metamask popup page', async function () {
})
it('screen \'Terms of Use\' has not empty agreement', async () => {
await delay(5000)
const terms = await waitUntilShowUp(screens.TOU.agreement, 300)
const text = await terms.getText()
assert.equal(text.length > 400, true, 'agreement is too short')
@ -135,7 +136,7 @@ describe('Metamask popup page', async function () {
await field.click()
const accountName = await waitUntilShowUp(screens.main.accountName)
assert.notEqual(accountName, false, '\'Account name\' change dialog isn\'t opened')
assert.equal(await accountName.getAttribute('value'), 'Account 1', 'incorrect placeholder')
assert.equal(await accountName.getAttribute('value'), 'Account 1', 'incorrect account name')
})
it('fill out new account\'s name', async () => {
@ -886,6 +887,8 @@ describe('Metamask popup page', async function () {
})
describe('Add Token: Custom', function () {
const symbol = 'TST'
const decimals = '0'
describe('Token Factory', function () {
@ -908,8 +911,8 @@ describe('Metamask popup page', async function () {
await totalSupply.sendKeys('100')
await tokenName.sendKeys('Test')
await tokenDecimal.sendKeys('0')
await tokenSymbol.sendKeys('TST')
await tokenDecimal.sendKeys(decimals)
await tokenSymbol.sendKeys(symbol)
await click(createToken)
await delay(1000)
})
@ -939,7 +942,7 @@ describe('Metamask popup page', async function () {
await delay(700)
})
})
describe('Add token', function () {
describe('Add token to LOCALHOST', function () {
it('navigates to the add token screen', async function () {
await waitUntilShowUp(screens.main.identicon)
@ -952,19 +955,38 @@ describe('Metamask popup page', async function () {
const addTokenScreen = await waitUntilShowUp(screens.addToken.title)
assert.equal(await addTokenScreen.getText(), screens.addToken.titleText)
})
it('adds token parameters', async function () {
it('open \'Add token\' tab', async function () {
const tab = await waitUntilShowUp(screens.addToken.tab.custom)
if (!await waitUntilShowUp(screens.addToken.custom.fields.contractAddress)) await tab.click()
})
it('address input is displayed and has correct placeholder', async function () {
const field = await waitUntilShowUp(screens.addToken.custom.fields.contractAddress)
assert.equal(await field.getAttribute('placeholder'), 'Token Contract Address', 'incorrect placeholder')
})
it('fill out address input', async function () {
const tokenContractAddress = await waitUntilShowUp(screens.addToken.custom.fields.contractAddress)
await tokenContractAddress.sendKeys(tokenAddress)
const button = await waitUntilShowUp(screens.addToken.custom.buttons.add)
await click(button)
})
it('field \'Symbol\' enabled and has correct value', async function () {
const field = await waitUntilShowUp(screens.addToken.custom.fields.tokenSymbol)
assert.equal(await field.isEnabled(), true, 'field disabled')
assert.equal(await field.getAttribute('placeholder'), 'Like "ETH"', 'incorrect placeholder')
assert.equal(await field.getAttribute('value'), symbol, 'incorrect value')
})
it('field \'Decimals\' enabled and has correct value', async function () {
const field = await waitUntilShowUp(screens.addToken.custom.fields.decimals)
assert.equal(await field.isEnabled(), false, 'field disabled')
assert.equal(await field.getAttribute('value'), decimals, 'incorrect value')
})
it('checks the token balance', async function () {
const button = await waitUntilShowUp(screens.addToken.custom.buttons.add)
await click(button)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.equal(await tokenBalance.getText(), '100 TST')
assert.equal(await tokenBalance.getText(), '100 TST', 'balance is incorrect or not displayed')
})
it('token balance updates if switch account', async function () {
@ -1012,55 +1034,44 @@ describe('Metamask popup page', async function () {
})
})
describe('Add token with the same address to each network ', async function () {
describe('Custom tokens validation ', async function () {
const tokenName = 'DVT'
const tokenDecimals = '13'
it('adds token with the same address to POA network', async function () {
it('can not add inexistent token to POA network', async function () {
await setProvider(NETWORKS.POA)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
assert(await isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in POA network')
})
it('adds token with the same address to SOKOL network', async function () {
it('can not add inexistent token to SOKOL network', async function () {
await setProvider(NETWORKS.SOKOL)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
assert(await isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in POA network')
})
it('adds token with the same address to ROPSTEN network', async function () {
it('can not add inexistent token to ROPSTEN network', async function () {
await setProvider(NETWORKS.ROPSTEN)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
assert(await isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in POA network')
})
it('adds token with the same address to KOVAN network', async function () {
it('can not add inexistent token to KOVAN network', async function () {
await setProvider(NETWORKS.KOVAN)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
assert(await isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in POA network')
})
it('adds token with the same address to RINKEBY network', async function () {
it('can not add inexistent token to RINKEBY network', async function () {
await setProvider(NETWORKS.RINKEBY)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
assert(await isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in POA network')
})
it('adds token with the same address to MAINNET network', async function () {
it('can not add inexistent token to MAINNET network', async function () {
await setProvider(NETWORKS.MAINNET)
await addToken(tokenAddress, tokenName, tokenDecimals)
const tokenBalance = await waitUntilShowUp(screens.main.tokens.balance)
assert.notEqual(await tokenBalance.getText(), '')
assert(await isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in POA network')
})
it('can not add inexistent token to LOCALHOST network', async function () {
await setProvider(NETWORKS.LOCALHOST)
assert(await isDisabledAddInexistentToken(tokenAddress.slice(0, tokenAddress.length - 2) + '0'), true, 'can add inexistent token in POA network')
})
it('token still should be displayed in LOCALHOST network', async function () {
await setProvider(NETWORKS.LOCALHOST)
await waitUntilDisappear(screens.main.tokens.amount)
assert.notEqual(await waitUntilShowUp(screens.main.tokens.amount), false, 'App is frozen')
const tokens = await driver.findElements(screens.main.tokens.amount)
@ -1108,36 +1119,6 @@ describe('Metamask popup page', async function () {
await click(button)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('check if token was removed from SOKOL network', async function () {
await setProvider(NETWORKS.SOKOL)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('check if token was removed from KOVAN network', async function () {
await setProvider(NETWORKS.KOVAN)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('check if token was removed from ROPSTEN network', async function () {
await setProvider(NETWORKS.ROPSTEN)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('check if token was removed from MAINNET network', async function () {
await setProvider(NETWORKS.MAINNET)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('check if token was removed from POA network', async function () {
await setProvider(NETWORKS.POA)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
it('check if token was removed from RINKEBY network', async function () {
await setProvider(NETWORKS.RINKEBY)
assert.equal(await assertTokensNotDisplayed(), true, 'tokens are displayed')
})
})
})
@ -1392,7 +1373,7 @@ describe('Metamask popup page', async function () {
}
}
async function addToken (tokenAddress, tokenName, tokenDecimals) {
async function isDisabledAddInexistentToken (tokenAddress) {
try {
const button = await waitUntilShowUp(screens.main.tokens.buttonAdd, 300)
await click(button)
@ -1404,17 +1385,25 @@ describe('Metamask popup page', async function () {
}
}
while (await waitUntilShowUp(screens.addToken.custom.fields.contractAddress) === false)
const field = await waitUntilShowUp(screens.addToken.custom.fields.contractAddress)
await clearField(field)
await field.sendKeys(tokenAddress)
const buttonAdd = await waitUntilShowUp(screens.addToken.custom.buttons.add)
await click(buttonAdd)
return true
} catch (err) {
console.log(err)
return false
}
const fieldAddress = await waitUntilShowUp(screens.addToken.custom.fields.contractAddress)
await clearField(fieldAddress)
await fieldAddress.sendKeys(tokenAddress)
const fieldSymbols = await waitUntilShowUp(screens.addToken.custom.fields.tokenSymbol)
if (await fieldSymbols.isEnabled()) return false
const fieldDecimals = await waitUntilShowUp(screens.addToken.custom.fields.tokenSymbol)
if (await fieldDecimals.isEnabled()) return false
const buttonAdd = await waitUntilShowUp(screens.addToken.custom.buttons.add)
if (await buttonAdd.isEnabled()) return false
const buttonCancel = await waitUntilShowUp(screens.addToken.custom.buttons.cancel)
await click(buttonCancel)
return true
}
async function checkBrowserForConsoleErrors () {

View File

@ -58,44 +58,20 @@ async function runAddTokenFlowTest (assert, done) {
const customAddress = (await findAsync($, '#token-address'))[0]
await customAddress.focus()
await timeout(1000)
await nativeInputValueSetter.call(customAddress, 'invalid address')
await customAddress.dispatchEvent(new Event('input', { bubbles: true }))
const buttonAdd = await queryAsync($, '#app-content > div > div.app-primary.from-right > div > div.flex-column.flex-justify-center.flex-grow.select-none > div.flex-space-around > div:nth-child(7) > button:nth-child(2)')
assert.ok(buttonAdd[0], 'add button rendered')
await buttonAdd[0].click()
// Verify contract error since contract address is invalid
const errorMessage = await queryAsync($, '.error')
assert.ok(errorMessage[0], 'error rendered')
// Input valid token contract address
await nativeInputValueSetter.call(customAddress, '0x177af043D3A1Aed7cc5f2397C70248Fc6cDC056c')
await customAddress.dispatchEvent(new Event('input', { bubbles: true }))
// Verify button add disabled since contract is invalid
const buttonAdd = await queryAsync($, '#app-content > div > div.app-primary.from-right > div > div.flex-column.flex-justify-center.flex-grow.select-none > div.flex-space-around > div:nth-child(7) > button:nth-child(2)')
assert.ok(buttonAdd[0], 'add button rendered')
assert.equal(await buttonAdd[0].getAttribute('disabled'), '', 'add button isn\'t disabled')
// Input token symbol with length more than 10
const customSymbol = (await findAsync($, '#token_symbol'))[0]
assert.ok(customSymbol, 'symbol field rendered')
/*
await customSymbol.focus()
await timeout(1000)
await nativeInputValueSetter.call(customSymbol, 'POAPOAPOA20')
await customSymbol.dispatchEvent(new Event('input', { bubbles: true }))
await buttonAdd[0].click()
// Verify symbol length error since length more than 10
errorMessage = await queryAsync($, '.error')[0]
assert.ok(errorMessage, 'error rendered')
*/
// Input valid token symbol
await nativeInputValueSetter.call(customSymbol, 'POA')
await customSymbol.dispatchEvent(new Event('input', { bubbles: true }))
assert.equal(await customSymbol.getAttribute('disabled'), '', 'symbol field isn\'t disabled')
// Input valid decimals
const customDecimals = (await findAsync($, '#token_decimals'))[0]
assert.ok(customDecimals, 'decimals field rendered')
// Click Add button
await buttonAdd[0].click()
// check if main screen
assert.ok((await queryAsync($, '.identicon-wrapper'))[0], 'returned to account detail wallet view')
assert.equal(await customDecimals.getAttribute('disabled'), '', 'decimals field isn\'t disabled')
}

View File

@ -102,9 +102,10 @@ async function runFirstTimeUsageTest(assert, done) {
assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.')
assert.ok(qrContainer, 'QR Container found')
await timeout(10000)
const networkMenu = (await findAsync(app, '.network-indicator'))[0]
networkMenu.click()
await timeout(5000)
const networkMenu2 = (await findAsync(app, '.network-indicator'))[0]
const children2 = networkMenu2.children
children2.length[3]