improve templates naming
yann300-patch-42
yann300 3 years ago committed by GitHub
commit 5ab3cc8e97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/remix-ide-e2e/src/tests/workspace.test.ts
  2. 11
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  3. 1
      libs/remix-ui/workspace/src/lib/templates/blank.ts
  4. 125
      libs/remix-ui/workspace/src/lib/templates/erc20.ts
  5. 2
      libs/remix-ui/workspace/src/lib/templates/index.ts
  6. 2
      libs/remix-ws-templates/src/index.ts
  7. 16
      libs/remix-ws-templates/src/templates/erc20/index.ts
  8. 4
      libs/remix-ws-templates/src/templates/ozerc20/contracts/SampleERC20.sol
  9. 16
      libs/remix-ws-templates/src/templates/ozerc20/index.ts
  10. 0
      libs/remix-ws-templates/src/templates/ozerc20/scripts/deploy_with_ethers.ts
  11. 0
      libs/remix-ws-templates/src/templates/ozerc20/scripts/deploy_with_web3.ts
  12. 0
      libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers.ts
  13. 0
      libs/remix-ws-templates/src/templates/ozerc20/scripts/web3.ts
  14. 0
      libs/remix-ws-templates/src/templates/ozerc20/tests/SampleERC20_test.sol
  15. 10
      libs/remix-ws-templates/src/templates/remixDefault/index.ts

