From c343a1254383dbc55c557f1facedbdfe0784e3e4 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 22 Jun 2018 09:43:01 -0230 Subject: Use locally served dapp to test contract calls in e2e beta tests --- test/e2e/beta/metamask-beta-ui.spec.js | 198 ++++++++++----------------------- 1 file changed, 57 insertions(+), 141 deletions(-) (limited to 'test/e2e/beta/metamask-beta-ui.spec.js') diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index 21578ae36..d5f41a6ef 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -16,7 +16,6 @@ const { checkBrowserForConsoleErrors, loadExtension, verboseReportOnFailure, - testContract, openNewPage, } = require('./helpers') @@ -417,45 +416,24 @@ describe('MetaMask', function () { }) }) - describe('Deploy contract and call contract method from Remix', () => { - it('writes a contract to remix', async () => { - await openNewPage(driver, 'https://remix.ethereum.org/') + describe('Deploy contract and call contract methods', () => { + let extension + let contractTestPage + it('confirms a deploy contract transaction', async () => { + await openNewPage(driver, 'http://127.0.0.1:8080/'); - const byFilePanel = By.css('#filepanel') - await driver.wait(until.elementLocated(byFilePanel)) + [extension, contractTestPage] = await driver.getAllWindowHandles() await delay(regularDelayMs) - const newContractButton = await findElement(driver, By.css('.fa-plus-circle')) - await newContractButton.click() + const deployContractButton = await findElement(driver, By.css('#deployButton')) + await deployContractButton.click() await delay(regularDelayMs) - const modalFooterOkay = await findElement(driver, By.css('#modal-footer-ok')) - await modalFooterOkay.click() - await delay(regularDelayMs) - - await driver.executeScript('window.document.getElementById("input").editor.session.setValue(arguments[0])', testContract) - await delay(regularDelayMs) - }) - - it('compiles the contract', async () => { - const [extension, remix] = await driver.getAllWindowHandles() - - const compileButton = await findElement(driver, By.css('#compile')) - compileButton.click() - const byOption = By.xpath(`//option[contains(text(), 'PiggyBank')]`) - await driver.wait(until.elementLocated(byOption, 10000)) - await delay(regularDelayMs) - - const runTab = await findElement(driver, By.xpath(`//li[contains(text(), 'Run')]`)) - await runTab.click() - await delay(regularDelayMs) - - const deployButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Deploy')]`)) - await deployButton.click() + await driver.switchTo().window(extension) await delay(regularDelayMs) - await driver.switchTo().window(extension) - await loadExtension(driver, extensionId) + const txListItem = await findElement(driver, By.css('.tx-list-item')) + await txListItem.click() await delay(regularDelayMs) const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`)) @@ -469,17 +447,19 @@ describe('MetaMask', function () { assert.equal(await txAccounts[0].getText(), 'Contract Deployment') }) - it('calls and confirms a contract method', async () => { - const [extension, remix] = await driver.getAllWindowHandles() - await driver.switchTo().window(remix) + it('calls and confirms a contract method where ETH is sent', async () => { + await driver.switchTo().window(contractTestPage) await delay(regularDelayMs) - const depositButton = await findElement(driver, By.xpath(`//button[contains(text(), 'deposit')]`)) + const depositButton = await findElement(driver, By.css('#depositButton')) await depositButton.click() await delay(regularDelayMs) await driver.switchTo().window(extension) - await loadExtension(driver, extensionId) + await delay(regularDelayMs) + + const txListItem = await findElement(driver, By.css('.tx-list-item')) + await txListItem.click() await delay(regularDelayMs) // Set the gas limit @@ -509,14 +489,49 @@ describe('MetaMask', function () { const txStatuses = await findElements(driver, By.css('.tx-list-status')) await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/)) + const txValues = await findElement(driver, By.css('.tx-list-value')) + await driver.wait(until.elementTextMatches(txValues, /3\sETH/), 10000) + const txAccounts = await findElements(driver, By.css('.tx-list-account')) const firstTxAddress = await txAccounts[0].getText() assert(firstTxAddress.match(/^0x\w{8}\.{3}\w{4}$/)) + }) + + it('calls and confirms a contract method where ETH is received', async () => { + await driver.switchTo().window(contractTestPage) + await delay(regularDelayMs) + + const withdrawButton = await findElement(driver, By.css('#withdrawButton')) + await withdrawButton.click() + await delay(regularDelayMs) + + await driver.switchTo().window(extension) + await delay(regularDelayMs) + + const txListItem = await findElement(driver, By.css('.tx-list-item')) + await txListItem.click() + await delay(regularDelayMs) + + const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`)) + await confirmButton.click() + await delay(regularDelayMs) + + const txStatuses = await findElements(driver, By.css('.tx-list-status')) + await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/)) - await driver.switchTo().window(remix) - await driver.executeScript("window.onbeforeunload = function() {};") + const txValues = await findElement(driver, By.css('.tx-list-value')) + await driver.wait(until.elementTextMatches(txValues, /0\sETH/), 10000) + + await driver.switchTo().window(contractTestPage) await driver.close() await driver.switchTo().window(extension) + }) + + it('renders the correct ETH balance', async () => { + const balance = await findElement(driver, By.css('.tx-view .balance-display .token-amount')) + await driver.wait(until.elementTextMatches(balance, /^86.*ETH.*$/), 10000) + const tokenAmount = await balance.getText() + assert.ok(/^86.*ETH.*$/.test(tokenAmount)) await delay(regularDelayMs) }) }) @@ -719,112 +734,13 @@ describe('MetaMask', function () { it('finds the transaction in the transactions list', async function () { const transactions = await findElements(driver, By.css('.tx-list-item')) - assert.equal(transactions.length, 5) - - const txValues = await findElements(driver, By.css('.tx-list-value')) - assert.equal(txValues.length, 5) - assert.equal(await txValues[0].getText(), '26 TST') - const txStatuses = await findElements(driver, By.css('.tx-list-status')) - await driver.wait(until.elementTextMatches(txStatuses[1], /Confirmed/)) - - const tokenBalanceAmount = await findElement(driver, By.css('.token-balance__amount')) - assert.equal(tokenBalanceAmount.getText(), '24 TST') - }) - }) - - describe('Send token from inside MetaMask', () => { - let gasModal - it('starts to send a transaction', async function () { - const sendButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Send')]`)) - await sendButton.click() - await delay(regularDelayMs) - - const inputAddress = await findElement(driver, By.css('input[placeholder="Recipient Address"]')) - const inputAmount = await findElement(driver, By.css('.currency-display__input')) - await inputAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') - await inputAmount.sendKeys('50') - - // Set the gas limit - const configureGas = await findElement(driver, By.css('.send-v2__gas-fee-display button')) - await configureGas.click() - await delay(regularDelayMs) - - gasModal = await driver.findElement(By.css('span .modal')) - }) - - it('customizes gas', async () => { - const [gasPriceInput, gasLimitInput] = await findElements(driver, By.css('.customize-gas-input')) - await gasPriceInput.clear() - await gasPriceInput.sendKeys('12.5') - await gasLimitInput.clear() - await gasLimitInput.sendKeys('56789') - - const save = await findElement(driver, By.xpath(`//button[contains(text(), 'Save')]`)) - await save.click() - await delay(regularDelayMs) - }) - - it('transitions to the confirm screen', async () => { - await driver.wait(until.stalenessOf(gasModal)) - - // Continue to next screen - const nextScreen = await findElement(driver, By.xpath(`//button[contains(text(), 'Next')]`)) - await nextScreen.click() - await delay(regularDelayMs) - }) - - it('submits the transaction', async function () { - const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`)) - await confirmButton.click() - await delay(regularDelayMs) - }) - - it('finds the transaction in the transactions list', async function () { - const transactions = await findElements(driver, By.css('.tx-list-item')) - assert.equal(transactions.length, 1) - - const txValues = await findElements(driver, By.css('.tx-list-value')) - assert.equal(txValues.length, 1) - assert.equal(await txValues[0].getText(), '50 TST') - const txStatuses = await findElements(driver, By.css('.tx-list-status')) - await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/)) - }) - }) - - describe('Send a custom token from TokenFactory', () => { - it('sends an already created token', async () => { - await driver.executeScript(`window.open("https://tokenfactory.surge.sh/#/token/${tokenAddress}")`) - await delay(waitingNewPageDelayMs) - - const [extension, tokenFactory] = await driver.getAllWindowHandles() - await driver.switchTo().window(tokenFactory) - const [ - transferToAddress, - transferToAmount, - ] = await findElements(driver, By.css('.form-control')) - - await transferToAddress.sendKeys('0x2f318C334780961FB129D2a6c30D0763d9a5C970') - await transferToAmount.sendKeys('26') - - const transferAmountButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Transfer Amount')]`)) - await transferAmountButton.click() - await delay(regularDelayMs) - - await driver.switchTo().window(extension) - await loadExtension(driver, extensionId) - await delay(regularDelayMs) - - const confirmButton = await findElement(driver, By.xpath(`//button[contains(text(), 'Confirm')]`)) - await confirmButton.click() - await delay(regularDelayMs) - }) it('finds the transaction in the transactions list', async function () { const transactions = await findElements(driver, By.css('.tx-list-item')) - assert.equal(transactions.length, 7) + assert.equal(transactions.length, 8) const txValues = await findElements(driver, By.css('.tx-list-value')) - assert.equal(txValues.length, 7) + assert.equal(txValues.length, 8) assert.equal(await txValues[0].getText(), '26 TST') const txStatuses = await findElements(driver, By.css('.tx-list-status')) await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/)) -- cgit v1.2.3