From 7b68fa50c5eb4b400cbb8b3bc43729b3aea5532e Mon Sep 17 00:00:00 2001 From: dennistikhomirov Date: Mon, 1 Oct 2018 01:18:12 -0700 Subject: [PATCH] e2e:custom token validation --- test/e2e/metamask.spec.js | 132 ++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 75 deletions(-) diff --git a/test/e2e/metamask.spec.js b/test/e2e/metamask.spec.js index 9d53083ef..9b03db25b 100644 --- a/test/e2e/metamask.spec.js +++ b/test/e2e/metamask.spec.js @@ -135,7 +135,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 +886,8 @@ describe('Metamask popup page', async function () { }) describe('Add Token: Custom', function () { + const symbol = 'TST' + const decimals = '0' describe('Token Factory', function () { @@ -908,8 +910,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) }) @@ -952,19 +954,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,51 +1033,36 @@ 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, true, 'canadd 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, true, 'canadd 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, true, 'canadd 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, true, 'canadd 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, true, 'canadd 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, true, 'canadd inexistent token in POA network') }) it('token still should be displayed in LOCALHOST network', async function () { @@ -1108,36 +1114,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 +1368,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 +1380,23 @@ 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 + + return true } async function checkBrowserForConsoleErrors () {