From 0a2bad63fcf3aee4ff9a4d07732cbbc189834b49 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 13 Sep 2024 16:59:24 +0200 Subject: [PATCH] template script and testing: use ethers6 --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 26 +++++++++---------- libs/ghaction-helper/src/methods.ts | 2 +- .../basic-contract-deploy.ts | 4 +-- .../create2-factory-deploy.ts | 2 +- .../scripts/deploy_with_ethers.ts | 2 +- .../gnosisSafeMultisig/scripts/ethers-lib.ts | 4 +-- .../ozerc1155/scripts/deploy_with_ethers.ts | 2 +- .../templates/ozerc1155/scripts/ethers-lib.ts | 4 +-- .../ozerc20/scripts/deploy_with_ethers.ts | 2 +- .../templates/ozerc20/scripts/ethers-lib.ts | 4 +-- .../ozerc721/scripts/deploy_with_ethers.ts | 2 +- .../templates/ozerc721/scripts/ethers-lib.ts | 4 +-- .../playground/scripts/deploy_with_ethers.ts | 2 +- .../playground/scripts/ethers-lib.ts | 4 +-- .../scripts/deploy_with_ethers.ts | 2 +- .../remixDefault/scripts/ethers-lib.ts | 4 +-- .../remixDefault/tests/storage.test.js | 4 +-- .../zeroxErc20/scripts/deploy_with_ethers.ts | 2 +- .../zeroxErc20/scripts/ethers-lib.ts | 4 +-- 19 files changed, 40 insertions(+), 40 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 9d73831389..0ea0cb3263 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -501,7 +501,7 @@ const deployWithEthersJs = ` 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() + const signer = (new ethers.BrowserProvider(web3Provider)).getSigner() let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) @@ -510,7 +510,7 @@ const deployWithEthersJs = ` console.log('Contract Address: ', contract.address); // The contract is NOT deployed yet; we must wait until it is mined - await contract.deployed() + await contract.waitForDeployment() console.log('Deployment successful.') contract.on('OwnerSet', (previousOwner, newOwner) => { @@ -531,20 +531,20 @@ describe("Storage with lib", function () { it("test initial value", async function () { // Make sure contract is compiled and artifacts are generated const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) - const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + const signer = (new ethers.BrowserProvider(web3Provider)).getSigner() let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) let storage = await Storage.deploy(); console.log('storage contract Address: ' + storage.address); - await storage.deployed() + await storage.waitForDeployment() expect((await storage.retrieve()).toNumber()).to.equal(0); }); it("test updating and retrieving updated value", async function () { const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) - const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + const signer = (new ethers.BrowserProvider(web3Provider)).getSigner() let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) let storage = await Storage.deploy(); - await storage.deployed() + await storage.waitForDeployment() const setValue = await storage.store(56); await setValue.wait(); expect((await storage.retrieve()).toNumber()).to.equal(56); @@ -552,10 +552,10 @@ describe("Storage with lib", function () { it("fail test updating and retrieving updated value", async function () { const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) - const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + const signer = (new ethers.BrowserProvider(web3Provider)).getSigner() let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) let storage = await Storage.deploy(); - await storage.deployed() + await storage.waitForDeployment() const setValue = await storage.store(56); await setValue.wait(); expect((await storage.retrieve()).toNumber(), 'incorrect number').to.equal(55); @@ -623,7 +623,7 @@ describe("Storage", function () { const optionsLib = {} const factoryLib = await ethers.getContractFactoryFromArtifact(artifactLib, optionsLib) const lib = await factoryLib.deploy(); - await lib.deployed() + await lib.waitForDeployment() const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/StorageWithLib.json')) const artifact = { @@ -643,7 +643,7 @@ describe("Storage", function () { const factory = await ethers.getContractFactoryFromArtifact(artifact, options) const storage = await factory.deploy(); - await storage.deployed() + await storage.waitForDeployment() const storeValue = await storage.store(333); await storeValue.wait(); expect((await storage.getFromLib()).toString()).to.equal('34'); @@ -779,7 +779,7 @@ const scriptAutoExec = { const lib = await factoryLib.deploy(); - await lib.deployed() + await lib.waitForDeployment() console.log('lib deployed', lib.address) @@ -803,7 +803,7 @@ const scriptAutoExec = { const storage = await factory.deploy(); - await storage.deployed() + await storage.waitForDeployment() const storeValue = await storage.store(333); @@ -826,7 +826,7 @@ const scriptBlockAndTransaction = ` try { web3.eth.getTransaction('0x0d2baaed96425861677e87dcf6961d34e2b73ad9a0929c32a05607ca94f98d17').then(console.log).catch(console.error) web3.eth.getBlock(4757766).then(console.log).catch(console.error) - let ethersProvider = new ethers.providers.Web3Provider(web3Provider) + let ethersProvider = new ethers.BrowserProvider(web3Provider) ethersProvider.getBlock(4757767).then(console.log).catch(console.error) } catch (e) { console.log(e.message) diff --git a/libs/ghaction-helper/src/methods.ts b/libs/ghaction-helper/src/methods.ts index d7ece2b6c6..e5087d2c80 100644 --- a/libs/ghaction-helper/src/methods.ts +++ b/libs/ghaction-helper/src/methods.ts @@ -14,7 +14,7 @@ const providerConfig = { const config = { defaultTransactionType: '0x0' } global.remixProvider = new Provider(providerConfig) global.remixProvider.init() -global.web3Provider = new ethers.providers.Web3Provider(global.remixProvider) +global.web3Provider = new ethers.BrowserProvider(global.remixProvider) global.provider = global.web3Provider global.ethereum = global.web3Provider global.web3 = new Web3(global.web3Provider) diff --git a/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts +++ b/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/script-templates/contract-deployer/create2-factory-deploy.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/create2-factory-deploy.ts index 6de36cfa20..65f6ab8bce 100644 --- a/libs/remix-ws-templates/src/script-templates/contract-deployer/create2-factory-deploy.ts +++ b/libs/remix-ws-templates/src/script-templates/contract-deployer/create2-factory-deploy.ts @@ -15,7 +15,7 @@ export const CREATE2_DEPLOYER_ADDRESS = '0x13b0D85CcB8bf860b6b79AF3029fCA081AE9b export const deploy = async (contractName: string, args: Array, salt: string, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) - const signer = new ethers.providers.Web3Provider(web3Provider).getSigner(accountIndex) + const signer = new ethers.BrowserProvider(web3Provider).getSigner(accountIndex) const factory = new ethers.Contract(CREATE2_DEPLOYER_ADDRESS, contractDeployerAbi, signer) //@ts-ignore diff --git a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/deploy_with_ethers.ts index b825f91a76..9a3114510e 100644 --- a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/deploy_with_ethers.ts @@ -3,7 +3,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('MultisigWallet', []) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/deploy_with_ethers.ts index 63533fd6f5..ff27dbf13e 100644 --- a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/deploy_with_ethers.ts @@ -3,7 +3,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('MyToken', []) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc20/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/ozerc20/scripts/deploy_with_ethers.ts index 63533fd6f5..ff27dbf13e 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/scripts/deploy_with_ethers.ts @@ -3,7 +3,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('MyToken', []) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts index 63533fd6f5..ff27dbf13e 100644 --- a/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts @@ -3,7 +3,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('MyToken', []) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/playground/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/playground/scripts/deploy_with_ethers.ts index d190d654f0..6773145fa0 100644 --- a/libs/remix-ws-templates/src/templates/playground/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/playground/scripts/deploy_with_ethers.ts @@ -7,7 +7,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('HelloWorld', []) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/remixDefault/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/remixDefault/scripts/deploy_with_ethers.ts index 513d496d76..3d5f4700f0 100644 --- a/libs/remix-ws-templates/src/templates/remixDefault/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/remixDefault/scripts/deploy_with_ethers.ts @@ -7,7 +7,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('Storage', []) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/remixDefault/tests/storage.test.js b/libs/remix-ws-templates/src/templates/remixDefault/tests/storage.test.js index 8e37b7c39b..eaee3ebefa 100644 --- a/libs/remix-ws-templates/src/templates/remixDefault/tests/storage.test.js +++ b/libs/remix-ws-templates/src/templates/remixDefault/tests/storage.test.js @@ -7,14 +7,14 @@ describe("Storage", function () { it("test initial value", async function () { const Storage = await ethers.getContractFactory("Storage"); const storage = await Storage.deploy(); - await storage.deployed(); + await storage.waitForDeployment(); console.log("storage deployed at:" + storage.address); expect((await storage.retrieve()).toNumber()).to.equal(0); }); it("test updating and retrieving updated value", async function () { const Storage = await ethers.getContractFactory("Storage"); const storage = await Storage.deploy(); - await storage.deployed(); + await storage.waitForDeployment(); const storage2 = await ethers.getContractAt("Storage", storage.address); const setValue = await storage2.store(56); await setValue.wait(); diff --git a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/deploy_with_ethers.ts index 1aadc32123..a16c54f5a9 100644 --- a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/deploy_with_ethers.ts +++ b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/deploy_with_ethers.ts @@ -3,7 +3,7 @@ import { deploy } from './ethers-lib' (async () => { try { const result = await deploy('SampleERC20', ["TestToken", "TST", 18, 1000]) - console.log(`address: ${result.address}`) + console.log(`address: ${await result.getAddress()}`) } catch (e) { console.log(e.message) } diff --git a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts index 8e4adf95a6..20ae79477e 100644 --- a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array, accountInde 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 signer = (new ethers.BrowserProvider(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() + await contract.waitForDeployment() return contract } \ No newline at end of file