Skip to content

Commit

Permalink
Merge pull request #4108 from ethereum/update_web3js_4
Browse files Browse the repository at this point in the history
Update web3js 4
  • Loading branch information
yann300 authored Oct 26, 2023
2 parents 0fdc8ab + 8fa6043 commit 82c366a
Show file tree
Hide file tree
Showing 71 changed files with 1,180 additions and 2,005 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ parameters:
default: true
```


## Important Links

- Official website: https://remix-project.org
Expand Down
4 changes: 2 additions & 2 deletions apps/remix-ide-e2e/src/tests/ballot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
},
Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = {
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
.testFunction('last',
{
status: 'false Transaction mined but execution failed',
status: '0x0 Transaction mined but execution failed',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
},
Expand Down
4 changes: 2 additions & 2 deletions apps/remix-ide-e2e/src/tests/ballot_0_4_14.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
},
Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = {
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
},
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/tests/erc721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
.createContract('')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': {}
}).end()
}
Expand Down
5 changes: 0 additions & 5 deletions apps/remix-ide-e2e/src/tests/plugin_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ const debugValues = async function (browser: NightwatchBrowser, field: string, e
return
}
browser.waitForElementVisible(`//*[@id="${field}"]`).getText(`//*[@id="${field}"]`, (result) => {
console.log(result)
if (!result.value.toString().includes(expected)) {
console.log('Actual result:')
console.log(result.value.toString())
console.log('Expected result:')
console.log(expected)
getBrowserLogs(browser)
browser.assert.ok(false, 'Returned value from call does not match expected value.')
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/tests/recorder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = {
.pause(1000)
.clickFunction('set2 - transact (not payable)', { types: 'uint256 _po', values: '10' })
.testFunction('last', {
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': { 'uint256 _po': '10' }
})
},
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/tests/remixd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ module.exports = {
.createContract('')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed'
status: '0x1 Transaction mined and execution succeed'
})


Expand Down
4 changes: 2 additions & 2 deletions apps/remix-ide-e2e/src/tests/runAndDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
.click('*[data-id="Deploy - transact (not payable)"]')
.pause(5000)
.testFunction('last', {
status: 'true Transaction mined and execution succeed'
status: '0x1 Transaction mined and execution succeed'
})
},

