remix-lib lint

git4refactor
filip mertens 7 months ago
parent c3db5384c9
commit c03bb35533
  1. 4
      libs/remix-lib/src/execution/eventsDecoder.ts
  2. 6
      libs/remix-lib/src/execution/logsManager.ts
  3. 12
      libs/remix-lib/src/execution/txFormat.ts
  4. 6
      libs/remix-lib/src/execution/txHelper.ts
  5. 4
      libs/remix-lib/src/execution/txRunnerVM.ts
  6. 20
      libs/remix-lib/src/execution/txRunnerWeb3.ts
  7. 8
      libs/remix-lib/src/helpers/txResultHelper.ts
  8. 4
      libs/remix-lib/src/init.ts
  9. 2
      libs/remix-lib/src/query-params.ts
  10. 6
      libs/remix-lib/src/util.ts
  11. 1
      libs/remix-lib/test/txFormat.ts
  12. 4
      libs/remix-lib/test/txHelper.ts
  13. 2
      libs/remix-lib/test/txResultHelper.ts
  14. 17
      libs/remix-lib/test/util.ts

@ -21,7 +21,7 @@ export class EventsDecoder {
* @param {Function} cb - callback * @param {Function} cb - callback
*/ */
parseLogs (tx, contractName, compiledContracts, cb) { parseLogs (tx, contractName, compiledContracts, cb) {
if (tx.isCall) return cb(null, { decoded: [], raw: [] }) if (tx.isCall) return cb(null, { decoded: [], raw: []})
this.resolveReceipt(tx, (error, receipt) => { this.resolveReceipt(tx, (error, receipt) => {
if (error) return cb(error) if (error) return cb(error)
this._decodeLogs(tx, receipt, contractName, compiledContracts, cb) this._decodeLogs(tx, receipt, contractName, compiledContracts, cb)
@ -33,7 +33,7 @@ export class EventsDecoder {
return cb('cannot decode logs - contract or receipt not resolved ') return cb('cannot decode logs - contract or receipt not resolved ')
} }
if (!receipt.logs) { if (!receipt.logs) {
return cb(null, { decoded: [], raw: [] }) return cb(null, { decoded: [], raw: []})
} }
this._decodeEvents(tx, receipt.logs, contract, contracts, cb) this._decodeEvents(tx, receipt.logs, contract, contracts, cb)
} }

@ -24,7 +24,7 @@ export class LogsManager {
if (!receipt) return next() if (!receipt) return next()
for (const log of receipt.logs) { for (const log of receipt.logs) {
this.oldLogs.push({ type: 'block', blockNumber, block, tx, log, txNumber: i, receipt }) this.oldLogs.push({ type: 'block', blockNumber, block, tx, log, txNumber: i, receipt })
const subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log, receipt}) const subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log, receipt })
for (const subscriptionId of subscriptions) { for (const subscriptionId of subscriptions) {
const result = { const result = {
logIndex: '0x1', // 1 logIndex: '0x1', // 1
@ -76,7 +76,7 @@ export class LogsManager {
const subscriptionParams = this.subscriptions[subscriptionId] const subscriptionParams = this.subscriptions[subscriptionId]
const [queryType, queryFilter] = subscriptionParams const [queryType, queryFilter] = subscriptionParams
if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || { topics: [] })) { if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || { topics: []})) {
matchedSubscriptions.push(subscriptionId) matchedSubscriptions.push(subscriptionId)
} }
} }
@ -135,7 +135,7 @@ export class LogsManager {
const tracking = this.filterTracking[filterId] const tracking = this.filterTracking[filterId]
if (logsOnly || filterType === 'filter') { if (logsOnly || filterType === 'filter') {
return this.getLogsFor(params || { topics: [] }) return this.getLogsFor(params || { topics: []})
} }
if (filterType === 'block') { if (filterType === 'block') {
const blocks = this.oldLogs.filter(x => x.type === 'block').filter(x => tracking.block === undefined || x.blockNumber >= tracking.block) const blocks = this.oldLogs.filter(x => x.type === 'block').filter(x => tracking.block === undefined || x.blockNumber >= tracking.block)

@ -88,7 +88,7 @@ export function encodeParams (params, funAbi, callback?) {
const result = { data: data, dataHex: dataHex, funArgs: funArgs } const result = { data: data, dataHex: dataHex, funArgs: funArgs }
callback && callback(null, result) callback && callback(null, result)
resolve(result) resolve(result)
}) })
} }
/** /**
@ -409,7 +409,7 @@ export function decodeResponse (response, fnabi) {
const name = fnabi.outputs[i].name const name = fnabi.outputs[i].name
json[i] = outputTypes[i] + ': ' + (name ? name + ' ' + decodedObj[i] : decodedObj[i]) json[i] = outputTypes[i] + ': ' + (name ? name + ' ' + decodedObj[i] : decodedObj[i])
} }
return json return json
} catch (e) { } catch (e) {
return { error: 'Failed to decode output: ' + e } return { error: 'Failed to decode output: ' + e }
@ -485,16 +485,16 @@ export const normalizeParam = (param) => {
try { try {
let paramTrimmed = param.replace(/^'/g, '').replace(/'$/g, '') let paramTrimmed = param.replace(/^'/g, '').replace(/'$/g, '')
paramTrimmed = paramTrimmed.replace(/^"/g, '').replace(/"$/g, '') paramTrimmed = paramTrimmed.replace(/^"/g, '').replace(/"$/g, '')
param = fromExponential(paramTrimmed) param = fromExponential(paramTrimmed)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
} }
} }
if (typeof param === 'string') { if (typeof param === 'string') {
if (param === 'true') param = true if (param === 'true') param = true
if (param === 'false') param = false if (param === 'false') param = false
} }
return param return param
} }

@ -16,8 +16,8 @@ export function encodeParams (funABI, args) {
const type = funABI.inputs[i].type const type = funABI.inputs[i].type
if (type === 'bool') { if (type === 'bool') {
if (args[i] === false || args[i] === 'false' || args[i] === '0' || args[i] === 0) args[i] = false if (args[i] === false || args[i] === 'false' || args[i] === '0' || args[i] === 0) args[i] = false
else if (args[i] === true || args[i] === 'true' || args[i] === '1' || args[i] === 1) args[i] = true else if (args[i] === true || args[i] === 'true' || args[i] === '1' || args[i] === 1) args[i] = true
else throw new Error(`provided value for boolean is invalid: ${args[i]}`) else throw new Error(`provided value for boolean is invalid: ${args[i]}`)
} }
types.push(type.indexOf('tuple') === 0 ? makeFullTypeDefinition(funABI.inputs[i]) : type) types.push(type.indexOf('tuple') === 0 ? makeFullTypeDefinition(funABI.inputs[i]) : type)
if (args.length < types.length) { if (args.length < types.length) {
@ -66,7 +66,7 @@ export function sortAbiFunction (contractabi) {
} }
export function getConstructorInterface (abi) { export function getConstructorInterface (abi) {
const funABI = { name: '', inputs: [], type: 'constructor', payable: false, outputs: [] } const funABI = { name: '', inputs: [], type: 'constructor', payable: false, outputs: []}
if (typeof abi === 'string') { if (typeof abi === 'string') {
try { try {
abi = JSON.parse(abi) abi = JSON.parse(abi)

@ -38,7 +38,7 @@ export class TxRunnerVM {
this.logsManager = new LogsManager() this.logsManager = new LogsManager()
// has a default for now for backwards compatibility // has a default for now for backwards compatibility
this.getVMObject = getVMObject this.getVMObject = getVMObject
this.commonContext = this.getVMObject().common this.commonContext = this.getVMObject().common
this.pendingTxs = {} this.pendingTxs = {}
this.vmaccounts = vmaccounts this.vmaccounts = vmaccounts
this.queusTxs = [] this.queusTxs = []
@ -137,7 +137,7 @@ export class TxRunnerVM {
}) })
} else { } else {
this.blockParentHash = block.hash() this.blockParentHash = block.hash()
this.runBlockInVm(tx, block, async (err, result) => { this.runBlockInVm(tx, block, async (err, result) => {
if (!err) { if (!err) {
if (!useCall) { if (!useCall) {
this.getVMObject().vm.blockchain.putBlock(block) this.getVMObject().vm.blockchain.putBlock(block)

@ -2,7 +2,7 @@
import { EventManager } from '../eventManager' import { EventManager } from '../eventManager'
import type { Transaction as InternalTransaction } from './txRunner' import type { Transaction as InternalTransaction } from './txRunner'
import Web3 from 'web3' import Web3 from 'web3'
import {toBigInt, toHex} from 'web3-utils' import { toBigInt, toHex } from 'web3-utils'
export class TxRunnerWeb3 { export class TxRunnerWeb3 {
event event
@ -65,9 +65,9 @@ export class TxRunnerWeb3 {
promptCb( promptCb(
async (value) => { async (value) => {
try { try {
const res = await (this.getWeb3() as any).eth.personal.sendTransaction({...tx, value}, { checkRevertBeforeSending: false, ignoreGasPricing: true }) const res = await (this.getWeb3() as any).eth.personal.sendTransaction({ ...tx, value }, { checkRevertBeforeSending: false, ignoreGasPricing: true })
cb(null, res.transactionHash) cb(null, res.transactionHash)
} catch (e) { } catch (e) {
console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `)
// in case the receipt is available, we consider that only the execution failed but the transaction went through. // in case the receipt is available, we consider that only the execution failed but the transaction went through.
// So we don't consider this to be an error. // So we don't consider this to be an error.
@ -81,9 +81,9 @@ export class TxRunnerWeb3 {
) )
} else { } else {
try { try {
const res = await this.getWeb3().eth.sendTransaction(tx, null, { checkRevertBeforeSending: false, ignoreGasPricing: true}) const res = await this.getWeb3().eth.sendTransaction(tx, null, { checkRevertBeforeSending: false, ignoreGasPricing: true })
cb(null, res.transactionHash) cb(null, res.transactionHash)
} catch (e) { } catch (e) {
console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `)
// in case the receipt is available, we consider that only the execution failed but the transaction went through. // in case the receipt is available, we consider that only the execution failed but the transaction went through.
// So we don't consider this to be an error. // So we don't consider this to be an error.
@ -121,7 +121,7 @@ export class TxRunnerWeb3 {
console.log(errNetWork) console.log(errNetWork)
return return
} }
const txCopy = { ...tx, type: undefined, maxFeePerGas: undefined, gasPrice: undefined } const txCopy = { ...tx, type: undefined, maxFeePerGas: undefined, gasPrice: undefined }
if (network && network.lastBlock) { if (network && network.lastBlock) {
if (network.lastBlock.baseFeePerGas) { if (network.lastBlock.baseFeePerGas) {
// the sending stack (web3.js / metamask need to have the type defined) // the sending stack (web3.js / metamask need to have the type defined)
@ -138,17 +138,17 @@ export class TxRunnerWeb3 {
gasEstimationForceSend(null, () => { gasEstimationForceSend(null, () => {
/* /*
* gasLimit is a value that can be set in the UI to hardcap value that can be put in a tx. * gasLimit is a value that can be set in the UI to hardcap value that can be put in a tx.
* e.g if the gasestimate * e.g if the gasestimate
*/ */
if (gasLimit !== '0x0' && gasEstimation > gasLimit) { if (gasLimit !== '0x0' && gasEstimation > gasLimit) {
return callback(`estimated gas for this transaction (${gasEstimation}) is higher than gasLimit set in the configuration (${gasLimit}). Please raise the gas limit.`) return callback(`estimated gas for this transaction (${gasEstimation}) is higher than gasLimit set in the configuration (${gasLimit}). Please raise the gas limit.`)
} }
if (gasLimit === '0x0') { if (gasLimit === '0x0') {
tx['gas'] = gasEstimation tx['gas'] = gasEstimation
} else { } else {
tx['gas'] = gasLimit tx['gas'] = gasLimit
} }
if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) {
return this._executeTx(tx, network, null, this._api, promptCb, callback) return this._executeTx(tx, network, null, this._api, promptCb, callback)

@ -8,13 +8,13 @@ function convertToPrefixedHex (input) {
if (input === undefined || input === null || isHexString(input)) { if (input === undefined || input === null || isHexString(input)) {
return input return input
} }
if ((input.constructor && input.constructor.name === 'BigNumber') if ((input.constructor && input.constructor.name === 'BigNumber')
|| BN.isBN(input) || BN.isBN(input)
|| isBigInt(input) || isBigInt(input)
|| typeof input === 'number') { || typeof input === 'number') {
return '0x' + input.toString(16) return '0x' + input.toString(16)
} }
try { try {
return bytesToHex(input) return bytesToHex(input)
} catch (e) { } catch (e) {
@ -26,7 +26,7 @@ function convertToPrefixedHex (input) {
return '0x' + input.toString(16) return '0x' + input.toString(16)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
return input return input
} }

@ -1,9 +1,9 @@
'use strict' 'use strict'
import Web3, { Web3PluginBase } from 'web3' import Web3, { Web3PluginBase } from 'web3'
import {toNumber} from 'web3-utils' import { toNumber } from 'web3-utils'
export function extendWeb3 (web3) { export function extendWeb3 (web3) {
if(!web3.debug){ if (!web3.debug){
web3.registerPlugin(new Web3DebugPlugin()) web3.registerPlugin(new Web3DebugPlugin())
} }
} }

@ -1,6 +1,6 @@
'use strict' 'use strict'
export class QueryParams { export class QueryParams {
update (params) { update (params) {
const currentParams = this.get() const currentParams = this.get()

@ -248,7 +248,7 @@ export function getinputParameters (value) {
export function compareByteCode (code1, code2) { export function compareByteCode (code1, code2) {
if (code1 === code2) return true if (code1 === code2) return true
if (code2 === '0x') return false // abstract contract. see comment if (code2 === '0x') return false // abstract contract. see comment
if (code1 === '0x00' || code2 === '0x00' && code1 !== code2) return false // // This can be removed some time once YUL returns correct bytecode if (code1 === '0x00' || code2 === '0x00' && code1 !== code2) return false // // This can be removed some time once YUL returns correct bytecode
if (code2.substr(2, 46) === '7300000000000000000000000000000000000000003014') { if (code2.substr(2, 46) === '7300000000000000000000000000000000000000003014') {
// testing the following signature: PUSH20 00..00 ADDRESS EQ // testing the following signature: PUSH20 00..00 ADDRESS EQ
@ -263,7 +263,7 @@ export function compareByteCode (code1, code2) {
} }
code1 = removeImmutableReference(code1, code2) code1 = removeImmutableReference(code1, code2)
code1 = extractinputParameters(code1) code1 = extractinputParameters(code1)
code1 = extractSwarmHash(code1) code1 = extractSwarmHash(code1)
code1 = extractcborMetadata(code1) code1 = extractcborMetadata(code1)
code2 = extractinputParameters(code2) code2 = extractinputParameters(code2)
@ -275,7 +275,7 @@ export function compareByteCode (code1, code2) {
// if the length isn't the same, we have an issue with extracting the metadata hash. // if the length isn't the same, we have an issue with extracting the metadata hash.
const minLength = code1.length > code2.length ? code2.length: code1.length const minLength = code1.length > code2.length ? code2.length: code1.length
code1 = code1.substr(0, minLength - 10) code1 = code1.substr(0, minLength - 10)
code2 = code2.substr(0, minLength - 10) code2 = code2.substr(0, minLength - 10)
} }
const compare = stringSimilarity.compareTwoStrings(code1, code2) const compare = stringSimilarity.compareTwoStrings(code1, code2)
return compare == 1 return compare == 1

@ -45,7 +45,6 @@ function testWithInput (st, params, expected) {
}, () => {}, () => {}) }, () => {}, () => {})
} }
tape('ContractStringParameters - (TxFormat.buildData) - format string input parameters', function (t) { tape('ContractStringParameters - (TxFormat.buildData) - format string input parameters', function (t) {
let output = compiler.compile(compilerInput(stringContract)) let output = compiler.compile(compilerInput(stringContract))
output = JSON.parse(output) output = JSON.parse(output)

@ -29,7 +29,7 @@ tape('getFunction', function (st) {
fn = txHelper.getFunctionLiner(testTupleAbi[0], true) fn = txHelper.getFunctionLiner(testTupleAbi[0], true)
st.equal(fn, 'setUser((string,uint256))') st.equal(fn, 'setUser((string,uint256))')
fn = txHelper.getFunctionLiner(testTupleAbi[0], false) fn = txHelper.getFunctionLiner(testTupleAbi[0], false)
st.equal(fn, 'setUser(tuple)') st.equal(fn, 'setUser(tuple)')
}) })
@ -165,4 +165,4 @@ const abi = `[
} }
]` ]`
const testTupleAbi = [{"inputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"age","type":"uint256"}],"internalType":"struct Example.User","name":"user","type":"tuple"}],"name":"setUser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userByAddress","outputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"age","type":"uint256"}],"stateMutability":"view","type":"function"}] const testTupleAbi = [{ "inputs":[{ "components":[{ "internalType":"string","name":"name","type":"string" },{ "internalType":"uint256","name":"age","type":"uint256" }],"internalType":"struct Example.User","name":"user","type":"tuple" }],"name":"setUser","outputs":[],"stateMutability":"nonpayable","type":"function" },{ "inputs":[{ "internalType":"address","name":"","type":"address" }],"name":"userByAddress","outputs":[{ "internalType":"string","name":"name","type":"string" },{ "internalType":"uint256","name":"age","type":"uint256" }],"stateMutability":"view","type":"function" }]

@ -59,7 +59,7 @@ const EXEC_RESULT = {
} }
const EXEC_RESULT_ERROR = { const EXEC_RESULT_ERROR = {
exceptionError: 'this is an error' exceptionError: 'this is an error'
} }
tape('converts node transaction result to RemixTx', function (t) { tape('converts node transaction result to RemixTx', function (t) {

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save