1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Pass correct params to fetchEstimatedL1Fee in the swaps controller (#18634)

This commit is contained in:
Dan J Miller 2023-04-18 12:15:18 -02:30 committed by GitHub
parent 66767d981c
commit e6f73f5fe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 2 deletions

View File

@ -304,6 +304,7 @@ export default class SwapsController {
Object.values(newQuotes).map(async (quote) => {
if (quote.trade) {
const multiLayerL1TradeFeeTotal = await fetchEstimatedL1Fee(
chainId,
{
txParams: quote.trade,
chainId,

View File

@ -156,12 +156,12 @@ const getEIP1559GasFeeEstimatesStub = sandbox.stub(() => {
describe('SwapsController', function () {
let provider;
const getSwapsController = () => {
const getSwapsController = (_provider = provider) => {
return new SwapsController({
getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
networkController: getMockNetworkController(),
onNetworkDidChange: sinon.stub(),
provider,
provider: _provider,
getProviderConfig: MOCK_GET_PROVIDER_CONFIG,
getTokenRatesState: MOCK_TOKEN_RATES_STORE,
fetchTradesInfo: fetchTradesInfoStub,
@ -722,6 +722,72 @@ describe('SwapsController', function () {
);
});
it('calls returns the correct quotes on the optimism chain', async function () {
fetchTradesInfoStub.resetHistory();
const OPTIMISM_MOCK_FETCH_METADATA = {
...MOCK_FETCH_METADATA,
chainId: CHAIN_IDS.OPTIMISM,
};
const optimismProviderResultStub = {
// 1 gwei
eth_gasPrice: '0x0de0b6b3a7640000',
// by default, all accounts are external accounts (not contracts)
eth_getCode: '0x',
eth_call:
'0x000000000000000000000000000000000000000000000000000103c18816d4e8',
};
const optimismProvider = createTestProviderTools({
scaffold: optimismProviderResultStub,
networkId: 10,
chainId: 10,
}).provider;
swapsController = getSwapsController(optimismProvider);
fetchTradesInfoStub.resolves(getMockQuotes());
// Make it so approval is not required
sandbox
.stub(swapsController, '_getERC20Allowance')
.resolves(BigNumber.from(1));
const [newQuotes] = await swapsController.fetchAndSetQuotes(
MOCK_FETCH_PARAMS,
OPTIMISM_MOCK_FETCH_METADATA,
);
assert.deepStrictEqual(newQuotes[TEST_AGG_ID_BEST], {
...getMockQuotes()[TEST_AGG_ID_BEST],
sourceTokenInfo: undefined,
destinationTokenInfo: {
symbol: 'FOO',
decimals: 18,
},
isBestQuote: true,
// TODO: find a way to calculate these values dynamically
gasEstimate: 2000000,
gasEstimateWithRefund: '0xb8cae',
savings: {
fee: '-0.061067',
metaMaskFee: '0.5050505050505050505',
performance: '6',
total: '5.4338824949494949495',
medianMetaMaskFee: '0.44444444444444444444',
},
ethFee: '0.113822',
multiLayerL1TradeFeeTotal: '0x0103c18816d4e8',
overallValueOfQuote: '49.886178',
metaMaskFeeInEth: '0.5050505050505050505',
ethValueOfTokens: '50',
});
assert.strictEqual(
fetchTradesInfoStub.calledOnceWithExactly(MOCK_FETCH_PARAMS, {
...OPTIMISM_MOCK_FETCH_METADATA,
}),
true,
);
});
it('performs the allowance check', async function () {
fetchTradesInfoStub.resolves(getMockQuotes());