lint fixes for remix-simulator

pull/4771/head
lianahus 9 months ago
parent 811d90ae36
commit 4ecaca9218
  1. 10
      libs/remix-simulator/src/VmProxy.ts
  2. 4
      libs/remix-simulator/src/methods/blocks.ts
  3. 2
      libs/remix-simulator/src/methods/transactions.ts
  4. 12
      libs/remix-simulator/src/provider.ts
  5. 3
      libs/remix-simulator/src/vm-context.ts
  6. 8
      libs/remix-simulator/test/blocks.ts
  7. 14
      libs/remix-simulator/test/misc.ts
  8. 2
      libs/remix-simulator/test/transactions.ts

@ -1,11 +1,11 @@
import { util } from '@remix-project/remix-lib' import { util } from '@remix-project/remix-lib'
const { toHexPaddedString, formatMemory } = util const { toHexPaddedString, formatMemory } = util
import { helpers } from '@remix-project/remix-lib' import { helpers } from '@remix-project/remix-lib'
const { normalizeHexAddress } = helpers.ui const { normalizeHexAddress } = helpers.ui
import { ConsoleLogs, hash } from '@remix-project/remix-lib' import { ConsoleLogs, hash } from '@remix-project/remix-lib'
import { toChecksumAddress, bytesToHex, Address, toBytes, bigIntToHex} from '@ethereumjs/util' import { toChecksumAddress, bytesToHex, Address, toBytes, bigIntToHex } from '@ethereumjs/util'
import utils, {toBigInt} from 'web3-utils' import utils, { toBigInt } from 'web3-utils'
import {isBigInt} from 'web3-validator' import { isBigInt } from 'web3-validator'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { VMContext } from './vm-context' import { VMContext } from './vm-context'
import type { EVMStateManagerInterface } from '@ethereumjs/common' import type { EVMStateManagerInterface } from '@ethereumjs/common'

@ -59,7 +59,7 @@ export class Blocks {
nonce: bigIntToHex(tx.nonce), nonce: bigIntToHex(tx.nonce),
transactionIndex: this.TX_INDEX, transactionIndex: this.TX_INDEX,
value: bigIntToHex(tx.value), value: bigIntToHex(tx.value),
to: receipt.to ? receipt.to : null to: receipt.to ? receipt.to : null
} }
} }
}) })
@ -113,7 +113,7 @@ export class Blocks {
nonce: bigIntToHex(tx.nonce), nonce: bigIntToHex(tx.nonce),
transactionIndex: this.TX_INDEX, transactionIndex: this.TX_INDEX,
value: bigIntToHex(tx.value), value: bigIntToHex(tx.value),
to: receipt.to ? receipt.to : null to: receipt.to ? receipt.to : null
} }
} }
}) })

@ -1,5 +1,5 @@
import { toHex, toNumber, toBigInt } from 'web3-utils' import { toHex, toNumber, toBigInt } from 'web3-utils'
import { toChecksumAddress, Address, bigIntToHex, bytesToHex} from '@ethereumjs/util' import { toChecksumAddress, Address, bigIntToHex, bytesToHex } from '@ethereumjs/util'
import { processTx } from './txProcess' import { processTx } from './txProcess'
import { execution } from '@remix-project/remix-lib' import { execution } from '@remix-project/remix-lib'
import { ethers } from 'ethers' import { ethers } from 'ethers'

