Skip to content

Commit

Permalink
template script and testing: use ethers6
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Sep 13, 2024
1 parent e97d280 commit 0a2bad6
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 40 deletions.
26 changes: 13 additions & 13 deletions apps/remix-ide-e2e/src/tests/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) => {
Expand All @@ -531,31 +531,31 @@ 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);
});
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);
Expand Down Expand Up @@ -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 = {
Expand All @@ -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');
Expand Down Expand Up @@ -779,7 +779,7 @@ const scriptAutoExec = {
const lib = await factoryLib.deploy();
await lib.deployed()
await lib.waitForDeployment()
console.log('lib deployed', lib.address)
Expand All @@ -803,7 +803,7 @@ const scriptAutoExec = {
const storage = await factory.deploy();
await storage.deployed()
await storage.waitForDeployment()
const storeValue = await storage.store(333);
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libs/ghaction-helper/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const CREATE2_DEPLOYER_ADDRESS = '0x13b0D85CcB8bf860b6b79AF3029fCA081AE9b
export const deploy = async (contractName: string, args: Array<any>, salt: string, accountIndex?: number): Promise<string> => {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const deploy = async (contractName: string, args: Array<any>, 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
}

0 comments on commit 0a2bad6

Please sign in to comment.