Expand Down Expand Up @@ -95,7 +95,7 @@ module.exports = {
.click('*[data-id="pluginManagerSettingsDeployAndRunLLTxSendTransaction"]')
.pause(5000)
.testFunction('last', {
status: 'true Transaction mined and execution succeed'
status: '0x1 Transaction mined and execution succeed'
})
// When this is removed and tests are running by connecting to metamask
// Consider adding tests to check return value of contract call
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/tests/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ const scriptBlockAndTransaction = `
(async () => {
try {
web3.eth.getTransaction('0x022ccd55747677ac50f8d9dfd1bf5b843fa2f36438a28c1d0a0958e057bb3e2a').then(console.log)
web3.eth.getBlock('7367447').then(console.log);
web3.eth.getBlock(7367447).then(console.log);
let ethersProvider = new ethers.providers.Web3Provider(web3Provider)
ethersProvider.getBlock(7367447).then(console.log)
} catch (e) {
Expand Down
16 changes: 8 additions & 8 deletions apps/remix-ide-e2e/src/tests/transactionExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ module.exports = {
.clickFunction('f - transact (not payable)')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': { 0: 'uint256: 8' }
})
.clickFunction('g - transact (not payable)')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': {
0: 'uint256: 345',
1: 'string: comment_comment_',
Expand All @@ -45,7 +45,7 @@ module.exports = {
.clickFunction('retunValues1 - transact (not payable)')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': {
0: 'bool: _b true',
1: 'uint256: _u 345',
Expand All @@ -56,7 +56,7 @@ module.exports = {
.clickFunction('retunValues2 - transact (not payable)')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': {
0: 'bytes1: _b 0x12',
1: 'bytes2: _b2 0x1223',
Expand All @@ -73,7 +73,7 @@ module.exports = {
.clickFunction('retunValues3 - transact (not payable)')
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': {
0: 'uint8: _en 2',
1: 'int256[5][]: _a1 1,-45,-78,56,60,-1,42,334,-45455,-446,1,10,-5435,45,-7'
Expand All @@ -89,7 +89,7 @@ module.exports = {
.clickFunction('inputValue1 - transact (not payable)', { types: 'uint256 _u, int256 _i, string _str', values: '"2343242", "-4324324", "string _ string _ string _ string _ string _ string _ string _ string _ string _ string _"' })
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': {
0: 'uint256: _uret 2343242',
1: 'int256: _iret -4324324',
Expand All @@ -99,7 +99,7 @@ module.exports = {
.pause(500)
.clickFunction('inputValue2 - transact (not payable)', { types: 'uint256[3] _n, bytes8[4] _b8', values: '[1,2,3], ["0x1234000000000000", "0x1234000000000000","0x1234000000000000","0x1234000000000000"]' })
.testFunction('last', {
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded output': {
0: 'uint256[3]: _nret 1,2,3',
1: 'bytes8[4]: _b8ret 0x1234000000000000,0x1234000000000000,0x1234000000000000,0x1234000000000000'
Expand Down Expand Up @@ -222,7 +222,7 @@ module.exports = {
.clickFunction('store - transact (not payable)', { types: 'uint256 num', values: '24' })
.testFunction('last', // we check if the contract is actually reachable.
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': {
'uint256 num': '24'
}
Expand Down
4 changes: 2 additions & 2 deletions apps/remix-ide-e2e/src/tests/txListener.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
.testFunction('last',
{
status: 'true Transaction mined and execution succeed',
status: '0x1 Transaction mined and execution succeed',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
.clickLaunchIcon('solidity')
Expand All @@ -40,7 +40,7 @@ module.exports = {
.clickFunction('delegate - transact (not payable)', { types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"' })
.testFunction('last',
{
status: 'false Transaction mined but execution failed',
status: '0x0 Transaction mined but execution failed',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
.end()
Expand Down
6 changes: 3 additions & 3 deletions apps/remix-ide/src/app/plugins/solidity-script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react' // eslint-disable-line
import {format} from 'util'
import {Plugin} from '@remixproject/engine'
import {compile} from '@remix-project/remix-solidity'
import {TransactionConfig} from 'web3-core'
import {Transaction} from 'web3-types'
const _paq = (window._paq = window._paq || []) //eslint-disable-line

const profile = {
Expand Down Expand Up @@ -69,7 +69,7 @@ export class SolidityScript extends Plugin {
}

// deploy the contract
let tx: TransactionConfig = {
let tx: Transaction = {
from: accounts[0],
data: bytecode
}
Expand All @@ -81,7 +81,7 @@ export class SolidityScript extends Plugin {
}
const receiptCall = await web3.eth.sendTransaction(tx)

const hhlogs = await web3.eth.getHHLogsForTx(receiptCall.transactionHash)
const hhlogs = await web3.remix.getHHLogsForTx(receiptCall.transactionHash)

if (hhlogs && hhlogs.length) {
const finalLogs = (
Expand Down
8 changes: 2 additions & 6 deletions apps/remix-ide/src/app/providers/injected-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,8 @@ export abstract class InjectedProvider extends Plugin implements IProvider {
}
try {
let resultData
if (web3Provider.send) resultData = await web3Provider.send(data.method, data.params)
else if (web3Provider.request)
resultData = await web3Provider.request({
method: data.method,
params: data.params
})
if (web3Provider.request) resultData = await web3Provider.request({method: data.method, params: data.params})
else if (web3Provider.send) resultData = await web3Provider.send(data.method, data.params)
else {
resolve({jsonrpc: '2.0', error: 'provider not valid', id: data.id})
return
Expand Down
6 changes: 3 additions & 3 deletions apps/remix-ide/src/app/tabs/debugger-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
'timestamp': block.timestamp,
}
if (block.baseFeePerGas) {
blockContext['basefee'] = Web3.utils.toBN(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
blockContext['basefee'] = Web3.utils.toBigInt(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})`
}
const msg = {
const msg = {
'sender': tx.from,
'sig': tx.input.substring(0, 10),
'value': tx.value + ' Wei'
Expand All @@ -97,7 +97,7 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
const txOrigin = {
'origin': tx.from
}

return {
block: blockContext,
msg,
Expand Down
3 changes: 2 additions & 1 deletion apps/remix-ide/src/app/tabs/network-module.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json'
import { Web3 } from 'web3'
import IpcProvider from 'web3-providers-ipc'

export const profile = {
name: 'network',
Expand Down Expand Up @@ -49,7 +50,7 @@ export class NetworkModule extends Plugin {

/** Add a custom network to the list of available networks */
addNetwork (network) { // { name, url }
const provider = network.url === 'ipc' ? new Web3.providers.IpcProvider() : new Web3.providers.HttpProvider(network.url)
const provider = network.url === 'ipc' ? new IpcProvider() : new Web3.providers.HttpProvider(network.url)
this.blockchain.addProvider({ name: network.name, provider })
}

Expand Down
18 changes: 14 additions & 4 deletions apps/remix-ide/src/app/tabs/web3-provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json'
import {isBigInt} from 'web3-validator'

export const profile = {
name: 'web3Provider',
Expand All @@ -10,6 +11,11 @@ export const profile = {
kind: 'provider'
}

const replacer = (key, value) => {
if (isBigInt(value)) value = value.toString()
return value
}

export class Web3ProviderModule extends Plugin {
constructor(blockchain) {
super(profile)
Expand All @@ -23,12 +29,11 @@ export class Web3ProviderModule extends Plugin {
sendAsync(payload) {

return new Promise((resolve, reject) => {
this.askUserPermission('sendAsync', `Calling ${payload.method} with parameters ${JSON.stringify(payload.params, null, '\t')}`).then(
this.askUserPermission('sendAsync', `Calling ${payload.method} with parameters ${JSON.stringify(payload.params, replacer, '\t')}`).then(
async (result) => {
if (result) {
const provider = this.blockchain.web3().currentProvider
// see https://github.com/ethereum/web3.js/pull/1018/files#diff-d25786686c1053b786cc2626dc6e048675050593c0ebaafbf0814e1996f22022R129
provider[provider.sendAsync ? 'sendAsync' : 'send'](payload, async (error, message) => {
const resultFn = async (error, message) => {
if (error) {
// Handle 'The method "debug_traceTransaction" does not exist / is not available.' error
if(error.message && error.code && error.code === -32601) {
Expand All @@ -55,7 +60,12 @@ export class Web3ProviderModule extends Plugin {
}
}
resolve(message)
})
}
try {
resultFn(null, await provider.sendAsync(payload))
} catch (e) {
resultFn(e.message)
}
} else {
reject(new Error('User denied permission'))
}
Expand Down
10 changes: 9 additions & 1 deletion apps/remix-ide/src/app/udapp/make-udapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ export function makeUdapp (blockchain, compilersArtefacts, logHtmlCallback) {
if (_transactionReceipts[tx.hash]) {
return cb(null, _transactionReceipts[tx.hash])
}
blockchain.web3().eth.getTransactionReceipt(tx.hash, (error, receipt) => {
let res = blockchain.web3().eth.getTransactionReceipt(tx.hash, (error, receipt) => {
if (error) {
return cb(error)
}
_transactionReceipts[tx.hash] = receipt
cb(null, receipt)
})
if(res && typeof res.then ==='function'){
res.then((receipt)=>{
_transactionReceipts[tx.hash] = receipt
cb(null, receipt)
}).catch((error)=>{
cb(error)
})
}
}

const txlistener = blockchain.getTxListener({
Expand Down
10 changes: 3 additions & 7 deletions apps/remix-ide/src/app/udapp/run-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,9 @@ export class RunTab extends ViewPlugin {
}
},
provider: {
async sendAsync(payload, callback) {
try {
const result = await udapp.call(name, 'sendAsync', payload)
callback(null, result)
} catch (e) {
callback(e)
}

async sendAsync (payload) {
return udapp.call(name, 'sendAsync', payload)
}
}
})
Expand Down
Loading

0 comments on commit 82c366a

Please sign in to comment.