Skip to content

Commit

Permalink
Merge pull request #2490 from ethereum/typescript_error_script
Browse files Browse the repository at this point in the history
fix typescript error
  • Loading branch information
yann300 authored Jun 6, 2022
2 parents 8704e64 + 0bff7aa commit 3f311aa
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 72 deletions.
4 changes: 2 additions & 2 deletions apps/remix-ide-e2e/src/tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ module.exports = {
.clearValue('*[id="search_include"]').pause(2000)
.setValue('*[id="search_include"]', '**').sendKeys('*[id="search_include"]', browser.Keys.ENTER).pause(4000)
.elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 48)
Array.isArray(res.value) && browser.assert.equal(res.value.length, 61)
})
.setValue('*[id="search_exclude"]', ',contracts/**').sendKeys('*[id="search_exclude"]', browser.Keys.ENTER).pause(4000)
.elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 42)
Array.isArray(res.value) && browser.assert.equal(res.value.length, 55)
})
.clearValue('*[id="search_include"]').setValue('*[id="search_include"]', '*.sol, *.js, *.txt')
.clearValue('*[id="search_exclude"]').setValue('*[id="search_exclude"]', '.*/**/*')
Expand Down
8 changes: 4 additions & 4 deletions apps/remix-ide-e2e/src/tests/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const deployWithEthersJs = `
// '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 factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
let contract = await factory.deploy(...constructorArgs);
Expand Down Expand Up @@ -320,7 +320,7 @@ describe("Storage with lib", 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()
let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
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()
Expand All @@ -330,7 +330,7 @@ describe("Storage with lib", function () {
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()
let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
let storage = await Storage.deploy();
await storage.deployed()
const setValue = await storage.store(56);
Expand All @@ -341,7 +341,7 @@ 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()
let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
let storage = await Storage.deploy();
await storage.deployed()
const setValue = await storage.store(56);
Expand Down
12 changes: 6 additions & 6 deletions apps/remix-ide-e2e/src/tests/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ module.exports = {
.click('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]')
.pause(2000)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => {`) !== -1,
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {`) !== -1,
'Incorrect content')
})
.assert.elementPresent('*[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<any>, from?: string): Promise<any> => { `) !== -1,
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {`) !== -1,
'Incorrect content')
})
.assert.elementPresent('*[data-id="treeViewLitreeViewItemtests"]')
Expand Down Expand Up @@ -145,14 +145,14 @@ module.exports = {
.click('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]')
.pause(100)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => {`) !== -1,
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {`) !== -1,
'Incorrect content')
})
.assert.elementPresent('*[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<any>, from?: string): Promise<any> => { `) !== -1,
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {`) !== -1,
'Incorrect content')
})
.assert.elementPresent('*[data-id="treeViewLitreeViewItemtests"]')
Expand Down Expand Up @@ -193,14 +193,14 @@ module.exports = {
.click('*[data-id="treeViewLitreeViewItemscripts/web3-lib.ts"]')
.pause(100)
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => {`) !== -1,
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {`) !== -1,
'Incorrect content')
})
.assert.elementPresent('*[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<any>, from?: string): Promise<any> => { `) !== -1,
browser.assert.ok(content.indexOf(`export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {`) !== -1,
'Incorrect content')
})
.assert.elementPresent('*[data-id="treeViewLitreeViewItemtests"]')
Expand Down
4 changes: 4 additions & 0 deletions libs/remix-ui/editor/src/lib/web-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export const loadTypes = async (monaco) => {
const indexWeb3Personal = await import('raw-loader!web3-eth-personal/types/index.d.ts')
monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Personal.default, `file:///node_modules/@types/web3-eth-personal/index.d.ts`)

// @ts-ignore
const indexWeb3Contract = await import('raw-loader!web3-eth-contract/types/index.d.ts')
monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Contract.default, `file:///node_modules/@types/web3-eth-contract/index.d.ts`)

// @ts-ignore
const indexWeb3Net = await import('raw-loader!web3-net/types/index.d.ts')
monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Net.default, `file:///node_modules/@types/web3-net/index.d.ts`)
Expand Down
23 changes: 13 additions & 10 deletions libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { ethers } from 'ethers'

export const deploy = async (contractName: string, args: Array<any>, from?: string): Promise<any> => {
/**
* 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`
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()

const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)

const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
const 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);
}
const contract = await factory.deploy(...args)

// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
Expand Down
19 changes: 14 additions & 5 deletions libs/remix-ws-templates/src/templates/ozerc20/scripts/web3-lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import Web3 from 'web3'
import { Contract, ContractSendMethod, Options } from 'web3-eth-contract'

export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => {
/**
* 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(window.web3Provider)
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
Expand All @@ -12,14 +21,14 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri

const accounts = await web3.eth.getAccounts()

let contract = new web3.eth.Contract(metadata.abi)
const contract: Contract = new web3.eth.Contract(metadata.abi)

contract = contract.deploy({
const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})

const newContractInstance = await contract.send({
const newContractInstance = await contractSend.send({
from: from || accounts[0],
gas: gas || 1500000
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { ethers } from 'ethers'

export const deploy = async (contractName: string, args: Array<any>, from?: string): Promise<any> => {
/**
* 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`
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()

const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)

const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
const 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);
}
const contract = await factory.deploy(...args)

// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
Expand Down
19 changes: 14 additions & 5 deletions libs/remix-ws-templates/src/templates/ozerc721/scripts/web3-lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import Web3 from 'web3'
import { Contract, ContractSendMethod, Options } from 'web3-eth-contract'

export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => {
/**
* 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(window.web3Provider)
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
Expand All @@ -12,14 +21,14 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri

const accounts = await web3.eth.getAccounts()

let contract = new web3.eth.Contract(metadata.abi)
const contract: Contract = new web3.eth.Contract(metadata.abi)

contract = contract.deploy({
const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})

const newContractInstance = await contract.send({
const newContractInstance = await contractSend.send({
from: from || accounts[0],
gas: gas || 1500000
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ethers } from 'ethers'

export const deploy = async (contractName: string, args: Array<any>, from?: string): Promise<any> => {
/**
* 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.
Expand All @@ -9,16 +16,12 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri

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.providers.Web3Provider(web3Provider)).getSigner(accountIndex)

const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
const 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);
}
const contract = await factory.deploy(...args)

// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import Web3 from 'web3'
import { Contract, ContractSendMethod, Options } from 'web3-eth-contract'

export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => {
/**
* 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(window.web3Provider)
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` // Change this for different path
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)
const contract: Contract = new web3.eth.Contract(metadata.abi)

contract = contract.deploy({
const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})

const newContractInstance = await contract.send({
const newContractInstance = await contractSend.send({
from: from || accounts[0],
gas: gas || 1500000
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { ethers } from 'ethers'

export const deploy = async (contractName: string, args: Array<any>, from?: string): Promise<any> => {
/**
* 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`
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()

const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)

const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
const 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);
}
const contract = await factory.deploy(...args)

// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
Expand Down
Loading

0 comments on commit 3f311aa

Please sign in to comment.