Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Nov 20, 2017
1 parent 3d05fdd commit eac5b88
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 50 deletions.
4 changes: 2 additions & 2 deletions ci/makeMockCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function gatherCompilationResults (callback) {
if ('@sources' in testDef) {
var sources = testDef['@sources']()
for (var files in sources) {
compile({sources: sources[files]}, 1, function (result) {
compile(sources[files], true, function (result) {
compilationResult[result.key] = result
})
compile({sources: sources[files]}, 0, function (result) {
compile(sources[files], false, function (result) {
compilationResult[result.key] = result
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function run () {

var staticAnalysisAPI = {
renderWarning: (label, warningContainer, type) => {
return renderer.error({ severity: 'warning', formattedMessage: label }, warningContainer, type)
return renderer.error(label, warningContainer, type)
},
offsetToLineColumn: (location, file) => {
return offsetToLineColumnConverter.offsetToLineColumn(location, file, compiler.lastCompilationResult)
Expand Down
3 changes: 1 addition & 2 deletions src/app/compiler/compiler-input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

module.exports = (sources, opts) => {
var target = opts.target ? opts.target : '*'
return JSON.stringify({
language: 'Solidity',
sources: sources,
Expand All @@ -13,7 +12,7 @@ module.exports = (sources, opts) => {
},
libraries: opts.libraries,
outputSelection: {
[target]: {
'*': {
'*': [ 'metadata', 'evm.bytecode', 'evm.deployedBytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/tabs/compile-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,18 @@ function compileTab (container, appAPI, appEvents, opts) {
var error = false
if (data['error']) {
error = true
appAPI.compilationMessage(data['error'], $(errorContainer))
appAPI.compilationMessage(data['error'].formattedMessage, $(errorContainer), {type: data['error'].severity})
}
if (data['errors']) {
if (data['errors'].length) error = true
data['errors'].forEach(function (err) {
appAPI.compilationMessage(err, $(errorContainer))
appAPI.compilationMessage(err.formattedMessage, $(errorContainer), {type: err.severity})
})
}
if (!error) {
if (data.contracts) {
appAPI.visitContracts((contract) => {
appAPI.compilationMessage({ formattedMessage: contract.name }, $(errorContainer), {type: 'success'})
appAPI.compilationMessage(contract.name, $(errorContainer), {type: 'success'})
})
}
}
Expand All @@ -315,7 +315,7 @@ function compileTab (container, appAPI, appEvents, opts) {
appEvents.staticAnalysis.register('staticAnaysisWarning', (count) => {
if (count) {
var errorContainer = container.querySelector('.error')
appAPI.compilationMessage({ severity: 'warning', formattedMessage: `Static Analysis raised ${count} warning(s) that requires your attention.` }, $(errorContainer), {
appAPI.compilationMessage(`Static Analysis raised ${count} warning(s) that requires your attention.`, $(errorContainer), {
type: 'warning',
click: () => appAPI.switchTab('staticanalysisView')
})
Expand Down
2 changes: 0 additions & 2 deletions src/app/ui/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ Renderer.prototype.error = function (message, container, opt) {
message = yo`<span>${message}</span>`
} else if (message.innerText) {
text = message.innerText
} else if (message.formattedMessage) {
text = message.formattedMessage
}

var errLocation = text.match(/^([^:]*):([0-9]*):(([0-9]*):)? /)
Expand Down
11 changes: 9 additions & 2 deletions test-browser/helpers/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function addFile (browser, name, content, done) {
done()
})
})
.setValue('#input textarea', content, function () {})
.setValue('#input textarea', content.content, function () {})
.pause(1000)
.perform(function () {
done()
Expand All @@ -129,7 +129,14 @@ function checkDebug (browser, id, debugValue, done) {
return document.querySelector('#' + id + ' .dropdownrawcontent').innerText
}, [id], function (result) {
console.log(id + ' ' + result.value)
var value = JSON.parse(result.value)
var value
try {
value = JSON.parse(result.value)
} catch (e) {
browser.assert.fail('cant parse solidity state', e.message, '')
done()
return
}
var equal = deepequal(debugValue, value)
if (!equal) {
browser.assert.fail('checkDebug on ' + id, 'info about error', '')
Expand Down
8 changes: 4 additions & 4 deletions test-browser/tests/ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var init = require('../helpers/init')
var sauce = require('./sauce')

var sources = [
{'browser/Untitled.sol': examples.ballot.content}
{'browser/Untitled.sol': {content: examples.ballot.content}}
]

module.exports = {
Expand All @@ -26,13 +26,13 @@ function runTests (browser, testData) {
browser
.waitForElementVisible('.newFile', 10000)
.click('.compileView')
contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['browser/Untitled.sol:Ballot'], function () {
contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['Ballot'], function () {
browser
.click('.runView')
.setValue('input[placeholder="uint8 _numProposals"]', '1', () => {})
.click('#runTabView div[class^="create"]')
.testFunction('delegate - transact (not payable)', '0xd3cd54e2f76f3993078ecf9e1b54a148def4520afc141a182293b3610bddf10f',
'[vm] from:0xca3...a733c, to:browser/Untitled.sol:Ballot.delegate(address) 0x692...77b3a, value:0 wei, data:0x5c1...4d2db, 0 logs, hash:0xd3c...df10f',
'[vm] from:0xca3...a733c, to:Ballot.delegate(address) 0x692...77b3a, value:0 wei, data:0x5c1...4d2db, 0 logs, hash:0xd3c...df10f',
{types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null)
.click('span#tx0xd3cd54e2f76f3993078ecf9e1b54a148def4520afc141a182293b3610bddf10f button[class^="debug"]')
.pause(1000)
Expand All @@ -45,7 +45,7 @@ function runTests (browser, testData) {
done()
})
})
.pause(2000)
.pause(5000)
.perform(function (client, done) {
contractHelper.checkDebug(browser, 'soliditystate', stateCheck, () => {
done()
Expand Down
20 changes: 10 additions & 10 deletions test-browser/tests/compiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ function runTests (browser) {
}

function testSimpleContract (browser, callback) {
contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['browser/Untitled.sol:TestContract'], function () {
contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract'], function () {
browser.click('.runView')
.click('#runTabView div[class^="create"]')
.pause(500)
.testFunction('f - transact (not payable)',
'0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc',
'[vm] from:0xca3...a733c, to:browser/Untitled.sol:TestContract.f() 0x692...77b3a, value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc', null,
'[vm] from:0xca3...a733c, to:TestContract.f() 0x692...77b3a, value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc', null,
`{
"0": "uint256: 8"
}`)
.pause(500)
.testFunction('g - transact (not payable)',
'0xb1532162e2e31397dc1e07ed0a1cf08f728e9b4487c6f9ed79d2f39410c92781',
'[vm] from:0xca3...a733c, to:browser/Untitled.sol:TestContract.g() 0x692...77b3a, value:0 wei, data:0xe21...79b8e, 0 logs, hash:0xb15...92781', null, `{
'[vm] from:0xca3...a733c, to:TestContract.g() 0x692...77b3a, value:0 wei, data:0xe21...79b8e, 0 logs, hash:0xb15...92781', null, `{
"0": "uint256: 345",
"1": "string: comment_comment_",
"2": "bool: true",
Expand All @@ -54,13 +54,13 @@ function testSimpleContract (browser, callback) {
}

function testReturnValues (browser, callback) {
contractHelper.testContracts(browser, 'returnValues.sol', sources[1]['browser/returnValues.sol'], ['browser/returnValues.sol:testReturnValues'], function () {
contractHelper.testContracts(browser, 'returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues'], function () {
browser.click('.runView')
.click('#runTabView div[class^="create"]')
.pause(500)
.testFunction('retunValues1 - transact (not payable)',
'0x79dc928d149d2ade02ab610a8ae290636222d034d4adce0bb08a68401e3d1f7f',
'[vm] from:0xca3...a733c, to:browser/returnValues.sol:testReturnValues.retunValues1() 0x5e7...26e9f, value:0 wei, data:0x9ed...59eb7, 0 logs, hash:0x79d...d1f7f',
'[vm] from:0xca3...a733c, to:testReturnValues.retunValues1() 0x5e7...26e9f, value:0 wei, data:0x9ed...59eb7, 0 logs, hash:0x79d...d1f7f',
null,
`{
"0": "bool: _b true",
Expand All @@ -71,7 +71,7 @@ function testReturnValues (browser, callback) {
.pause(500)
.testFunction('retunValues2 - transact (not payable)',
'0x09175dcb30227b3af422d75786dbba3b0549985e5c7f59f86d12c7e1043ccb8c',
'[vm] from:0xca3...a733c, to:browser/returnValues.sol:testReturnValues.retunValues2() 0x5e7...26e9f, value:0 wei, data:0xf57...4036c, 0 logs, hash:0x091...ccb8c', null, `{
'[vm] from:0xca3...a733c, to:testReturnValues.retunValues2() 0x5e7...26e9f, value:0 wei, data:0xf57...4036c, 0 logs, hash:0x091...ccb8c', null, `{
"0": "bytes1: _b 0x12",
"1": "bytes2: _b2 0x1223",
"2": "bytes3: _b3 0x000000",
Expand All @@ -84,29 +84,29 @@ function testReturnValues (browser, callback) {
"9": "bytes32: _b32 0x0000000000000000000000000000000000032523532532523532523532523532"
}`).pause(500).testFunction('retunValues3 - transact (not payable)',
'0x7faab07aeaafc8afe6bf283bb83be70c000dff381dec04e779354e354da14aff',
'[vm] from:0xca3...a733c, to:browser/returnValues.sol:testReturnValues.retunValues3() 0x5e7...26e9f, value:0 wei, data:0x033...e0a7d, 0 logs, hash:0x7fa...14aff', null, `{
'[vm] from:0xca3...a733c, to:testReturnValues.retunValues3() 0x5e7...26e9f, value:0 wei, data:0x033...e0a7d, 0 logs, hash:0x7fa...14aff', null, `{
"0": "uint8: _en 2",
"1": "int256[5][]: _a1 1,-45,-78,56,60, -1,42,334,-45455,-446, 1,10,-5435,45,-7"
}`).perform(() => { callback(null, browser) })
})
}

function testInputValues (browser, callback) {
contractHelper.testContracts(browser, 'inputValues.sol', sources[2]['browser/inputValues.sol'], ['browser/inputValues.sol:test'], function () {
contractHelper.testContracts(browser, 'inputValues.sol', sources[2]['browser/inputValues.sol'], ['test'], function () {
browser.click('.runView')
.click('#runTabView div[class^="create"]')
.pause(500)
.testFunction('inputValue1 - transact (not payable)',
'0x917a873d27d105213eaf5461e14780387ccceb66fed574f8432d1963917832ae',
'[vm] from:0xca3...a733c, to:browser/inputValues.sol:test.inputValue1(uint256,int256,string) 0x8c1...401f5, value:0 wei, data:0xd69...00000, 0 logs, hash:0x917...832ae',
'[vm] from:0xca3...a733c, to:test.inputValue1(uint256,int256,string) 0x8c1...401f5, value:0 wei, data:0xd69...00000, 0 logs, hash:0x917...832ae',
{types: 'uint256 _u, int256 _i, string _str', values: '"2343242", "-4324324", "string _ string _ string _ string _ string _ string _ string _ string _ string _ string _"'},
`{
"0": "uint256: _uret 2343242",
"1": "int256: _iret -4324324",
"2": "string: _strret string _ string _ string _ string _ string _ string _ string _ string _ string _ string _"
}`).pause(500).testFunction('inputValue2 - transact (not payable)',
'0x487d09e244853bcb108b3a22cd6ee57b6431e50869619c9b918e9764fc16ef7f',
'[vm] from:0xca3...a733c, to:browser/inputValues.sol:test.inputValue2(uint256[3],bytes8[4]) 0x8c1...401f5, value:0 wei, data:0x1b7...00000, 1 logs, hash:0x487...6ef7f',
'[vm] from:0xca3...a733c, to:test.inputValue2(uint256[3],bytes8[4]) 0x8c1...401f5, value:0 wei, data:0x1b7...00000, 1 logs, hash:0x487...6ef7f',
{types: 'uint256[3] _n, bytes8[4] _b8', values: '[1,2,3], ["0x1234", "0x1234","0x1234","0x1234"]'},
`{
"0": "uint256[3]: _nret 1, 2, 3",
Expand Down
2 changes: 1 addition & 1 deletion test-browser/tests/sharedFolderExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var sauce = require('./sauce')

var sources = [
{
'localhost/folder1/contract2.sol': 'contract test2 { function get () returns (uint) { return 11; }}'
'localhost/folder1/contract2.sol': {content: 'contract test2 { function get () returns (uint) { return 11; }}'}
}
]

Expand Down
35 changes: 18 additions & 17 deletions test-browser/tests/simpleContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,27 @@ function runTests (browser) {
async.waterfall([function (callback) { callback(null, browser) },
testSimpleContract,
testSuccessImport,
testFailedImport,
testGitHubImport],
testFailedImport /* testGitHubImport */
],
function () {
browser.end()
})
})
}

function testSimpleContract (browser, callback) {
console.log('testSimpleContract')
contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['test1', 'test2'], function () {
browser.end()
callback(null, browser)
})
}

function testSuccessImport (browser, callback) {
console.log('testSuccessImport')
contractHelper.addFile(browser, 'Untitled1.sol', sources[1]['browser/Untitled1.sol'], () => {
contractHelper.addFile(browser, 'Untitled2.sol', sources[1]['browser/Untitled2.sol'], () => {
contractHelper.switchFile(browser, 'browser/Untitled1.sol', function () {
contractHelper.verifyContract(browser, ['browser/Untitled1.sol:test6', 'browser/Untitled2.sol:test4', 'browser/Untitled2.sol:test5'], function () {
contractHelper.verifyContract(browser, ['test6', 'test4', 'test5'], function () {
callback(null, browser)
})
})
Expand All @@ -54,6 +56,7 @@ function testSuccessImport (browser, callback) {
}

function testFailedImport (browser, callback) {
console.log('testFailedImport')
contractHelper.addFile(browser, 'Untitled3.sol', sources[2]['browser/Untitled3.sol'], () => {
browser.assert.containsText('#compileTabView .error pre', 'Unable to import "browser/Untitled11.sol": File not found')
.perform(function () {
Expand All @@ -62,9 +65,8 @@ function testFailedImport (browser, callback) {
})
}

/*
function testGitHubImport (browser, callback) {
// cant' import from github from Travis ... (got "Forbidden"")
/*
contractHelper.addFile(browser, 'Untitled4.sol', sources[3]['browser/Untitled4.sol'], () => {
browser.pause(10000)
.perform(function () {
Expand All @@ -73,9 +75,8 @@ function testGitHubImport (browser, callback) {
})
})
})
*/
callback(null, browser)
}
*/

var abstractENS = `pragma solidity ^0.4.0;
Expand Down Expand Up @@ -198,22 +199,22 @@ contract ENS is AbstractENS {

var sources = [
{
'browser/Untitled.sol': 'contract test1 {} contract test2 {}'
'browser/Untitled.sol': {content: 'contract test1 {} contract test2 {}'}
},
{
'browser/Untitled1.sol': 'import "./Untitled2.sol"; contract test6 {}',
'browser/Untitled2.sol': 'contract test4 {} contract test5 {}'
'browser/Untitled1.sol': {content: 'import "./Untitled2.sol"; contract test6 {}'},
'browser/Untitled2.sol': {content: 'contract test4 {} contract test5 {}'}
},
{
'browser/Untitled3.sol': 'import "./Untitled11.sol"; contract test6 {}'
'browser/Untitled3.sol': {content: 'import "./Untitled11.sol"; contract test6 {}'}
},
{
'browser/Untitled4.sol': 'import "github.com/ethereum/ens/contracts/ENS.sol"; contract test7 {}',
'github.com/ethereum/ens/contracts/ENS.sol': ENS
'browser/Untitled4.sol': {content: 'import "github.com/ethereum/ens/contracts/ENS.sol"; contract test7 {}'},
'github.com/ethereum/ens/contracts/ENS.sol': {content: ENS}
},
{
'browser/Untitled4.sol': 'import "github.com/ethereum/ens/contracts/ENS.sol"; contract test7 {}',
'github.com/ethereum/ens/contracts/ENS.sol': ENS,
'github.com/ethereum/ens/contracts/AbstractENS.sol': abstractENS
'browser/Untitled4.sol': {content: 'import "github.com/ethereum/ens/contracts/ENS.sol"; contract test7 {}'},
'github.com/ethereum/ens/contracts/ENS.sol': {content: ENS},
'github.com/ethereum/ens/contracts/AbstractENS.sol': {content: abstractENS}
}
]
11 changes: 6 additions & 5 deletions test-browser/tests/staticanalysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var dom = require('../helpers/dom')

var sources = [
{
'browser/Untitled.sol': `
'browser/Untitled.sol': {content: `
contract test1 { address test = tx.origin; }
contract test2 {}
contract TooMuchGas {
Expand All @@ -16,7 +16,7 @@ contract TooMuchGas {
uint test;
uint test1;
}
}`}
}`}}
]

module.exports = {
Expand All @@ -41,9 +41,10 @@ function runTests (browser) {
.click('.staticanalysisView')
.click('#staticanalysisView button')
.waitForElementPresent('#staticanalysisresult .warning', 2000, true, function () {
dom.listSelectorContains(['browser/Untitled.sol:2:33: Use of tx.origin',
'Fallback function of contract TooMuchGas requires too much gas'],
'#staticanalysisresult .warning span',
dom.listSelectorContains(['browser/Untitled.sol:2:33:Use of tx.origin',
'Fallback function of contract TooMuchGas requires too much gas',
'TooMuchGas.(): Variables have very similar names test and test1.'],
'#staticanalysisresult .warning',
browser, function () {
browser.end()
}
Expand Down

0 comments on commit eac5b88

Please sign in to comment.