Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
ba2d67f5
Commit
ba2d67f5
authored
Oct 20, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mock compiler
parent
05fce5c1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
265 additions
and
6 deletions
+265
-6
browser_tests.sh
ci/browser_tests.sh
+1
-1
makeMockCompiler.js
ci/makeMockCompiler.js
+56
-0
nightwatch.js
nightwatch.js
+5
-2
contracts.js
test-browser/helpers/contracts.js
+23
-0
compiler.js
test-browser/mockcompiler/compiler.js
+41
-0
requests.js
test-browser/mockcompiler/requests.js
+77
-0
ballot.js
test-browser/tests/ballot.js
+31
-0
debugger.js
test-browser/tests/debugger.js
+1
-1
new-file-test.js
test-browser/tests/new-file-test.js
+1
-1
simpleContract.js
test-browser/tests/simpleContract.js
+28
-0
smoke-test.js
test-browser/tests/smoke-test.js
+1
-1
No files found.
ci/browser_tests.sh
View file @
ba2d67f5
...
...
@@ -8,7 +8,7 @@ SAUCECONNECT_JOBIDENTIFIER="browsersolidity_tests_${TRAVIS_JOB_NUMBER}"
SAUCECONNECT_READYFILE
=
"sc.ready"
TEST_EXITCODE
=
0
n
pm run build
n
ode ci/makeMockCompiler.js
npm run serve &
wget
"
$SAUCECONNECT_URL
"
...
...
ci/makeMockCompiler.js
0 → 100644
View file @
ba2d67f5
var
fs
=
require
(
'fs'
);
var
solc
=
require
(
'solc/wrapper'
);
var
soljson
=
require
(
'../soljson'
);
var
compiler
=
solc
(
soljson
);
var
inputs
=
require
(
'../test-browser/mockcompiler/requests.js'
);
var
compilationResult
=
gatherCompilationResults
(
inputs
);
replaceSolCompiler
(
compilationResult
);
function
gatherCompilationResults
(
sol
)
{
var
compilationResult
=
{};
for
(
var
k
in
sol
)
{
var
item
=
sol
[
k
];
var
result
=
compile
(
item
,
1
);
compilationResult
[
result
.
key
]
=
result
;
result
=
compile
(
item
,
0
);
compilationResult
[
result
.
key
]
=
result
;
}
return
compilationResult
;
}
function
compile
(
source
,
optimization
)
{
var
missingInputs
=
[];
var
result
=
compiler
.
compile
(
source
,
optimization
,
function
(
path
)
{
missingInputs
.
push
(
path
);
});
var
key
=
optimization
.
toString
();
for
(
var
k
in
source
.
sources
)
{
key
+=
k
+
source
.
sources
[
k
];
}
key
=
key
.
replace
(
/
(\t)
|
(\n)
|
(
)
/g
,
''
);
return
{
key
:
key
,
source
:
source
,
optimization
:
optimization
,
missingInputs
:
missingInputs
,
result
:
result
};
}
function
replaceSolCompiler
(
results
)
{
fs
.
readFile
(
'./test-browser/mockcompiler/compiler.js'
,
'utf8'
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
log
(
error
);
process
.
exit
(
1
);
return
;
}
data
=
data
+
'
\
n
\
nvar mockData = '
+
JSON
.
stringify
(
results
)
+
';
\
n'
;
fs
.
writeFile
(
'./soljson.js'
,
data
,
'utf8'
,
function
(
error
)
{
if
(
error
)
{
console
.
log
(
error
);
process
.
exit
(
1
);
return
;
}
});
});
}
nightwatch.js
View file @
ba2d67f5
...
...
@@ -3,7 +3,7 @@
var
TRAVIS_JOB_NUMBER
=
process
.
env
.
TRAVIS_JOB_NUMBER
module
.
exports
=
{
'src_folders'
:
[
'test-browser'
],
'src_folders'
:
[
'test-browser
/tests
'
],
'output_folder'
:
'reports'
,
'custom_commands_path'
:
''
,
'custom_assertions_path'
:
''
,
...
...
@@ -50,7 +50,8 @@ module.exports = {
'desiredCapabilities'
:
{
'browserName'
:
'safari'
,
'javascriptEnabled'
:
true
,
'platform'
:
'MAC'
,
'platform'
:
'OS X 10.10'
,
'version'
:
'8.0'
,
'acceptSslCerts'
:
true
,
'build'
:
'build-'
+
TRAVIS_JOB_NUMBER
,
'tunnel-identifier'
:
'browsersolidity_tests_'
+
TRAVIS_JOB_NUMBER
...
...
@@ -62,6 +63,8 @@ module.exports = {
'browserName'
:
'internet explorer'
,
'javascriptEnabled'
:
true
,
'acceptSslCerts'
:
true
,
'platform'
:
'WIN8.1'
,
'version'
:
'11'
,
'build'
:
'build-'
+
TRAVIS_JOB_NUMBER
,
'tunnel-identifier'
:
'browsersolidity_tests_'
+
TRAVIS_JOB_NUMBER
}
...
...
test-browser/helpers/contracts.js
0 → 100644
View file @
ba2d67f5
module
.
exports
=
{
checkCompiledContracts
:
function
(
browser
,
compiled
,
callback
)
{
browser
.
execute
(
function
()
{
var
contracts
=
document
.
querySelectorAll
(
'.udapp .contract'
);
var
ret
=
[];
for
(
var
k
in
contracts
)
{
var
el
=
contracts
[
k
];
if
(
el
.
querySelector
)
{
ret
.
push
({
name
:
el
.
querySelector
(
'.title'
).
innerText
.
replace
(
el
.
querySelector
(
'.size'
).
innerText
,
''
).
replace
(
/
(\t)
|
(\r)
|
(\n)
/g
,
''
)
// IE/firefox add \r\n
});
}
}
return
ret
;
},
[
''
],
function
(
result
)
{
browser
.
assert
.
equal
(
result
.
value
.
length
,
compiled
.
length
);
result
.
value
.
map
(
function
(
item
,
i
)
{
browser
.
assert
.
equal
(
item
.
name
,
compiled
[
i
]);
});
callback
();
});
}
};
test-browser/mockcompiler/compiler.js
0 → 100644
View file @
ba2d67f5
var
Module
=
{
// eslint-disable-line
cwrap
:
function
()
{
return
arguments
[
0
]
===
'version'
?
version
:
compile
;
},
writeStringToMemory
:
function
()
{},
setValue
:
function
()
{},
Pointer_stringify
:
function
()
{},
Runtime
:
{
addFunction
:
function
()
{},
removeFunction
:
function
()
{}
},
_compileJSONMulti
:
{},
_compileJSONCallback
:
{},
_compileJSON
:
{}
};
function
compile
(
source
,
optimization
,
missingInputs
)
{
if
(
typeof
source
===
'string'
)
{
source
=
JSON
.
parse
(
source
);
}
var
key
=
optimization
.
toString
();
for
(
var
k
in
source
.
sources
)
{
key
+=
k
+
source
.
sources
[
k
];
}
key
=
key
.
replace
(
/
(\t)
|
(\n)
|
(
)
/g
,
''
);
var
data
=
mockData
[
key
];
// eslint-disable-line
if
(
data
===
undefined
)
{
return
JSON
.
stringify
({
errors
:
[
'mock compiler: source not found'
]
});
}
else
{
data
.
missingInputs
.
map
(
function
(
item
,
i
)
{
if
(
missingInputs
)
{
missingInputs
(
item
);
}
});
}
return
JSON
.
stringify
(
data
.
result
);
}
function
version
()
{
return
'mock compiler'
;
}
test-browser/mockcompiler/requests.js
0 → 100644
View file @
ba2d67f5
module
.
exports
=
{
'testSimpleContract'
:
{
'sources'
:
{
'Untitled1'
:
'contract test1 {} contract test2 {}'
}
},
'ballot'
:
{
'sources'
:
{
'Untitled1'
:
`pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
uint voteCount;
}
address chairperson;
mapping(address => Voter) voters;
Proposal[] proposals;
/// Create a new ballot with $(_numProposals) different proposals.
function Ballot(uint8 _numProposals) {
chairperson = msg.sender;
voters[chairperson].weight = 1;
proposals.length = _numProposals;
}
/// Give $(voter) the right to vote on this ballot.
/// May only be called by $(chairperson).
function giveRightToVote(address voter) {
if (msg.sender != chairperson || voters[voter].voted) return;
voters[voter].weight = 1;
}
/// Delegate your vote to the voter $(to).
function delegate(address to) {
Voter sender = voters[msg.sender]; // assigns reference
if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
to = voters[to].delegate;
if (to == msg.sender) return;
sender.voted = true;
sender.delegate = to;
Voter delegate = voters[to];
if (delegate.voted)
proposals[delegate.vote].voteCount += sender.weight;
else
delegate.weight += sender.weight;
}
/// Give a single vote to proposal $(proposal).
function vote(uint8 proposal) {
Voter sender = voters[msg.sender];
if (sender.voted || proposal >= proposals.length) return;
sender.voted = true;
sender.vote = proposal;
proposals[proposal].voteCount += sender.weight;
}
function winningProposal() constant returns (uint8 winningProposal) {
uint256 winningVoteCount = 0;
for (uint8 proposal = 0; proposal < proposals.length; proposal++)
if (proposals[proposal].voteCount > winningVoteCount) {
winningVoteCount = proposals[proposal].voteCount;
winningProposal = proposal;
}
}
}
`
}
}
};
test-browser/tests/ballot.js
0 → 100644
View file @
ba2d67f5
'use strict'
;
var
testData
=
require
(
'../mockcompiler/requests'
);
// var contractHelper = require('../helpers/contracts');
module
.
exports
=
{
'Ballot'
:
function
(
browser
)
{
runTests
(
browser
,
testData
);
}
};
function
runTests
(
browser
,
testData
)
{
browser
.
url
(
'http://127.0.0.1:8080/#version=builtin'
)
.
waitForElementVisible
(
'.newFile'
,
10000
);
browser
.
assert
.
notEqual
(
testData
,
null
);
// TODO add Ballot tests. -> setValue('#input textarea', ... ) is not working properly with that contract.
/* testBallot(browser, testData.ballot.sources.Untitled1, function () {
browser.end();
});*/
}
/*
function testBallot (browser, contract, callback) {
browser
.click('.newFile')
.clearValue('#input textarea')
.setValue('#input textarea', contract, function () {
browser.pause('10000');
contractHelper.checkCompiledContracts(browser, ['Ballot'], callback);
});
}*/
test-browser/debugger.js
→
test-browser/
tests/
debugger.js
View file @
ba2d67f5
...
...
@@ -3,7 +3,7 @@
module
.
exports
=
{
'Debugger Render'
:
function
(
browser
)
{
browser
.
url
(
'http://127.0.0.1:8080'
)
.
url
(
'http://127.0.0.1:8080
/#version=builtin
'
)
.
waitForElementPresent
(
'#debugger'
,
10000
)
.
waitForElementPresent
(
'#debugger #slider'
,
10000
)
.
end
();
...
...
test-browser/new-file-test.js
→
test-browser/
tests/
new-file-test.js
View file @
ba2d67f5
...
...
@@ -3,7 +3,7 @@
module
.
exports
=
{
'New file test'
:
function
(
browser
)
{
browser
.
url
(
'http://127.0.0.1:8080'
)
.
url
(
'http://127.0.0.1:8080
/#version=builtin
'
)
.
waitForElementVisible
(
'.newFile'
,
10000
)
.
click
(
'.newFile'
)
.
pause
(
'10000'
)
...
...
test-browser/tests/simpleContract.js
0 → 100644
View file @
ba2d67f5
'use strict'
;
var
testData
=
require
(
'../mockcompiler/requests'
);
var
contractHelper
=
require
(
'../helpers/contracts'
);
module
.
exports
=
{
'Simple Contract'
:
function
(
browser
)
{
runTests
(
browser
,
testData
);
}
};
function
runTests
(
browser
,
testData
)
{
browser
.
url
(
'http://127.0.0.1:8080/#version=builtin'
)
.
waitForElementVisible
(
'.newFile'
,
10000
);
browser
.
assert
.
notEqual
(
testData
,
null
);
testSimpleContract
(
browser
,
testData
.
testSimpleContract
.
sources
.
Untitled1
,
function
()
{
browser
.
end
();
});
}
function
testSimpleContract
(
browser
,
contract
,
callback
)
{
browser
.
click
(
'.newFile'
)
.
clearValue
(
'#input textarea'
)
.
setValue
(
'#input textarea'
,
contract
)
.
pause
(
'5000'
);
contractHelper
.
checkCompiledContracts
(
browser
,
[
'test1'
,
'test2'
],
callback
);
}
test-browser/smoke-test.js
→
test-browser/
tests/
smoke-test.js
View file @
ba2d67f5
...
...
@@ -3,7 +3,7 @@
module
.
exports
=
{
'Smoke test'
:
function
(
browser
)
{
browser
.
url
(
'http://127.0.0.1:8080'
)
.
url
(
'http://127.0.0.1:8080
/#version=builtin
'
)
.
waitForElementVisible
(
'#righthand-panel'
,
10000
)
.
pause
(
'10000'
)
.
assert
.
containsText
(
'#righthand-panel'
,
'Solidity version'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment