2022-01-06 03:47:26 +01:00
|
|
|
import { PRIORITY_LEVELS } from '../../../shared/constants/gas';
|
|
|
|
|
|
|
|
import {
|
|
|
|
addTenPercent,
|
|
|
|
gasEstimateGreaterThanGasUsedPlusTenPercent,
|
2022-03-11 19:59:58 +01:00
|
|
|
formatGasFeeOrFeeRange,
|
2022-01-06 03:47:26 +01:00
|
|
|
} from './gas';
|
|
|
|
|
|
|
|
describe('Gas utils', () => {
|
|
|
|
describe('gasEstimateGreaterThanGasUsedPlusTenPercent', () => {
|
|
|
|
const compareGas = (estimateValues) => {
|
|
|
|
return gasEstimateGreaterThanGasUsedPlusTenPercent(
|
|
|
|
{
|
2022-01-26 19:18:43 +01:00
|
|
|
maxFeePerGas: '0x59682f10',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
2022-01-06 03:47:26 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
medium: estimateValues,
|
|
|
|
},
|
|
|
|
PRIORITY_LEVELS.MEDIUM,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should return true if gas used in transaction + 10% is greater that estimate', () => {
|
|
|
|
const result = compareGas({
|
|
|
|
suggestedMaxPriorityFeePerGas: '7',
|
|
|
|
suggestedMaxFeePerGas: '70',
|
|
|
|
});
|
|
|
|
expect(result).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if gas used in transaction + 10% is less that estimate', () => {
|
|
|
|
const result = compareGas({
|
|
|
|
suggestedMaxPriorityFeePerGas: '.5',
|
|
|
|
suggestedMaxFeePerGas: '1',
|
|
|
|
});
|
|
|
|
expect(result).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addTenPercent', () => {
|
|
|
|
it('should add 10% to hex value passed', () => {
|
|
|
|
const result = addTenPercent('0x59682f00');
|
|
|
|
expect(result).toStrictEqual('0x62590080');
|
|
|
|
});
|
|
|
|
it('should return undefined if undefined value is passed', () => {
|
|
|
|
const result = addTenPercent(undefined);
|
|
|
|
expect(result).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
2022-03-11 19:59:58 +01:00
|
|
|
|
|
|
|
describe('formatGasFeeOrFeeRange', () => {
|
|
|
|
describe('given a singular fee', () => {
|
|
|
|
it('should return a string "X GWEI" where X is the fee rounded to the given precision', () => {
|
|
|
|
expect(formatGasFeeOrFeeRange('23.43', { precision: 1 })).toStrictEqual(
|
|
|
|
'23.4 GWEI',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('given an array of two fees', () => {
|
|
|
|
describe('given a single precision', () => {
|
|
|
|
it('should return a string "X - Y GWEI" where X and Y are the fees rounded to the given precision', () => {
|
|
|
|
expect(
|
|
|
|
formatGasFeeOrFeeRange(['23.43', '83.9342'], { precision: 1 }),
|
|
|
|
).toStrictEqual('23.4 - 83.9 GWEI');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('given two precisions', () => {
|
|
|
|
it('should return a string "X - Y GWEI" where X and Y are the fees rounded to the given precisions', () => {
|
|
|
|
expect(
|
|
|
|
formatGasFeeOrFeeRange(['23.43', '83.9342'], { precision: [1, 0] }),
|
|
|
|
).toStrictEqual('23.4 - 84 GWEI');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('given more than two precisions', () => {
|
|
|
|
it('should ignore precisions past 2', () => {
|
|
|
|
expect(
|
|
|
|
formatGasFeeOrFeeRange(['23.43', '83.9342'], {
|
|
|
|
precision: [1, 0, 999],
|
|
|
|
}),
|
|
|
|
).toStrictEqual('23.4 - 84 GWEI');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('given an array of more than two fees', () => {
|
|
|
|
it('should ignore fees past two', () => {
|
|
|
|
expect(
|
|
|
|
formatGasFeeOrFeeRange(['23.43', '83.9342', '300.3414'], {
|
|
|
|
precision: 1,
|
|
|
|
}),
|
|
|
|
).toStrictEqual('23.4 - 83.9 GWEI');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('if the fee is null', () => {
|
|
|
|
it('should return null', () => {
|
|
|
|
expect(formatGasFeeOrFeeRange(null, { precision: 1 })).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('if the fee is undefined', () => {
|
|
|
|
it('should return null', () => {
|
|
|
|
expect(formatGasFeeOrFeeRange(null, { precision: 1 })).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-01-06 03:47:26 +01:00
|
|
|
});
|