@ -26,7 +26,7 @@ export interface JSONRPCResponsePayload {
jsonrpc: string; jsonrpc: string;
} }
export type JSONRPCResponseCallback = (err: Error, result?: JSONRPCResponsePayload) => void export type JSONRPCResponseCallback = (err: Error, result?: JSONRPCResponsePayload) => void
export type State = Record<string, string> export type State = Record<string, string>
@ -83,7 +83,7 @@ export class Provider {
} }
} }
_send(payload: JSONRPCRequestPayload, callback: (err: Error, result?: JSONRPCResponsePayload) => void) { _send(payload: JSONRPCRequestPayload, callback: (err: Error, result?: JSONRPCResponsePayload) => void) {
// log.info('payload method is ', payload.method) // commented because, this floods the IDE console // log.info('payload method is ', payload.method) // commented because, this floods the IDE console
if (!this.initialized) { if (!this.initialized) {
this.pendingRequests.push({ payload, callback }) this.pendingRequests.push({ payload, callback })
@ -109,13 +109,13 @@ export class Provider {
callback(new Error('unknown method ' + payload.method)) callback(new Error('unknown method ' + payload.method))
} }
sendAsync (payload: JSONRPCRequestPayload, callback: (err: Error, result?: JSONRPCResponsePayload) => void) { sendAsync (payload: JSONRPCRequestPayload, callback: (err: Error, result?: JSONRPCResponsePayload) => void) {
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
const cb = (err, result) => { const cb = (err, result) => {
if(typeof callback==='function'){ if (typeof callback==='function'){
callback(err,result) callback(err,result)
} }
if(err){ if (err){
return reject(err) return reject(err)
} }
return resolve(result) return resolve(result)
@ -146,7 +146,7 @@ export class Provider {
} }
export function extend (web3) { export function extend (web3) {
if(!web3.remix){ if (!web3.remix){
web3.registerPlugin(new Web3TestPlugin()) web3.registerPlugin(new Web3TestPlugin())
} }
} }

@ -59,7 +59,7 @@ class StateManagerCommonStorageDump extends DefaultStateManager {
} }
shallowCopy(): StateManagerCommonStorageDump { shallowCopy(): StateManagerCommonStorageDump {
const copyState = new StateManagerCommonStorageDump({ const copyState = new StateManagerCommonStorageDump({
trie: this._trie.shallowCopy(false), trie: this._trie.shallowCopy(false),
}) })
copyState.keyHashes = this.keyHashes copyState.keyHashes = this.keyHashes
@ -250,7 +250,6 @@ class CustomEthersStateManager extends StateManagerCommonStorageDump {
} }
} }
export type CurrentVm = { export type CurrentVm = {
vm: VM, vm: VM,
web3vm: VmProxy, web3vm: VmProxy,

@ -93,7 +93,7 @@ describe('blocks', () => {
it('should get block given its hash', async () => { it('should get block given its hash', async () => {
const correctBlock = await web3.eth.getBlock(0) const correctBlock = await web3.eth.getBlock(0)
const numberTransactions = await (new Promise((resolve, reject) => { const numberTransactions = await (new Promise((resolve, reject) => {
web3['_requestManager'].send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}) web3['_requestManager'].send({ method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]})
.then(numberTransactions => resolve(numberTransactions)) .then(numberTransactions => resolve(numberTransactions))
.catch(err => reject(err)) .catch(err => reject(err))
})) }))
@ -105,7 +105,7 @@ describe('blocks', () => {
it('should get block given its number', async () => { it('should get block given its number', async () => {
const correctBlock = await web3.eth.getBlock(0) const correctBlock = await web3.eth.getBlock(0)
const numberTransactions = await (new Promise((resolve, reject) => { const numberTransactions = await (new Promise((resolve, reject) => {
web3['_requestManager'].send({method: 'eth_getUncleCountByBlockHash', params: [0]}) web3['_requestManager'].send({ method: 'eth_getUncleCountByBlockHash', params: [0]})
.then(numberTransactions => resolve(numberTransactions)) .then(numberTransactions => resolve(numberTransactions))
.catch(err => reject(err)) .catch(err => reject(err))
})) }))
@ -201,7 +201,7 @@ describe('blocks', () => {
const contract = new web3.eth.Contract(abi) const contract = new web3.eth.Contract(abi)
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
const contractInstance: any = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: '400000' }) const contractInstance: any = await contract.deploy({ data: code, arguments: [100]}).send({ from: accounts[0], gas: '400000' })
contractInstance.currentProvider = web3.eth.currentProvider contractInstance.currentProvider = web3.eth.currentProvider
// contractInstance.givenProvider = web3.eth.currentProvider // contractInstance.givenProvider = web3.eth.currentProvider
@ -307,7 +307,7 @@ describe('blocks', () => {
const contract = new web3.eth.Contract(abi) const contract = new web3.eth.Contract(abi)
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
const contractInstance: any = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: '400000' }) const contractInstance: any = await contract.deploy({ data: code, arguments: [100]}).send({ from: accounts[0], gas: '400000' })
contractInstance.currentProvider = web3.eth.currentProvider contractInstance.currentProvider = web3.eth.currentProvider
const value = await contractInstance.methods.get().call({ from: accounts[0] }) const value = await contractInstance.methods.get().call({ from: accounts[0] })

@ -13,7 +13,7 @@ describe('Misc', () => {
describe('web3_clientVersion', () => { describe('web3_clientVersion', () => {
it('should get correct remix simulator version', async () => { it('should get correct remix simulator version', async () => {
web3['_requestManager'].send({ method: 'web3_clientVersion', params: [] }) web3['_requestManager'].send({ method: 'web3_clientVersion', params: []})
.then(version => { .then(version => {
const remixVersion = require('../package.json').version const remixVersion = require('../package.json').version
assert.equal(version, 'Remix Simulator/' + remixVersion) assert.equal(version, 'Remix Simulator/' + remixVersion)
@ -24,7 +24,7 @@ describe('Misc', () => {
describe('eth_protocolVersion', () => { describe('eth_protocolVersion', () => {
it('should get protocol version', async () => { it('should get protocol version', async () => {
web3['_requestManager'].send({ method: 'eth_protocolVersion', params: [] }) web3['_requestManager'].send({ method: 'eth_protocolVersion', params: []})
.then(result => assert.equal(result, '0x3f')) .then(result => assert.equal(result, '0x3f'))
.catch(err => { throw new Error(err) }) .catch(err => { throw new Error(err) })
}) })
@ -53,7 +53,7 @@ describe('Misc', () => {
describe('web3_sha3', () => { describe('web3_sha3', () => {
it('should get result of a sha3', async () => { it('should get result of a sha3', async () => {
web3['_requestManager'].send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64'] }) web3['_requestManager'].send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64']})
.then(result => assert.equal(result, '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad')) .then(result => assert.equal(result, '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'))
.catch(err => { throw new Error(err)} ) .catch(err => { throw new Error(err)} )
}) })
@ -61,7 +61,7 @@ describe('Misc', () => {
describe('eth_getCompilers', () => { describe('eth_getCompilers', () => {
it('should get list of compilers', async () => { it('should get list of compilers', async () => {
web3['_requestManager'].send({ method: 'eth_getCompilers', params: [] }) web3['_requestManager'].send({ method: 'eth_getCompilers', params: []})
.then(result => assert.equal(result, 0)) .then(result => assert.equal(result, 0))
.catch(err => { throw new Error(err) }) .catch(err => { throw new Error(err) })
}) })
@ -69,7 +69,7 @@ describe('Misc', () => {
describe('eth_compileSolidity', () => { describe('eth_compileSolidity', () => {
it('get unsupported result when requesting solidity compiler', async () => { it('get unsupported result when requesting solidity compiler', async () => {
web3['_requestManager'].send({ method: 'eth_compileSolidity', params: [] }) web3['_requestManager'].send({ method: 'eth_compileSolidity', params: []})
.then(result => assert.equal(result, 'unsupported')) .then(result => assert.equal(result, 'unsupported'))
.catch(err => { throw new Error(err) }) .catch(err => { throw new Error(err) })
}) })
@ -77,7 +77,7 @@ describe('Misc', () => {
describe('eth_compileLLL', () => { describe('eth_compileLLL', () => {
it('get unsupported result when requesting LLL compiler', async () => { it('get unsupported result when requesting LLL compiler', async () => {
web3['_requestManager'].send({ method: 'eth_compileLLL', params: [] }) web3['_requestManager'].send({ method: 'eth_compileLLL', params: []})
.then(result => assert.equal(result, 'unsupported')) .then(result => assert.equal(result, 'unsupported'))
.catch(err => { throw new Error(err) }) .catch(err => { throw new Error(err) })
}) })
@ -85,7 +85,7 @@ describe('Misc', () => {
describe('eth_compileSerpent', () => { describe('eth_compileSerpent', () => {
it('get unsupported result when requesting serpent compiler', async () => { it('get unsupported result when requesting serpent compiler', async () => {
web3['_requestManager'].send({ method: 'eth_compileSerpent', params: [] }) web3['_requestManager'].send({ method: 'eth_compileSerpent', params: []})
.then(result => assert.equal(result, 'unsupported')) .then(result => assert.equal(result, 'unsupported'))
.catch(err => { throw new Error(err)} ) .catch(err => { throw new Error(err)} )
}) })

@ -6,7 +6,7 @@ import * as assert from 'assert'
describe('Transactions', () => { describe('Transactions', () => {
before(async function () { before(async function () {
const provider = new Provider({ fork: 'shanghai'}) const provider = new Provider({ fork: 'shanghai' })
await provider.init() await provider.init()
web3.setProvider(provider as any) web3.setProvider(provider as any)
}) })

Loading…
Cancel
Save