From 453824efb992d43ea2a426f3719dd0c8212d3249 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 20 Sep 2022 15:32:46 +0530 Subject: [PATCH 1/2] features for oz templates --- .../workspace/src/lib/remix-ui-workspace.tsx | 30 +++++++++++++++++-- .../src/templates/ozerc1155/index.ts | 6 ++++ .../src/templates/ozerc20/index.ts | 6 ++++ .../src/templates/ozerc721/index.ts | 6 ++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 5610fc2b1d..3fe327f9e5 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -16,6 +16,7 @@ export function Workspace () { const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean}>(null) const [showDropdown, setShowDropdown] = useState(false) const displayOzCustomRef = useRef() + const ozFeatures = useRef({mintable: false, burnable: false, pausable: false}) const upgradeable = useRef() const global = useContext(FileSystemContext) const workspaceRenameInput = useRef() @@ -108,9 +109,10 @@ export function Workspace () { // @ts-ignore: Object is possibly 'null'. const workspaceTemplateName = workspaceCreateTemplateInput.current.value || 'remixDefault' const initGitRepo = initGitRepoRef.current.checked - + const features = ozFeatures.current const opts = { - upgradeable: upgradeable.current + upgradeable: upgradeable.current, + features } try { @@ -150,6 +152,7 @@ export function Workspace () { if (workspaceCreateTemplateInput.current.value.startsWith('oz') && displayOzCustomRef && displayOzCustomRef.current) { displayOzCustomRef.current.style.display = 'block' upgradeable.current = undefined + ozFeatures.current = {mintable: false, burnable: false, pausable: false} } else displayOzCustomRef.current.style.display = 'none' // @ts-ignore @@ -177,6 +180,11 @@ export function Workspace () { workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value + '_upgradeable'}_${Date.now()}` } + const handleFeatures = (e) => { + // @ts-ignore + ozFeatures.current[e.target.value] = e.target.checked + } + const createModalMessage = () => { return ( <> @@ -198,6 +206,23 @@ export function Workspace () {
+ + +
handleFeatures(e)}> +
+ + +
+
+ + +
+
+ + +
+
+
handleUpgradeability(e)}>
@@ -209,6 +234,7 @@ export function Workspace () {
+
diff --git a/libs/remix-ws-templates/src/templates/ozerc1155/index.ts b/libs/remix-ws-templates/src/templates/ozerc1155/index.ts index 2bbd5a5673..4164d91e76 100644 --- a/libs/remix-ws-templates/src/templates/ozerc1155/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc1155/index.ts @@ -1,6 +1,12 @@ import { erc1155 } from '@openzeppelin/wizard'; export default async (opts) => { + if (opts.features) { + erc1155.defaults.mintable = opts.features.mintable + erc1155.defaults.burnable = opts.features.burnable + erc1155.defaults.pausable = opts.features.pausable + } + const filesObj = { 'contracts/MyToken.sol': erc1155.print({ ...erc1155.defaults, upgradeable: opts.upgradeable}), // @ts-ignore diff --git a/libs/remix-ws-templates/src/templates/ozerc20/index.ts b/libs/remix-ws-templates/src/templates/ozerc20/index.ts index 3a070be29e..5eca9475f8 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/index.ts @@ -1,6 +1,12 @@ import { erc20 } from '@openzeppelin/wizard'; export default async (opts) => { + if (opts.features) { + erc20.defaults.mintable = opts.features.mintable + erc20.defaults.burnable = opts.features.burnable + erc20.defaults.pausable = opts.features.pausable + } + const filesObj = { 'contracts/MyToken.sol': erc20.print({ ...erc20.defaults, upgradeable: opts.upgradeable}), // @ts-ignore diff --git a/libs/remix-ws-templates/src/templates/ozerc721/index.ts b/libs/remix-ws-templates/src/templates/ozerc721/index.ts index 35f91450b3..5c7f01293d 100644 --- a/libs/remix-ws-templates/src/templates/ozerc721/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc721/index.ts @@ -1,6 +1,12 @@ import { erc721 } from '@openzeppelin/wizard'; export default async (opts) => { + if (opts.features) { + erc721.defaults.mintable = opts.features.mintable + erc721.defaults.burnable = opts.features.burnable + erc721.defaults.pausable = opts.features.pausable + } + const filesObj = { 'contracts/MyToken.sol': erc721.print({ ...erc721.defaults, upgradeable: opts.upgradeable}), // @ts-ignore From ba62741ae39faa81df5fadcefd92b71966e50dd8 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Tue, 20 Sep 2022 18:39:15 +0530 Subject: [PATCH 2/2] e2e tests --- .../remix-ide-e2e/src/tests/workspace.test.ts | 84 ++++++++++++++++--- .../workspace/src/lib/remix-ui-workspace.tsx | 2 +- 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/workspace.test.ts b/apps/remix-ide-e2e/src/tests/workspace.test.ts index bf683aa722..139c50d77b 100644 --- a/apps/remix-ide-e2e/src/tests/workspace.test.ts +++ b/apps/remix-ide-e2e/src/tests/workspace.test.ts @@ -66,7 +66,7 @@ module.exports = { }) .waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]') .click('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]') - .pause(2000) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, from?: string, gas?: number): Promise => {`) !== -1, 'Incorrect content') @@ -129,28 +129,28 @@ module.exports = { .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(5000) + .pause(100) .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(4000) + .pause(100) .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(4000) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, from?: string, gas?: number): Promise => {`) !== -1, 'Incorrect content') }) .waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') .click('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') - .pause(4000) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => {`) !== -1, 'Incorrect content') @@ -177,28 +177,28 @@ module.exports = { .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) + .pause(100) .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(4000) + .pause(100) .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(4000) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, from?: string, gas?: number): Promise => {`) !== -1, 'Incorrect content') }) .waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') .click('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') - .pause(4000) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => {`) !== -1, 'Incorrect content') @@ -225,28 +225,28 @@ module.exports = { .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) + .pause(1000) .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) + .pause(100) .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) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, from?: string, gas?: number): Promise => {`) !== -1, 'Incorrect content') }) .waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') .click('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') - .pause(1000) + .pause(100) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => {`) !== -1, 'Incorrect content') @@ -255,6 +255,64 @@ module.exports = { .waitForElementVisible('*[data-id="treeViewLitreeViewItemtests/MyToken_test.sol"]') }, + 'Should create ERC1155 workspace with template customizations #group1': function (browser: NightwatchBrowser) { + browser + .click('*[data-id="workspaceCreate"]') + .waitForElementVisible('*[data-id="modalDialogCustomPromptTextCreate"]') + .waitForElementVisible('[data-id="fileSystemModalDialogModalFooter-react"] > button') + .click('select[id="wstemplate"]') + .click('select[id="wstemplate"] option[value=ozerc1155]') + .waitForElementPresent('*[data-id="ozCustomization"]') + .click('*[data-id="featureTypeMintable"]') + .click('*[data-id="featureTypeBurnable"]') + .click('*[data-id="featureTypePausable"]') + .click('*[data-id="upgradeTypeUups"]') + .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"]') + .click('*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]') + .pause(1000) + .getEditorValue((content) => { + browser.assert.ok(content.indexOf(`contract MyToken is Initializable, ERC1155Upgradeable, OwnableUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable, UUPSUpgradeable {`) !== -1, + 'Incorrect content') + }) + .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(100) + .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(100) + .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(100) + .getEditorValue((content) => { + browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, from?: string, gas?: number): Promise => {`) !== -1, + 'Incorrect content') + browser.assert.ok(content.indexOf(`gas: gas || 3600000`) !== -1, + 'Incorrect gas cost') + }) + .waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') + .click('*[data-id="treeViewLitreeViewItemscripts/ethers-lib.ts"]') + .pause(100) + .getEditorValue((content) => { + browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => {`) !== -1, + 'Incorrect content') + }) + // No test file is added in upgradeable contract template + }, + // WORKSPACE TEMPLATES E2E END 'Should create two workspace and switch to the first one #group1': function (browser: NightwatchBrowser) { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 3fe327f9e5..7aef284f10 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -204,7 +204,7 @@ export function Workspace () { -
+