lint fixes for remix-simulator

pull/4771/head
lianahus 6 months ago
parent 811d90ae36
commit 4ecaca9218
  1. 18
      libs/remix-simulator/src/VmProxy.ts
  2. 2
      libs/remix-simulator/src/methods/accounts.ts
  3. 4
      libs/remix-simulator/src/methods/blocks.ts
  4. 6
      libs/remix-simulator/src/methods/transactions.ts
  5. 12
      libs/remix-simulator/src/provider.ts
  6. 2
      libs/remix-simulator/src/server.ts
  7. 19
      libs/remix-simulator/src/vm-context.ts
  8. 8
      libs/remix-simulator/test/blocks.ts
  9. 8
      libs/remix-simulator/test/events.ts
  10. 14
      libs/remix-simulator/test/misc.ts
  11. 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
import { helpers } from '@remix-project/remix-lib'
const { normalizeHexAddress } = helpers.ui
const { normalizeHexAddress } = helpers.ui
import { ConsoleLogs, hash } from '@remix-project/remix-lib'
import { toChecksumAddress, bytesToHex, Address, toBytes, bigIntToHex} from '@ethereumjs/util'
import utils, {toBigInt} from 'web3-utils'
import {isBigInt} from 'web3-validator'
import { toChecksumAddress, bytesToHex, Address, toBytes, bigIntToHex } from '@ethereumjs/util'
import utils, { toBigInt } from 'web3-utils'
import { isBigInt } from 'web3-validator'
import { ethers } from 'ethers'
import { VMContext } from './vm-context'
import type { EVMStateManagerInterface } from '@ethereumjs/common'
@ -99,7 +99,7 @@ export class VmProxy {
setVM (vm) {
if (this.vm === vm) return
this.vm = vm
this.vm.evm.events.on('step', async (data: InterpreterStep, resolve: (result?: any) => void) => {
this.vm.evm.events.on('step', async (data: InterpreterStep, resolve: (result?: any) => void) => {
await this.pushTrace(data)
resolve()
})
@ -110,7 +110,7 @@ export class VmProxy {
})
this.vm.events.on('beforeTx', async (data: TypedTransaction, resolve: (result?: any) => void) => {
this.txRunning = true
await this.txWillProcess(data)
await this.txWillProcess(data)
resolve()
})
}
@ -124,7 +124,7 @@ export class VmProxy {
recordVMSteps (record) {
this.flagrecordVMSteps = record
}
async txWillProcess (data: TypedTransaction) {
if (!this.flagrecordVMSteps) return
this.lastMemoryUpdate = []
@ -234,7 +234,7 @@ export class VmProxy {
async pushTrace (data: InterpreterStep) {
if (!this.flagrecordVMSteps) return
try {
const depth = data.depth + 1 // geth starts the depth from 1
if (!this.processingHash) {

@ -56,7 +56,7 @@ export class Web3Accounts {
} catch (e) {
console.error(e)
}
}
newAccount (cb) {

@ -59,7 +59,7 @@ export class Blocks {
nonce: bigIntToHex(tx.nonce),
transactionIndex: this.TX_INDEX,
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),
transactionIndex: this.TX_INDEX,
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 { toChecksumAddress, Address, bigIntToHex, bytesToHex} from '@ethereumjs/util'
import { toChecksumAddress, Address, bigIntToHex, bytesToHex } from '@ethereumjs/util'
import { processTx } from './txProcess'
import { execution } from '@remix-project/remix-lib'
import { ethers } from 'ethers'
@ -59,7 +59,7 @@ export class Transactions {
this.txRunnerInstance = new TxRunner(this.txRunnerVMInstance, {})
this.txRunnerInstance.vmaccounts = accounts
}
methods () {
return {
eth_sendTransaction: this.eth_sendTransaction.bind(this),
@ -163,7 +163,7 @@ export class Transactions {
this.txRunnerInstance.internalRunner.standaloneTx = false
this.vmContext.web3().recordVMSteps(true)
if (error) return cb(error)
const result: any = value.result
const result: any = value.result
if ((result as any).receipt?.status === '0x0' || (result as any).receipt?.status === 0) {
try {
const msg = `${bytesToHex(result.execResult.returnValue) || '0x00'}`

@ -26,7 +26,7 @@ export interface JSONRPCResponsePayload {
jsonrpc: string;
}
export type JSONRPCResponseCallback = (err: Error, result?: JSONRPCResponsePayload) => void
export type JSONRPCResponseCallback = (err: Error, result?: JSONRPCResponsePayload) => void
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
if (!this.initialized) {
this.pendingRequests.push({ payload, callback })
@ -109,13 +109,13 @@ export class Provider {
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)=>{
const cb = (err, result) => {
if(typeof callback==='function'){
if (typeof callback==='function'){
callback(err,result)
}
if(err){
if (err){
return reject(err)
}
return resolve(result)
@ -146,7 +146,7 @@ export class Provider {
}
export function extend (web3) {
if(!web3.remix){
if (!web3.remix){
web3.registerPlugin(new Web3TestPlugin())
}
}

@ -22,7 +22,7 @@ class Server {
start (host, port) {
const wsApp = expressWs(app)
app.use(cors())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())

@ -59,7 +59,7 @@ class StateManagerCommonStorageDump extends DefaultStateManager {
}
shallowCopy(): StateManagerCommonStorageDump {
const copyState = new StateManagerCommonStorageDump({
const copyState = new StateManagerCommonStorageDump({
trie: this._trie.shallowCopy(false),
})
copyState.keyHashes = this.keyHashes
@ -93,7 +93,7 @@ class StateManagerCommonStorageDump extends DefaultStateManager {
})
} catch (e) {
reject(e)
}
}
})
}
}
@ -110,7 +110,7 @@ export interface CustomEthersStateManagerOpts {
class CustomEthersStateManager extends StateManagerCommonStorageDump {
private provider: ethers.providers.StaticJsonRpcProvider | ethers.providers.JsonRpcProvider
private blockTag: string
constructor(opts: CustomEthersStateManagerOpts) {
super(opts)
if (typeof opts.provider === 'string') {
@ -188,7 +188,7 @@ class CustomEthersStateManager extends StateManagerCommonStorageDump {
async accountExists(address: Address): Promise<boolean> {
const account = await super.getAccount(address)
if (!account.isEmpty()) return true
// Get merkle proof for `address` from provider
const proof = await this.provider.send('eth_getProof', [address.toString(), [], this.blockTag])
@ -245,12 +245,11 @@ class CustomEthersStateManager extends StateManagerCommonStorageDump {
codeHash: hexToBytes(codeHash)
// storageRoot: toBuffer([]), // we have to remove this in order to force the creation of the Trie in the local state.
})
}
}
return account
}
}
export type CurrentVm = {
vm: VM,
web3vm: VmProxy,
@ -263,7 +262,7 @@ export class VMCommon extends Common {
/**
* Always return the fork set at initialization
*/
setHardforkBy() {
setHardforkBy() {
return this._hardfork;
}
}
@ -281,7 +280,7 @@ export class VMContext {
txByHash: Record<string, TypedTransaction>
currentVm: CurrentVm
web3vm: VmProxy
logsManager: any // LogsManager
logsManager: any // LogsManager
exeResults: Record<string, TypedTransaction>
nodeUrl: string
blockNumber: number | 'latest'
@ -332,7 +331,7 @@ export class VMContext {
const db = this.stateDb ? new Map(Object.entries(this.stateDb).map(([k, v]) => [k, hexToBytes(v)])) : new Map()
const mapDb = new MapDB(db)
const trie = await Trie.create({ useKeyHashing: true, db: mapDb, useRootPersistence: true })
stateManager = new StateManagerCommonStorageDump({ trie })
}
@ -357,7 +356,7 @@ export class VMContext {
const blockchain = await Blockchain.create({ common, validateBlocks: false, validateConsensus: false, genesisBlock })
const evm = await EVM.create({ common, allowUnlimitedContractSize: true, stateManager, blockchain })
const vm = await VM.create({
common,
activatePrecompiles: true,

@ -93,7 +93,7 @@ describe('blocks', () => {
it('should get block given its hash', async () => {
const correctBlock = await web3.eth.getBlock(0)
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))
.catch(err => reject(err))
}))
@ -105,7 +105,7 @@ describe('blocks', () => {
it('should get block given its number', async () => {
const correctBlock = await web3.eth.getBlock(0)
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))
.catch(err => reject(err))
}))
@ -201,7 +201,7 @@ describe('blocks', () => {
const contract = new web3.eth.Contract(abi)
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.givenProvider = web3.eth.currentProvider
@ -307,7 +307,7 @@ describe('blocks', () => {
const contract = new web3.eth.Contract(abi)
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
const value = await contractInstance.methods.get().call({ from: accounts[0] })

@ -47,7 +47,7 @@ describe('Events', () => {
toBlock: 'latest',
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735', '0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc']
})
// this should include the event triggered by the "set" transaction call.
assert.equal(testLogs.length, 1, '1) testLogs length should be equal to 1')
assert.equal(ownerLogs.length, 1, '2) ownerLogs length should be equal to 1')
@ -80,8 +80,8 @@ pragma solidity >=0.7.0 <0.9.0;
import "hardhat/console.sol";
contract test {
event testEvent(uint indexed value);
contract test {
event testEvent(uint indexed value);
function set(Owner p) public {
p.changeOwner(address(this));
emit testEvent(123);
@ -119,5 +119,5 @@ contract Owner {
function getOwner() external view returns (address) {
return owner;
}
}
}
*/

@ -13,7 +13,7 @@ describe('Misc', () => {
describe('web3_clientVersion', () => {
it('should get correct remix simulator version', async () => {
web3['_requestManager'].send({ method: 'web3_clientVersion', params: [] })
web3['_requestManager'].send({ method: 'web3_clientVersion', params: []})
.then(version => {
const remixVersion = require('../package.json').version
assert.equal(version, 'Remix Simulator/' + remixVersion)
@ -24,7 +24,7 @@ describe('Misc', () => {
describe('eth_protocolVersion', () => {
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'))
.catch(err => { throw new Error(err) })
})
@ -53,7 +53,7 @@ describe('Misc', () => {
describe('web3_sha3', () => {
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'))
.catch(err => { throw new Error(err)} )
})
@ -61,7 +61,7 @@ describe('Misc', () => {
describe('eth_getCompilers', () => {
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))
.catch(err => { throw new Error(err) })
})
@ -69,7 +69,7 @@ describe('Misc', () => {
describe('eth_compileSolidity', () => {
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'))
.catch(err => { throw new Error(err) })
})
@ -77,7 +77,7 @@ describe('Misc', () => {
describe('eth_compileLLL', () => {
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'))
.catch(err => { throw new Error(err) })
})
@ -85,7 +85,7 @@ describe('Misc', () => {
describe('eth_compileSerpent', () => {
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'))
.catch(err => { throw new Error(err)} )
})

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

Loading…
Cancel
Save