@ -1,5 +1,6 @@
import React from 'react' ;
import { act , screen } from '@testing-library/react' ;
import BigNumber from 'bignumber.js' ;
import {
EDIT _GAS _MODES ,
@ -10,9 +11,47 @@ import mockEstimates from '../../../../test/data/mock-estimates.json';
import mockState from '../../../../test/data/mock-state.json' ;
import { GasFeeContextProvider } from '../../../contexts/gasFee' ;
import configureStore from '../../../store/store' ;
import {
hexWEIToDecETH ,
decGWEIToHexWEI ,
} from '../../../helpers/utils/conversions.util' ;
import CancelSpeedupPopover from './cancel-speedup-popover' ;
const MAXFEEPERGAS _ABOVE _MOCK _MEDIUM _HEX = '0x174876e800' ;
const MAXGASCOST _ABOVE _MOCK _MEDIUM _BN = new BigNumber (
MAXFEEPERGAS _ABOVE _MOCK _MEDIUM _HEX ,
16 ,
) . times ( 21000 , 10 ) ;
const MAXGASCOST _ABOVE _MOCK _MEDIUM _BN _PLUS _TEN _PCT _HEX = MAXGASCOST _ABOVE _MOCK _MEDIUM _BN . times (
1.1 ,
10 ,
) . toString ( 16 ) ;
const EXPECTED _ETH _FEE _1 = hexWEIToDecETH (
MAXGASCOST _ABOVE _MOCK _MEDIUM _BN _PLUS _TEN _PCT _HEX ,
) ;
const MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _DEC _GWEI =
mockEstimates [ GAS _ESTIMATE _TYPES . FEE _MARKET ] . gasFeeEstimates . medium
. suggestedMaxFeePerGas ;
const MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _BN _WEI = new BigNumber (
decGWEIToHexWEI ( MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _DEC _GWEI ) ,
16 ,
) ;
const MAXFEEPERGAS _BELOW _MOCK _MEDIUM _HEX = MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _BN _WEI . div (
10 ,
10 ,
) . toString ( 16 ) ;
const EXPECTED _ETH _FEE _2 = hexWEIToDecETH (
MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _BN _WEI . times ( 21000 , 10 ) . toString ( 16 ) ,
) ;
const MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _HEX _WEI = MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _BN _WEI . toString (
16 ,
) ;
jest . mock ( '../../../store/actions' , ( ) => ( {
disconnectGasFeeEstimatePoller : jest . fn ( ) ,
getGasFeeTimeEstimate : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ,
@ -21,7 +60,6 @@ jest.mock('../../../store/actions', () => ({
. mockImplementation ( ( ) => Promise . resolve ( ) ) ,
addPollingTokenToAppState : jest . fn ( ) ,
removePollingTokenFromAppState : jest . fn ( ) ,
updateTransaction : ( ) => ( { type : 'UPDATE_TRANSACTION_PARAMS' } ) ,
updateTransactionGasFees : ( ) => ( { type : 'UPDATE_TRANSACTION_PARAMS' } ) ,
updatePreviousGasParams : ( ) => ( { type : 'UPDATE_TRANSACTION_PARAMS' } ) ,
createTransactionEventFragment : jest . fn ( ) ,
@ -34,7 +72,10 @@ jest.mock('../../../contexts/transaction-modal', () => ({
} ) ,
} ) ) ;
const render = ( props ) => {
const render = (
props ,
maxFeePerGas = MOCK _SUGGESTED _MEDIUM _MAXFEEPERGAS _HEX _WEI ,
) => {
const store = configureStore ( {
metamask : {
... mockState . metamask ,
@ -56,7 +97,7 @@ const render = (props) => {
userFeeLevel : 'tenPercentIncreased' ,
txParams : {
gas : '0x5208' ,
maxFeePerGas : '0x59682f10' ,
maxFeePerGas ,
maxPriorityFeePerGas : '0x59682f00' ,
} ,
} }
@ -80,12 +121,32 @@ describe('CancelSpeedupPopover', () => {
expect ( screen . queryByText ( '🚀Speed Up' ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should show correct gas values' , async ( ) => {
it ( 'should show correct gas values, increased by 10%, when initial initial gas value is above estimated medium ' , async ( ) => {
await act ( async ( ) =>
render ( {
editGasMode : EDIT _GAS _MODES . SPEED _UP ,
} ) ,
render (
{
editGasMode : EDIT _GAS _MODES . SPEED _UP ,
} ,
MAXFEEPERGAS _ABOVE _MOCK _MEDIUM _HEX ,
) ,
) ;
expect ( screen . queryAllByTitle ( '0.0000315 ETH' ) . length ) . toBeGreaterThan ( 0 ) ;
expect (
screen . queryAllByTitle ( ` ${ EXPECTED _ETH _FEE _1 } ETH ` ) . length ,
) . toBeGreaterThan ( 0 ) ;
} ) ;
it ( 'should show correct gas values, set to the estimated medium, when initial initial gas value is below estimated medium' , async ( ) => {
await act ( async ( ) =>
render (
{
editGasMode : EDIT _GAS _MODES . SPEED _UP ,
} ,
` 0x ${ MAXFEEPERGAS _BELOW _MOCK _MEDIUM _HEX } ` ,
) ,
) ;
expect (
screen . queryAllByTitle ( ` ${ EXPECTED _ETH _FEE _2 } ETH ` ) . length ,
) . toBeGreaterThan ( 0 ) ;
} ) ;
} ) ;