From 910418783e99787090d99a4723ab32fd97a0428c Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 19 Apr 2024 10:26:16 +0100 Subject: [PATCH 1/7] fix format for pinned contracts --- .../src/tests/pinned_contracts.test.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/pinned_contracts.test.ts b/apps/remix-ide-e2e/src/tests/pinned_contracts.test.ts index 6b26008928..8c57a89947 100644 --- a/apps/remix-ide-e2e/src/tests/pinned_contracts.test.ts +++ b/apps/remix-ide-e2e/src/tests/pinned_contracts.test.ts @@ -29,7 +29,7 @@ module.exports = { .assert.textContains('*[data-id="deployAndRunNoInstanceText"]', 'Currently you have no unpinned contracts to interact with.') .assert.not.elementPresent('*[data-id="NoPinnedInstanceText"]') .assert.elementPresent('*[data-id="pinnedInstance0xd9145CCE52D386f254917e481eB44e9943F39138"]') - }, + }, 'Test pinned contract loading on environment change #group1': function (browser: NightwatchBrowser) { browser .switchEnvironment('vm-shanghai') @@ -41,7 +41,7 @@ module.exports = { .assert.textContains('*[data-id="pinnedContractsSublabel"]', '(network: vm-cancun)') .assert.not.elementPresent('*[data-id="NoPinnedInstanceText"]') .assert.elementPresent('*[data-id="pinnedInstance0xd9145CCE52D386f254917e481eB44e9943F39138"]') - }, + }, 'Interact with pinned contract #group1': function (browser: NightwatchBrowser) { browser .click('*[data-id="universalDappUiTitleExpander0"]') @@ -51,23 +51,23 @@ module.exports = { .assert.textContains('*[data-id="instanceContractFilePath"]', 'default_workspace/contracts/1_Storage.sol') .clickFunction('retrieve - call') .testFunction('last', - { - to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', - 'decoded output': { "0": "uint256: 0" } - }) + { + to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', + 'decoded output': { "0": "uint256: 0" } + }) .clickFunction('store - transact (not payable)', { types: 'uint256 num', values: '35' }) .testFunction('last', - { - status: '0x1 Transaction mined and execution succeed', - 'decoded input': { "uint256 num": "35" } - }) + { + status: '0x1 Transaction mined and execution succeed', + 'decoded input': { "uint256 num": "35" } + }) .clickFunction('retrieve - call') .testFunction('last', - { - to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', - 'decoded output': { "0": "uint256: 35" } - }) - }, + { + to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', + 'decoded output': { "0": "uint256: 35" } + }) + }, 'Unpin & interact #group1': function (browser: NightwatchBrowser) { browser .click('*[data-id="universalDappUiUdappUnpin"]') @@ -78,23 +78,23 @@ module.exports = { .assert.not.elementPresent('*[data-id="instanceContractFilePath"]') .clickFunction('retrieve - call') .testFunction('last', - { - to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', - 'decoded output': { "0": "uint256: 35" } - }) + { + to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', + 'decoded output': { "0": "uint256: 35" } + }) .clickFunction('store - transact (not payable)', { types: 'uint256 num', values: '55' }) .testFunction('last', - { - status: '0x1 Transaction mined and execution succeed', - 'decoded input': { "uint256 num": "55" } - }) + { + status: '0x1 Transaction mined and execution succeed', + 'decoded input': { "uint256 num": "55" } + }) .clickFunction('retrieve - call') .testFunction('last', - { - to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', - 'decoded output': { "0": "uint256: 55" } - }) - }, + { + to: 'Storage.retrieve() 0xd9145CCE52D386f254917e481eB44e9943F39138', + 'decoded output': { "0": "uint256: 55" } + }) + }, 'Re-pin & delete immediately #group1': function (browser: NightwatchBrowser) { browser .click('*[data-id="universalDappUiUdappPin"]') @@ -102,5 +102,5 @@ module.exports = { .click('*[data-id="universalDappUiUdappDelete"]') .assert.textContains('*[data-id="NoPinnedInstanceText"]', 'No pinned contracts found for selected workspace & network') .assert.textContains('*[data-id="deployAndRunNoInstanceText"]', 'Currently you have no unpinned contracts to interact with.') - }, -} \ No newline at end of file + }, +} From a2660c4a8872488e737447784b25d04be1a46e8a Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 19 Apr 2024 12:00:31 +0100 Subject: [PATCH 2/7] format tests. update test to use snekmate --- apps/remix-ide-e2e/src/commands/openFile.ts | 16 ++++++------- .../remix-ide-e2e/src/tests/vyper_api.test.ts | 24 +++++++++++-------- apps/vyper/src/app/utils/remix-client.tsx | 8 +++---- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/openFile.ts b/apps/remix-ide-e2e/src/commands/openFile.ts index f214100eee..a049b125e9 100644 --- a/apps/remix-ide-e2e/src/commands/openFile.ts +++ b/apps/remix-ide-e2e/src/commands/openFile.ts @@ -31,15 +31,15 @@ function openFile (browser: NightwatchBrowser, name: string, done: VoidFunction) done() }) } - - }) - }) - .waitForElementVisible('li[data-id="treeViewLitreeViewItem' + name + '"', 60000) - .click('li[data-id="treeViewLitreeViewItem' + name + '"') - .pause(2000) - .perform(() => { - done() + + }) }) + .waitForElementVisible('li[data-id="treeViewLitreeViewItem' + name + '"', 60000) + .click('li[data-id="treeViewLitreeViewItem' + name + '"') + .pause(2000) + .perform(() => { + done() + }) } module.exports = OpenFile diff --git a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts index 3ef6892284..683a31b017 100644 --- a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts +++ b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts @@ -27,28 +27,29 @@ module.exports = { .frameParent() .clickLaunchIcon('filePanel') .waitForElementVisible({ - selector: "//*[@data-id='workspacesSelect' and contains(.,'vyper-lang')]", + selector: "//*[@data-id='workspacesSelect' and contains(.,'snekmate')]", locateStrategy: 'xpath', timeout: 60000 }) - .currentWorkspaceIs('vyper-lang') + .currentWorkspaceIs('snekmate') .waitForElementVisible({ selector: "//*[@data-id='treeViewLitreeViewItemexamples' and contains(.,'examples')]", locateStrategy: 'xpath', timeout: 60000 }) - .openFile('examples') - .openFile('examples/auctions') - .openFile('examples/auctions/blind_auction.vy') + .openFile('src') + .openFile('src/tokens') + .openFile('src/tokens/ERC721.vy') }, // 'Add vyper file to run tests #group1': function (browser: NightwatchBrowser) { // browser.addFile('TestBallot.sol', sources[0]['TestBallot.sol']) // }, - + '@sources': () => sources, 'Context menu click to compile blind_auction should succeed #group1': function (browser: NightwatchBrowser) { browser - .click('*[data-id="treeViewLitreeViewItemexamples/auctions/blind_auction.vy"]') - .rightClick('*[data-id="treeViewLitreeViewItemexamples/auctions/blind_auction.vy"]') + .addFile('blind_auction.vy', sources[0]['blindAuction']) + .click('*[data-id="treeViewLitreeViewItemblind_auction.vy"]') + .rightClick('*[data-id="treeViewLitreeViewItemblind_auction.vy"]') .waitForElementPresent('[data-id="contextMenuItemvyper"]') .click('[data-id="contextMenuItemvyper"]') .clickLaunchIcon('vyper') @@ -180,8 +181,9 @@ def _createPokemon(_name: String[32], _dna: uint256, _HP: uint256): wins: 0 }) self.totalPokemonCount += 1` +const sources = [{ -const blindAuction = ` + 'blindAuction' : { content: ` # Blind Auction. Adapted to Vyper from [Solidity by Example](https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst#blind-auction-1) #pragma version ^0.3.10 @@ -358,4 +360,6 @@ def auctionEnd(): # Transfer funds to beneficiary send(self.beneficiary, self.highestBid) -` +`} +} +] diff --git a/apps/vyper/src/app/utils/remix-client.tsx b/apps/vyper/src/app/utils/remix-client.tsx index 94d149167b..088aa6c36d 100644 --- a/apps/vyper/src/app/utils/remix-client.tsx +++ b/apps/vyper/src/app/utils/remix-client.tsx @@ -80,20 +80,20 @@ export class RemixClient extends PluginClient { async cloneVyperRepo() { try { // @ts-ignore - this.call('notification', 'toast', 'cloning Vyper repository...') + this.call('notification', 'toast', 'cloning Snekmate Vyper repository...') await this.call('manager', 'activatePlugin', 'dGitProvider') await this.call( 'dGitProvider', 'clone', - {url: 'https://github.com/vyperlang/vyper', token: null, branch: 'v0.3.10'}, + {url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'v0.0.5'}, // @ts-ignore - 'vyper-lang' + 'snekmate' ) this.call( // @ts-ignore 'notification', 'toast', - 'Vyper repository cloned, the workspace Vyper has been created.' + 'Snekmate Vyper repository cloned, the workspace snekmate has been created.' ) } catch (e) { // @ts-ignore From fd4a4311761a492383da48194b0a8fe25ae18566 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 19 Apr 2024 12:21:16 +0100 Subject: [PATCH 3/7] addFileSnekmate for vyper. update vyper e2e --- .../src/commands/addFileSnekmate.ts | 74 +++++++++++++++++++ .../remix-ide-e2e/src/tests/vyper_api.test.ts | 9 ++- apps/remix-ide-e2e/src/types/index.d.ts | 1 + 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 apps/remix-ide-e2e/src/commands/addFileSnekmate.ts diff --git a/apps/remix-ide-e2e/src/commands/addFileSnekmate.ts b/apps/remix-ide-e2e/src/commands/addFileSnekmate.ts new file mode 100644 index 0000000000..a41cff8d06 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/addFileSnekmate.ts @@ -0,0 +1,74 @@ +import EventEmitter from 'events' +import { NightwatchBrowser, NightwatchContractContent } from 'nightwatch' + +class AddFileSnekmate extends EventEmitter { + command(this: NightwatchBrowser, name: string, content: NightwatchContractContent): NightwatchBrowser { + this.api.perform((done) => { + addFileSnekmate(this.api, name, content, () => { + done() + this.emit('complete') + }) + }) + return this + } +} + +function addFileSnekmate(browser: NightwatchBrowser, name: string, content: NightwatchContractContent, done: VoidFunction) { + browser + .isVisible({ + selector: "//*[@data-id='sidePanelSwapitTitle' and contains(.,'File explorer')]", + locateStrategy: 'xpath', + suppressNotFoundErrors: true, + timeout: 1000 + }, (okVisible) => { + if (!okVisible.value) { + browser.clickLaunchIcon('filePanel') + } + }) + .scrollInto('li[data-id="treeViewLitreeViewItemREADME.txt"]') + .waitForElementVisible('li[data-id="treeViewLitreeViewItemLICENSE"]') + .click('li[data-id="treeViewLitreeViewItemLICENSE"]').pause(1000) // focus on root directory + .isVisible({ + selector: `//*[@data-id="treeViewLitreeViewItem${name}"]`, + locateStrategy: 'xpath', + abortOnFailure: false, + suppressNotFoundErrors: true, + timeout: 2000 + }, (okVisible) => { + // @ts-ignore + // status === -1 means the element is not visible, 0 means it is visible. + if (okVisible.status === 0) { + browser.openFile(name) + .perform(function () { + done() + }) + } else { + browser.click('[data-id="fileExplorerNewFilecreateNewFile"]') + .waitForElementContainsText('*[data-id$="fileExplorerTreeItemInput"]', '', 60000) + .sendKeys('*[data-id$="fileExplorerTreeItemInput"]', name) + .sendKeys('*[data-id$="fileExplorerTreeItemInput"]', browser.Keys.ENTER) + // isvisible is protocol action called isDisplayed https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html#isDisplayed-- + .isVisible({ + selector: `li[data-id="treeViewLitreeViewItem${name}"]`, + abortOnFailure: false, + suppressNotFoundErrors: true, + timeout: 60000 + }) + .waitForElementVisible({ + selector: `//*[@data-id='tab-active' and contains(@data-path, "${name}")]`, + locateStrategy: 'xpath' + }) + .setEditorValue(content.content) + .getEditorValue((result) => { + if(result != content.content) { + browser.setEditorValue(content.content) + } + }) + .perform(function () { + done() + }) + } + }) +} + +module.exports = AddFileSnekmate diff --git a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts index 683a31b017..62fff378fb 100644 --- a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts +++ b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts @@ -33,13 +33,14 @@ module.exports = { }) .currentWorkspaceIs('snekmate') .waitForElementVisible({ - selector: "//*[@data-id='treeViewLitreeViewItemexamples' and contains(.,'examples')]", + selector: "//*[@data-id='treeViewLitreeViewItemsrc' and contains(.,'src')]", locateStrategy: 'xpath', timeout: 60000 }) .openFile('src') - .openFile('src/tokens') - .openFile('src/tokens/ERC721.vy') + .openFile('src/snekmate') + .openFile('src/snekmate/tokens') + .openFile('src/snekmate/tokens/ERC721.vy') }, // 'Add vyper file to run tests #group1': function (browser: NightwatchBrowser) { // browser.addFile('TestBallot.sol', sources[0]['TestBallot.sol']) @@ -47,7 +48,7 @@ module.exports = { '@sources': () => sources, 'Context menu click to compile blind_auction should succeed #group1': function (browser: NightwatchBrowser) { browser - .addFile('blind_auction.vy', sources[0]['blindAuction']) + .addFileSnekmate('blind_auction.vy', sources[0]['blindAuction']) .click('*[data-id="treeViewLitreeViewItemblind_auction.vy"]') .rightClick('*[data-id="treeViewLitreeViewItemblind_auction.vy"]') .waitForElementPresent('[data-id="contextMenuItemvyper"]') diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index 74f9e518fe..8440ab3e24 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -73,6 +73,7 @@ declare module 'nightwatch' { waitForElementNotContainsText: (id: string, value: string, timeout: number = 10000) => NightwatchBrowser hideToolTips: (this: NightwatchBrowser) => NightwatchBrowser enableClipBoard: () => NightwatchBrowser + addFileSnekmate: (name: string, content: NightwatchContractContent) => NightwatchBrowser } export interface NightwatchBrowser { From 3809f1b42932ddf60b103d671ba534c290157b49 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 19 Apr 2024 13:10:15 +0100 Subject: [PATCH 4/7] add one more test. update clone button text --- .../remix-ide-e2e/src/tests/vyper_api.test.ts | 28 +++++++++++++++++++ apps/vyper/src/app/app.tsx | 2 +- apps/vyper/src/app/utils/compiler.tsx | 4 +-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts index 62fff378fb..8731bf9e3d 100644 --- a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts +++ b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts @@ -147,6 +147,34 @@ module.exports = { browser.verifyCallReturnValue(contractAddress, ['0:uint256: 0']) .perform(() => done()) }) + }, + + 'Compile Ownable contract from snekmate #group1': function (browser: NightwatchBrowser) { + let contractAddress + browser + .frameParent() + .clickLaunchIcon('filePanel') + .switchWorkspace('snekmate') + .openFile('src') + .openFile('src/snekmate') + .openFile('src/snekmate/auth') + .openFile('src/snekmate/auth/Ownable.vy') + // .click('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/Ownable.vy"]') + .rightClick('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/Ownable.vy"]') + .waitForElementVisible('*[data-id="contextMenuItemvyper"]') + .click('*[data-id="contextMenuItemvyper"]') + .clickLaunchIcon('vyper') + // @ts-ignore + .frame(0) + .click('[data-id="compile"]') + .waitForElementVisible({ + selector:'[data-id="compilation-details"]', + timeout: 60000 + }) + .click('[data-id="compilation-details"]') + .frameParent() + .waitForElementVisible('[data-id="copy-abi"]') + .end() } } diff --git a/apps/vyper/src/app/app.tsx b/apps/vyper/src/app/app.tsx index 63634ca316..7b265e0bdc 100644 --- a/apps/vyper/src/app/app.tsx +++ b/apps/vyper/src/app/app.tsx @@ -119,7 +119,7 @@ const App = () => {
diff --git a/apps/vyper/src/app/utils/compiler.tsx b/apps/vyper/src/app/utils/compiler.tsx index 824c076283..902c4f1691 100644 --- a/apps/vyper/src/app/utils/compiler.tsx +++ b/apps/vyper/src/app/utils/compiler.tsx @@ -148,10 +148,10 @@ const fixContractContent = (content: string) => { const pragma = '#pragma version ^0.3.10' const evmVer = '#pragma evm-version shanghai' - if (!evmVerFound) { + if (evmVerFound === false) { content = `${evmVer}\n${content}` } - if (!pragmaFound) { + if (pragmaFound === false) { content = `${pragma}\n${content}` } return content From cd9af4bdb41b11b33f0f33e86de89323c1419f24 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 19 Apr 2024 14:00:30 +0100 Subject: [PATCH 5/7] address bad pragma line in vyper contract on snekmate --- apps/remix-ide-e2e/src/tests/vyper_api.test.ts | 1 - apps/vyper/src/app/utils/compiler.tsx | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts index 8731bf9e3d..356752a56a 100644 --- a/apps/remix-ide-e2e/src/tests/vyper_api.test.ts +++ b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts @@ -159,7 +159,6 @@ module.exports = { .openFile('src/snekmate') .openFile('src/snekmate/auth') .openFile('src/snekmate/auth/Ownable.vy') - // .click('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/Ownable.vy"]') .rightClick('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/Ownable.vy"]') .waitForElementVisible('*[data-id="contextMenuItemvyper"]') .click('*[data-id="contextMenuItemvyper"]') diff --git a/apps/vyper/src/app/utils/compiler.tsx b/apps/vyper/src/app/utils/compiler.tsx index 902c4f1691..3a7f4fbd0b 100644 --- a/apps/vyper/src/app/utils/compiler.tsx +++ b/apps/vyper/src/app/utils/compiler.tsx @@ -144,6 +144,7 @@ const compileReturnType = (output, contract) => { const fixContractContent = (content: string) => { if (content.length === 0) return const pragmaFound = content.includes('#pragma version ^0.3.10') + const wrongpragmaFound = content.includes('# pragma version ^0.3.10') const evmVerFound = content.includes('#pragma evm-version shanghai') const pragma = '#pragma version ^0.3.10' const evmVer = '#pragma evm-version shanghai' @@ -151,7 +152,10 @@ const fixContractContent = (content: string) => { if (evmVerFound === false) { content = `${evmVer}\n${content}` } - if (pragmaFound === false) { + if (wrongpragmaFound === true) { + content = content.replace('# pragma version ^0.3.10', '') + } + if (pragmaFound === false ) { content = `${pragma}\n${content}` } return content From b8e38136befd2928ddbf3b7459698d3ccbe4d5a1 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sun, 21 Apr 2024 22:11:48 +0100 Subject: [PATCH 6/7] Update app.tsx Update clone button text --- apps/vyper/src/app/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vyper/src/app/app.tsx b/apps/vyper/src/app/app.tsx index 7b265e0bdc..36f14e2d38 100644 --- a/apps/vyper/src/app/app.tsx +++ b/apps/vyper/src/app/app.tsx @@ -119,7 +119,7 @@ const App = () => {
From ba2b3f850cdfdbe9b043c38ab8a6a7357200f884 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Sun, 21 Apr 2024 22:15:23 +0100 Subject: [PATCH 7/7] Update app.tsx Update tooltip messaging --- apps/vyper/src/app/app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vyper/src/app/app.tsx b/apps/vyper/src/app/app.tsx index 36f14e2d38..58a5d92a04 100644 --- a/apps/vyper/src/app/app.tsx +++ b/apps/vyper/src/app/app.tsx @@ -117,7 +117,7 @@ const App = () => {
- +