Merge branch 'master' of https://github.com/ethereum/remix-project into optimizecircle

pull/2868/head
filip mertens 2 years ago
commit 47f282e329
  1. 48
      apps/remix-ide-e2e/src/tests/workspace.test.ts
  2. 2
      libs/remix-solidity/src/compiler/compiler.ts
  3. 6
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  4. 4
      libs/remix-ws-templates/src/index.ts
  5. 20
      libs/remix-ws-templates/src/templates/ozerc1155/index.ts
  6. 10
      libs/remix-ws-templates/src/templates/ozerc1155/scripts/deploy_with_ethers.ts
  7. 10
      libs/remix-ws-templates/src/templates/ozerc1155/scripts/deploy_with_web3.ts
  8. 29
      libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts
  9. 36
      libs/remix-ws-templates/src/templates/ozerc1155/scripts/web3-lib.ts
  10. 19
      libs/remix-ws-templates/src/templates/ozerc1155/tests/MyToken_test.sol
  11. 12
      libs/remix-ws-templates/src/templates/ozerc20/index.ts
  12. 12
      libs/remix-ws-templates/src/templates/ozerc721/index.ts

@ -207,6 +207,54 @@ module.exports = {
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtests/MyToken_test.sol"]') .waitForElementVisible('*[data-id="treeViewLitreeViewItemtests/MyToken_test.sol"]')
}, },
'Should create ERC1155 workspace with files #group1': function (browser: NightwatchBrowser) {
browser
.click('*[data-id="workspaceCreate"]')
.waitForElementVisible('*[data-id="modalDialogCustomPromptTextCreate"]')
.waitForElementVisible('[data-id="fileSystemModalDialogModalFooter-react"] > button')
// eslint-disable-next-line dot-notation
.execute(function () { document.querySelector('*[data-id="modalDialogCustomPromptTextCreate"]')['value'] = 'workspace_erc1155' })
.click('select[id="wstemplate"]')
.click('select[id="wstemplate"] option[value=ozerc1155]')
.waitForElementPresent('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok')
.execute(function () { (document.querySelector('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') as HTMLElement).click() })
.pause(100)
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/deploy_with_web3.ts"]')
// check js and ts files are not transformed
.click('*[data-id="treeViewLitreeViewItemscripts/deploy_with_web3.ts"]')
.pause(4000)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`import { deploy } from './web3-lib'`) !== -1,
'Incorrect content')
})
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/deploy_with_ethers.ts"]')
.click('*[data-id="treeViewLitreeViewItemscripts/deploy_with_ethers.ts"]')
.pause(1000)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`import { deploy } from './ethers-lib'`) !== -1,
'Incorrect content')
})
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]')
.click('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]')
.pause(1000)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {`) !== -1,
'Incorrect content')
})
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]')
.click('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]')
.pause(1000)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {`) !== -1,
'Incorrect content')
})
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtests"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtests/MyToken_test.sol"]')
},
// WORKSPACE TEMPLATES E2E END // WORKSPACE TEMPLATES E2E END
'Should create two workspace and switch to the first one #group1': function (browser: NightwatchBrowser) { 'Should create two workspace and switch to the first one #group1': function (browser: NightwatchBrowser) {

@ -281,7 +281,7 @@ export class Compiler {
} }
switch (data.cmd) { switch (data.cmd) {
case 'versionLoaded': case 'versionLoaded':
if (data.data && data.license) this.onCompilerLoaded(data.data, data.license) if (data.data) this.onCompilerLoaded(data.data, data.license)
break break
case 'compiled': case 'compiled':
{ {

@ -147,9 +147,10 @@ export function Workspace () {
const updateWsName = () => { const updateWsName = () => {
// @ts-ignore // @ts-ignore
if (workspaceCreateTemplateInput.current.value.startsWith('oz') && displayOzCustomRef && displayOzCustomRef.current) if (workspaceCreateTemplateInput.current.value.startsWith('oz') && displayOzCustomRef && displayOzCustomRef.current) {
displayOzCustomRef.current.style.display = 'block' displayOzCustomRef.current.style.display = 'block'
else displayOzCustomRef.current.style.display = 'none' upgradeable.current = undefined
} else displayOzCustomRef.current.style.display = 'none'
// @ts-ignore // @ts-ignore
workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value || 'remixDefault'}_${Date.now()}` workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value || 'remixDefault'}_${Date.now()}`
@ -188,6 +189,7 @@ export function Workspace () {
<optgroup style={{fontSize: "medium"}} label="OpenZepplin"> <optgroup style={{fontSize: "medium"}} label="OpenZepplin">
<option style={{fontSize: "small"}} value='ozerc20'>ERC20</option> <option style={{fontSize: "small"}} value='ozerc20'>ERC20</option>
<option style={{fontSize: "small"}} value='ozerc721'>ERC721</option> <option style={{fontSize: "small"}} value='ozerc721'>ERC721</option>
<option style={{fontSize: "small"}} value='ozerc1155'>ERC1155</option>
</optgroup> </optgroup>
<optgroup style={{fontSize: "medium"}} label="0xProject"> <optgroup style={{fontSize: "medium"}} label="0xProject">
<option style={{fontSize: "small"}} value='zeroxErc20'>ERC20</option> <option style={{fontSize: "small"}} value='zeroxErc20'>ERC20</option>

@ -1,5 +1,7 @@
export { default as remixDefault } from './templates/remixDefault' export { default as remixDefault } from './templates/remixDefault'
export { default as blank } from './templates/blank' export { default as blank } from './templates/blank'
export { default as ozerc20 } from './templates/ozerc20' export { default as ozerc20 } from './templates/ozerc20'
export { default as zeroxErc20 } from './templates/zeroxErc20'
export { default as ozerc721 } from './templates/ozerc721' export { default as ozerc721 } from './templates/ozerc721'
export { default as ozerc1155 } from './templates/ozerc1155'
export { default as zeroxErc20 } from './templates/zeroxErc20'

@ -0,0 +1,20 @@
import { erc1155 } from '@openzeppelin/wizard';
export default async (opts) => {
const filesObj = {
'contracts/MyToken.sol': erc1155.print({ ...erc1155.defaults, upgradeable: opts.upgradeable}),
// @ts-ignore
'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default,
// @ts-ignore
'scripts/deploy_with_web3.ts': (await import('!!raw-loader!./scripts/deploy_with_web3.ts')).default,
// @ts-ignore
'scripts/ethers-lib.ts': (await import('!!raw-loader!./scripts/ethers-lib.ts')).default,
// @ts-ignore
'scripts/web3-lib.ts': (await import('!!raw-loader!./scripts/web3-lib.ts')).default
}
// If no options is selected, opts.upgradeable will be undefined
// We do not show test file for upgradeable contract
// @ts-ignore
if (opts.upgradeable === undefined || !opts.upgradeable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default
return filesObj
}

@ -0,0 +1,10 @@
import { deploy } from './ethers-lib'
(async () => {
try {
const result = await deploy('MyToken', [])
console.log(`address: ${result.address}`)
} catch (e) {
console.log(e.message)
}
})()

@ -0,0 +1,10 @@
import { deploy } from './web3-lib'
(async () => {
try {
const result = await deploy('MyToken', [])
console.log(`address: ${result.address}`)
} catch (e) {
console.log(e.message)
}
})()

@ -0,0 +1,29 @@
import { ethers } from 'ethers'
/**
* Deploy the given contract
* @param {string} contractName name of the contract to deploy
* @param {Array<any>} args list of constructor' parameters
* @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract
*/
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
const contract = await factory.deploy(...args)
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
return contract
}

@ -0,0 +1,36 @@
import Web3 from 'web3'
import { Contract, ContractSendMethod, Options } from 'web3-eth-contract'
/**
* Deploy the given contract
* @param {string} contractName name of the contract to deploy
* @param {Array<any>} args list of constructor' parameters
* @param {string} from account used to send the transaction
* @param {number} gas gas limit
* @return {Options} deployed contract
*/
export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {
const web3 = new Web3(web3Provider)
console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json`
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const accounts = await web3.eth.getAccounts()
const contract: Contract = new web3.eth.Contract(metadata.abi)
const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})
const newContractInstance = await contractSend.send({
from: from || accounts[0],
gas: gas || 3600000
})
return newContractInstance.options
}

@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol";
import "../contracts/MyToken.sol";
contract MyTokenTest {
MyToken s;
function beforeAll () public {
s = new MyToken();
}
function testSetURI () public {
string memory uri = "https://testuri.io/token";
s.setURI(uri);
Assert.equal(s.uri(1), uri, "uri did not match");
}
}

@ -1,7 +1,7 @@
import { erc20 } from '@openzeppelin/wizard'; import { erc20 } from '@openzeppelin/wizard';
export default async (opts) => { export default async (opts) => {
return { const filesObj = {
'contracts/MyToken.sol': erc20.print({ ...erc20.defaults, upgradeable: opts.upgradeable}), 'contracts/MyToken.sol': erc20.print({ ...erc20.defaults, upgradeable: opts.upgradeable}),
// @ts-ignore // @ts-ignore
'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default,
@ -10,8 +10,12 @@ export default async (opts) => {
// @ts-ignore // @ts-ignore
'scripts/ethers-lib.ts': (await import('!!raw-loader!./scripts/ethers-lib.ts')).default, 'scripts/ethers-lib.ts': (await import('!!raw-loader!./scripts/ethers-lib.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/web3-lib.ts': (await import('!!raw-loader!./scripts/web3-lib.ts')).default, 'scripts/web3-lib.ts': (await import('!!raw-loader!./scripts/web3-lib.ts')).default
// @ts-ignore
'tests/MyToken_test.sol': (await import('raw-loader!./tests/MyToken_test.sol')).default
} }
// If no options is selected, opts.upgradeable will be undefined
// We do not show test file for upgradeable contract
// @ts-ignore
if (opts.upgradeable === undefined || !opts.upgradeable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default
return filesObj
} }

@ -1,7 +1,7 @@
import { erc721 } from '@openzeppelin/wizard'; import { erc721 } from '@openzeppelin/wizard';
export default async (opts) => { export default async (opts) => {
return { const filesObj = {
'contracts/MyToken.sol': erc721.print({ ...erc721.defaults, upgradeable: opts.upgradeable}), 'contracts/MyToken.sol': erc721.print({ ...erc721.defaults, upgradeable: opts.upgradeable}),
// @ts-ignore // @ts-ignore
'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default,
@ -10,8 +10,12 @@ export default async (opts) => {
// @ts-ignore // @ts-ignore
'scripts/ethers-lib.ts': (await import('!!raw-loader!./scripts/ethers-lib.ts')).default, 'scripts/ethers-lib.ts': (await import('!!raw-loader!./scripts/ethers-lib.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/web3-lib.ts': (await import('!!raw-loader!./scripts/web3-lib.ts')).default, 'scripts/web3-lib.ts': (await import('!!raw-loader!./scripts/web3-lib.ts')).default
// @ts-ignore
'tests/MyToken_test.sol': (await import('raw-loader!./tests/MyToken_test.sol')).default
} }
// If no options is selected, opts.upgradeable will be undefined
// We do not show test file for upgradeable contract
// @ts-ignore
if (opts.upgradeable === undefined || !opts.upgradeable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default
return filesObj
} }
Loading…
Cancel
Save