@ -89,7 +89,7 @@ module.exports = {
// eslint-disable-next-line dot-notation
.execute(function () { document.querySelector('*[data-id="modalDialogCustomPromptTextCreate"]')['value'] = 'workspace_erc20' })
.click('select[id="wstemplate"]')
.click('select[id="wstemplate"] option[value=erc20]')
.click('select[id="wstemplate"] option[value=ozerc20]')
.waitForElementPresent('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok')
.execute(function () { (document.querySelector('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') as HTMLElement).click() })
.pause(1000)

@ -119,16 +119,21 @@ export function Workspace () {
}
}
const updateWsName = () => {
// @ts-ignore
workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value || 'remixDefault'}_${Date.now()}`
}
const createModalMessage = () => {
return (
<>
<label id="wsName" className="form-check-label">Workspace name</label>
<input type="text" data-id="modalDialogCustomPromptTextCreate" defaultValue={`workspace_${Date.now()}`} ref={workspaceCreateInput} className="form-control" /><br/>
<input type="text" data-id="modalDialogCustomPromptTextCreate" defaultValue={`remixDefault_${Date.now()}`} ref={workspaceCreateInput} className="form-control" /><br/>
<label id="selectWsTemplate" className="form-check-label">Choose a template</label>
<select name="wstemplate" className="form-control custom-select" id="wstemplate" defaultValue='remixDefault' ref={workspaceCreateTemplateInput}>
<select name="wstemplate" className="form-control custom-select" id="wstemplate" defaultValue='remixDefault' ref={workspaceCreateTemplateInput} onChange={updateWsName}>
<option value='remixDefault'>Default</option>
<option value='blank'>Blank</option>
<option value='erc20'>ERC20</option>
<option value='ozerc20'>OpenZeppelin ERC20</option>
</select>
</>
)

@ -1,125 +0,0 @@
'use strict'
const erc20 = `// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title SampleERC20
* @dev Create a sample ERC20 standard token
*/
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract SampleERC20 is ERC20 {
constructor(string memory tokenName, string memory tokenSymbol) ERC20(tokenName, tokenSymbol) {}
}`
const erc20_test = `// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol";
import "../contracts/SampleERC20.sol";
contract SampleERC20Test {
SampleERC20 s;
function beforeAll () public {
s = new SampleERC20("TestToken", "TST");
}
function testTokenNameAndSymbol () public {
Assert.equal(s.name(), "TestToken", "token name did not match");
Assert.equal(s.symbol(), "TST", "token symbol did not match");
}
}
`
/* eslint-disable no-useless-escape */
const deployWithWeb3 = `import { deploy } from './web3.ts'
(async () => {
try {
const result = await deploy('SampleERC20', ['testToken', 'TST'])
console.log(\`address: \${result.address\}\`)
} catch (e) {
console.log(e.message)
}
})()`
const deployWithEthers = `import { deploy } from './ethers.ts'
(async () => {
try {
const result = await deploy('SampleERC20', ['testToken', 'TST'])
console.log(\`address: \${result.address\}\`)
} catch (e) {
console.log(e.message)
}
})()`
const libWeb3 = `
export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number) => {
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()
let contract = new web3.eth.Contract(metadata.abi)
contract = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})
const newContractInstance = await contract.send({
from: from || accounts[0],
gas: gas || 1500000
})
return newContractInstance.options
}: Promise<any>`
const libEthers = `
export const deploy = async (contractName: string, args: Array<any>, from?: string) => {
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))
// 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner()
let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
let contract
if (from) {
contract = await factory.connect(from).deploy(...args);
} else {
contract = await factory.deploy(...args);
}
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
return contract
}: Promise<any>`
/* eslint-enable no-useless-escape */
export default {
erc20: { name: 'contracts/SampleERC20.sol', content: erc20 },
erc20_test: { name: 'tests/SampleERC20_test.sol', content: erc20_test },
deployWithWeb3: { name: 'scripts/deploy_with_web3.ts', content: deployWithWeb3 },
deployWithEthers: { name: 'scripts/deploy_with_ethers.ts', content: deployWithEthers },
web3: { name: 'scripts/web3.ts', content: libWeb3 },
ethers: { name: 'scripts/ethers.ts', content: libEthers },
}

@ -1,2 +0,0 @@
export { default as erc20 } from './erc20'
export { default as blank } from './blank'

@ -1,3 +1,3 @@
export { default as remixDefault } from './templates/remixDefault'
export { default as erc20 } from './templates/erc20'
export { default as ozerc20 } from './templates/ozerc20'
export { default as blank } from './templates/blank'

@ -1,16 +0,0 @@
export default async () => {
return {
// @ts-ignore
'contracts/SampleERC20.sol': (await import('raw-loader!./contracts/SampleERC20.sol')).default,
// @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.ts': (await import('!!raw-loader!./scripts/ethers.ts')).default,
// @ts-ignore
'scripts/web3.ts': (await import('!!raw-loader!./scripts/web3.ts')).default,
// @ts-ignore
'tests/SampleERC20_test.sol': (await import('raw-loader!./tests/SampleERC20_test.sol')).default
}
}

@ -2,13 +2,13 @@
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/**
* @title SampleERC20
* @dev Create a sample ERC20 standard token
*/
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract SampleERC20 is ERC20 {
constructor(string memory tokenName, string memory tokenSymbol) ERC20(tokenName, tokenSymbol) {}

@ -0,0 +1,16 @@
export default async () => {
return {
// @ts-ignore
'contracts/SampleERC20.sol': (await import('raw-loader!./contracts/SampleERC20.sol')).default,
// @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.ts': (await import('raw-loader!./scripts/ethers.ts')).default,
// @ts-ignore
'scripts/web3.ts': (await import('raw-loader!./scripts/web3.ts')).default,
// @ts-ignore
'tests/SampleERC20_test.sol': (await import('raw-loader!./tests/SampleERC20_test.sol')).default
}
}

@ -7,17 +7,17 @@ export default async () => {
// @ts-ignore
'contracts/3_Ballot.sol': (await import('raw-loader!./contracts/3_Ballot.sol')).default,
// @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,
// @ts-ignore
'scripts/deploy_with_web3.ts': (await import('!!raw-loader!./scripts/deploy_with_web3.ts')).default,
'scripts/deploy_with_web3.ts': (await import('raw-loader!./scripts/deploy_with_web3.ts')).default,
// @ts-ignore
'scripts/ethers.ts': (await import('!!raw-loader!./scripts/ethers.ts')).default,
'scripts/ethers.ts': (await import('raw-loader!./scripts/ethers.ts')).default,
// @ts-ignore
'scripts/web3.ts': (await import('!!raw-loader!./scripts/web3.ts')).default,
'scripts/web3.ts': (await import('raw-loader!./scripts/web3.ts')).default,
// @ts-ignore
'tests/Ballot_test.sol': (await import('raw-loader!./tests/Ballot_test.sol')).default,
// @ts-ignore
'tests/storage.test.js': (await import('!!raw-loader!./tests/storage.test.js')).default,
'tests/storage.test.js': (await import('raw-loader!./tests/storage.test.js')).default,
// @ts-ignore
'README.txt': (await import('raw-loader!./README.txt')).default,
}

Loading…
Cancel
Save