Unverified Commit 93ccf19a authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #2103 from ethereum/refactorBrowserTest

Refactor browser test
parents 67fc7e56 78bc8a16
...@@ -14,13 +14,7 @@ module.exports = { ...@@ -14,13 +14,7 @@ module.exports = {
'@sources': function () { '@sources': function () {
return sources return sources
}, },
'Ballot': function (browser) { 'Deploy Ballot': function (browser) {
runTests(browser)
},
tearDown: sauce
}
function runTests (browser, testData) {
browser browser
.waitForElementVisible('#icon-panel', 10000) .waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('solidity') .clickLaunchIcon('solidity')
...@@ -33,7 +27,10 @@ function runTests (browser, testData) { ...@@ -33,7 +27,10 @@ function runTests (browser, testData) {
.testFunction('delegate - transact (not payable)', '0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e', .testFunction('delegate - transact (not payable)', '0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e',
`[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0x057...3ce2e`, `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0x057...3ce2e`,
{types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null)
.pause(500) },
'Debug Ballot / delegate': function (browser) {
browser.pause(500)
.click('span#tx0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e button[class^="debug"]') .click('span#tx0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e button[class^="debug"]')
.pause(2000) .pause(2000)
.clickLaunchIcon('debugger') .clickLaunchIcon('debugger')
...@@ -43,7 +40,10 @@ function runTests (browser, testData) { ...@@ -43,7 +40,10 @@ function runTests (browser, testData) {
.pause(1000) .pause(1000)
.checkVariableDebug('soliditystate', stateCheck) .checkVariableDebug('soliditystate', stateCheck)
.checkVariableDebug('soliditylocals', localsCheck) .checkVariableDebug('soliditylocals', localsCheck)
.clickLaunchIcon('run') },
'Access Ballot via at address': function (browser) {
browser.clickLaunchIcon('run')
.click('button[class^="udappClose"]') .click('button[class^="udappClose"]')
.addFile('ballot.abi', { content: ballotABI }) .addFile('ballot.abi', { content: ballotABI })
.addAtAddressInstance('0x692a70D2e424a56D2C6C27aA97D1a86395877b3B', true, false) .addAtAddressInstance('0x692a70D2e424a56D2C6C27aA97D1a86395877b3B', true, false)
...@@ -56,6 +56,8 @@ function runTests (browser, testData) { ...@@ -56,6 +56,8 @@ function runTests (browser, testData) {
`[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0xd3c...df10f`, `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0xd3c...df10f`,
{types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null)
.end() .end()
},
tearDown: sauce
} }
var localsCheck = { var localsCheck = {
......
'use strict' 'use strict'
var init = require('../helpers/init') var init = require('../helpers/init')
var sauce = require('./sauce') var sauce = require('./sauce')
var async = require('async')
var testRecorder = require('./units/testRecorder') var testRecorder = require('./units/testRecorder')
module.exports = { module.exports = {
...@@ -11,25 +10,8 @@ module.exports = { ...@@ -11,25 +10,8 @@ module.exports = {
'@sources': function () { '@sources': function () {
return sources return sources
}, },
'Compiling': function (browser) {
runTests(browser)
},
tearDown: sauce
}
function runTests (browser) {
browser
.waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('solidity')
.perform(() => {
// the first fn is used to pass browser to the other ones.
async.waterfall([function (callback) { callback(null, browser) }, testSimpleContract, testReturnValues, testInputValues, testRecorder.test], function () {
browser.end()
})
})
}
function testSimpleContract (browser, callback) { 'Test Simple Contract': function (browser) {
browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract']) browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract'])
.clickLaunchIcon('run') .clickLaunchIcon('run')
.click('#runTabView button[class^="instanceButton"]') .click('#runTabView button[class^="instanceButton"]')
...@@ -54,10 +36,9 @@ function testSimpleContract (browser, callback) { ...@@ -54,10 +36,9 @@ function testSimpleContract (browser, callback) {
"3": "uint256: 4" "3": "uint256: 4"
}`) }`)
.click('i[class^="clearinstance"]') .click('i[class^="clearinstance"]')
.perform(() => { callback(null, browser) }) },
}
function testReturnValues (browser, callback) { 'Test Return Values': function (browser) {
browser.testContracts('returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues']) browser.testContracts('returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues'])
.clickLaunchIcon('run') .clickLaunchIcon('run')
.click('#runTabView button[class^="instanceButton"]') .click('#runTabView button[class^="instanceButton"]')
...@@ -91,10 +72,10 @@ function testReturnValues (browser, callback) { ...@@ -91,10 +72,10 @@ function testReturnValues (browser, callback) {
'[vm]\nfrom:0xca3...a733c\nto:testReturnValues.retunValues3() 0x5e7...26e9f\nvalue:0 wei\ndata:0x033...e0a7d\nlogs:0\nhash:0x94c...9d28a', null, `{ '[vm]\nfrom:0xca3...a733c\nto:testReturnValues.retunValues3() 0x5e7...26e9f\nvalue:0 wei\ndata:0x033...e0a7d\nlogs:0\nhash:0x94c...9d28a', null, `{
"0": "uint8: _en 2", "0": "uint8: _en 2",
"1": "int256[5][]: _a1 1,-45,-78,56,60,-1,42,334,-45455,-446,1,10,-5435,45,-7" "1": "int256[5][]: _a1 1,-45,-78,56,60,-1,42,334,-45455,-446,1,10,-5435,45,-7"
}`).click('i[class^="clearinstance"]').perform(() => { callback(null, browser) }) }`).click('i[class^="clearinstance"]')
} },
function testInputValues (browser, callback) { 'Test Input Values': function (browser) {
browser.testContracts('inputValues.sol', sources[2]['browser/inputValues.sol'], ['test']) browser.testContracts('inputValues.sol', sources[2]['browser/inputValues.sol'], ['test'])
.clickLaunchIcon('run') .clickLaunchIcon('run')
.click('#runTabView button[class^="instanceButton"]') .click('#runTabView button[class^="instanceButton"]')
...@@ -144,7 +125,15 @@ function testInputValues (browser, callback) { ...@@ -144,7 +125,15 @@ function testInputValues (browser, callback) {
} }
]`) ]`)
.click('i[class^="clearinstance"]') .click('i[class^="clearinstance"]')
.perform(() => { callback(null, browser) }) },
'Test Recorder': function (browser) {
testRecorder.test(browser, () => {
browser.end()
})
},
tearDown: sauce
} }
// @TODO test: bytes8[3][] type as input // @TODO test: bytes8[3][] type as input
......
'use strict' 'use strict'
var init = require('../helpers/init') var init = require('../helpers/init')
var sauce = require('./sauce') var sauce = require('./sauce')
var async = require('async')
module.exports = { module.exports = {
before: function (browser, done) { before: function (browser, done) {
...@@ -10,71 +9,28 @@ module.exports = { ...@@ -10,71 +9,28 @@ module.exports = {
'@sources': function () { '@sources': function () {
return sources return sources
}, },
'Simple Contract': function (browser) { 'Test Simple Contract': function (browser) {
runTests(browser)
},
tearDown: sauce
}
function runTests (browser) {
browser
.waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('solidity')
.clickLaunchIcon('fileExplorers')
.perform(() => {
// the first fn is used to pass browser to the other ones.
async.waterfall([function (callback) { callback(null, browser) },
testSimpleContract,
testSuccessImport,
testFailedImport, /* testGitHubImport, */
addDeployLibTestFile,
testAutoDeployLib,
testManualDeployLib,
testSignature
],
function () {
browser.end()
})
})
}
function testSimpleContract (browser, callback) {
console.log('testSimpleContract') console.log('testSimpleContract')
browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['test1', 'test2']) browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['test1', 'test2'])
.perform(() => { },
callback(null, browser) 'Test Success Import': function (browser) {
})
}
function testSuccessImport (browser, callback) {
console.log('testSuccessImport') console.log('testSuccessImport')
browser.addFile('Untitled1.sol', sources[1]['browser/Untitled1.sol']) browser.addFile('Untitled1.sol', sources[1]['browser/Untitled1.sol'])
.addFile('Untitled2.sol', sources[1]['browser/Untitled2.sol']) .addFile('Untitled2.sol', sources[1]['browser/Untitled2.sol'])
.switchFile('browser/Untitled1.sol') .switchFile('browser/Untitled1.sol')
.verifyContracts(['test6', 'test4', 'test5']) .verifyContracts(['test6', 'test4', 'test5'])
.perform(() => { },
callback(null, browser)
})
}
function testFailedImport (browser, callback) { 'Test Failed Import': function (browser) {
console.log('testFailedImport') console.log('testFailedImport')
browser.addFile('Untitled3.sol', sources[2]['browser/Untitled3.sol']) browser.addFile('Untitled3.sol', sources[2]['browser/Untitled3.sol'])
.clickLaunchIcon('solidity') .clickLaunchIcon('solidity')
.assert.containsText('#compileTabView .error pre', 'Unable to import "browser/Untitled11.sol": File not found') .assert.containsText('#compileTabView .error pre', 'Unable to import "browser/Untitled11.sol": File not found')
.perform(function () { },
callback(null, browser) 'Add Lib Test File': function (browser) {
})
}
function addDeployLibTestFile (browser, callback) {
browser.addFile('Untitled5.sol', sources[5]['browser/Untitled5.sol']) browser.addFile('Untitled5.sol', sources[5]['browser/Untitled5.sol'])
.perform(() => { },
callback(null, browser) 'Test Auto Deploy Lib': function (browser) {
})
}
function testAutoDeployLib (browser, callback) {
console.log('testAutoDeployLib') console.log('testAutoDeployLib')
let addressRef let addressRef
browser.verifyContracts(['test']) browser.verifyContracts(['test'])
...@@ -86,16 +42,13 @@ function testAutoDeployLib (browser, callback) { ...@@ -86,16 +42,13 @@ function testAutoDeployLib (browser, callback) {
}) })
.waitForElementPresent('.instance:nth-of-type(2)') .waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button') .click('.instance:nth-of-type(2) > div > button')
.perform(() => { .perform((done) => {
browser browser.testConstantFunction(addressRef, 'get - call', '', '0: uint256: 45').perform(() => {
.testConstantFunction(addressRef, 'get - call', '', '0: uint256: 45') done()
.perform(() => {
callback(null, browser)
}) })
}) })
} },
'Test Manual Deploy Lib': function (browser) {
function testManualDeployLib (browser, callback) {
console.log('testManualDeployLib') console.log('testManualDeployLib')
browser.click('i[class^="clearinstance"]') browser.click('i[class^="clearinstance"]')
.pause(5000) .pause(5000)
...@@ -106,14 +59,47 @@ function testManualDeployLib (browser, callback) { ...@@ -106,14 +59,47 @@ function testManualDeployLib (browser, callback) {
.verifyContracts(['test']) .verifyContracts(['test'])
.selectContract('lib') // deploy lib .selectContract('lib') // deploy lib
.createContract('') .createContract('')
.getAddressAtPosition(0, (address) => { .perform((done) => {
browser.getAddressAtPosition(0, (address) => {
console.log(address) console.log(address)
checkDeployShouldFail(browser, () => { checkDeployShouldFail(browser, () => {
checkDeployShouldSucceed(browser, address, () => { checkDeployShouldSucceed(browser, address, () => {
callback(null, browser) done()
})
})
})
})
},
'Test Signature': function (browser) {
let hash, signature
browser.signMessage('test message', (h, s) => {
hash = h
signature = s
browser.assert.ok(typeof hash.value === 'string', 'type of hash.value must be String')
browser.assert.ok(typeof signature.value === 'string', 'type of signature.value must be String')
})
.addFile('signMassage.sol', sources[6]['browser/signMassage.sol'])
.switchFile('browser/signMassage.sol')
.selectContract('ECVerify')
.createContract('')
.waitForElementPresent('.instance:nth-of-type(4)')
.click('.instance:nth-of-type(4) > div > button')
.perform((done) => {
browser.getAttribute('.instance:nth-of-type(4)', 'id', (result) => {
// skip 'instance' part of e.g. 'instance0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
const address = result.value.slice('instance'.length)
browser.clickFunction('ecrecovery - call', {types: 'bytes32 hash, bytes sig', values: `"${hash.value}","${signature.value}"`})
.verifyCallReturnValue(
address,
['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'])
.perform(() => {
done()
}) })
}) })
}) })
.end()
},
tearDown: sauce
} }
function checkDeployShouldFail (browser, callback) { function checkDeployShouldFail (browser, callback) {
...@@ -160,33 +146,6 @@ function checkDeployShouldSucceed (browser, address, callback) { ...@@ -160,33 +146,6 @@ function checkDeployShouldSucceed (browser, address, callback) {
}) })
} }
function testSignature (browser, callback) {
let hash, signature
browser.signMessage('test message', (h, s) => {
hash = h
signature = s
browser.assert.ok(typeof hash.value === 'string', 'type of hash.value must be String')
browser.assert.ok(typeof signature.value === 'string', 'type of signature.value must be String')
})
.addFile('signMassage.sol', sources[6]['browser/signMassage.sol'])
.switchFile('browser/signMassage.sol')
.selectContract('ECVerify')
.createContract('')
.waitForElementPresent('.instance:nth-of-type(4)')
.click('.instance:nth-of-type(4) > div > button')
.getAttribute('.instance:nth-of-type(4)', 'id', (result) => {
// skip 'instance' part of e.g. 'instance0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
const address = result.value.slice('instance'.length)
browser.clickFunction('ecrecovery - call', {types: 'bytes32 hash, bytes sig', values: `"${hash.value}","${signature.value}"`})
.verifyCallReturnValue(
address,
['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'])
.perform(() => {
callback(null, browser)
})
})
}
/* /*
function testGitHubImport (browser, callback) { function testGitHubImport (browser, callback) {
contractHelper.addFile(browser, 'Untitled4.sol', sources[3]['browser/Untitled4.sol'], () => { contractHelper.addFile(browser, 'Untitled4.sol', sources[3]['browser/Untitled4.sol'], () => {
......
...@@ -38,7 +38,7 @@ module.exports = { ...@@ -38,7 +38,7 @@ module.exports = {
'@sources': function () { '@sources': function () {
return sources return sources
}, },
'SharedFolderExplorer': function (browser) { 'Test Shared Folder Explorer': function (browser) {
runTests(browser) runTests(browser)
}, },
tearDown: sauce tearDown: sauce
......
'use strict' 'use strict'
module.exports = { module.exports = {
'@disabled': true, // run by compiling.j '@disabled': true, // run by compiling.
'@sources': function () { '@sources': function () {
return sources return sources
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment