2023-01-27 19:28:03 +01:00
|
|
|
import { GasEstimateTypes } from '../../shared/constants/gas';
|
2022-07-01 15:58:35 +02:00
|
|
|
import { getInitialSendStateWithExistingTxState } from '../../test/jest/mocks';
|
2021-04-15 20:01:46 +02:00
|
|
|
import {
|
2018-08-16 14:28:27 +02:00
|
|
|
getCustomGasLimit,
|
|
|
|
getCustomGasPrice,
|
2021-03-02 23:19:56 +01:00
|
|
|
isCustomPriceSafe,
|
2021-03-05 18:32:09 +01:00
|
|
|
isCustomPriceExcessive,
|
2021-04-15 20:01:46 +02:00
|
|
|
} from './custom-gas';
|
2018-08-16 14:28:27 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('custom-gas selectors', () => {
|
|
|
|
describe('getCustomGasPrice()', () => {
|
|
|
|
it('should return gas.customData.price', () => {
|
2022-07-01 15:58:35 +02:00
|
|
|
const mockState = {
|
|
|
|
gas: { customData: { price: 'mockPrice' } },
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(getCustomGasPrice(mockState)).toStrictEqual('mockPrice');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('isCustomGasPriceSafe()', () => {
|
|
|
|
it('should return true for gas.customData.price 0x77359400', () => {
|
2021-03-02 23:19:56 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
low: '1',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-02 23:19:56 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x77359400' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceSafe(mockState)).toStrictEqual(true);
|
2021-03-02 23:19:56 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true for gas.customData.price null', () => {
|
2021-03-02 23:19:56 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
low: '1',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-02 23:19:56 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: null },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceSafe(mockState)).toStrictEqual(true);
|
2021-03-02 23:19:56 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true gas.customData.price undefined', () => {
|
2021-03-02 23:19:56 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
low: '1',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-02 23:19:56 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: undefined },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceSafe(mockState)).toStrictEqual(true);
|
2021-03-02 23:19:56 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false gas.basicEstimates.safeLow undefined', () => {
|
2021-03-02 23:19:56 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.none,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
low: undefined,
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-02 23:19:56 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x77359400' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceSafe(mockState)).toStrictEqual(false);
|
2021-03-02 23:19:56 +01:00
|
|
|
});
|
|
|
|
});
|
2018-08-16 14:28:27 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('isCustomPriceExcessive()', () => {
|
|
|
|
it('should return false for gas.customData.price null', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '150',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: null },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState)).toStrictEqual(false);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false gas.basicEstimates.fast undefined', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: undefined,
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x77359400' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState)).toStrictEqual(false);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false gas.basicEstimates.price 0x205d0bae00 (139)', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '139',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x205d0bae00' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState)).toStrictEqual(false);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false gas.basicEstimates.price 0x1bf08eb000 (120)', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '139',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x1bf08eb000' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState)).toStrictEqual(false);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false gas.basicEstimates.price 0x28bed01600 (175)', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '139',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x28bed01600' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState)).toStrictEqual(false);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true gas.basicEstimates.price 0x30e4f9b400 (210)', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '139',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: '0x30e4f9b400' },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState)).toStrictEqual(true);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false gas.basicEstimates.price 0x28bed01600 (175) (checkSend=true)', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '139',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2022-07-01 15:58:35 +02:00
|
|
|
send: getInitialSendStateWithExistingTxState({
|
2021-06-23 23:35:25 +02:00
|
|
|
gas: {
|
|
|
|
gasPrice: '0x28bed0160',
|
|
|
|
},
|
2022-07-01 15:58:35 +02:00
|
|
|
}),
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: null },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState, true)).toStrictEqual(false);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true gas.basicEstimates.price 0x30e4f9b400 (210) (checkSend=true)', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
const mockState = {
|
2021-07-16 18:06:32 +02:00
|
|
|
metamask: {
|
2023-01-27 19:28:03 +01:00
|
|
|
gasEstimateType: GasEstimateTypes.legacy,
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates: {
|
|
|
|
high: '139',
|
|
|
|
},
|
|
|
|
networkDetails: {
|
|
|
|
EIPS: {},
|
|
|
|
},
|
|
|
|
},
|
2022-07-01 15:58:35 +02:00
|
|
|
send: getInitialSendStateWithExistingTxState({
|
2021-06-23 23:35:25 +02:00
|
|
|
gas: {
|
|
|
|
gasPrice: '0x30e4f9b400',
|
|
|
|
},
|
2022-07-01 15:58:35 +02:00
|
|
|
}),
|
2021-03-05 18:32:09 +01:00
|
|
|
gas: {
|
|
|
|
customData: { price: null },
|
|
|
|
},
|
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(isCustomPriceExcessive(mockState, true)).toStrictEqual(true);
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getCustomGasLimit()', () => {
|
|
|
|
it('should return gas.customData.limit', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const mockState = { gas: { customData: { limit: 'mockLimit' } } };
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(getCustomGasLimit(mockState)).toStrictEqual('mockLimit');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|