From 4c5df11fd3ac6c9350c7799c9f1e3891c9b13d24 Mon Sep 17 00:00:00 2001 From: Przemyslaw Rzad Date: Tue, 2 Jul 2019 15:12:57 +0200 Subject: [PATCH] E2E files linting (#117) * Introduced linting for oracle-e2e. * Fixed linting errors. * Introduced linting for ui-e2e * Fixed linting errors. * Typo. --- oracle-e2e/.eslintrc | 14 + oracle-e2e/package.json | 3 +- oracle-e2e/test/ercToErc.js | 10 +- oracle-e2e/test/ercToNative.js | 5 +- oracle-e2e/test/nativeToErc.js | 9 +- package.json | 2 +- ui-e2e/.eslintrc | 14 + ui-e2e/MetaMask.js | 224 ++++++------ ui-e2e/Page.js | 171 ++++----- ui-e2e/User.js | 88 ++--- ui-e2e/Utils.js | 36 +- ui-e2e/mainPage.js | 212 ++++++----- ui-e2e/package.json | 7 +- ui-e2e/test.js | 625 +++++++++++++++++++-------------- 14 files changed, 771 insertions(+), 649 deletions(-) create mode 100644 oracle-e2e/.eslintrc create mode 100644 ui-e2e/.eslintrc diff --git a/oracle-e2e/.eslintrc b/oracle-e2e/.eslintrc new file mode 100644 index 00000000..cb10c2c1 --- /dev/null +++ b/oracle-e2e/.eslintrc @@ -0,0 +1,14 @@ +{ + "extends": [ + "plugin:node/recommended", + "airbnb-base", + "../.eslintrc" + ], + "plugins": ["node"], + "rules": { + "node/no-unpublished-require": "off" + }, + "env": { + "mocha": true + } +} diff --git a/oracle-e2e/package.json b/oracle-e2e/package.json index 5ec2ca96..98e594e8 100644 --- a/oracle-e2e/package.json +++ b/oracle-e2e/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "start": "mocha" + "start": "mocha", + "lint": "eslint . --ignore-path ../.eslintignore" }, "author": "", "license": "ISC", diff --git a/oracle-e2e/test/ercToErc.js b/oracle-e2e/test/ercToErc.js index c19b67d0..1d2f2790 100644 --- a/oracle-e2e/test/ercToErc.js +++ b/oracle-e2e/test/ercToErc.js @@ -20,14 +20,8 @@ homeWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey) const tokenAbi = require(path.join(abisDir, 'ERC677BridgeToken.json')).abi -const erc20Token = new foreignWeb3.eth.Contract( - tokenAbi, - ercToErcBridge.foreignToken -) -const erc677Token = new homeWeb3.eth.Contract( - tokenAbi, - ercToErcBridge.homeToken -) +const erc20Token = new foreignWeb3.eth.Contract(tokenAbi, ercToErcBridge.foreignToken) +const erc677Token = new homeWeb3.eth.Contract(tokenAbi, ercToErcBridge.homeToken) describe('erc to erc', () => { it('should convert tokens in foreign to tokens in home', async () => { diff --git a/oracle-e2e/test/ercToNative.js b/oracle-e2e/test/ercToNative.js index 89ae65a5..8176518b 100644 --- a/oracle-e2e/test/ercToNative.js +++ b/oracle-e2e/test/ercToNative.js @@ -20,10 +20,7 @@ homeWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey) const tokenAbi = require(path.join(abisDir, 'ERC677BridgeToken.json')).abi -const erc20Token = new foreignWeb3.eth.Contract( - tokenAbi, - ercToNativeBridge.foreignToken -) +const erc20Token = new foreignWeb3.eth.Contract(tokenAbi, ercToNativeBridge.foreignToken) describe('erc to native', () => { it('should convert tokens in foreign to coins in home', async () => { diff --git a/oracle-e2e/test/nativeToErc.js b/oracle-e2e/test/nativeToErc.js index e2d5b70e..b3007045 100644 --- a/oracle-e2e/test/nativeToErc.js +++ b/oracle-e2e/test/nativeToErc.js @@ -2,7 +2,14 @@ const path = require('path') const Web3 = require('web3') const assert = require('assert') const promiseRetry = require('promise-retry') -const { user, validator, nativeToErcBridge, secondUser, homeRPC, foreignRPC } = require('../../e2e-commons/constants.json') +const { + user, + validator, + nativeToErcBridge, + secondUser, + homeRPC, + foreignRPC +} = require('../../e2e-commons/constants.json') const { abiPath } = require('../config.json') const { generateNewBlock } = require('../../e2e-commons/utils') diff --git a/package.json b/package.json index ffccef29..44595797 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "scripts": { "initialize": "yarn clean && git submodule update --init && yarn install --unsafe-perm --frozen-lockfile && yarn install:deploy && yarn compile:contracts", "build": "yarn workspace ui run build", - "lint": "yarn wsrun --exclude oracle-e2e --exclude ui-e2e --exclude poa-parity-bridge-contracts lint", + "lint": "yarn wsrun --exclude poa-parity-bridge-contracts lint", "test": "yarn wsrun --exclude monitor --exclude oracle-e2e --exclude ui-e2e test", "ansible-lint": "./deployment/lint.sh", "oracle-e2e": "./oracle-e2e/run-tests.sh", diff --git a/ui-e2e/.eslintrc b/ui-e2e/.eslintrc new file mode 100644 index 00000000..cb10c2c1 --- /dev/null +++ b/ui-e2e/.eslintrc @@ -0,0 +1,14 @@ +{ + "extends": [ + "plugin:node/recommended", + "airbnb-base", + "../.eslintrc" + ], + "plugins": ["node"], + "rules": { + "node/no-unpublished-require": "off" + }, + "env": { + "mocha": true + } +} diff --git a/ui-e2e/MetaMask.js b/ui-e2e/MetaMask.js index de9a8df6..7f531a80 100644 --- a/ui-e2e/MetaMask.js +++ b/ui-e2e/MetaMask.js @@ -1,152 +1,168 @@ -const key = require('selenium-webdriver').Key; -const Page = require('./Page.js').Page; -const By = require('selenium-webdriver/lib/by').By; -const {homeRPC, foreignRPC} = require('../e2e-commons/constants.json') -const IDMetaMask = "nkbihfbeogaeaoehlefnkodbefgpgknn"; -const URL = "chrome-extension://" + IDMetaMask + "//popup.html"; -const buttonSubmit = By.className("confirm btn-green"); -const buttonAccept = By.xpath('//*[@id="app-content"]/div/div[4]/div/button'); -const agreement = By.xpath("//*[@id=\"app-content\"]/div/div[4]/div/div/div/p[1]/strong"); -const fieldNewPass = By.xpath("//*[@id=\"password-box\"]"); -const fieldConfirmPass = By.xpath("//*[@id=\"password-box-confirm\"]"); -const buttonCreate = By.xpath("//*[@id=\"app-content\"]/div/div[4]/div/button"); -const buttonIveCopied = By.xpath("//*[@id=\"app-content\"]/div/div[4]/div/button[1]"); -const popupNetwork = By.className("network-name"); -const popupAccount = By.xpath("//*[@id=\"app-content\"]/div/div[1]/div/div[2]/span/div"); -const fieldPrivateKey = By.xpath("//*[@id=\"private-key-box\"]"); -const pass = "qwerty12345"; -const buttonImport = By.xpath("//*[@id=\"app-content\"]/div/div[4]/div/div[3]/button"); -const fieldNewRPCURL = By.id("new_rpc"); -const buttonSave = By.xpath("//*[@id=\"app-content\"]/div/div[4]/div/div[3]/div/div[2]/button"); -const arrowBackRPCURL = By.xpath("//*[@id=\"app-content\"]/div/div[4]/div/div[1]/i"); -const iconChangeAccount = By.className("cursor-pointer color-orange accounts-selector"); +/* eslint-disable no-return-await */ +// eslint-disable-next-line import/no-extraneous-dependencies +const { Key } = require('selenium-webdriver') +// eslint-disable-next-line import/no-extraneous-dependencies +const { By } = require('selenium-webdriver/lib/by') +const { Page } = require('./Page.js') +const { homeRPC, foreignRPC } = require('../e2e-commons/constants.json') -var accountOrderNumber = 1; -var networks = [0, 3, 43, 4, 8545]; +const IDMetaMask = 'nkbihfbeogaeaoehlefnkodbefgpgknn' +const URL = 'chrome-extension://' + IDMetaMask + '//popup.html' +const buttonSubmit = By.className('confirm btn-green') +const buttonAccept = By.xpath('//*[@id="app-content"]/div/div[4]/div/button') +const agreement = By.xpath('//*[@id="app-content"]/div/div[4]/div/div/div/p[1]/strong') +const fieldNewPass = By.xpath('//*[@id="password-box"]') +const fieldConfirmPass = By.xpath('//*[@id="password-box-confirm"]') +const buttonCreate = By.xpath('//*[@id="app-content"]/div/div[4]/div/button') +const buttonIveCopied = By.xpath('//*[@id="app-content"]/div/div[4]/div/button[1]') +const popupNetwork = By.className('network-name') +const popupAccount = By.xpath('//*[@id="app-content"]/div/div[1]/div/div[2]/span/div') +const fieldPrivateKey = By.xpath('//*[@id="private-key-box"]') +const pass = 'qwerty12345' +const buttonImport = By.xpath('//*[@id="app-content"]/div/div[4]/div/div[3]/button') +const fieldNewRPCURL = By.id('new_rpc') +const buttonSave = By.xpath('//*[@id="app-content"]/div/div[4]/div/div[3]/div/div[2]/button') +const arrowBackRPCURL = By.xpath('//*[@id="app-content"]/div/div[4]/div/div[1]/i') +const iconChangeAccount = By.className('cursor-pointer color-orange accounts-selector') + +let accountOrderNumber = 1 +const networks = [0, 3, 43, 4, 8545] class MetaMask extends Page { - constructor(driver) { - super(driver); - this.driver = driver; - this.URL = URL; + super(driver) + this.driver = driver + this.URL = URL } async clickButtonSubmitTransaction() { - return await this.clickWithWait(buttonSubmit); + return this.clickWithWait(buttonSubmit) } async activate() { - return await this.switchToNextPage() && - (await this.open(this.URL) === this.URL) && - await this.clickWithWait(buttonAccept) && - await this.clickWithWait(agreement) && - await this.clickKey(key.TAB, 15) && - await this.clickWithWait(buttonAccept) && - await this.waitUntilLocated(fieldNewPass) && - await this.clickWithWait(fieldNewPass) && - await this.fillWithWait(fieldNewPass, pass) && - await this.fillWithWait(fieldConfirmPass, pass) && - await this.clickWithWait(buttonCreate) && - await this.waitUntilDisplayed(buttonIveCopied) && - await this.clickWithWait(buttonIveCopied) && - await this.switchToNextPage(); + return ( + (await this.switchToNextPage()) && + (await this.open(this.URL)) === this.URL && + (await this.clickWithWait(buttonAccept)) && + (await this.clickWithWait(agreement)) && + (await this.clickKey(Key.TAB, 15)) && + (await this.clickWithWait(buttonAccept)) && + (await this.waitUntilLocated(fieldNewPass)) && + (await this.clickWithWait(fieldNewPass)) && + (await this.fillWithWait(fieldNewPass, pass)) && + (await this.fillWithWait(fieldConfirmPass, pass)) && + (await this.clickWithWait(buttonCreate)) && + (await this.waitUntilDisplayed(buttonIveCopied)) && + (await this.clickWithWait(buttonIveCopied)) && + (await this.switchToNextPage()) + ) } async importAccount(user) { - user.accountOrderInMetamask = accountOrderNumber - 1; - return await this.switchToNextPage() && - await this.setNetwork(user.networkID) && - await this.clickImportAccount() && - await this.fillWithWait(fieldPrivateKey, user.privateKey) && - await this.waitUntilDisplayed(buttonImport) && - await this.clickWithWait(buttonImport) && - await this.switchToNextPage(); + user.accountOrderInMetamask = accountOrderNumber - 1 + return ( + (await this.switchToNextPage()) && + (await this.setNetwork(user.networkID)) && + (await this.clickImportAccount()) && + (await this.fillWithWait(fieldPrivateKey, user.privateKey)) && + (await this.waitUntilDisplayed(buttonImport)) && + (await this.clickWithWait(buttonImport)) && + (await this.switchToNextPage()) + ) } async selectAccount(user) { try { - await this.switchToNextPage(); - await this.setNetwork(user.networkID); - await super.clickWithWait(popupAccount); - await this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[" + - user.accountOrderInMetamask + "].click();"); - await this.switchToNextPage(); - return true; - } - catch (err) { - return false; + await this.switchToNextPage() + await this.setNetwork(user.networkID) + await super.clickWithWait(popupAccount) + await this.driver.executeScript( + "document.getElementsByClassName('dropdown-menu-item')[" + + user.accountOrderInMetamask + + '].click();' + ) + await this.switchToNextPage() + return true + } catch (err) { + return false } } async clickImportAccount() { try { - await super.clickWithWait(popupAccount); - await this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[" - + (accountOrderNumber + 1) + "].click();"); - accountOrderNumber++; - return true; - } - catch (err) { - return false; + await super.clickWithWait(popupAccount) + await this.driver.executeScript( + "document.getElementsByClassName('dropdown-menu-item')[" + + (accountOrderNumber + 1) + + '].click();' + ) + accountOrderNumber++ + return true + } catch (err) { + return false } } async signTransaction(refreshCount) { - await this.switchToNextPage(); - let counter = 5; - if (refreshCount !== undefined) counter = refreshCount; + await this.switchToNextPage() + let counter = 5 + if (refreshCount !== undefined) counter = refreshCount do { - await this.refresh(); - await super.waitUntilLocated(iconChangeAccount); + await this.refresh() + await super.waitUntilLocated(iconChangeAccount) if (await this.isElementDisplayed(buttonSubmit)) { - return await this.clickButtonSubmitTransaction() && - await this.switchToNextPage(); + return (await this.clickButtonSubmitTransaction()) && (await this.switchToNextPage()) } - await this.driver.sleep(3000); - } while (counter-- >= 0); + await this.driver.sleep(3000) + } while (counter-- >= 0) - await this.switchToNextPage(); - return false; + await this.switchToNextPage() + return false } async setNetwork(provider) { try { - await super.clickWithWait(popupNetwork); - let orderNumber = networks.indexOf(provider); - let script = "document.getElementsByClassName('dropdown-menu-item')[" + orderNumber + "].click();" - if (orderNumber < 0) await this.addNetwork(provider); - else await this.driver.executeScript(script); - return true; - } - catch (err) { - return false; + await super.clickWithWait(popupNetwork) + const orderNumber = networks.indexOf(provider) + const script = + "document.getElementsByClassName('dropdown-menu-item')[" + orderNumber + '].click();' + if (orderNumber < 0) await this.addNetwork(provider) + else await this.driver.executeScript(script) + return true + } catch (err) { + return false } } async addNetwork(provider) { - let url; + let url switch (provider) { case homeRPC.ID: { - url = "http://localhost:8541"; - networks.push(177); - break; + url = 'http://localhost:8541' + networks.push(177) + break } case foreignRPC.ID: { - url = "http://localhost:8542"; - networks.push(142); - break; + url = 'http://localhost:8542' + networks.push(142) + break + } + default: { + throw new Error(`Unexcpected provider ${provider}`) } } - const index = networks.length > 8 ? 8 : networks.length; - await this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[" + - (index - 1) + "].click();"); - return await super.fillWithWait(fieldNewRPCURL, url) && - await super.clickWithWait(buttonSave) && - await super.clickWithWait(arrowBackRPCURL); + const index = networks.length > 8 ? 8 : networks.length + await this.driver.executeScript( + "document.getElementsByClassName('dropdown-menu-item')[" + (index - 1) + '].click();' + ) + return ( + (await super.fillWithWait(fieldNewRPCURL, url)) && + (await super.clickWithWait(buttonSave)) && + (await super.clickWithWait(arrowBackRPCURL)) + ) } } module.exports = { - MetaMask: MetaMask -}; + MetaMask +} diff --git a/ui-e2e/Page.js b/ui-e2e/Page.js index 4ba59b85..dc4d8d54 100644 --- a/ui-e2e/Page.js +++ b/ui-e2e/Page.js @@ -1,166 +1,151 @@ -const webdriver = require('selenium-webdriver'); -const Twait = 20000; +/* eslint-disable no-return-await */ +// eslint-disable-next-line import/no-extraneous-dependencies +const webdriver = require('selenium-webdriver') + +const Twait = 20000 class Page { - constructor(driver) { - this.driver = driver; + this.driver = driver } async waitUntilDisplayed(element, Twaiting) { - let counter = Twaiting; - if (counter === undefined) counter = 180; + let counter = Twaiting + if (counter === undefined) counter = 180 try { do { - await this.driver.sleep(300); - if (await this.isElementDisplayed(element)) return true; - } while (counter-- > 0); - return false; - } - catch (err) { - return false; + await this.driver.sleep(300) + if (await this.isElementDisplayed(element)) return true + } while (counter-- > 0) + return false + } catch (err) { + return false } } async waitUntilDisappear(element, Twaiting) { - let counter = Twaiting; - if (counter === undefined) counter = 180; + let counter = Twaiting + if (counter === undefined) counter = 180 try { do { - await this.driver.sleep(300); - if (!await this.isElementDisplayed(element)) return true; - } while (counter-- > 0); - return false; - } - catch (err) { - return false; + await this.driver.sleep(300) + if (!(await this.isElementDisplayed(element))) return true + } while (counter-- > 0) + return false + } catch (err) { + return false } } async waitUntilLocated(element, Twaiting) { - let counter = Twaiting; - if (counter === undefined) counter = 180; + let counter = Twaiting + if (counter === undefined) counter = 180 try { do { - await this.driver.sleep(300); - if (await this.isElementLocated(element)) return true; - } while (counter-- > 0); - return false; - } - catch (err) { - return false; + await this.driver.sleep(300) + if (await this.isElementLocated(element)) return true + } while (counter-- > 0) + return false + } catch (err) { + return false } } async isElementDisplayed(element) { try { - return await this.driver.findElement(element).isDisplayed(); - } - catch (err) { - return false; + return await this.driver.findElement(element).isDisplayed() + } catch (err) { + return false } } async isElementLocated(element) { - return (await this.driver.findElements(element)).length > 0; + return (await this.driver.findElements(element)).length > 0 } async clickWithWait(element) { try { - let field; - if (element.constructor.name !== "WebElement") { - field = await this.driver.wait(webdriver.until.elementLocated(element), Twait); - } - else field = element; - await field.click(); - return true; - } - catch (err) { - return false; + let field + if (element.constructor.name !== 'WebElement') { + field = await this.driver.wait(webdriver.until.elementLocated(element), Twait) + } else field = element + await field.click() + return true + } catch (err) { + return false } } async fillWithWait(element, text) { try { - let field; - if (element.constructor.name !== "WebElement") { - field = await this.driver.wait(webdriver.until.elementLocated(element), Twait); - } - else field = element; - await field.sendKeys(text); - return true; - } - catch (err) { - return false; + let field + if (element.constructor.name !== 'WebElement') { + field = await this.driver.wait(webdriver.until.elementLocated(element), Twait) + } else field = element + await field.sendKeys(text) + return true + } catch (err) { + return false } } async findWithWait(element) { try { - await this.driver.wait(webdriver.until.elementLocated(element), Twait); - return await this.driver.findElements(element); - } - catch (err) { - return null; + await this.driver.wait(webdriver.until.elementLocated(element), Twait) + return await this.driver.findElements(element) + } catch (err) { + return null } } async switchToNextPage() { - let allHandles = []; - let curHandle; + let allHandles = [] + let curHandle try { - allHandles = await this.driver.getAllWindowHandles(); - curHandle = await this.driver.getWindowHandle(); + allHandles = await this.driver.getAllWindowHandles() + curHandle = await this.driver.getWindowHandle() if (allHandles.length > 2) { - let arr = []; - arr[0] = allHandles[0]; - arr[1] = allHandles[1]; - allHandles = arr; + allHandles = [allHandles[0], allHandles[1]] } - let handle; + let handle for (let i = 0; i < allHandles.length; i++) { if (curHandle !== allHandles[i]) { - handle = allHandles[i]; - break; + handle = allHandles[i] + break } } - await this.driver.switchTo().window(handle); - await this.driver.sleep(500); - return true; - } - catch (err) { - return false; + await this.driver.switchTo().window(handle) + await this.driver.sleep(500) + return true + } catch (err) { + return false } } async refresh() { - await this.driver.navigate().refresh(); + await this.driver.navigate().refresh() } async getUrl() { - return await this.driver.getCurrentUrl(); + return await this.driver.getCurrentUrl() } async open(url) { - await this.driver.get(url); - return this.getUrl(); + await this.driver.get(url) + return this.getUrl() } async clickKey(key, times) { try { - const action = this.driver.actions(); - for (let i = 0; i < times; i++) - await action.sendKeys(key).perform(); - return true; - } - catch (err) { - return false; + const action = this.driver.actions() + for (let i = 0; i < times; i++) await action.sendKeys(key).perform() + return true + } catch (err) { + return false } } - } module.exports = { - Page: Page -}; - + Page +} diff --git a/ui-e2e/User.js b/ui-e2e/User.js index 41f9d35d..f8f97f19 100644 --- a/ui-e2e/User.js +++ b/ui-e2e/User.js @@ -1,51 +1,53 @@ -const fs = require('fs-extra'); -const MetaMask = require('./MetaMask.js').MetaMask; -const MainPage = require('./mainPage.js').MainPage; +/* eslint-disable no-return-await */ +const { MetaMask } = require('./MetaMask.js') +const { MainPage } = require('./mainPage.js') class User { - constructor(driver, obj) { - try { - this.driver = driver; - this.account = obj.account; - this.privateKey = obj.privateKey; - this.networkID = obj.networkID; - this.accountOrderInMetamask = "undefined";//for MetaMaskPage usage only - } - catch (err) { - console.log("instance User was not created"); - console.log(err); - } - } + constructor(driver, obj) { + try { + this.driver = driver + this.account = obj.account + this.privateKey = obj.privateKey + this.networkID = obj.networkID + this.accountOrderInMetamask = 'undefined' // for MetaMaskPage usage only + } catch (err) { + console.log('instance User was not created') + console.log(err) + } + } - async transferTokens(amount) { - let mainPage = new MainPage(this.driver); - let metaMask = new MetaMask(this.driver); - return await mainPage.fillFieldAmount(amount) && - await mainPage.clickButtonTransfer() && - await mainPage.waitUntilShowUpButtonTransferConfirm() && - await mainPage.clickButtonTransferConfirm() && - await metaMask.signTransaction() && - await mainPage.waitUntilTransactionDone() && - await mainPage.waitUntilShowUpButtonOk() && - await mainPage.clickButtonOk() - } + async transferTokens(amount) { + const mainPage = new MainPage(this.driver) + const metaMask = new MetaMask(this.driver) + return ( + (await mainPage.fillFieldAmount(amount)) && + (await mainPage.clickButtonTransfer()) && + (await mainPage.waitUntilShowUpButtonTransferConfirm()) && + (await mainPage.clickButtonTransferConfirm()) && + (await metaMask.signTransaction()) && + (await mainPage.waitUntilTransactionDone()) && + (await mainPage.waitUntilShowUpButtonOk()) && + (await mainPage.clickButtonOk()) + ) + } - async setMetaMaskNetwork() { - let metaMask = new MetaMask(this.driver); - return await metaMask.switchToNextPage() && - await metaMask.setNetwork(this.networkID) && - await metaMask.switchToNextPage(); - } + async setMetaMaskNetwork() { + const metaMask = new MetaMask(this.driver) + return ( + (await metaMask.switchToNextPage()) && + (await metaMask.setNetwork(this.networkID)) && + (await metaMask.switchToNextPage()) + ) + } - async setMetaMaskAccount() { - let metaMask = new MetaMask(this.driver); - if (this.accountOrderInMetamask === "undefined") { - return await metaMask.importAccount(this); - } else - return await metaMask.selectAccount(this); - } + async setMetaMaskAccount() { + const metaMask = new MetaMask(this.driver) + if (this.accountOrderInMetamask === 'undefined') { + return await metaMask.importAccount(this) + } else return await metaMask.selectAccount(this) + } } module.exports = { - User: User -}; + User +} diff --git a/ui-e2e/Utils.js b/ui-e2e/Utils.js index ccdf55d0..fda90722 100644 --- a/ui-e2e/Utils.js +++ b/ui-e2e/Utils.js @@ -1,9 +1,17 @@ -const webdriver = require('selenium-webdriver'); -const chrome = require('selenium-webdriver/chrome'); -const {user, nativeToErcBridge, ercToErcBridge, ercToNativeBridge, homeRPC, foreignRPC} = require('../e2e-commons/constants.json') +/* eslint-disable import/no-extraneous-dependencies */ +/* eslint-disable no-return-await */ +const webdriver = require('selenium-webdriver') +const chrome = require('selenium-webdriver/chrome') +const { + user, + nativeToErcBridge, + ercToErcBridge, + ercToNativeBridge, + homeRPC, + foreignRPC +} = require('../e2e-commons/constants.json') class Utils { - static async getHomeAccount() { return { account: user.address, @@ -21,25 +29,25 @@ class Utils { } static async getStartURL() { - return nativeToErcBridge.ui; + return nativeToErcBridge.ui } static async getErc20StartURL() { - return ercToErcBridge.ui; + return ercToErcBridge.ui } static async getErc20NativeStartURL() { - return ercToNativeBridge.ui; + return ercToNativeBridge.ui } static async startBrowserWithMetamask() { - let source = './MetaMask.crx'; - let options = new chrome.Options(); - await options.addExtensions(source); - await options.addArguments('disable-popup-blocking'); - let driver = await new webdriver.Builder().withCapabilities(options.toCapabilities()).build(); - await driver.sleep(5000); - return driver; + const source = './MetaMask.crx' + const options = new chrome.Options() + await options.addExtensions(source) + await options.addArguments('disable-popup-blocking') + const driver = await new webdriver.Builder().withCapabilities(options.toCapabilities()).build() + await driver.sleep(5000) + return driver } } diff --git a/ui-e2e/mainPage.js b/ui-e2e/mainPage.js index 377b370a..f5751d95 100644 --- a/ui-e2e/mainPage.js +++ b/ui-e2e/mainPage.js @@ -1,133 +1,125 @@ -const Page = require('./Page.js').Page; -const By = require('selenium-webdriver/lib/by').By; -const fieldAmount = By.id("amount"); -const buttonTransfer = By.className("bridge-form-button "); -const buttonOk = By.className("swal-button swal-button--confirm"); -const fieldsBalance = By.className("network-balance"); -const classWeb3Loaded = By.className("web3-loaded"); -const classPendingTransaction = By.className("pending-transaction"); -const loadingContainer = By.className("loading-container"); -const buttonTransferConfirm = By.className("transfer-confirm"); -const buttonDisclaimerConfirm = By.className("disclaimer-confirm"); -const checkboxDisclaimer = By.className("disclaimer-checkbox"); -const disclaimer = By.className("disclaimer-title"); +/* eslint-disable no-return-await */ +// eslint-disable-next-line import/no-extraneous-dependencies +const { By } = require('selenium-webdriver/lib/by') +const { Page } = require('./Page.js') + +const fieldAmount = By.id('amount') +const buttonTransfer = By.className('bridge-form-button ') +const buttonOk = By.className('swal-button swal-button--confirm') +const fieldsBalance = By.className('network-balance') +const classWeb3Loaded = By.className('web3-loaded') +const classPendingTransaction = By.className('pending-transaction') +const loadingContainer = By.className('loading-container') +const buttonTransferConfirm = By.className('transfer-confirm') +const buttonDisclaimerConfirm = By.className('disclaimer-confirm') +const checkboxDisclaimer = By.className('disclaimer-checkbox') +const disclaimer = By.className('disclaimer-title') class MainPage extends Page { - constructor(driver) { - super(driver); - this.url; - this.fieldHomePOABalance; - this.fieldForeignPOABalance; - } + async initFieldsBalance() { + if (!(await this.waitUntilWeb3Loaded())) return null + try { + const array = await super.findWithWait(fieldsBalance) + /* eslint-disable prefer-destructuring */ + this.fieldHomePOABalance = array[0] + this.fieldForeignPOABalance = array[1] + /* eslint-enable prefer-destructuring */ + return array + } catch (err) { + return null + } + } - async initFieldsBalance() { - if (!(await this.waitUntilWeb3Loaded())) return null; - try { - let array; - array = await super.findWithWait(fieldsBalance); - this.fieldHomePOABalance = array[0]; - this.fieldForeignPOABalance = array[1]; - return array; - } - catch (err) { - return null; - } - } + async getHomePOABalance() { + await this.initFieldsBalance() + return parseFloat(await this.fieldHomePOABalance.getText()) + } - async getHomePOABalance() { - await this.initFieldsBalance(); - return parseFloat(await this.fieldHomePOABalance.getText()); - } + async getForeignPOABalance() { + await this.initFieldsBalance() + return parseFloat(await this.fieldForeignPOABalance.getText()) + } - async getForeignPOABalance() { - await this.initFieldsBalance(); - return parseFloat(await this.fieldForeignPOABalance.getText()); - } + async fillFieldAmount(amount) { + try { + await this.clickWithWait(fieldAmount) + await this.fillWithWait(fieldAmount, amount) + return true + } catch (err) { + return false + } + } - async fillFieldAmount(amount) { - try { - await this.clickWithWait(fieldAmount); - await this.fillWithWait(fieldAmount, amount); - return true; - } - catch (err) { - return false; - } - } + async clickButtonTransfer() { + return this.clickWithWait(buttonTransfer) + } - async clickButtonTransfer() { - return await this.clickWithWait(buttonTransfer); - } + async clickButtonOk() { + return super.clickWithWait(buttonOk) + } - async clickButtonOk() { - return await super.clickWithWait(buttonOk); - } + async clickButtonTransferConfirm() { + return super.clickWithWait(buttonTransferConfirm) + } - async clickButtonTransferConfirm() { - return await super.clickWithWait(buttonTransferConfirm); - } + async isPresentButtonOk() { + return super.isElementDisplayed(buttonOk, 180) + } - async isPresentButtonOk() { - return await super.isElementDisplayed(buttonOk, 180); - } + async waitUntilWeb3Loaded() { + return this.waitUntilLocated(classWeb3Loaded, 180) + } - async waitUntilWeb3Loaded() { - return await this.waitUntilLocated(classWeb3Loaded, 180); - } + async isPendingTransaction() { + return super.isElementLocated(classPendingTransaction) + } - async isPendingTransaction() { - return await super.isElementLocated(classPendingTransaction); - } + async waitUntilTransactionDone() { + return this.waitUntilDisappear(classPendingTransaction, 360) + } - async waitUntilTransactionDone() { - return await this.waitUntilDisappear(classPendingTransaction, 360); - } + async waitUntilShowUpButtonOk() { + return super.waitUntilDisplayed(buttonOk, 360) + } - async waitUntilShowUpButtonOk() { - return await super.waitUntilDisplayed(buttonOk, 360); - } + async waitUntilShowUpButtonTransferConfirm() { + return super.waitUntilDisplayed(buttonTransferConfirm, 360) + } - async waitUntilShowUpButtonTransferConfirm() { - return await super.waitUntilDisplayed(buttonTransferConfirm, 360); - } + async waitUntilShowUpLoadingContainer() { + return super.waitUntilDisplayed(loadingContainer, 180) + } - async waitUntilShowUpButtonOk() { - return await super.waitUntilDisplayed(buttonOk, 360); - } + async isDisplayedLoadingContainer() { + return super.isElementDisplayed(loadingContainer) + } - async waitUntilShowUpLoadingContainer() { - return await super.waitUntilDisplayed(loadingContainer, 180); - } + async confirmDisclaimer() { + return ( + (await super.waitUntilDisplayed(disclaimer, 180)) && + // await this.clickCheckboxDisclaimer() && + (await this.clickButtonDisclaimerConfirm()) + ) + } - async isDisplayedLoadingContainer() { - return await super.isElementDisplayed(loadingContainer); - } + async clickButtonDisclaimerConfirm() { + return super.clickWithWait(buttonDisclaimerConfirm) + } - async confirmDisclaimer() { - return await super.waitUntilDisplayed(disclaimer, 180) && - //await this.clickCheckboxDisclaimer() && - await this.clickButtonDisclaimerConfirm(); - } - - async clickButtonDisclaimerConfirm() { - return await super.clickWithWait(buttonDisclaimerConfirm); - } - - async clickCheckboxDisclaimer() { - return await super.clickWithWait(checkboxDisclaimer); - } - - async open(url) { - let counter = 60; - do { - await this.driver.sleep(1000); - await super.open(url); - } while (counter-- >= 0 && !await this.isElementDisplayed(disclaimer)) - return (counter >= 0); - } + async clickCheckboxDisclaimer() { + return super.clickWithWait(checkboxDisclaimer) + } + async open(url) { + let counter = 60 + do { + await this.driver.sleep(1000) + await super.open(url) + } while (counter-- >= 0 && !(await this.isElementDisplayed(disclaimer))) + return counter >= 0 + } } module.exports = { - MainPage: MainPage -}; + MainPage +} diff --git a/ui-e2e/package.json b/ui-e2e/package.json index 88d8655d..b1160f23 100644 --- a/ui-e2e/package.json +++ b/ui-e2e/package.json @@ -6,5 +6,10 @@ "devDependencies": { "selenium-webdriver": "3.6.0" }, - "scripts": {} + "scripts": { + "lint": "eslint . --ignore-path ../.eslintignore" + }, + "engines": { + "node": ">= 8.9" + } } diff --git a/ui-e2e/test.js b/ui-e2e/test.js index 491ebd00..69a91953 100644 --- a/ui-e2e/test.js +++ b/ui-e2e/test.js @@ -1,310 +1,397 @@ -let test = require('selenium-webdriver/testing'); -let assert = require('assert'); -const Utils = require('./Utils.js').Utils; -const MetaMask = require('./MetaMask.js').MetaMask; -const MainPage = require('./mainPage.js').MainPage; -const User = require("./User.js").User; +/* eslint-disable import/no-extraneous-dependencies */ +/* eslint-disable no-return-await */ +const test = require('selenium-webdriver/testing') +const assert = require('assert') +const { Utils } = require('./Utils.js') +const { MetaMask } = require('./MetaMask.js') +const { MainPage } = require('./mainPage.js') +const { User } = require('./User.js') -test.describe('e2e-test for bridge.poa, version 1.5.0', async function () { - this.timeout(5 * 60000); - this.slow(1 * 60000); - this.retries(2); +test.describe('e2e-test for bridge.poa, version 1.5.0', async function() { + this.timeout(5 * 60000) + this.slow(1 * 60000) + this.retries(2) - const maxAmountPerTransactionLimit = 1; - let startURL; - let driver; - let mainPage; - let homeAccount; - let foreignAccount; - let metaMask; - let foreignBalanceBefore; - let homeBalanceBefore; + const maxAmountPerTransactionLimit = 1 + let startURL + let driver + let mainPage + let homeAccount + let foreignAccount + let metaMask + let foreignBalanceBefore + let homeBalanceBefore - test.before(async function () { - try { - driver = await Utils.startBrowserWithMetamask(); - mainPage = new MainPage(driver); - homeAccount = new User(driver, await Utils.getHomeAccount()); - foreignAccount = new User(driver, await Utils.getForeignAccount()); - metaMask = new MetaMask(driver); - await metaMask.activate(); - await homeAccount.setMetaMaskAccount(); - } catch (e) { - console.log(e) - } - }); - - test.after(async function () { + test.before(async () => { try { - await driver.quit(); + driver = await Utils.startBrowserWithMetamask() + mainPage = new MainPage(driver) + homeAccount = new User(driver, await Utils.getHomeAccount()) + foreignAccount = new User(driver, await Utils.getForeignAccount()) + metaMask = new MetaMask(driver) + await metaMask.activate() + await homeAccount.setMetaMaskAccount() } catch (e) { console.log(e) } - }); + }) - test.it('User is able to open main page of bridge-ui ', - async function () { - startURL = await Utils.getStartURL(); - let result = await mainPage.open(startURL); - console.log("Test URL: " + startURL); - return await assert.equal(result, true, "Test FAILED. Build failed."); - }); + test.after(async () => { + try { + await driver.quit() + } catch (e) { + console.log(e) + } + }) - test.it('Home page: disclaimer is displayed ', - async function () { - let result = await mainPage.confirmDisclaimer(); - return await assert.equal(result, true, "Test FAILED. Disclaimer is not displayed"); - }); + test.it('User is able to open main page of bridge-ui ', async () => { + startURL = await Utils.getStartURL() + const result = await mainPage.open(startURL) + console.log('Test URL: ' + startURL) + return await assert.strictEqual(result, true, 'Test FAILED. Build failed.') + }) - test.it('Main page: foreign POA balance is displayed ', - async function () { - foreignBalanceBefore = await mainPage.getForeignPOABalance(); - console.log("foreignBalanceBefore = "+foreignBalanceBefore); - let result = foreignBalanceBefore === 0; - return await assert.equal(result, true, "Test FAILED.Foreign POA balance is zero or not displayed "); - }); + test.it('Home page: disclaimer is displayed ', async () => { + const result = await mainPage.confirmDisclaimer() + return await assert.strictEqual(result, true, 'Test FAILED. Disclaimer is not displayed') + }) - test.it('Main page: home POA balance is displayed ', - async function () { - homeBalanceBefore = await mainPage.getHomePOABalance(); - console.log("homeBalanceBefore = "+homeBalanceBefore); - let result = homeBalanceBefore !== 0; - return await assert.equal(result, true, "Test FAILED.Home POA balance is zero or not displayed "); - }); + test.it('Main page: foreign POA balance is displayed ', async () => { + foreignBalanceBefore = await mainPage.getForeignPOABalance() + console.log('foreignBalanceBefore = ' + foreignBalanceBefore) + const result = foreignBalanceBefore === 0 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Foreign POA balance is zero or not displayed ' + ) + }) - test.it('User is able to send tokens from Home account to Foreign account ', - async function () { - let result = await homeAccount.transferTokens(maxAmountPerTransactionLimit); - return await assert.equal(result, true, "Test FAILED. User is able send tokens from Home account to Foreign account"); - }); + test.it('Main page: home POA balance is displayed ', async () => { + homeBalanceBefore = await mainPage.getHomePOABalance() + console.log('homeBalanceBefore = ' + homeBalanceBefore) + const result = homeBalanceBefore !== 0 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is zero or not displayed ' + ) + }) - test.it('Home POA balance has correctly changed after transaction', - async function () { - let newHomeBalance = await mainPage.getHomePOABalance(); - let shouldBe = homeBalanceBefore - maxAmountPerTransactionLimit; - console.log("newHomeBalance = " + newHomeBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newHomeBalance)) < (maxAmountPerTransactionLimit / 100); - homeBalanceBefore = newHomeBalance; - return await assert.equal(result, true, "Test FAILED.Home POA balance is not correct after transaction"); - }); + test.it('User is able to send tokens from Home account to Foreign account ', async () => { + const result = await homeAccount.transferTokens(maxAmountPerTransactionLimit) + return await assert.strictEqual( + result, + true, + 'Test FAILED. User is able send tokens from Home account to Foreign account' + ) + }) - test.it('Foreign account has received correct amount of tokens after transaction ', - async function () { - let newForeignBalance = await mainPage.getForeignPOABalance(); + test.it('Home POA balance has correctly changed after transaction', async () => { + const newHomeBalance = await mainPage.getHomePOABalance() + const shouldBe = homeBalanceBefore - maxAmountPerTransactionLimit + console.log('newHomeBalance = ' + newHomeBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100 + homeBalanceBefore = newHomeBalance + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is not correct after transaction' + ) + }) - let shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit; - console.log("newForeignBalance = " + newForeignBalance); - console.log("shouldBe = " + shouldBe); + test.it('Foreign account has received correct amount of tokens after transaction ', async () => { + const newForeignBalance = await mainPage.getForeignPOABalance() - let result = (Math.abs(shouldBe - newForeignBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED. Foreign POA balance is not correct after transaction"); - }); + const shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit + console.log('newForeignBalance = ' + newForeignBalance) + console.log('shouldBe = ' + shouldBe) - test.it('User is able to send tokens from Foreign account to Home account ', - async function () { - await foreignAccount.setMetaMaskNetwork(); - foreignBalanceBefore = await mainPage.getHomePOABalance(); - let result = await foreignAccount.transferTokens(maxAmountPerTransactionLimit); - return await assert.equal(result, true, "Test FAILED. User is able send tokens from Home account to Foreign account"); - }); + const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED. Foreign POA balance is not correct after transaction' + ) + }) - test.it('Foreign POA balance has correctly changed after transaction', - async function () { - let newForeignBalance = await mainPage.getHomePOABalance(); - let shouldBe = foreignBalanceBefore - maxAmountPerTransactionLimit; - console.log("newForeignBalance = " + newForeignBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newForeignBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED.Foreign POA balance is not correct after transaction"); - }); + test.it('User is able to send tokens from Foreign account to Home account ', async () => { + await foreignAccount.setMetaMaskNetwork() + foreignBalanceBefore = await mainPage.getHomePOABalance() + const result = await foreignAccount.transferTokens(maxAmountPerTransactionLimit) + return await assert.strictEqual( + result, + true, + 'Test FAILED. User is able send tokens from Home account to Foreign account' + ) + }) - test.it('Home account has received correct amount of tokens after transaction ', - async function () { - let newHomeBalance = await mainPage.getForeignPOABalance(); - let shouldBe = homeBalanceBefore + maxAmountPerTransactionLimit; - console.log("newHomeBalance = " + newHomeBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newHomeBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED.Home POA balance is not correct after transaction"); - }); + test.it('Foreign POA balance has correctly changed after transaction', async () => { + const newForeignBalance = await mainPage.getHomePOABalance() + const shouldBe = foreignBalanceBefore - maxAmountPerTransactionLimit + console.log('newForeignBalance = ' + newForeignBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Foreign POA balance is not correct after transaction' + ) + }) - test.it('ERC20-ERC20 - User is able to open main page of bridge-ui ', - async function () { - startURL = await Utils.getErc20StartURL(); - let result = await mainPage.open(startURL); - console.log("Test URL: " + startURL); - return await assert.equal(result, true, "Test FAILED. Build failed."); - }); + test.it('Home account has received correct amount of tokens after transaction ', async () => { + const newHomeBalance = await mainPage.getForeignPOABalance() + const shouldBe = homeBalanceBefore + maxAmountPerTransactionLimit + console.log('newHomeBalance = ' + newHomeBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is not correct after transaction' + ) + }) - test.it('ERC20-ERC20 - Home page: disclaimer is displayed ', - async function () { - let result = await mainPage.confirmDisclaimer(); - return await assert.equal(result, true, "Test FAILED. Disclaimer is not displayed"); - }); + test.it('ERC20-ERC20 - User is able to open main page of bridge-ui ', async () => { + startURL = await Utils.getErc20StartURL() + const result = await mainPage.open(startURL) + console.log('Test URL: ' + startURL) + return await assert.strictEqual(result, true, 'Test FAILED. Build failed.') + }) - test.it('ERC20-ERC20 - Main page: foreign erc20 balance is displayed ', - async function () { - foreignBalanceBefore = await mainPage.getForeignPOABalance(); - console.log("foreignBalanceBefore = "+foreignBalanceBefore); - let result = foreignBalanceBefore === 0; - return await assert.equal(result, true, "Test FAILED. Foreign erc20 balance is not zero"); - }); + test.it('ERC20-ERC20 - Home page: disclaimer is displayed ', async () => { + const result = await mainPage.confirmDisclaimer() + return await assert.strictEqual(result, true, 'Test FAILED. Disclaimer is not displayed') + }) - test.it('ERC20-ERC20 - Main page: home erc20 balance is displayed ', - async function () { - homeBalanceBefore = await mainPage.getHomePOABalance(); - console.log("homeBalanceBefore = "+homeBalanceBefore); - let result = homeBalanceBefore !== 0; - return await assert.equal(result, true, "Test FAILED. Home erc20 balance is zero or not displayed "); - }); + test.it('ERC20-ERC20 - Main page: foreign erc20 balance is displayed ', async () => { + foreignBalanceBefore = await mainPage.getForeignPOABalance() + console.log('foreignBalanceBefore = ' + foreignBalanceBefore) + const result = foreignBalanceBefore === 0 + return await assert.strictEqual(result, true, 'Test FAILED. Foreign erc20 balance is not zero') + }) - test.it('ERC20-ERC20 - User is able to send tokens from Foreign account to Home account ', - async function () { - homeBalanceBefore = await mainPage.getForeignPOABalance(); - foreignBalanceBefore = await mainPage.getHomePOABalance(); - let result = await foreignAccount.transferTokens(maxAmountPerTransactionLimit); - return await assert.equal(result, true, "Test FAILED. User is able send tokens from Foreign account to Home account"); - }); + test.it('ERC20-ERC20 - Main page: home erc20 balance is displayed ', async () => { + homeBalanceBefore = await mainPage.getHomePOABalance() + console.log('homeBalanceBefore = ' + homeBalanceBefore) + const result = homeBalanceBefore !== 0 + return await assert.strictEqual( + result, + true, + 'Test FAILED. Home erc20 balance is zero or not displayed ' + ) + }) - test.it('ERC20-ERC20 - Foreign POA balance has correctly changed after transaction', - async function () { - let newForeignBalance = await mainPage.getHomePOABalance(); - let shouldBe = foreignBalanceBefore - maxAmountPerTransactionLimit; - console.log("newForeignBalance = " + newForeignBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newForeignBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED.Foreign POA balance is not correct after transaction"); - }); + test.it( + 'ERC20-ERC20 - User is able to send tokens from Foreign account to Home account ', + async () => { + homeBalanceBefore = await mainPage.getForeignPOABalance() + foreignBalanceBefore = await mainPage.getHomePOABalance() + const result = await foreignAccount.transferTokens(maxAmountPerTransactionLimit) + return await assert.strictEqual( + result, + true, + 'Test FAILED. User is able send tokens from Foreign account to Home account' + ) + } + ) - test.it('ERC20-ERC20 - Home account has received correct amount of tokens after transaction ', - async function () { - let newHomeBalance = await mainPage.getForeignPOABalance(); - let shouldBe = homeBalanceBefore + maxAmountPerTransactionLimit; - console.log("newHomeBalance = " + newHomeBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newHomeBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED.Home POA balance is not correct after transaction"); - }); - test.it('ERC20-ERC20 - User is able to send tokens from Home account to Foreign account ', - async function () { - await homeAccount.setMetaMaskNetwork(); - homeBalanceBefore = await mainPage.getHomePOABalance(); - foreignBalanceBefore = await mainPage.getForeignPOABalance(); - let result = await homeAccount.transferTokens(maxAmountPerTransactionLimit); - return await assert.equal(result, true, "Test FAILED. User is able send tokens from Home account to Foreign account"); - }); + test.it('ERC20-ERC20 - Foreign POA balance has correctly changed after transaction', async () => { + const newForeignBalance = await mainPage.getHomePOABalance() + const shouldBe = foreignBalanceBefore - maxAmountPerTransactionLimit + console.log('newForeignBalance = ' + newForeignBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Foreign POA balance is not correct after transaction' + ) + }) - test.it('ERC20-ERC20 - Home POA balance has correctly changed after transaction', - async function () { - let newHomeBalance = await mainPage.getHomePOABalance(); - let shouldBe = homeBalanceBefore - maxAmountPerTransactionLimit; - console.log("newHomeBalance = " + newHomeBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newHomeBalance)) < (maxAmountPerTransactionLimit / 100); - homeBalanceBefore = newHomeBalance; - return await assert.equal(result, true, "Test FAILED.Home POA balance is not correct after transaction"); - }); + test.it( + 'ERC20-ERC20 - Home account has received correct amount of tokens after transaction ', + async () => { + const newHomeBalance = await mainPage.getForeignPOABalance() + const shouldBe = homeBalanceBefore + maxAmountPerTransactionLimit + console.log('newHomeBalance = ' + newHomeBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is not correct after transaction' + ) + } + ) + test.it( + 'ERC20-ERC20 - User is able to send tokens from Home account to Foreign account ', + async () => { + await homeAccount.setMetaMaskNetwork() + homeBalanceBefore = await mainPage.getHomePOABalance() + foreignBalanceBefore = await mainPage.getForeignPOABalance() + const result = await homeAccount.transferTokens(maxAmountPerTransactionLimit) + return await assert.strictEqual( + result, + true, + 'Test FAILED. User is able send tokens from Home account to Foreign account' + ) + } + ) - test.it('ERC20-ERC20 - Foreign account has received correct amount of tokens after transaction ', - async function () { - let newForeignBalance = await mainPage.getForeignPOABalance(); + test.it('ERC20-ERC20 - Home POA balance has correctly changed after transaction', async () => { + const newHomeBalance = await mainPage.getHomePOABalance() + const shouldBe = homeBalanceBefore - maxAmountPerTransactionLimit + console.log('newHomeBalance = ' + newHomeBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100 + homeBalanceBefore = newHomeBalance + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is not correct after transaction' + ) + }) - let shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit; - console.log("newForeignBalance = " + newForeignBalance); - console.log("shouldBe = " + shouldBe); + test.it( + 'ERC20-ERC20 - Foreign account has received correct amount of tokens after transaction ', + async () => { + const newForeignBalance = await mainPage.getForeignPOABalance() - let result = (Math.abs(shouldBe - newForeignBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED. Foreign POA balance is not correct after transaction"); - }); + const shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit + console.log('newForeignBalance = ' + newForeignBalance) + console.log('shouldBe = ' + shouldBe) - test.it('ERC20-Native - User is able to open main page of bridge-ui ', - async function () { - startURL = await Utils.getErc20NativeStartURL(); - let result = await mainPage.open(startURL); - console.log("Test URL: " + startURL); - return await assert.equal(result, true, "Test FAILED. Build failed."); - }); + const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED. Foreign POA balance is not correct after transaction' + ) + } + ) - test.it('ERC20-Native - Home page: disclaimer is displayed ', - async function () { - let result = await mainPage.confirmDisclaimer(); - return await assert.equal(result, true, "Test FAILED. Disclaimer is not displayed"); - }); + test.it('ERC20-Native - User is able to open main page of bridge-ui ', async () => { + startURL = await Utils.getErc20NativeStartURL() + const result = await mainPage.open(startURL) + console.log('Test URL: ' + startURL) + return await assert.strictEqual(result, true, 'Test FAILED. Build failed.') + }) - test.it('ERC20-Native - Main page: foreign erc20 balance is displayed ', - async function () { - await foreignAccount.setMetaMaskNetwork(); - foreignBalanceBefore = await mainPage.getForeignPOABalance(); - console.log("foreignBalanceBefore = "+foreignBalanceBefore); - let result = foreignBalanceBefore !== 0; - return await assert.equal(result, true, "Test FAILED. Foreign erc20 balance is zero"); - }); + test.it('ERC20-Native - Home page: disclaimer is displayed ', async () => { + const result = await mainPage.confirmDisclaimer() + return await assert.strictEqual(result, true, 'Test FAILED. Disclaimer is not displayed') + }) - test.it('ERC20-Native - Main page: home erc20 balance is displayed ', - async function () { - homeBalanceBefore = await mainPage.getHomePOABalance(); - console.log("homeBalanceBefore = "+homeBalanceBefore); - let result = homeBalanceBefore !== 0; - return await assert.equal(result, true, "Test FAILED. Home erc20 balance is zero or not displayed "); - }); + test.it('ERC20-Native - Main page: foreign erc20 balance is displayed ', async () => { + await foreignAccount.setMetaMaskNetwork() + foreignBalanceBefore = await mainPage.getForeignPOABalance() + console.log('foreignBalanceBefore = ' + foreignBalanceBefore) + const result = foreignBalanceBefore !== 0 + return await assert.strictEqual(result, true, 'Test FAILED. Foreign erc20 balance is zero') + }) - test.it('ERC20-Native - User is able to send tokens from Foreign account to Home account ', - async function () { - homeBalanceBefore = await mainPage.getForeignPOABalance(); - foreignBalanceBefore = await mainPage.getHomePOABalance(); - let result = await foreignAccount.transferTokens(maxAmountPerTransactionLimit); - return await assert.equal(result, true, "Test FAILED. User is able send tokens from Foreign account to Home account"); - }); + test.it('ERC20-Native - Main page: home erc20 balance is displayed ', async () => { + homeBalanceBefore = await mainPage.getHomePOABalance() + console.log('homeBalanceBefore = ' + homeBalanceBefore) + const result = homeBalanceBefore !== 0 + return await assert.strictEqual( + result, + true, + 'Test FAILED. Home erc20 balance is zero or not displayed ' + ) + }) - test.it('ERC20-Native - Foreign POA balance has correctly changed after transaction', - async function () { - let newForeignBalance = await mainPage.getHomePOABalance(); - let shouldBe = foreignBalanceBefore - maxAmountPerTransactionLimit; - console.log("newForeignBalance = " + newForeignBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newForeignBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED.Foreign POA balance is not correct after transaction"); - }); + test.it( + 'ERC20-Native - User is able to send tokens from Foreign account to Home account ', + async () => { + homeBalanceBefore = await mainPage.getForeignPOABalance() + foreignBalanceBefore = await mainPage.getHomePOABalance() + const result = await foreignAccount.transferTokens(maxAmountPerTransactionLimit) + return await assert.strictEqual( + result, + true, + 'Test FAILED. User is able send tokens from Foreign account to Home account' + ) + } + ) - test.it('ERC20-Native - Home account has received correct amount of tokens after transaction ', - async function () { - let newHomeBalance = await mainPage.getForeignPOABalance(); - let shouldBe = homeBalanceBefore + maxAmountPerTransactionLimit; - console.log("newHomeBalance = " + newHomeBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newHomeBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED.Home POA balance is not correct after transaction"); - }); - test.it('ERC20-Native - User is able to send tokens from Home account to Foreign account ', - async function () { - await homeAccount.setMetaMaskNetwork(); - homeBalanceBefore = await mainPage.getHomePOABalance(); - foreignBalanceBefore = await mainPage.getForeignPOABalance(); - let result = await homeAccount.transferTokens(maxAmountPerTransactionLimit); - return await assert.equal(result, true, "Test FAILED. User is able send tokens from Home account to Foreign account"); - }); + test.it( + 'ERC20-Native - Foreign POA balance has correctly changed after transaction', + async () => { + const newForeignBalance = await mainPage.getHomePOABalance() + const shouldBe = foreignBalanceBefore - maxAmountPerTransactionLimit + console.log('newForeignBalance = ' + newForeignBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Foreign POA balance is not correct after transaction' + ) + } + ) - test.it('ERC20-Native - Home POA balance has correctly changed after transaction', - async function () { - let newHomeBalance = await mainPage.getHomePOABalance(); - let shouldBe = homeBalanceBefore - maxAmountPerTransactionLimit; - console.log("newHomeBalance = " + newHomeBalance); - console.log("shouldBe = " + shouldBe); - let result = (Math.abs(shouldBe - newHomeBalance)) < (maxAmountPerTransactionLimit / 100); - homeBalanceBefore = newHomeBalance; - return await assert.equal(result, true, "Test FAILED.Home POA balance is not correct after transaction"); - }); + test.it( + 'ERC20-Native - Home account has received correct amount of tokens after transaction ', + async () => { + const newHomeBalance = await mainPage.getForeignPOABalance() + const shouldBe = homeBalanceBefore + maxAmountPerTransactionLimit + console.log('newHomeBalance = ' + newHomeBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is not correct after transaction' + ) + } + ) + test.it( + 'ERC20-Native - User is able to send tokens from Home account to Foreign account ', + async () => { + await homeAccount.setMetaMaskNetwork() + homeBalanceBefore = await mainPage.getHomePOABalance() + foreignBalanceBefore = await mainPage.getForeignPOABalance() + const result = await homeAccount.transferTokens(maxAmountPerTransactionLimit) + return await assert.strictEqual( + result, + true, + 'Test FAILED. User is able send tokens from Home account to Foreign account' + ) + } + ) - test.it('ERC20-Native - Foreign account has received correct amount of tokens after transaction ', - async function () { - let newForeignBalance = await mainPage.getForeignPOABalance(); + test.it('ERC20-Native - Home POA balance has correctly changed after transaction', async () => { + const newHomeBalance = await mainPage.getHomePOABalance() + const shouldBe = homeBalanceBefore - maxAmountPerTransactionLimit + console.log('newHomeBalance = ' + newHomeBalance) + console.log('shouldBe = ' + shouldBe) + const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100 + homeBalanceBefore = newHomeBalance + return await assert.strictEqual( + result, + true, + 'Test FAILED.Home POA balance is not correct after transaction' + ) + }) - let shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit; - console.log("newForeignBalance = " + newForeignBalance); - console.log("shouldBe = " + shouldBe); + test.it( + 'ERC20-Native - Foreign account has received correct amount of tokens after transaction ', + async () => { + const newForeignBalance = await mainPage.getForeignPOABalance() - let result = (Math.abs(shouldBe - newForeignBalance)) < (maxAmountPerTransactionLimit / 100); - return await assert.equal(result, true, "Test FAILED. Foreign POA balance is not correct after transaction"); - }); -}); + const shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit + console.log('newForeignBalance = ' + newForeignBalance) + console.log('shouldBe = ' + shouldBe) + + const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100 + return await assert.strictEqual( + result, + true, + 'Test FAILED. Foreign POA balance is not correct after transaction' + ) + } + ) +})