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
5c64c6c5
Commit
5c64c6c5
authored
Feb 02, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
look directory for tests and run each one; update log output
parent
25d30843
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
5 deletions
+135
-5
simple_storage2_test.sol
examples/simple_storage2_test.sol
+29
-0
simple_storage_test.sol
examples/simple_storage_test.sol
+2
-2
index.js
index.js
+60
-1
run.js
run.js
+6
-0
compiler.js
src/compiler.js
+38
-2
No files found.
examples/simple_storage2_test.sol
0 → 100644
View file @
5c64c6c5
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_storage.sol";
contract MyTest2 {
SimpleStorage foo;
uint i = 0;
function beforeEach() {
foo = new SimpleStorage();
if (i == 1) {
foo.set(200);
}
i += 1;
}
function initialValueShouldBe100() public constant returns (bool) {
//return Assert.equal(foo.get(), 100, "initial value is not correct");
return foo.get() == 100;
}
function initialValueShouldBe200() public constant returns (bool) {
//return Assert.equal(foo.get(), 200, "initial value is not correct");
return foo.get() == 200;
}
}
examples/simple_storage_test.sol
View file @
5c64c6c5
...
...
@@ -11,12 +11,12 @@ contract MyTest {
function initialValueShouldBe100() public constant returns (bool) {
//return Assert.equal(foo.get(), 100, "initial value is not correct");
return
true
;
return
foo.get() == 100
;
}
function initialValueShouldBe200() public constant returns (bool) {
//return Assert.equal(foo.get(), 200, "initial value is not correct");
return f
alse
;
return f
oo.get() == 200
;
}
}
...
...
index.js
View file @
5c64c6c5
const
async
=
require
(
'async'
);
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
require
(
'colors'
);
let
Compiler
=
require
(
'./src/compiler.js'
);
...
...
@@ -28,7 +29,7 @@ var runTestFile = function(filename, web3) {
function
runTests
(
contractsToTest
,
contracts
,
next
)
{
var
testCallback
=
function
(
result
)
{
if
(
result
.
type
===
'contract'
)
{
console
.
log
((
"
#
"
+
result
.
value
).
green
);
console
.
log
((
"
\
t
"
+
result
.
value
).
green
);
}
else
if
(
result
.
type
===
'testPass'
)
{
console
.
log
(
"
\
t✓ "
.
green
.
bold
+
result
.
value
.
grey
);
}
else
if
(
result
.
type
===
'testFailure'
)
{
...
...
@@ -55,7 +56,65 @@ var runTestFile = function(filename, web3) {
});
}
var
runTestFiles
=
function
(
directory
,
web3
)
{
async
.
waterfall
([
function
compile
(
next
)
{
Compiler
.
compileFiles
(
directory
,
next
);
},
function
deployAllContracts
(
compilationResult
,
next
)
{
Deployer
.
deployAll
(
compilationResult
,
web3
,
function
(
err
,
contracts
)
{
if
(
err
)
{
next
(
err
);
}
let
contractsToTest
=
[];
fs
.
readdirSync
(
directory
).
forEach
(
filename
=>
{
if
(
filename
.
indexOf
(
'_test.sol'
)
<
0
)
{
return
;
}
Object
.
keys
(
compilationResult
[
path
.
basename
(
filename
)]).
forEach
(
contractName
=>
{
contractsToTest
.
push
(
contractName
)
})
})
next
(
null
,
contractsToTest
,
contracts
);
});
},
function
runTests
(
contractsToTest
,
contracts
,
next
)
{
var
testCallback
=
function
(
result
)
{
if
(
result
.
type
===
'contract'
)
{
console
.
log
(
"
\
n "
+
result
.
value
);
}
else
if
(
result
.
type
===
'testPass'
)
{
console
.
log
(
"
\
t✓ "
.
green
.
bold
+
result
.
value
.
grey
);
}
else
if
(
result
.
type
===
'testFailure'
)
{
console
.
log
(
"
\
t✘ "
.
bold
.
red
+
result
.
value
.
red
);
}
}
var
resultsCallback
=
function
(
_err
,
result
,
cb
)
{
if
(
result
.
passingNum
>
0
)
{
console
.
log
((
result
.
passingNum
+
" passing"
).
green
);
}
if
(
result
.
failureNum
>
0
)
{
console
.
log
((
result
.
failureNum
+
" failing"
).
red
);
}
cb
();
}
async
.
eachOfLimit
(
contractsToTest
,
1
,
(
contractName
,
index
,
cb
)
=>
{
runTest
(
contractName
,
contracts
[
contractName
],
testCallback
,
(
err
,
result
)
=>
{
if
(
err
)
{
return
cb
(
err
);
}
resultsCallback
(
null
,
result
,
cb
);
});
},
next
);
}
],
function
()
{
});
}
module
.
exports
=
{
runTestFile
:
runTestFile
,
runTestFiles
:
runTestFiles
,
runTest
:
runTest
};
run.js
View file @
5c64c6c5
const
commander
=
require
(
'commander'
);
const
Web3
=
require
(
'web3'
);
const
RemixTests
=
require
(
'./index.js'
);
const
fs
=
require
(
'fs'
);
commander
.
action
(
function
(
filename
)
{
let
web3
=
new
Web3
();
web3
.
setProvider
(
new
web3
.
providers
.
HttpProvider
(
'http://localhost:8545'
));
if
(
fs
.
lstatSync
(
filename
).
isDirectory
())
{
RemixTests
.
runTestFiles
(
filename
,
web3
);
}
else
{
RemixTests
.
runTestFile
(
filename
,
web3
);
}
});
if
(
!
process
.
argv
.
slice
(
2
).
length
)
{
...
...
src/compiler.js
View file @
5c64c6c5
...
...
@@ -7,6 +7,7 @@ let compilerInput = remixLib.helpers.compiler;
let
RemixCompiler
=
require
(
'remix-solidity'
).
Compiler
;
// TODO: replace this with remix's own compiler code
function
compileFile
(
filename
,
cb
)
{
let
compiler
;
const
sources
=
{
...
...
@@ -32,7 +33,7 @@ function compileFile(filename, cb) {
compiler
.
event
.
register
(
'compilationFinished'
,
this
,
function
(
success
,
data
,
source
)
{
next
(
null
,
data
);
});
compiler
.
compile
(
sources
,
"examples/"
);
compiler
.
compile
(
sources
,
filepath
);
}
],
function
(
err
,
result
)
{
cb
(
err
,
result
.
contracts
);
...
...
@@ -40,7 +41,42 @@ function compileFile(filename, cb) {
}
function
compileFiles
(
directory
,
cb
)
{
let
compiler
;
const
sources
=
{
"tests.sol"
:
{
content
:
fs
.
readFileSync
(
"sol/tests.sol"
).
toString
()},
}
// TODO: for now assumes filepath dir contains all tests, later all this
// should be replaced with remix's & browser solidity compiler code
fs
.
readdirSync
(
directory
).
forEach
(
file
=>
{
sources
[
file
]
=
{
content
:
fs
.
readFileSync
(
path
.
join
(
directory
,
file
)).
toString
()}
});
async
.
waterfall
([
function
loadCompiler
(
next
)
{
compiler
=
new
RemixCompiler
();
compiler
.
onInternalCompilerLoaded
();
//compiler.event.register('compilerLoaded', this, function (version) {
next
();
//});
},
function
doCompilation
(
next
)
{
compiler
.
event
.
register
(
'compilationFinished'
,
this
,
function
(
success
,
data
,
source
)
{
next
(
null
,
data
);
});
compiler
.
compile
(
sources
,
directory
);
}
],
function
(
err
,
result
)
{
cb
(
err
,
result
.
contracts
);
});
}
module
.
exports
=
{
compileFile
:
compileFile
compileFile
:
compileFile
,
compileFiles
:
compileFiles
}
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