Move amb message utils to commons
This commit is contained in:
parent
751b885f73
commit
e5ce665656
@ -17,4 +17,23 @@ const FEE_MANAGER_MODE = {
|
|||||||
UNDEFINED: 'UNDEFINED'
|
UNDEFINED: 'UNDEFINED'
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { BRIDGE_MODES, ERC_TYPES, FEE_MANAGER_MODE }
|
const GAS_PRICE_OPTIONS = {
|
||||||
|
UNDEFINED: '00',
|
||||||
|
GAS_PRICE: '01',
|
||||||
|
SPEED: '02'
|
||||||
|
}
|
||||||
|
|
||||||
|
const ORACLE_GAS_PRICE_SPEEDS = {
|
||||||
|
SLOW: 'slow',
|
||||||
|
STANDARD: 'standard',
|
||||||
|
FAST: 'fast',
|
||||||
|
INSTANT: 'instant'
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
BRIDGE_MODES,
|
||||||
|
ERC_TYPES,
|
||||||
|
FEE_MANAGER_MODE,
|
||||||
|
GAS_PRICE_OPTIONS,
|
||||||
|
ORACLE_GAS_PRICE_SPEEDS
|
||||||
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
const constants = require('./constants')
|
const constants = require('./constants')
|
||||||
const abis = require('./abis')
|
const abis = require('./abis')
|
||||||
const utils = require('./utils')
|
const utils = require('./utils')
|
||||||
|
const message = require('./message')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...constants,
|
...constants,
|
||||||
...abis,
|
...abis,
|
||||||
...utils
|
...utils,
|
||||||
|
...message
|
||||||
}
|
}
|
||||||
|
63
commons/message.js
Normal file
63
commons/message.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
const web3Utils = require('web3-utils')
|
||||||
|
const { GAS_PRICE_OPTIONS, ORACLE_GAS_PRICE_SPEEDS } = require('./constants')
|
||||||
|
|
||||||
|
const gasPriceSpeedMapper = {
|
||||||
|
'01': ORACLE_GAS_PRICE_SPEEDS.INSTANT,
|
||||||
|
'02': ORACLE_GAS_PRICE_SPEEDS.FAST,
|
||||||
|
'03': ORACLE_GAS_PRICE_SPEEDS.STANDARD,
|
||||||
|
'04': ORACLE_GAS_PRICE_SPEEDS.SLOW
|
||||||
|
}
|
||||||
|
|
||||||
|
function strip0x(input) {
|
||||||
|
return input.replace(/^0x/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTxHashToData({ encodedData, transactionHash }) {
|
||||||
|
return encodedData.slice(0, 82) + strip0x(transactionHash) + encodedData.slice(82)
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseAMBMessage(message) {
|
||||||
|
message = strip0x(message)
|
||||||
|
|
||||||
|
const sender = `0x${message.slice(0, 40)}`
|
||||||
|
const executor = `0x${message.slice(40, 80)}`
|
||||||
|
const txHash = `0x${message.slice(80, 144)}`
|
||||||
|
const gasLimit = web3Utils.toBN(message.slice(144, 208))
|
||||||
|
const dataType = message.slice(208, 210)
|
||||||
|
let gasPrice = null
|
||||||
|
let gasPriceSpeed = null
|
||||||
|
let dataStart = 210
|
||||||
|
|
||||||
|
switch (dataType) {
|
||||||
|
case GAS_PRICE_OPTIONS.GAS_PRICE:
|
||||||
|
gasPrice = web3Utils.toBN(message.slice(210, 274))
|
||||||
|
dataStart += 64
|
||||||
|
break
|
||||||
|
case GAS_PRICE_OPTIONS.SPEED:
|
||||||
|
gasPriceSpeed = gasPriceSpeedMapper[message.slice(210, 212)]
|
||||||
|
dataStart += 2
|
||||||
|
break
|
||||||
|
case GAS_PRICE_OPTIONS.UNDEFINED:
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = `0x${message.slice(dataStart, message.length)}`
|
||||||
|
|
||||||
|
return {
|
||||||
|
sender,
|
||||||
|
executor,
|
||||||
|
txHash,
|
||||||
|
gasLimit,
|
||||||
|
dataType,
|
||||||
|
gasPrice,
|
||||||
|
gasPriceSpeed,
|
||||||
|
data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
addTxHashToData,
|
||||||
|
parseAMBMessage,
|
||||||
|
strip0x
|
||||||
|
}
|
@ -6,5 +6,12 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --ignore-path ../.eslintignore",
|
"lint": "eslint . --ignore-path ../.eslintignore",
|
||||||
"test": "NODE_ENV=test mocha"
|
"test": "NODE_ENV=test mocha"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"web3-utils": "1.0.0-beta.34"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"bn-chai": "^1.0.1",
|
||||||
|
"chai": "^4.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
154
commons/test/message.test.js
Normal file
154
commons/test/message.test.js
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
const { BN, toBN } = require('web3-utils')
|
||||||
|
const { expect } = require('chai').use(require('bn-chai')(BN))
|
||||||
|
const { parseAMBMessage, strip0x, addTxHashToData } = require('../message')
|
||||||
|
const { ORACLE_GAS_PRICE_SPEEDS } = require('../constants')
|
||||||
|
|
||||||
|
describe('strip0x', () => {
|
||||||
|
it('should remove 0x from input', () => {
|
||||||
|
// Given
|
||||||
|
const input = '0x12345'
|
||||||
|
|
||||||
|
// When
|
||||||
|
const result = strip0x(input)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(result).to.be.equal('12345')
|
||||||
|
})
|
||||||
|
it('should not modify input if 0x is not present', () => {
|
||||||
|
// Given
|
||||||
|
const input = '12345'
|
||||||
|
|
||||||
|
// When
|
||||||
|
const result = strip0x(input)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(result).to.be.equal(input)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('addTxHashToData', () => {
|
||||||
|
it('should add txHash to encoded data at position 82', () => {
|
||||||
|
// Given
|
||||||
|
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
||||||
|
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
||||||
|
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
||||||
|
const msgDataType = '00'
|
||||||
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||||
|
const encodedData = `0x${strip0x(msgSender)}${strip0x(
|
||||||
|
msgExecutor
|
||||||
|
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
|
||||||
|
|
||||||
|
const transactionHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
||||||
|
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
||||||
|
transactionHash
|
||||||
|
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
|
||||||
|
|
||||||
|
// When
|
||||||
|
const result = addTxHashToData({ encodedData, transactionHash })
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(result).to.be.equal(message)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('parseAMBMessage', () => {
|
||||||
|
it('should parse data type 00', () => {
|
||||||
|
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
||||||
|
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
||||||
|
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
||||||
|
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
||||||
|
const msgDataType = '00'
|
||||||
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||||
|
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
||||||
|
msgTxHash
|
||||||
|
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
|
||||||
|
|
||||||
|
// when
|
||||||
|
const {
|
||||||
|
sender,
|
||||||
|
executor,
|
||||||
|
txHash,
|
||||||
|
gasLimit,
|
||||||
|
dataType,
|
||||||
|
gasPrice,
|
||||||
|
gasPriceSpeed,
|
||||||
|
data
|
||||||
|
} = parseAMBMessage(message)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(sender).to.be.equal(msgSender)
|
||||||
|
expect(executor).to.be.equal(msgExecutor)
|
||||||
|
expect(txHash).to.be.equal(msgTxHash)
|
||||||
|
expect(gasLimit).to.eq.BN(toBN(msgGasLimit))
|
||||||
|
expect(dataType).to.be.equal(msgDataType)
|
||||||
|
expect(gasPrice).to.be.equal(null)
|
||||||
|
expect(gasPriceSpeed).to.be.equal(null)
|
||||||
|
expect(data).to.be.equal(msgData)
|
||||||
|
})
|
||||||
|
it('should parse data type 01', () => {
|
||||||
|
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
||||||
|
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
||||||
|
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
||||||
|
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
||||||
|
const msgDataType = '01'
|
||||||
|
const msgGasPrice = '0000000000000000000000000000000000000000000000000000000165a0bc00'
|
||||||
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||||
|
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
||||||
|
msgTxHash
|
||||||
|
)}${msgGasLimit}${msgDataType}${msgGasPrice}${strip0x(msgData)}`
|
||||||
|
|
||||||
|
// when
|
||||||
|
const {
|
||||||
|
sender,
|
||||||
|
executor,
|
||||||
|
txHash,
|
||||||
|
gasLimit,
|
||||||
|
dataType,
|
||||||
|
gasPrice,
|
||||||
|
gasPriceSpeed,
|
||||||
|
data
|
||||||
|
} = parseAMBMessage(message)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(sender).to.be.equal(msgSender)
|
||||||
|
expect(executor).to.be.equal(msgExecutor)
|
||||||
|
expect(txHash).to.be.equal(msgTxHash)
|
||||||
|
expect(gasLimit).to.eq.BN(toBN(msgGasLimit))
|
||||||
|
expect(dataType).to.be.equal(msgDataType)
|
||||||
|
expect(gasPrice).to.eq.BN(toBN(msgGasPrice))
|
||||||
|
expect(gasPriceSpeed).to.be.equal(null)
|
||||||
|
expect(data).to.be.equal(msgData)
|
||||||
|
})
|
||||||
|
it('should parse data type 02', () => {
|
||||||
|
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
||||||
|
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
||||||
|
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
||||||
|
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
||||||
|
const msgDataType = '02'
|
||||||
|
const msgGasPriceSpeed = '0x03'
|
||||||
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||||
|
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
||||||
|
msgTxHash
|
||||||
|
)}${msgGasLimit}${msgDataType}${strip0x(msgGasPriceSpeed)}${strip0x(msgData)}`
|
||||||
|
|
||||||
|
// when
|
||||||
|
const {
|
||||||
|
sender,
|
||||||
|
executor,
|
||||||
|
txHash,
|
||||||
|
gasLimit,
|
||||||
|
dataType,
|
||||||
|
gasPrice,
|
||||||
|
gasPriceSpeed,
|
||||||
|
data
|
||||||
|
} = parseAMBMessage(message)
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(sender).to.be.equal(msgSender)
|
||||||
|
expect(executor).to.be.equal(msgExecutor)
|
||||||
|
expect(txHash).to.be.equal(msgTxHash)
|
||||||
|
expect(gasLimit).to.eq.BN(toBN(msgGasLimit))
|
||||||
|
expect(dataType).to.be.equal(msgDataType)
|
||||||
|
expect(gasPrice).to.be.equal(null)
|
||||||
|
expect(gasPriceSpeed).to.be.equal(ORACLE_GAS_PRICE_SPEEDS.STANDARD)
|
||||||
|
expect(data).to.be.equal(msgData)
|
||||||
|
})
|
||||||
|
})
|
@ -1,5 +1,5 @@
|
|||||||
const web3Utils = require('web3').utils
|
const web3Utils = require('web3').utils
|
||||||
const { addTxHashToData, parseAMBMessage } = require('../../oracle/src/utils/message')
|
const { addTxHashToData, parseAMBMessage } = require('../../commons')
|
||||||
|
|
||||||
function deliveredMsgNotProcessed(processedList) {
|
function deliveredMsgNotProcessed(processedList) {
|
||||||
return deliveredMsg => {
|
return deliveredMsg => {
|
||||||
|
@ -6,7 +6,7 @@ const { web3Home } = require('../../services/web3')
|
|||||||
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
||||||
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
||||||
const estimateGas = require('./estimateGas')
|
const estimateGas = require('./estimateGas')
|
||||||
const { addTxHashToData, parseAMBMessage } = require('../../utils/message')
|
const { addTxHashToData, parseAMBMessage } = require('../../../../commons')
|
||||||
const { generateGasPriceOptions } = require('../../utils/utils')
|
const { generateGasPriceOptions } = require('../../utils/utils')
|
||||||
const {
|
const {
|
||||||
AlreadyProcessedError,
|
AlreadyProcessedError,
|
||||||
|
@ -4,7 +4,8 @@ const { HttpListProviderError } = require('http-list-provider')
|
|||||||
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
||||||
const rootLogger = require('../../services/logger')
|
const rootLogger = require('../../services/logger')
|
||||||
const { web3Home, web3Foreign } = require('../../services/web3')
|
const { web3Home, web3Foreign } = require('../../services/web3')
|
||||||
const { signatureToVRS, parseAMBMessage } = require('../../utils/message')
|
const { signatureToVRS } = require('../../utils/message')
|
||||||
|
const { parseAMBMessage } = require('../../../../commons')
|
||||||
const { generateGasPriceOptions } = require('../../utils/utils')
|
const { generateGasPriceOptions } = require('../../utils/utils')
|
||||||
const estimateGas = require('./estimateGas')
|
const estimateGas = require('./estimateGas')
|
||||||
const {
|
const {
|
||||||
|
@ -4,7 +4,7 @@ const { HttpListProviderError } = require('http-list-provider')
|
|||||||
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi
|
||||||
const rootLogger = require('../../services/logger')
|
const rootLogger = require('../../services/logger')
|
||||||
const { web3Home } = require('../../services/web3')
|
const { web3Home } = require('../../services/web3')
|
||||||
const { addTxHashToData, parseAMBMessage } = require('../../utils/message')
|
const { addTxHashToData, parseAMBMessage } = require('../../../../commons')
|
||||||
const estimateGas = require('../processSignatureRequests/estimateGas')
|
const estimateGas = require('../processSignatureRequests/estimateGas')
|
||||||
const {
|
const {
|
||||||
AlreadyProcessedError,
|
AlreadyProcessedError,
|
||||||
|
@ -10,9 +10,9 @@ const { setIntervalAndRun } = require('../utils/utils')
|
|||||||
const {
|
const {
|
||||||
DEFAULT_UPDATE_INTERVAL,
|
DEFAULT_UPDATE_INTERVAL,
|
||||||
GAS_PRICE_BOUNDARIES,
|
GAS_PRICE_BOUNDARIES,
|
||||||
DEFAULT_GAS_PRICE_FACTOR,
|
DEFAULT_GAS_PRICE_FACTOR
|
||||||
GAS_PRICE_OPTIONS
|
|
||||||
} = require('../utils/constants')
|
} = require('../utils/constants')
|
||||||
|
const { GAS_PRICE_OPTIONS } = require('../../../commons')
|
||||||
|
|
||||||
const HomeABI = bridgeConfig.homeBridgeAbi
|
const HomeABI = bridgeConfig.homeBridgeAbi
|
||||||
const ForeignABI = bridgeConfig.foreignBridgeAbi
|
const ForeignABI = bridgeConfig.foreignBridgeAbi
|
||||||
|
@ -21,16 +21,5 @@ module.exports = {
|
|||||||
ERC_TYPES: {
|
ERC_TYPES: {
|
||||||
ERC20: 'ERC20',
|
ERC20: 'ERC20',
|
||||||
ERC677: 'ERC677'
|
ERC677: 'ERC677'
|
||||||
},
|
|
||||||
GAS_PRICE_OPTIONS: {
|
|
||||||
UNDEFINED: '00',
|
|
||||||
GAS_PRICE: '01',
|
|
||||||
SPEED: '02'
|
|
||||||
},
|
|
||||||
ORACLE_GAS_PRICE_SPEEDS: {
|
|
||||||
SLOW: 'slow',
|
|
||||||
STANDARD: 'standard',
|
|
||||||
FAST: 'fast',
|
|
||||||
INSTANT: 'instant'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,6 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const Web3Utils = require('web3-utils')
|
const Web3Utils = require('web3-utils')
|
||||||
const { ORACLE_GAS_PRICE_SPEEDS, GAS_PRICE_OPTIONS } = require('./constants')
|
const { strip0x } = require('../../../commons')
|
||||||
|
|
||||||
const gasPriceSpeedMapper = {
|
|
||||||
'01': ORACLE_GAS_PRICE_SPEEDS.INSTANT,
|
|
||||||
'02': ORACLE_GAS_PRICE_SPEEDS.FAST,
|
|
||||||
'03': ORACLE_GAS_PRICE_SPEEDS.STANDARD,
|
|
||||||
'04': ORACLE_GAS_PRICE_SPEEDS.SLOW
|
|
||||||
}
|
|
||||||
// strips leading "0x" if present
|
|
||||||
function strip0x(input) {
|
|
||||||
return input.replace(/^0x/, '')
|
|
||||||
}
|
|
||||||
|
|
||||||
function createMessage({
|
function createMessage({
|
||||||
recipient,
|
recipient,
|
||||||
@ -79,55 +68,8 @@ function signatureToVRS(signature) {
|
|||||||
return { v, r, s }
|
return { v, r, s }
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTxHashToData({ encodedData, transactionHash }) {
|
|
||||||
return encodedData.slice(0, 82) + strip0x(transactionHash) + encodedData.slice(82)
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseAMBMessage(message) {
|
|
||||||
message = strip0x(message)
|
|
||||||
|
|
||||||
const sender = `0x${message.slice(0, 40)}`
|
|
||||||
const executor = `0x${message.slice(40, 80)}`
|
|
||||||
const txHash = `0x${message.slice(80, 144)}`
|
|
||||||
const gasLimit = Web3Utils.toBN(message.slice(144, 208))
|
|
||||||
const dataType = message.slice(208, 210)
|
|
||||||
let gasPrice = null
|
|
||||||
let gasPriceSpeed = null
|
|
||||||
let dataStart = 210
|
|
||||||
|
|
||||||
switch (dataType) {
|
|
||||||
case GAS_PRICE_OPTIONS.GAS_PRICE:
|
|
||||||
gasPrice = Web3Utils.toBN(message.slice(210, 274))
|
|
||||||
dataStart += 64
|
|
||||||
break
|
|
||||||
case GAS_PRICE_OPTIONS.SPEED:
|
|
||||||
gasPriceSpeed = gasPriceSpeedMapper[message.slice(210, 212)]
|
|
||||||
dataStart += 2
|
|
||||||
break
|
|
||||||
case GAS_PRICE_OPTIONS.UNDEFINED:
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = `0x${message.slice(dataStart, message.length)}`
|
|
||||||
|
|
||||||
return {
|
|
||||||
sender,
|
|
||||||
executor,
|
|
||||||
txHash,
|
|
||||||
gasLimit,
|
|
||||||
dataType,
|
|
||||||
gasPrice,
|
|
||||||
gasPriceSpeed,
|
|
||||||
data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createMessage,
|
createMessage,
|
||||||
parseMessage,
|
parseMessage,
|
||||||
signatureToVRS,
|
signatureToVRS
|
||||||
addTxHashToData,
|
|
||||||
parseAMBMessage,
|
|
||||||
strip0x
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ const BigNumber = require('bignumber.js')
|
|||||||
const promiseRetry = require('promise-retry')
|
const promiseRetry = require('promise-retry')
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const Web3Utils = require('web3-utils')
|
const Web3Utils = require('web3-utils')
|
||||||
const { GAS_PRICE_OPTIONS } = require('./constants')
|
const { GAS_PRICE_OPTIONS } = require('../../../commons')
|
||||||
|
|
||||||
const retrySequence = [1, 2, 3, 5, 8, 13, 21, 34, 55, 60]
|
const retrySequence = [1, 2, 3, 5, 8, 13, 21, 34, 55, 60]
|
||||||
|
|
||||||
|
@ -8,12 +8,8 @@ const {
|
|||||||
gasPriceWithinLimits,
|
gasPriceWithinLimits,
|
||||||
normalizeGasPrice
|
normalizeGasPrice
|
||||||
} = require('../src/services/gasPrice')
|
} = require('../src/services/gasPrice')
|
||||||
const {
|
const { DEFAULT_UPDATE_INTERVAL, GAS_PRICE_BOUNDARIES } = require('../src/utils/constants')
|
||||||
DEFAULT_UPDATE_INTERVAL,
|
const { GAS_PRICE_OPTIONS, ORACLE_GAS_PRICE_SPEEDS } = require('../../commons')
|
||||||
GAS_PRICE_OPTIONS,
|
|
||||||
ORACLE_GAS_PRICE_SPEEDS,
|
|
||||||
GAS_PRICE_BOUNDARIES
|
|
||||||
} = require('../src/utils/constants')
|
|
||||||
|
|
||||||
describe('gasPrice', () => {
|
describe('gasPrice', () => {
|
||||||
describe('fetchGasPrice', () => {
|
describe('fetchGasPrice', () => {
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
const { BN, toBN } = require('web3').utils
|
const { BN, toBN } = require('web3').utils
|
||||||
const { expect } = require('chai').use(require('bn-chai')(BN))
|
const { expect } = require('chai').use(require('bn-chai')(BN))
|
||||||
const {
|
const { createMessage, parseMessage, signatureToVRS } = require('../src/utils/message')
|
||||||
createMessage,
|
|
||||||
parseMessage,
|
|
||||||
signatureToVRS,
|
|
||||||
parseAMBMessage,
|
|
||||||
strip0x
|
|
||||||
} = require('../src/utils/message')
|
|
||||||
const { ORACLE_GAS_PRICE_SPEEDS } = require('../src/utils/constants')
|
|
||||||
|
|
||||||
describe('message utils', () => {
|
describe('message utils', () => {
|
||||||
const expectedMessageLength = 104
|
const expectedMessageLength = 104
|
||||||
@ -300,107 +293,4 @@ describe('message utils', () => {
|
|||||||
expect(signatureThunk).to.throw()
|
expect(signatureThunk).to.throw()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('parseAMBMessage', () => {
|
|
||||||
it('should parse data type 00', () => {
|
|
||||||
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
|
||||||
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
|
||||||
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
|
||||||
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
|
||||||
const msgDataType = '00'
|
|
||||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
|
||||||
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
|
||||||
msgTxHash
|
|
||||||
)}${msgGasLimit}${msgDataType}${strip0x(msgData)}`
|
|
||||||
|
|
||||||
// when
|
|
||||||
const {
|
|
||||||
sender,
|
|
||||||
executor,
|
|
||||||
txHash,
|
|
||||||
gasLimit,
|
|
||||||
dataType,
|
|
||||||
gasPrice,
|
|
||||||
gasPriceSpeed,
|
|
||||||
data
|
|
||||||
} = parseAMBMessage(message)
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(sender).to.be.equal(msgSender)
|
|
||||||
expect(executor).to.be.equal(msgExecutor)
|
|
||||||
expect(txHash).to.be.equal(msgTxHash)
|
|
||||||
expect(gasLimit).to.eq.BN(toBN(msgGasLimit))
|
|
||||||
expect(dataType).to.be.equal(msgDataType)
|
|
||||||
expect(gasPrice).to.be.equal(null)
|
|
||||||
expect(gasPriceSpeed).to.be.equal(null)
|
|
||||||
expect(data).to.be.equal(msgData)
|
|
||||||
})
|
|
||||||
it('should parse data type 01', () => {
|
|
||||||
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
|
||||||
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
|
||||||
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
|
||||||
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
|
||||||
const msgDataType = '01'
|
|
||||||
const msgGasPrice = '0000000000000000000000000000000000000000000000000000000165a0bc00'
|
|
||||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
|
||||||
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
|
||||||
msgTxHash
|
|
||||||
)}${msgGasLimit}${msgDataType}${msgGasPrice}${strip0x(msgData)}`
|
|
||||||
|
|
||||||
// when
|
|
||||||
const {
|
|
||||||
sender,
|
|
||||||
executor,
|
|
||||||
txHash,
|
|
||||||
gasLimit,
|
|
||||||
dataType,
|
|
||||||
gasPrice,
|
|
||||||
gasPriceSpeed,
|
|
||||||
data
|
|
||||||
} = parseAMBMessage(message)
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(sender).to.be.equal(msgSender)
|
|
||||||
expect(executor).to.be.equal(msgExecutor)
|
|
||||||
expect(txHash).to.be.equal(msgTxHash)
|
|
||||||
expect(gasLimit).to.eq.BN(toBN(msgGasLimit))
|
|
||||||
expect(dataType).to.be.equal(msgDataType)
|
|
||||||
expect(gasPrice).to.eq.BN(toBN(msgGasPrice))
|
|
||||||
expect(gasPriceSpeed).to.be.equal(null)
|
|
||||||
expect(data).to.be.equal(msgData)
|
|
||||||
})
|
|
||||||
it('should parse data type 02', () => {
|
|
||||||
const msgSender = '0x003667154bb32e42bb9e1e6532f19d187fa0082e'
|
|
||||||
const msgExecutor = '0xf4bef13f9f4f2b203faf0c3cbbaabe1afe056955'
|
|
||||||
const msgTxHash = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
|
||||||
const msgGasLimit = '000000000000000000000000000000000000000000000000000000005b877705'
|
|
||||||
const msgDataType = '02'
|
|
||||||
const msgGasPriceSpeed = '0x03'
|
|
||||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
|
||||||
const message = `0x${strip0x(msgSender)}${strip0x(msgExecutor)}${strip0x(
|
|
||||||
msgTxHash
|
|
||||||
)}${msgGasLimit}${msgDataType}${strip0x(msgGasPriceSpeed)}${strip0x(msgData)}`
|
|
||||||
|
|
||||||
// when
|
|
||||||
const {
|
|
||||||
sender,
|
|
||||||
executor,
|
|
||||||
txHash,
|
|
||||||
gasLimit,
|
|
||||||
dataType,
|
|
||||||
gasPrice,
|
|
||||||
gasPriceSpeed,
|
|
||||||
data
|
|
||||||
} = parseAMBMessage(message)
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(sender).to.be.equal(msgSender)
|
|
||||||
expect(executor).to.be.equal(msgExecutor)
|
|
||||||
expect(txHash).to.be.equal(msgTxHash)
|
|
||||||
expect(gasLimit).to.eq.BN(toBN(msgGasLimit))
|
|
||||||
expect(dataType).to.be.equal(msgDataType)
|
|
||||||
expect(gasPrice).to.be.equal(null)
|
|
||||||
expect(gasPriceSpeed).to.be.equal(ORACLE_GAS_PRICE_SPEEDS.STANDARD)
|
|
||||||
expect(data).to.be.equal(msgData)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,7 @@ const BigNumber = require('bignumber.js')
|
|||||||
const proxyquire = require('proxyquire')
|
const proxyquire = require('proxyquire')
|
||||||
const Web3Utils = require('web3-utils')
|
const Web3Utils = require('web3-utils')
|
||||||
const { addExtraGas, syncForEach, generateGasPriceOptions } = require('../src/utils/utils')
|
const { addExtraGas, syncForEach, generateGasPriceOptions } = require('../src/utils/utils')
|
||||||
const { GAS_PRICE_OPTIONS, ORACLE_GAS_PRICE_SPEEDS } = require('../src/utils/constants')
|
const { GAS_PRICE_OPTIONS, ORACLE_GAS_PRICE_SPEEDS } = require('../../commons')
|
||||||
|
|
||||||
chai.use(chaiAsPromised)
|
chai.use(chaiAsPromised)
|
||||||
const { expect } = chai
|
const { expect } = chai
|
||||||
|
Loading…
Reference in New Issue
Block a user