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
c8a5be63
Commit
c8a5be63
authored
Mar 25, 2020
by
ioedeveloper
Committed by
Aniket
Apr 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test for simple and advance solidity unit testing
parent
587a53c8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
3 deletions
+110
-3
test-tab.js
src/app/tabs/test-tab.js
+2
-1
solidityUnittests.js
test-browser/tests/solidityUnittests.js
+108
-2
No files found.
src/app/tabs/test-tab.js
View file @
c8a5be63
...
...
@@ -267,7 +267,7 @@ module.exports = class TestTab extends ViewPlugin {
}
render
()
{
this
.
onActivationInternal
()
this
.
testsOutput
=
yo
`<div class="
${
css
.
container
}
m-3 border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="solidityUnittestsOutput"></div>`
this
.
testsOutput
=
yo
`<div class="
${
css
.
container
}
m-3 border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="solidityUnittestsOutput"
data-id="testTabSolidityUnitTestsOutput"
></div>`
this
.
testsSummary
=
yo
`<div class="
${
css
.
container
}
border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="solidityUnittestsSummary"></div>`
this
.
loading
=
yo
`<span class='text-info ml-1'>Running tests...</span>`
this
.
loading
.
hidden
=
true
...
...
@@ -289,6 +289,7 @@ module.exports = class TestTab extends ViewPlugin {
${
this
.
updateRunAction
()}
<label class="
${
css
.
label
}
mx-4 m-2" for="checkAllTests">
<input id="checkAllTests"
data-id="testTabCheckAllTests"
type="checkbox"
onclick="
${(
event
)
=>
{
this
.
checkAll
(
event
)
}}
"
checked="
true
"
...
...
test-browser/tests/solidityUnittests.js
View file @
c8a5be63
...
...
@@ -33,7 +33,22 @@ module.exports = {
.
waitForElementPresent
(
'*[title="browser/test_test.sol"]'
)
},
'Should run unit test for simple_storage.sol file'
:
function
(
browser
)
{
'Should run simple unit test `simple_storage_test.sol` '
:
function
(
browser
)
{
browser
.
waitForElementPresent
(
'*[data-id="verticalIconsKindfileExplorers"]'
)
.
clickLaunchIcon
(
'fileExplorers'
)
.
addFile
(
'simple_storage_test.sol'
,
sources
[
0
][
'browser/simple_storage_test.sol'
])
.
click
(
'*[data-id="verticalIconsKindsolidityUnitTesting"]'
)
.
waitForElementPresent
(
'*[data-id="testTabCheckAllTests"]'
)
.
click
(
'*[data-id="testTabCheckAllTests"]'
)
.
click
(
'.singleTestLabel:nth-of-type(3)'
)
.
scrollAndClick
(
'#runTestsTabRunAction'
)
.
pause
(
10000
)
.
assert
.
containsText
(
'*[data-id="testTabSolidityUnitTestsOutput"]'
,
'browser/simple_storage_test.sol (MyTest)'
)
.
assert
.
containsText
(
'*[data-id="testTabSolidityUnitTestsOutput"]'
,
'✓ (Initial value should be100)'
)
.
assert
.
containsText
(
'*[data-id="testTabSolidityUnitTestsOutput"]'
,
'✓ (Value is set200)'
)
},
'Should run advance unit test using natspec and experimental ABIEncoderV2 `ks2b_test.sol` '
:
function
(
browser
)
{
browser
.
pause
(
100000
)
},
...
...
@@ -104,7 +119,98 @@ var sources = [
foo.set(200);
return Assert.equal(foo.get(), 200, "value is not 200");
}
}
}
`
},
'browser/ks2a.sol'
:
{
content
:
`
pragma solidity >=0.4.22 <0.6.0;
contract Kickstarter {
enum State { Started, Completed }
struct Project {
address owner;
string name;
uint goal;
uint fundsAvailable; // added
uint amountContributed; // added
State state;
mapping(address => uint) funders; // added
}
Project[] public projects;
constructor() public {
}
function createProject(string memory name, uint goal) public {
projects.length++; // new line
Project storage project = projects[projects.length - 1];
project.name = name;
project.goal = goal;
project.owner = msg.sender;
project.state = State.Started;
}
function fundProject(uint projectId) payable public {
Project storage project = projects[projectId];
// require project exists
// PLEASE CHECK / or erase
// not this: require(projects[projectId].exists, "the project must exist to be funded");
// require for... underflow/overflow protection
project.funders[msg.sender] += msg.value;
project.amountContributed += msg.value;
project.fundsAvailable += msg.value;
if (project.amountContributed >= project.goal) {
project.state = State.Completed;
}
}
// this function is here because we can't use web3 when using the VM
function getContractBalance() public view returns(uint balance) {
return address(this).balance;
}
}
`
},
'ks2b_test.sol'
:
{
content
:
`
pragma solidity >=0.4.22 <0.6.0;
pragma experimental ABIEncoderV2;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "remix_accounts.sol";
import "./ks2a.sol";
contract kickstarterTest {
enum State { Started, Completed }
Kickstarter kickstarter;
/// #sender: account-0
function beforeAll () public {
kickstarter = new Kickstarter();
kickstarter.createProject("ProjectA", 123000);
kickstarter.createProject("ProjectB", 100);
}
/// #sender: account-0
/// #value: 10000000
function checkProjectExists () public payable {
(address owner, string memory name, uint goal, uint fundsAvailable, uint amountContributed, Kickstarter.State state) = kickstarter.projects(0);
Assert.equal(name, "ProjectA", "project name is incorrect");
Assert.equal(owner, address(this), "owner is incorrect");
Assert.equal(goal, 123000, "funding goal is incorrect");
}
function checkProjectIsFundable () public {
kickstarter.fundProject.value(120000)(0);
(address owner, string memory name, uint goal, uint fundsAvailable, uint amountContributed, Kickstarter.State state) = kickstarter.projects(0);
Assert.equal(amountContributed, 120000, "contributed amount is incorrect");
}
}
`
}
}
...
...
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