Lint fixes

This commit is contained in:
Gerardo Nardelli 2019-08-22 13:37:38 -03:00
parent 7f15733ad3
commit 3ff096ef55
11 changed files with 44 additions and 168 deletions

@ -33,9 +33,7 @@ describe('addTxHashToData', () => {
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
const msgDataType = '00'
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
const encodedData = `0x${strip0x(msgSender)}${strip0x(
msgExecutor
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
const encodedData = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
const transactionHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
const message = `0x${strip0x(transactionHash)}${strip0x(msgSender)}${strip0x(
@ -62,16 +60,7 @@ describe('parseAMBMessage', () => {
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
// when
const {
sender,
executor,
txHash,
gasLimit,
dataType,
gasPrice,
gasPriceSpeed,
data
} = parseAMBMessage(message)
const { sender, executor, txHash, gasLimit, dataType, gasPrice, gasPriceSpeed, data } = parseAMBMessage(message)
// then
expect(sender).to.be.equal(msgSender)
@ -96,16 +85,7 @@ describe('parseAMBMessage', () => {
)}${msgGasLimit}${msgDataType}${msgGasPrice}${strip0x(msgData)}`
// when
const {
sender,
executor,
txHash,
gasLimit,
dataType,
gasPrice,
gasPriceSpeed,
data
} = parseAMBMessage(message)
const { sender, executor, txHash, gasLimit, dataType, gasPrice, gasPriceSpeed, data } = parseAMBMessage(message)
// then
expect(sender).to.be.equal(msgSender)
@ -130,16 +110,7 @@ describe('parseAMBMessage', () => {
)}${msgGasLimit}${msgDataType}${strip0x(msgGasPriceSpeed)}${strip0x(msgData)}`
// when
const {
sender,
executor,
txHash,
gasLimit,
dataType,
gasPrice,
gasPriceSpeed,
data
} = parseAMBMessage(message)
const { sender, executor, txHash, gasLimit, dataType, gasPrice, gasPriceSpeed, data } = parseAMBMessage(message)
// then
expect(sender).to.be.equal(msgSender)

@ -15,13 +15,7 @@ const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider)
async function main() {
const {
foreignDeposits,
homeDeposits,
homeWithdrawals,
foreignWithdrawals,
bridgeMode
} = await eventsInfo()
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals, bridgeMode } = await eventsInfo()
let xSignatures
let xAffirmations

@ -70,28 +70,18 @@ async function main() {
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
return {
home: {
deliveredMsgNotProcessedInForeign: homeDeposits.filter(
deliveredMsgNotProcessed(foreignDeposits)
),
processedMsgNotDeliveredInForeign: homeWithdrawals.filter(
processedMsgNotDelivered(foreignWithdrawals)
)
deliveredMsgNotProcessedInForeign: homeDeposits.filter(deliveredMsgNotProcessed(foreignDeposits)),
processedMsgNotDeliveredInForeign: homeWithdrawals.filter(processedMsgNotDelivered(foreignWithdrawals))
},
foreign: {
deliveredMsgNotProcessedInHome: foreignWithdrawals.filter(
deliveredMsgNotProcessed(homeWithdrawals)
),
processedMsgNotDeliveredInHome: foreignDeposits.filter(
processedMsgNotDelivered(homeDeposits)
)
deliveredMsgNotProcessedInHome: foreignWithdrawals.filter(deliveredMsgNotProcessed(homeWithdrawals)),
processedMsgNotDeliveredInHome: foreignDeposits.filter(processedMsgNotDelivered(homeDeposits))
},
lastChecked: Math.floor(Date.now() / 1000)
}
} else {
const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits))
const onlyInForeignDeposits = foreignDeposits
.concat([])
.filter(compareDepositsForeign(homeDeposits))
const onlyInForeignDeposits = foreignDeposits.concat([]).filter(compareDepositsForeign(homeDeposits))
const onlyInHomeWithdrawals = isExternalErc20
? homeWithdrawals.filter(compareTransferHome(foreignWithdrawals))

@ -36,15 +36,13 @@ async function main(mode) {
let isExternalErc20
let erc20Contract
if (bridgeMode !== BRIDGE_MODES.ARBITRARY_MESSAGE) {
const tokenType = await getTokenType(foreignBridge, FOREIGN_BRIDGE_ADDRESS)
const erc20MethodName = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()
const tokenType = await getTokenType(
new web3Foreign.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, erc20Address),
FOREIGN_BRIDGE_ADDRESS
)
isExternalErc20 = tokenType === ERC_TYPES.ERC20
const erc20MethodName =
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()const tokenType = await getTokenType(
new web3Foreign.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, erc20Address),
FOREIGN_BRIDGE_ADDRESS
)
const isExternalErc20 = tokenType === ERC_TYPES.ERC20
erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
}

@ -98,12 +98,7 @@ describe('arbitrary message bridging', () => {
const initialUserBalance = toBN(await foreignWeb3.eth.getBalance(user.address))
const tx = await homeBox.methods
.withdrawFromDepositOnOtherNetworkGasPrice(
user.address,
amb.home,
amb.foreign,
'1000000000'
)
.withdrawFromDepositOnOtherNetworkGasPrice(user.address, amb.home, amb.foreign, '1000000000')
.send({
from: user.address,
gas: '1000000'
@ -164,10 +159,7 @@ describe('arbitrary message bridging', () => {
assert(foreignMode === subsidizedHash, 'foreign mode incorrect')
const initialValue = await foreignBox.methods.value().call()
assert(
!toBN(initialValue).eq(toBN(newValue)),
'initial value should be different from new value'
)
assert(!toBN(initialValue).eq(toBN(newValue)), 'initial value should be different from new value')
const setValueTx = await homeBox.methods
.setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000')
@ -265,12 +257,7 @@ describe('arbitrary message bridging', () => {
const initialUserBalance = toBN(await homeWeb3.eth.getBalance(user.address))
await foreignBox.methods
.withdrawFromDepositOnOtherNetworkGasPrice(
user.address,
amb.foreign,
amb.home,
'1000000000'
)
.withdrawFromDepositOnOtherNetworkGasPrice(user.address, amb.foreign, amb.home, '1000000000')
.send({
from: user.address,
gas: '1000000'
@ -315,10 +302,7 @@ describe('arbitrary message bridging', () => {
assert(foreignMode === subsidizedHash, 'foreign mode incorrect')
const initialValue = await homeBox.methods.value().call()
assert(
!toBN(initialValue).eq(toBN(newValue)),
'initial value should be different from new value'
)
assert(!toBN(initialValue).eq(toBN(newValue)), 'initial value should be different from new value')
await foreignBox.methods
.setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000')

@ -1,9 +1,5 @@
const { HttpListProviderError } = require('http-list-provider')
const {
AlreadyProcessedError,
AlreadySignedError,
InvalidValidatorError
} = require('../../utils/errors')
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
const logger = require('../../services/logger').child({
module: 'processAffirmationRequests:estimateGas'
})
@ -27,9 +23,7 @@ async function estimateGas({ web3, homeBridge, validatorContract, message, addre
// Check if minimum number of validations was already reached
logger.debug('Check if minimum number of validations was already reached')
const numAffirmationsSigned = await homeBridge.methods.numAffirmationsSigned(messageHash).call()
const alreadyProcessed = await homeBridge.methods
.isAlreadyProcessed(numAffirmationsSigned)
.call()
const alreadyProcessed = await homeBridge.methods.isAlreadyProcessed(numAffirmationsSigned).call()
if (alreadyProcessed) {
throw new AlreadyProcessedError(e.message)

@ -8,11 +8,7 @@ const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
const estimateGas = require('./estimateGas')
const { addTxHashToData, parseAMBMessage } = require('../../../../commons')
const { generateGasPriceOptions } = require('../../utils/utils')
const {
AlreadyProcessedError,
AlreadySignedError,
InvalidValidatorError
} = require('../../utils/errors')
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
const limit = promiseLimit(MAX_CONCURRENT_EVENTS)
@ -48,10 +44,7 @@ function processAffirmationRequestsBuilder(config) {
const { sender, executor, dataType, gasPrice, gasPriceSpeed } = parseAMBMessage(message)
logger.info(
{ sender, executor },
`Processing affirmationRequest ${affirmationRequest.transactionHash}`
)
logger.info({ sender, executor }, `Processing affirmationRequest ${affirmationRequest.transactionHash}`)
let gasEstimate
try {
@ -67,9 +60,7 @@ function processAffirmationRequestsBuilder(config) {
logger.debug({ gasEstimate }, 'Gas estimated')
} catch (e) {
if (e instanceof HttpListProviderError) {
throw new Error(
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
)
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
} else if (e instanceof InvalidValidatorError) {
logger.fatal({ address: config.validatorAddress }, 'Invalid validator')
process.exit(EXIT_CODES.INCOMPATIBILITY)
@ -78,9 +69,7 @@ function processAffirmationRequestsBuilder(config) {
return
} else if (e instanceof AlreadyProcessedError) {
logger.info(
`affirmationRequest ${
affirmationRequest.transactionHash
} was already processed by other validators`
`affirmationRequest ${affirmationRequest.transactionHash} was already processed by other validators`
)
return
} else {

@ -1,10 +1,6 @@
const Web3 = require('web3')
const { HttpListProviderError } = require('http-list-provider')
const {
AlreadyProcessedError,
IncompatibleContractError,
InvalidValidatorError
} = require('../../utils/errors')
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
const logger = require('../../services/logger').child({
module: 'processCollectedSignatures:estimateGas'
})
@ -26,12 +22,10 @@ async function estimateGas({
gasPrice
}) {
try {
const gasEstimate = await foreignBridge.methods
.executeSignatures(message, signatures)
.estimateGas({
from: address,
gasPrice
})
const gasEstimate = await foreignBridge.methods.executeSignatures(message, signatures).estimateGas({
from: address,
gasPrice
})
return gasEstimate
} catch (e) {
if (e instanceof HttpListProviderError) {

@ -8,11 +8,7 @@ const { signatureToVRS, signatureToVRSAMB, packSignatures } = require('../../uti
const { parseAMBMessage } = require('../../../../commons')
const { generateGasPriceOptions } = require('../../utils/utils')
const estimateGas = require('./estimateGas')
const {
AlreadyProcessedError,
IncompatibleContractError,
InvalidValidatorError
} = require('../../utils/errors')
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
const { MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
const limit = promiseLimit(MAX_CONCURRENT_EVENTS)
@ -22,10 +18,7 @@ let validatorContract = null
function processCollectedSignaturesBuilder(config) {
const homeBridge = new web3Home.eth.Contract(config.homeBridgeAbi, config.homeBridgeAddress)
const foreignBridge = new web3Foreign.eth.Contract(
config.foreignBridgeAbi,
config.foreignBridgeAddress
)
const foreignBridge = new web3Foreign.eth.Contract(config.foreignBridgeAbi, config.foreignBridgeAddress)
return async function processCollectedSignatures(signatures) {
const txToSend = []
@ -35,28 +28,19 @@ function processCollectedSignaturesBuilder(config) {
const validatorContractAddress = await foreignBridge.methods.validatorContract().call()
rootLogger.debug({ validatorContractAddress }, 'Validator contract address obtained')
validatorContract = new web3Foreign.eth.Contract(
bridgeValidatorsABI,
validatorContractAddress
)
validatorContract = new web3Foreign.eth.Contract(bridgeValidatorsABI, validatorContractAddress)
}
rootLogger.debug(`Processing ${signatures.length} CollectedSignatures events`)
const callbacks = signatures.map(colSignature =>
limit(async () => {
const {
authorityResponsibleForRelay,
messageHash,
NumberOfCollectedSignatures
} = colSignature.returnValues
const { authorityResponsibleForRelay, messageHash, NumberOfCollectedSignatures } = colSignature.returnValues
const logger = rootLogger.child({
eventTransactionHash: colSignature.transactionHash
})
if (
authorityResponsibleForRelay === web3Home.utils.toChecksumAddress(config.validatorAddress)
) {
if (authorityResponsibleForRelay === web3Home.utils.toChecksumAddress(config.validatorAddress)) {
logger.info(`Processing CollectedSignatures ${colSignature.transactionHash}`)
const message = await homeBridge.methods.message(messageHash).call()
@ -102,16 +86,11 @@ function processCollectedSignaturesBuilder(config) {
logger.debug({ gasEstimate }, 'Gas estimated')
} catch (e) {
if (e instanceof HttpListProviderError) {
throw new Error(
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
)
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
} else if (e instanceof AlreadyProcessedError) {
logger.info(`Already processed CollectedSignatures ${colSignature.transactionHash}`)
return
} else if (
e instanceof IncompatibleContractError ||
e instanceof InvalidValidatorError
) {
} else if (e instanceof IncompatibleContractError || e instanceof InvalidValidatorError) {
logger.error(`The message couldn't be processed; skipping: ${e.message}`)
return
} else {
@ -129,11 +108,7 @@ function processCollectedSignaturesBuilder(config) {
gasPriceOptions
})
} else {
logger.info(
`Validator not responsible for relaying CollectedSignatures ${
colSignature.transactionHash
}`
)
logger.info(`Validator not responsible for relaying CollectedSignatures ${colSignature.transactionHash}`)
}
})
)

@ -6,11 +6,7 @@ const rootLogger = require('../../services/logger')
const { web3Home } = require('../../services/web3')
const { addTxHashToData, parseAMBMessage } = require('../../../../commons')
const estimateGas = require('../processSignatureRequests/estimateGas')
const {
AlreadyProcessedError,
AlreadySignedError,
InvalidValidatorError
} = require('../../utils/errors')
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
const { VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
@ -48,10 +44,7 @@ function processSignatureRequestsBuilder(config) {
})
const { sender, executor } = parseAMBMessage(message)
logger.info(
{ sender, executor },
`Processing signatureRequest ${signatureRequest.transactionHash}`
)
logger.info({ sender, executor }, `Processing signatureRequest ${signatureRequest.transactionHash}`)
const signature = web3Home.eth.accounts.sign(message, `0x${VALIDATOR_ADDRESS_PRIVATE_KEY}`)
@ -69,9 +62,7 @@ function processSignatureRequestsBuilder(config) {
logger.debug({ gasEstimate }, 'Gas estimated')
} catch (e) {
if (e instanceof HttpListProviderError) {
throw new Error(
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
)
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
} else if (e instanceof InvalidValidatorError) {
logger.fatal({ address: config.validatorAddress }, 'Invalid validator')
process.exit(EXIT_CODES.INCOMPATIBILITY)
@ -80,9 +71,7 @@ function processSignatureRequestsBuilder(config) {
return
} else if (e instanceof AlreadyProcessedError) {
logger.info(
`signatureRequest ${
signatureRequest.transactionHash
} was already processed by other validators`
`signatureRequest ${signatureRequest.transactionHash} was already processed by other validators`
)
return
} else {

@ -140,9 +140,7 @@ describe('utils', () => {
it('should work for GAS_PRICE option', () => {
// given
const dataType = GAS_PRICE_OPTIONS.GAS_PRICE
const gasPrice = Web3Utils.toBN(
'0000000000000000000000000000000000000000000000000000000165a0bc00'
)
const gasPrice = Web3Utils.toBN('0000000000000000000000000000000000000000000000000000000165a0bc00')
const gasPriceSpeed = null
const expectedResult = {