Skip to content

Commit

Permalink
Merge pull request #199 from poanetwork/double-fired-events-fix
Browse files Browse the repository at this point in the history
(Fix) Doubled fired events
  • Loading branch information
vbaranov authored Nov 23, 2018
2 parents b2066c4 + df797d8 commit f577d69
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 59 deletions.
70 changes: 21 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"eth-block-tracker": "^4.0.3",
"eth-contract-metadata": "github:MetaMask/eth-contract-metadata#master",
"eth-ens-namehash": "^2.0.8",
"eth-json-rpc-filters": "^3.0.1",
"eth-json-rpc-filters": "github:poanetwork/eth-json-rpc-filters#3.0.2",
"eth-json-rpc-infura": "^3.0.0",
"eth-keychain-controller": "^5.0.0",
"eth-ledger-bridge-keyring": "^0.1.0",
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ module.exports = {
},
},
screens: {
eventsEmitter: {
button: By.className('btn btn-default'),
event: By.className('Toastify__toast-body'),
},
signMessage: {
buttons: {
sign: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row.flex-space-around > button:nth-child(2)'),
Expand Down Expand Up @@ -161,6 +165,10 @@ module.exports = {
button: {
submit: By.css('#pending-tx-form > div.flex-row.flex-space-around.conf-buttons > input'),
},
fields: {
gasLimit: By.css('#pending-tx-form > div:nth-child(1) > div.table-box > div:nth-child(3) > div.cell.value > div > div > input'),
gasPrice: By.css('#pending-tx-form > div:nth-child(1) > div.table-box > div:nth-child(4) > div.cell.value > div > div > input'),
},
},
sendTransaction: {
title: By.css('#app-content > div > div.app-primary.from-right > div > h3:nth-child(2)'),
Expand Down Expand Up @@ -233,7 +241,8 @@ module.exports = {
menu: By.className('wallet-view__tab-history'),
tokens: By.className('activeForm right'),
},
balance: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > div.ether-balance.ether-balance-amount > div > div > div:nth-child(1) > div:nth-child(1)'),
// balance: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > div.ether-balance.ether-balance-amount > div > div > div:nth-child(1) > div:nth-child(1)'),
balance: By.xpath('//*[@id="app-content"]/div/div[2]/div/div/div[2]/div[1]/div/div/div[1]/div[1]'),
address: By.css('#app-content > div > div.app-primary.from-left > div > div > div:nth-child(1) > flex-column > div.flex-row > div'),
tokens: {
menu: By.id('wallet-view__tab-tokens'),
Expand Down
82 changes: 74 additions & 8 deletions test/e2e/metamask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const { By, Key } = webdriver
const { delay, buildChromeWebDriver, buildFirefoxWebdriver, installWebExt, getExtensionIdChrome, getExtensionIdFirefox } = require('./func')
const { menus, screens, elements, NETWORKS } = require('./elements')
const testSeedPhrase = 'juice teach unaware view expand beef divorce spatial evolve rack scheme foster'
const account1 = '0x00caA30bb79b3a1CDbdAE146e17e0D7d8710b5EF'
const account2 = '0x27836ca9B60E2E1aE13852388edd9a130Be81475'
const eventsEmitter = 'https://vbaranov.github.io/event-listener-dapp/'

describe('Metamask popup page', async function () {
let driver, accountAddress, tokenAddress, extensionId
Expand Down Expand Up @@ -52,7 +54,7 @@ describe('Metamask popup page', async function () {
})

after(async function () {
// await driver.quit()
// await driver.quit()
})

describe('Setup', async function () {
Expand Down Expand Up @@ -320,11 +322,11 @@ describe('Metamask popup page', async function () {

it('Auto-detect tokens for POA core network ', async function () {
// await setProvider(NETWORKS.POA)
const tab = await waitUntilShowUp(screens.main.tokens.menu)
await tab.click()
const balance = await waitUntilShowUp(screens.main.tokens.balance)
console.log(await balance.getText())
assert.equal(await balance.getText(), '1 DOPR', 'token isnt\' auto-detected')
const tab = await waitUntilShowUp(screens.main.tokens.menu)
await tab.click()
const balance = await waitUntilShowUp(screens.main.tokens.balance)
console.log(await balance.getText())
assert.equal(await balance.getText(), '1 DOPR', 'token isnt\' auto-detected')
})

it('Auto-detect tokens for MAIN core network ', async function () {
Expand Down Expand Up @@ -481,7 +483,7 @@ describe('Metamask popup page', async function () {

it('balance renders', async function () {
const balance = await waitUntilShowUp(screens.main.balance)
assert.equal(await balance.getText(), '100.000')
assert.equal(await balance.getText(), '100.000', "balance isn't correct")
})

it('sends transaction', async function () {
Expand Down Expand Up @@ -513,6 +515,71 @@ describe('Metamask popup page', async function () {
assert.equal(await transactionAmount.getText(), '10.0')
})
})

describe(' Check the filter of emitted events', function () {

it('emit event', async function () {
await setProvider(NETWORKS.SOKOL)
let account
if (process.env.SELENIUM_BROWSER === 'chrome') {
account = account1
} else if (process.env.SELENIUM_BROWSER === 'firefox') {
account = account2
const accountMenu = await waitUntilShowUp(menus.account.menu)
await accountMenu.click()
const item = await waitUntilShowUp(menus.account.account2)
await item.click()
}

const balanceField = await waitUntilShowUp(screens.main.balance)
await delay(2000)
const balance = await balanceField.getText()
console.log('Account = ' + account)
console.log('Balance = ' + balance)
assert.equal(parseInt(balance) > 0.001, true, 'Balance of account ' + account + ' TOO LOW !!! Please refill with Sokol eth!!!!')
await driver.get(eventsEmitter)
const button = await waitUntilShowUp(screens.eventsEmitter.button)
await button.click()
await delay(1000)
})

it('confirms transaction in MetaMask popup', async function () {
const windowHandles = await driver.getAllWindowHandles()
await driver.switchTo().window(windowHandles[windowHandles.length - 1])

const gasPrice = await waitUntilShowUp(screens.confirmTransaction.fields.gasPrice)
await gasPrice.sendKeys('10')
const button = await waitUntilShowUp(screens.confirmTransaction.button.submit)
await click(button)
await delay(5000)
})

it('check number of events', async function () {
const windowHandles = await driver.getAllWindowHandles()
await driver.switchTo().window(windowHandles[0])
const event = await waitUntilShowUp(screens.eventsEmitter.event, 1200)
const events = await driver.findElements(screens.eventsEmitter.event)
console.log('number of events = ' + events.length)
if (!event) console.log("event wasn't created or transaction failed")
else {
const events = await driver.findElements(screens.eventsEmitter.event)
assert.equal(events.length, 1, 'More than 1 event was fired: ' + events.length + ' events')
}
})

it('open app', async function () {
if (process.env.SELENIUM_BROWSER === 'chrome') {
await driver.get(`chrome-extension://${extensionId}/popup.html`)
} else if (process.env.SELENIUM_BROWSER === 'firefox') {
await driver.get(`moz-extension://${extensionId}/popup.html`)
const accountMenu = await waitUntilShowUp(menus.account.menu)
await accountMenu.click()
const item = await waitUntilShowUp(menus.account.account1)
await item.click()
}
})
})

describe('Add Token: Custom', function () {
const symbol = 'TST'
const decimals = '0'
Expand Down Expand Up @@ -542,7 +609,6 @@ describe('Metamask popup page', async function () {
await tokenSymbol.sendKeys('TST')
await click(createToken)
await delay(1000)

})

it('confirms transaction in MetaMask popup', async function () {
Expand Down

0 comments on commit f577d69

Please sign in to comment.