|
| 1 | +import { BRIDGE_PREFERRED_GAS_ESTIMATE } from '@metamask/bridge-controller'; |
1 | 2 | import type { GasFeeState } from '@metamask/gas-fee-controller'; |
2 | 3 | import type { FeeMarketGasFeeEstimates } from '@metamask/transaction-controller'; |
3 | 4 | import { GasFeeEstimateLevel } from '@metamask/transaction-controller'; |
@@ -45,23 +46,50 @@ describe('gas calculation utils', () => { |
45 | 46 | }); |
46 | 47 | }); |
47 | 48 |
|
48 | | - it('should handle missing high property in txGasFeeEstimates', () => { |
49 | | - // Call the function |
| 49 | + it('should handle missing property in txGasFeeEstimates', () => { |
50 | 50 | const result = getTxGasEstimates({ |
51 | 51 | txGasFeeEstimates: {} as never, |
52 | 52 | networkGasFeeEstimates: { |
53 | 53 | estimatedBaseFee: '0.00000001', |
54 | 54 | } as GasFeeState['gasFeeEstimates'], |
55 | 55 | }); |
56 | 56 |
|
57 | | - // Verify the result |
58 | 57 | expect(result).toStrictEqual({ |
59 | 58 | baseAndPriorityFeePerGas: undefined, |
60 | 59 | maxFeePerGas: undefined, |
61 | 60 | maxPriorityFeePerGas: undefined, |
62 | 61 | }); |
63 | 62 | }); |
64 | 63 |
|
| 64 | + it('should use Bridge preferred gas estimate as gas estimates', () => { |
| 65 | + const estimates = { |
| 66 | + type: 'fee-market', |
| 67 | + [GasFeeEstimateLevel.Low]: { |
| 68 | + maxFeePerGas: '0xLOW', |
| 69 | + maxPriorityFeePerGas: '0xLOW_PRIORITY', |
| 70 | + }, |
| 71 | + [GasFeeEstimateLevel.Medium]: { |
| 72 | + maxFeePerGas: '0xMEDIUM', |
| 73 | + maxPriorityFeePerGas: '0xMEDIUM_PRIORITY', |
| 74 | + }, |
| 75 | + [GasFeeEstimateLevel.High]: { |
| 76 | + maxFeePerGas: '0xHIGH', |
| 77 | + maxPriorityFeePerGas: '0xHIGH_PRIORITY', |
| 78 | + }, |
| 79 | + } as FeeMarketGasFeeEstimates; |
| 80 | + const result = getTxGasEstimates({ |
| 81 | + txGasFeeEstimates: estimates, |
| 82 | + networkGasFeeEstimates: mockNetworkGasFeeEstimates, |
| 83 | + }); |
| 84 | + |
| 85 | + expect(result.maxFeePerGas).toBe( |
| 86 | + estimates[BRIDGE_PREFERRED_GAS_ESTIMATE]?.maxFeePerGas, |
| 87 | + ); |
| 88 | + expect(result.maxPriorityFeePerGas).toBe( |
| 89 | + estimates[BRIDGE_PREFERRED_GAS_ESTIMATE]?.maxPriorityFeePerGas, |
| 90 | + ); |
| 91 | + }); |
| 92 | + |
65 | 93 | it('should use default estimatedBaseFee when not provided in networkGasFeeEstimates', () => { |
66 | 94 | // Mock data |
67 | 95 |
|
@@ -143,7 +171,7 @@ describe('gas calculation utils', () => { |
143 | 171 | }); |
144 | 172 | const mockEstimateGasFeeFn = jest.fn().mockResolvedValueOnce({ |
145 | 173 | estimates: { |
146 | | - [GasFeeEstimateLevel.High]: { |
| 174 | + [GasFeeEstimateLevel.Medium]: { |
147 | 175 | maxFeePerGas: '0x1234567890', |
148 | 176 | maxPriorityFeePerGas: '0x1234567890', |
149 | 177 | }, |
|
0 commit comments