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
490db5a7
Commit
490db5a7
authored
Feb 02, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add beforeEach; update tests
parent
349080c9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
136 additions
and
11 deletions
+136
-11
testRunner.js
src/testRunner.js
+2
-2
simple_storage.sol
tests/examples_1/simple_storage.sol
+17
-0
simple_storage_test.sol
tests/examples_1/simple_storage_test.sol
+23
-0
simple_storage.sol
tests/examples_2/simple_storage.sol
+17
-0
simple_storage_test.sol
tests/examples_2/simple_storage_test.sol
+28
-0
testRunner.js
tests/testRunner.js
+49
-9
No files found.
src/testRunner.js
View file @
490db5a7
...
...
@@ -3,8 +3,8 @@ var changeCase = require('change-case');
function
runTest
(
testName
,
testObject
,
testCallback
,
resultsCallback
)
{
let
runList
=
[];
let
specialFunctions
=
[
'beforeAll'
];
let
availableFunctions
=
testObject
.
_jsonInterface
.
filter
((
x
)
=>
x
.
type
===
'function'
).
map
((
x
)
=>
x
.
name
);
let
specialFunctions
=
[
'beforeAll'
,
'beforeEach'
];
let
availableFunctions
=
testObject
.
_jsonInterface
.
reverse
().
filter
((
x
)
=>
x
.
type
===
'function'
).
map
((
x
)
=>
x
.
name
);
let
testFunctions
=
testObject
.
_jsonInterface
.
filter
((
x
)
=>
specialFunctions
.
indexOf
(
x
.
name
)
<
0
&&
x
.
type
===
'function'
);
if
(
availableFunctions
.
indexOf
(
"beforeAll"
)
>=
0
)
{
...
...
tests/examples_1/simple_storage.sol
0 → 100644
View file @
490db5a7
pragma solidity ^0.4.7;
contract SimpleStorage {
uint public storedData;
function SimpleStorage() public {
storedData = 100;
}
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint retVal) {
return storedData;
}
}
tests/examples_1/simple_storage_test.sol
0 → 100644
View file @
490db5a7
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_storage.sol";
contract MyTest {
SimpleStorage foo;
function beforeAll() {
foo = new SimpleStorage();
}
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;
}
}
tests/examples_2/simple_storage.sol
0 → 100644
View file @
490db5a7
pragma solidity ^0.4.7;
contract SimpleStorage {
uint public storedData;
function SimpleStorage() public {
storedData = 100;
}
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint retVal) {
return storedData;
}
}
tests/examples_2/simple_storage_test.sol
0 → 100644
View file @
490db5a7
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_storage.sol";
contract MyTest {
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;
}
}
tests/testRunner.js
View file @
490db5a7
...
...
@@ -23,20 +23,16 @@ function compileAndDeploy(filename, callback) {
}
describe
(
'testRunner'
,
function
()
{
describe
(
"
simple test
"
,
function
()
{
let
filename
=
'
examples
/simple_storage_test.sol'
describe
(
"
test with beforeAll
"
,
function
()
{
let
filename
=
'
tests/examples_1
/simple_storage_test.sol'
let
tests
=
[],
results
=
{};
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
function
(
_err
,
contracts
)
{
var
testCallback
=
function
()
{
console
.
log
(
"testCallback"
);
console
.
dir
(
arguments
);
tests
.
push
(
arguments
);
var
testCallback
=
function
(
test
)
{
tests
.
push
(
test
);
}
var
resultsCallback
=
function
(
_err
,
_results
)
{
console
.
log
(
"resultsCallback"
);
console
.
dir
(
_results
);
results
=
_results
;
done
();
}
...
...
@@ -48,9 +44,53 @@ describe('testRunner', function() {
assert
.
equal
(
results
.
passingNum
,
1
)
});
it
(
'should 1
pass
ing test'
,
function
()
{
it
(
'should 1
fail
ing test'
,
function
()
{
assert
.
equal
(
results
.
failureNum
,
1
)
});
it
(
'should returns 3 messages'
,
function
()
{
assert
.
deepEqual
(
tests
,
[
{
type
:
'contract'
,
value
:
'tests/examples_1/simple_storage_test.sol'
},
{
type
:
'testPass'
,
value
:
'Initial value should be100'
},
{
type
:
'testFailure'
,
value
:
'Initial value should be200'
}
]);
});
});
describe
(
"test with beforeEach"
,
function
()
{
let
filename
=
'tests/examples_2/simple_storage_test.sol'
let
tests
=
[],
results
=
{};
before
(
function
(
done
)
{
compileAndDeploy
(
filename
,
function
(
_err
,
contracts
)
{
var
testCallback
=
function
(
test
)
{
tests
.
push
(
test
);
}
var
resultsCallback
=
function
(
_err
,
_results
)
{
results
=
_results
;
done
();
}
TestRunner
.
runTest
(
filename
,
contracts
.
MyTest
,
testCallback
,
resultsCallback
);
});
});
it
(
'should 2 passing tests'
,
function
()
{
assert
.
equal
(
results
.
passingNum
,
2
)
});
it
(
'should 0 failing tests'
,
function
()
{
assert
.
equal
(
results
.
failureNum
,
0
)
});
it
(
'should returns 3 messages'
,
function
()
{
assert
.
deepEqual
(
tests
,
[
{
type
:
'contract'
,
value
:
'tests/examples_2/simple_storage_test.sol'
},
{
type
:
'testPass'
,
value
:
'Initial value should be100'
},
{
type
:
'testPass'
,
value
:
'Initial value should be200'
}
]);
});
});
});
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