remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/test-browser/tests/solidityUnittests.js

218 lines
7.5 KiB

'use strict'
var init = require('../helpers/init')
var sauce = require('./sauce')
module.exports = {
before: function (browser, done) {
init(browser, done)
},
'@sources': function () {
return sources
},
'Should launch solidity unit test plugin': function (browser) {
browser.waitForElementPresent('*[data-id="verticalIconsKindfileExplorers"]')
.clickLaunchIcon('fileExplorers')
.addFile('simple_storage.sol', sources[0]['browser/simple_storage.sol'])
.clickLaunchIcon('pluginManager')
.scrollAndClick('*[data-id="pluginManagerComponentActivateButtonsolidityUnitTesting"]')
.click('*[data-id="verticalIconsKindsolidityUnitTesting"]')
.waitForElementPresent('*[data-id="sidePanelSwapitTitle"]')
.assert.containsText('*[data-id="sidePanelSwapitTitle"]', 'SOLIDITY UNIT TESTING')
},
'Should generate test file': function (browser) {
browser.waitForElementPresent('*[data-id="verticalIconsKindfileExplorers"]')
.clickLaunchIcon('fileExplorers')
.switchFile('browser/simple_storage.sol')
.click('*[data-id="verticalIconsKindsolidityUnitTesting"]')
.waitForElementPresent('*[data-id="testTabGenerateTestFile"]')
.click('*[data-id="testTabGenerateTestFile"]')
.waitForElementPresent('*[title="browser/test_test.sol"]')
},
'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)
},
'Solidity Unittests': function (browser) {
runTests(browser)
},
tearDown: sauce
}
function runTests (browser) {
browser
.waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('fileExplorers')
.switchFile('browser/3_Ballot.sol')
.clickLaunchIcon('solidityUnitTesting')
.scrollAndClick('#runTestsTabRunAction')
Nightwatch config for running tests in parallel Added drivers path for chrome and firefox Changed firefox port Installed geckodriver Changed firefox config cli_args config Fixed linting error Modified config Revert nightwatch config Fixed linting error Set drivers path Fixed linting error point driver path to new location Set marionette to false Removed cli_args option Set parallel command in ci Retry firefox in pipeline Retry firefox in ci pipeline Remove cli_args from nightwatch config Retry ci pipeline Load gecko in circleci Debug circleci Debug circleci Retry pipeline Retry pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Retry pipeline Retry pipeline Retry pipeline Retry pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Debug pipeline Changed CI selenium-server-standalone to selenium-standalone Fixed linting error Set marionette to false Add download of old firefox to ci build Set marionette to true Set permission Rearranged steps Fix ci error Remove gecko driver Use node_modules selenium standalone Change build steps Change firefox version Update firefox version Renamed firefox start step Test yml changes Test yml changes Test yml changes Test yml changes Setup workflows for running firefox and chrome tests in parallel Setup workflows for running firefox and chrome tests in parallel Setup workflows for running firefox and chrome tests in parallel Setup workflows for running firefox and chrome tests in parallel Use selenium-standalone Use selenium-standalone Set selenium-server version Added selenium config Fixed liniting error Fixed Build error path Fixed Selenium config error path Changed selenium server version Test for chrome Added config for chrome Test firefox and chrome in parallel Add firefox config to seleniumConfig Downgrade firefox driver version Download firefox browser Test circleci parallelism Test circleci parallelism Remove parallelism Added delay to ZoKrates test to fix failing test Fixed failing gist tests for firefox Disabled remixd tests for firefox browser Fix linting error Fixed failing terminal test Remove gecko driver dependency Disable remixd test for firefox Fixed failing solidity unit tests switch to .keys() to .sendKeys() since it is supported by both chrome and firefox
5 years ago
.pause(5000)
.waitForElementPresent('#solidityUnittestsOutput div[class^="testPass"]')
.pause(10000)
.assert.containsText('#solidityUnittestsOutput', 'browser/4_Ballot_test.sol (BallotTest)')
5 years ago
.assert.containsText('#solidityUnittestsOutput', '✓ (Check winning proposal)')
.assert.containsText('#solidityUnittestsOutput', '✓ (Check winnin proposal with return value)')
.end()
}
var sources = [
{
'browser/simple_storage.sol': {
content: `
pragma solidity >=0.4.22 <0.7.0;
contract SimpleStorage {
uint public storedData;
constructor() public {
storedData = 100;
}
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint retVal) {
return storedData;
}
}
`
},
'browser/simple_storage_test.sol': {
content: `
pragma solidity >=0.4.22 <0.7.0;
import "remix_tests.sol";
import "./simple_storage.sol";
contract MyTest {
SimpleStorage foo;
function beforeEach() public {
foo = new SimpleStorage();
}
function initialValueShouldBe100() public returns (bool) {
return Assert.equal(foo.get(), 100, "initial value is not correct");
}
function valueIsSet200() public returns (bool) {
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");
}
}
`
}
}
]