From 6630dcf609f386dec7ee96b0d5e3150671b90229 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 13 Jul 2022 14:03:55 +0200 Subject: [PATCH] fix done --- apps/remix-ide-e2e/src/commands/openFile.ts | 12 +- .../src/tests/editorAutoComplete.test.ts | 166 +++++++++++++++++- .../src/tests/specialFunctions.test.ts | 26 +-- 3 files changed, 182 insertions(+), 22 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/openFile.ts b/apps/remix-ide-e2e/src/commands/openFile.ts index f8191e874f..d764fa2c0a 100644 --- a/apps/remix-ide-e2e/src/commands/openFile.ts +++ b/apps/remix-ide-e2e/src/commands/openFile.ts @@ -5,6 +5,7 @@ class OpenFile extends EventEmitter { command (this: NightwatchBrowser, name: string) { this.api.perform((done) => { openFile(this.api, name, () => { + console.log('doing done') done() this.emit('complete') }) @@ -17,14 +18,21 @@ class OpenFile extends EventEmitter { function openFile (browser: NightwatchBrowser, name: string, done: VoidFunction) { browser.perform((done) => { browser.isVisible('[data-id="remixIdeSidePanel"]', (result) => { + console.log('visible remixIdeSidePanel',result) if (result.value) { // if side panel is shown, check this is the file panel browser.element('css selector', '[data-id="verticalIconsKindfilePanel"] img[data-id="selected"]', (result) => { + console.log('selected file panel', result) if (result.status === 0) { + console.log('selected file panel') done() - } else browser.clickLaunchIcon('filePanel').perform(done) + } else browser.clickLaunchIcon('filePanel').perform(done()) }) - } else browser.clickLaunchIcon('filePanel').perform(done) + } else { + + browser.clickLaunchIcon('filePanel').perform(done()) + } + }) }) .waitForElementVisible('li[data-id="treeViewLitreeViewItem' + name + '"', 60000) diff --git a/apps/remix-ide-e2e/src/tests/editorAutoComplete.test.ts b/apps/remix-ide-e2e/src/tests/editorAutoComplete.test.ts index f38db91b0f..7aff6ce885 100644 --- a/apps/remix-ide-e2e/src/tests/editorAutoComplete.test.ts +++ b/apps/remix-ide-e2e/src/tests/editorAutoComplete.test.ts @@ -7,11 +7,163 @@ module.exports = { init(browser, done, 'http://127.0.0.1:8080', false) }, 'Should show hover over contract in editor #group1': function (browser: NightwatchBrowser) { - browser.waitForElementVisible('div[data-id="mainPanelPluginsContainer"]') - .clickLaunchIcon('filePanel') - .waitForElementVisible('div[data-id="filePanelFileExplorerTree"]') - .openFile('contracts') - .openFile('contracts/1_Storage.sol') - .waitForElementVisible('#editorView') - } + browser.useCss().element('css selector', '[data-id="verticalIconsKindfilePanel"] img[data-id="selected"]', (result) => { + console.log(result) + }) + }, + 'Should load the test file': function (browser: NightwatchBrowser) { + browser.openFile('README.txt') + // .openFile('contracts') + // .openFile('contracts/3_Ballot.sol') + // .waitForElementVisible('#editorView') + // .setEditorValue('bad') + // .pause(4000) // wait for the compiler to finish + // .openFile('contracts') + // .openFile('contracts/3_Ballot.sol') + }, +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const BallotWithARefToOwner = `// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +import "./2_Owner.sol"; + +/** + * @title Ballot + * @dev Implements voting process along with vote delegation + */ +contract BallotHoverTest { + Owner cowner; + struct Voter { + uint weight; // weight is accumulated by delegation + bool voted; // if true, that person already voted + address delegate; // person delegated to + uint vote; // index of the voted proposal + } + + struct Proposal { + // If you can limit the length to a certain number of bytes, + // always use one of bytes1 to bytes32 because they are much cheaper + bytes32 name; // short name (up to 32 bytes) + uint voteCount; // number of accumulated votes + } + + address public chairperson; + + mapping(address => Voter) public voters; + + Proposal[] public proposals; + + /** + * @dev Create a new ballot to choose one of 'proposalNames'. + * @param proposalNames names of proposals + */ + constructor(bytes32[] memory proposalNames) { + cowner = new Owner(); + cowner.getOwner(); + chairperson = msg.sender; + voters[chairperson].weight = 1; + + for (uint i = 0; i < proposalNames.length; i++) { + // 'Proposal({...})' creates a temporary + // Proposal object and 'proposals.push(...)' + // appends it to the end of 'proposals'. + proposals.push(Proposal({ + name: proposalNames[i], + voteCount: 0 + })); + } + } + + /** + * @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. + * @param voter address of voter + */ + function giveRightToVote(address voter) public { + require( + msg.sender == chairperson, + "Only chairperson can give right to vote." + ); + require( + !voters[voter].voted, + "The voter already voted." + ); + require(voters[voter].weight == 0); + voters[voter].weight = 1; + } + + /** + * @dev Delegate your vote to the voter 'to'. + * @param to address to which vote is delegated + */ + function delegate(address to) public { + Voter storage sender = voters[msg.sender]; + require(!sender.voted, "You already voted."); + require(to != msg.sender, "Self-delegation is disallowed."); + + while (voters[to].delegate != address(0)) { + to = voters[to].delegate; + + // We found a loop in the delegation, not allowed. + require(to != msg.sender, "Found loop in delegation."); + } + sender.voted = true; + sender.delegate = to; + Voter storage delegate_ = voters[to]; + if (delegate_.voted) { + // If the delegate already voted, + // directly add to the number of votes + proposals[delegate_.vote].voteCount += sender.weight; + } else { + // If the delegate did not vote yet, + // add to her weight. + delegate_.weight += sender.weight; + } + } + + /** + * @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. + * @param proposal index of proposal in the proposals array + */ + function vote(uint proposal) public { + Voter storage sender = voters[msg.sender]; + require(sender.weight != 0, "Has no right to vote"); + require(!sender.voted, "Already voted."); + sender.voted = true; + sender.vote = proposal; + + // If 'proposal' is out of the range of the array, + // this will throw automatically and revert all + // changes. + proposals[proposal].voteCount += sender.weight; + } + + /** + * @dev Computes the winning proposal taking all previous votes into account. + * @return winningProposal_ index of winning proposal in the proposals array + */ + function winningProposal() public view + returns (uint winningProposal_) + { + uint winningVoteCount = 0; + for (uint p = 0; p < proposals.length; p++) { + if (proposals[p].voteCount > winningVoteCount) { + winningVoteCount = proposals[p].voteCount; + winningProposal_ = p; + } + } + } + + /** + * @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then + * @return winnerName_ the name of the winner + */ + function winnerName() public view + returns (bytes32 winnerName_) + { + winnerName_ = proposals[winningProposal()].name; + } } +` \ No newline at end of file diff --git a/apps/remix-ide-e2e/src/tests/specialFunctions.test.ts b/apps/remix-ide-e2e/src/tests/specialFunctions.test.ts index bcdc3c4977..ad41980081 100644 --- a/apps/remix-ide-e2e/src/tests/specialFunctions.test.ts +++ b/apps/remix-ide-e2e/src/tests/specialFunctions.test.ts @@ -33,7 +33,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(fallback)') .journalLastChildIncludes('value: 0 wei') .journalLastChildIncludes('data: 0xaa') - .perform(done) + .perform(done()) }) }) }, @@ -46,7 +46,7 @@ module.exports = { .pause(1000) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, 'The calldata should be a valid hexadecimal value with size of at least one byte.') - .perform(done) + .perform(done()) }) }) }, @@ -58,7 +58,7 @@ module.exports = { .pause(1000) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, 'The calldata should be a valid hexadecimal value.') - .perform(done) + .perform(done()) }) }) }, @@ -71,7 +71,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(receive)') .journalLastChildIncludes('value: 1 wei') .journalLastChildIncludes('data: 0x') - .perform(done) + .perform(done()) }) }) }, @@ -83,7 +83,7 @@ module.exports = { .pause(1000) .journalLastChildIncludes('to CheckSpecials.(fallback) errored:') .journalLastChildIncludes('The called function should be payable if you send value') - .perform(done) + .perform(done()) }) }) }, @@ -101,7 +101,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(receive)') .journalLastChildIncludes('value: 1 wei') .journalLastChildIncludes('data: 0x') - .perform(done) + .perform(done()) }) }) }, @@ -113,7 +113,7 @@ module.exports = { .pause(1000) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, '\'Fallback\' function is not defined') - .perform(done) + .perform(done()) }) }) }, @@ -131,7 +131,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(fallback)') .journalLastChildIncludes('value: 1 wei') .journalLastChildIncludes('data: 0x') - .perform(done) + .perform(done()) }) }) }, @@ -144,7 +144,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(fallback)') .journalLastChildIncludes('value: 1 wei') .journalLastChildIncludes('data: 0xaa') - .perform(done) + .perform(done()) }) }) }, @@ -161,7 +161,7 @@ module.exports = { .pause(1000) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, 'should have either \'receive\' or payable \'fallback\'') - .perform(done) + .perform(done()) }) }) }, @@ -184,7 +184,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(fallback)') .journalLastChildIncludes('value: 999999998765257135 wei') .journalLastChildIncludes('data: 0xaa') - .perform(done) + .perform(done()) }) }) }, @@ -196,7 +196,7 @@ module.exports = { .journalLastChildIncludes('to: CheckSpecials.(receive)') .journalLastChildIncludes('value: 1 wei') .journalLastChildIncludes('data: 0x') - .perform(done) + .perform(done()) }) }) }, @@ -217,7 +217,7 @@ module.exports = { .pause(1000) .waitForElementVisible(`#instance${address} label[id="deployAndRunLLTxError"]`) .assert.containsText(`#instance${address} label[id="deployAndRunLLTxError"]`, 'Both \'receive\' and \'fallback\' functions are not defined') - .perform(done) + .perform(done()) }) }) .end()