mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
e2e beta tests for contract deployment and calling a contract method.
This commit is contained in:
parent
e293233c5e
commit
797a3ee686
@ -3,12 +3,41 @@ const mkdirp = require('mkdirp')
|
|||||||
const pify = require('pify')
|
const pify = require('pify')
|
||||||
const {until} = require('selenium-webdriver')
|
const {until} = require('selenium-webdriver')
|
||||||
|
|
||||||
|
const testContract = `
|
||||||
|
pragma solidity ^0.4.0;
|
||||||
|
contract PiggyBank {
|
||||||
|
|
||||||
|
uint private balance;
|
||||||
|
address public owner;
|
||||||
|
|
||||||
|
function PiggyBank() public {
|
||||||
|
owner = msg.sender;
|
||||||
|
balance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deposit() public payable returns (uint) {
|
||||||
|
balance += msg.value;
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdraw(uint withdrawAmount) public returns (uint remainingBal) {
|
||||||
|
require(msg.sender == owner);
|
||||||
|
balance -= withdrawAmount;
|
||||||
|
|
||||||
|
msg.sender.transfer(withdrawAmount);
|
||||||
|
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkBrowserForConsoleErrors,
|
checkBrowserForConsoleErrors,
|
||||||
loadExtension,
|
loadExtension,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
findElement,
|
findElement,
|
||||||
findElements,
|
findElements,
|
||||||
|
testContract,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadExtension (driver, extensionId) {
|
async function loadExtension (driver, extensionId) {
|
||||||
|
@ -16,6 +16,7 @@ const {
|
|||||||
checkBrowserForConsoleErrors,
|
checkBrowserForConsoleErrors,
|
||||||
loadExtension,
|
loadExtension,
|
||||||
verboseReportOnFailure,
|
verboseReportOnFailure,
|
||||||
|
testContract,
|
||||||
} = require('./helpers')
|
} = require('./helpers')
|
||||||
|
|
||||||
describe('MetaMask', function () {
|
describe('MetaMask', function () {
|
||||||
@ -353,6 +354,7 @@ describe('MetaMask', function () {
|
|||||||
await delay(regularDelayMs)
|
await delay(regularDelayMs)
|
||||||
|
|
||||||
const gasModal = await driver.findElement(By.css('span .modal'))
|
const gasModal = await driver.findElement(By.css('span .modal'))
|
||||||
|
|
||||||
const save = await findElement(driver, By.xpath(`//button[contains(text(), 'Save')]`))
|
const save = await findElement(driver, By.xpath(`//button[contains(text(), 'Save')]`))
|
||||||
await save.click()
|
await save.click()
|
||||||
await driver.wait(until.stalenessOf(gasModal))
|
await driver.wait(until.stalenessOf(gasModal))
|
||||||
@ -412,6 +414,108 @@ describe('MetaMask', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('Deploy contract and call contract method from Remix', () => {
|
||||||
|
it('writes a contract to remix', async () => {
|
||||||
|
await driver.executeScript('window.open("https://remix.ethereum.org/")')
|
||||||
|
await delay(waitingNewPageDelayMs)
|
||||||
|
|
||||||
|
const [extension, remix] = await driver.getAllWindowHandles()
|
||||||
|
await driver.switchTo().window(remix)
|
||||||
|
|
||||||
|
const newContractButton = await findElement(driver, By.css('.fa-plus-circle'))
|
||||||
|
await newContractButton.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 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)
|
||||||
|
|
||||||
|
const txStatuses = await findElements(driver, By.css('.tx-list-status'))
|
||||||
|
await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/))
|
||||||
|
|
||||||
|
const txAccounts = await findElements(driver, By.css('.tx-list-account'))
|
||||||
|
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)
|
||||||
|
await delay(regularDelayMs)
|
||||||
|
|
||||||
|
const depositButton = await findElement(driver, By.xpath(`//button[contains(text(), 'deposit')]`))
|
||||||
|
await depositButton.click()
|
||||||
|
await delay(regularDelayMs)
|
||||||
|
|
||||||
|
await driver.switchTo().window(extension)
|
||||||
|
await loadExtension(driver, extensionId)
|
||||||
|
await delay(regularDelayMs)
|
||||||
|
|
||||||
|
// Set the gas limit
|
||||||
|
const configureGas = await findElement(driver, By.css('.sliders-icon-container'))
|
||||||
|
await configureGas.click()
|
||||||
|
await delay(regularDelayMs)
|
||||||
|
|
||||||
|
let gasModal = await driver.findElement(By.css('span .modal'))
|
||||||
|
|
||||||
|
const [gasPriceInput, gasLimitInput] = await findElements(driver, By.css('.customize-gas-input'))
|
||||||
|
await gasPriceInput.clear()
|
||||||
|
await gasPriceInput.sendKeys('10')
|
||||||
|
await gasLimitInput.clear()
|
||||||
|
await gasLimitInput.sendKeys('60001')
|
||||||
|
|
||||||
|
const save = await findElement(driver, By.xpath(`//button[contains(text(), 'Save')]`))
|
||||||
|
await save.click()
|
||||||
|
await delay(regularDelayMs)
|
||||||
|
|
||||||
|
await driver.wait(until.stalenessOf(gasModal))
|
||||||
|
|
||||||
|
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/))
|
||||||
|
|
||||||
|
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}$/))
|
||||||
|
|
||||||
|
await driver.switchTo().window(remix)
|
||||||
|
await driver.close()
|
||||||
|
await driver.switchTo().window(extension)
|
||||||
|
await delay(regularDelayMs)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('Add a custom token from TokenFactory', () => {
|
describe('Add a custom token from TokenFactory', () => {
|
||||||
it('creates a new token', async () => {
|
it('creates a new token', async () => {
|
||||||
await driver.executeScript('window.open("https://tokenfactory.surge.sh/#/factory")')
|
await driver.executeScript('window.open("https://tokenfactory.surge.sh/#/factory")')
|
||||||
@ -677,10 +781,10 @@ describe('MetaMask', function () {
|
|||||||
|
|
||||||
it('finds the transaction in the transactions list', async function () {
|
it('finds the transaction in the transactions list', async function () {
|
||||||
const transactions = await findElements(driver, By.css('.tx-list-item'))
|
const transactions = await findElements(driver, By.css('.tx-list-item'))
|
||||||
assert.equal(transactions.length, 5)
|
assert.equal(transactions.length, 7)
|
||||||
|
|
||||||
const txValues = await findElements(driver, By.css('.tx-list-value'))
|
const txValues = await findElements(driver, By.css('.tx-list-value'))
|
||||||
assert.equal(txValues.length, 5)
|
assert.equal(txValues.length, 7)
|
||||||
assert.equal(await txValues[0].getText(), '26 TST')
|
assert.equal(await txValues[0].getText(), '26 TST')
|
||||||
const txStatuses = await findElements(driver, By.css('.tx-list-status'))
|
const txStatuses = await findElements(driver, By.css('.tx-list-status'))
|
||||||
await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/))
|
await driver.wait(until.elementTextMatches(txStatuses[0], /Confirmed/))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user