mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
tests - tx-utils gasBuffer calc - fix bug and user easier numbers
This commit is contained in:
parent
ff49e5e5cf
commit
16b5f4a210
@ -14,8 +14,8 @@ describe('txUtils', function() {
|
|||||||
|
|
||||||
describe('addGasBuffer', function() {
|
describe('addGasBuffer', function() {
|
||||||
it('multiplies by 1.5, when within block gas limit', function() {
|
it('multiplies by 1.5, when within block gas limit', function() {
|
||||||
// naive estimatedGas: 0x123fad (~1.2 mil)
|
// naive estimatedGas: 0x16e360 (1.5 mil)
|
||||||
const inputHex = '0x123fad'
|
const inputHex = '0x16e360'
|
||||||
// dummy gas limit: 0x3d4c52 (4 mil)
|
// dummy gas limit: 0x3d4c52 (4 mil)
|
||||||
const blockGasLimitHex = '0x3d4c52'
|
const blockGasLimitHex = '0x3d4c52'
|
||||||
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
|
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
|
||||||
@ -26,8 +26,8 @@ describe('txUtils', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('uses original estimatedGas, when above block gas limit', function() {
|
it('uses original estimatedGas, when above block gas limit', function() {
|
||||||
// naive estimatedGas: 0x123fad (~1.2 mil)
|
// naive estimatedGas: 0x16e360 (1.5 mil)
|
||||||
const inputHex = '0x123fad'
|
const inputHex = '0x16e360'
|
||||||
// dummy gas limit: 0x0f4240 (1 mil)
|
// dummy gas limit: 0x0f4240 (1 mil)
|
||||||
const blockGasLimitHex = '0x0f4240'
|
const blockGasLimitHex = '0x0f4240'
|
||||||
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
|
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
|
||||||
@ -37,16 +37,18 @@ describe('txUtils', function() {
|
|||||||
assert(outputBn.eq(expectedBn), 'returns the original estimatedGas value')
|
assert(outputBn.eq(expectedBn), 'returns the original estimatedGas value')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('buffers up to block gas limit', function() {
|
it('buffers up to reccomend gas limit reccomended ceiling', function() {
|
||||||
// naive estimatedGas: 0x123fad (~1.2 mil)
|
// naive estimatedGas: 0x16e360 (1.5 mil)
|
||||||
const inputHex = '0x1e8480'
|
const inputHex = '0x16e360'
|
||||||
// dummy gas limit: 0x1e8480 (2 mil)
|
// dummy gas limit: 0x1e8480 (2 mil)
|
||||||
const blockGasLimitHex = '0x1e8480'
|
const blockGasLimitHex = '0x1e8480'
|
||||||
|
const blockGasLimitBn = hexToBn(blockGasLimitHex)
|
||||||
|
const ceilGasLimitBn = blockGasLimitBn.muln(0.9)
|
||||||
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
|
const output = txUtils.addGasBuffer(inputHex, blockGasLimitHex)
|
||||||
const inputBn = hexToBn(inputHex)
|
// const inputBn = hexToBn(inputHex)
|
||||||
const outputBn = hexToBn(output)
|
// const outputBn = hexToBn(output)
|
||||||
const expectedBn = hexToBn(blockGasLimitHex)
|
const expectedHex = bnToHex(ceilGasLimitBn)
|
||||||
assert(outputBn.eq(expectedBn), 'returns the block gas limit value')
|
assert.equal(output, expectedHex, 'returns the gas limit reccomended ceiling value')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -55,4 +57,8 @@ describe('txUtils', function() {
|
|||||||
|
|
||||||
function hexToBn(inputHex) {
|
function hexToBn(inputHex) {
|
||||||
return new BN(ethUtil.stripHexPrefix(inputHex), 16)
|
return new BN(ethUtil.stripHexPrefix(inputHex), 16)
|
||||||
|
}
|
||||||
|
|
||||||
|
function bnToHex(inputBn) {
|
||||||
|
return ethUtil.addHexPrefix(inputBn.toString(16))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user