Skip to content

Commit

Permalink
fix: return transaction.feesStrategy gasOption instead of the medium …
Browse files Browse the repository at this point in the history
…value (#7652)

* fix: return transaction.feesStrategy instead of medium

* chore: tests
  • Loading branch information
CremaFR authored Aug 27, 2024
1 parent 3de9eb6 commit e7db725
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-eyes-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/coin-evm": minor
---

fix evm getFeeData to return requested option value
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe("EVM Family", () => {
}
});

it("should return the medium value of the Ledger explorers gas tracker", async () => {
it("should return the fee data based on the transaction's feesStrategy", async () => {
jest.spyOn(LEDGER_GAS_TRACKER, "getGasOptions").mockImplementation(async () => ({
slow: {
maxFeePerGas: new BigNumber(1),
Expand All @@ -408,16 +408,64 @@ describe("EVM Family", () => {
},
}));

const legacyFeeData = await LEDGER_API.getFeeData(currency, { type: 0 } as any);
const eip1559FeeData = await LEDGER_API.getFeeData(currency, { type: 2 } as any);

expect(legacyFeeData).toEqual({
const slowFeeData = await LEDGER_API.getFeeData(currency, {
type: 2,
feesStrategy: "slow",
} as any);
const mediumFeeData = await LEDGER_API.getFeeData(currency, {
type: 2,
feesStrategy: "medium",
} as any);
const fastFeeData = await LEDGER_API.getFeeData(currency, {
type: 2,
feesStrategy: "fast",
} as any);

expect(slowFeeData).toEqual({
maxFeePerGas: new BigNumber(1),
maxPriorityFeePerGas: new BigNumber(2),
gasPrice: new BigNumber(3),
nextBaseFee: new BigNumber(4),
});
expect(mediumFeeData).toEqual({
maxFeePerGas: new BigNumber(5),
maxPriorityFeePerGas: new BigNumber(6),
gasPrice: new BigNumber(7),
nextBaseFee: new BigNumber(8),
});
expect(eip1559FeeData).toEqual({
expect(fastFeeData).toEqual({
maxFeePerGas: new BigNumber(9),
maxPriorityFeePerGas: new BigNumber(10),
gasPrice: new BigNumber(11),
nextBaseFee: new BigNumber(12),
});
});

it("should return medium fee data if feesStrategy is not provided", async () => {
jest.spyOn(LEDGER_GAS_TRACKER, "getGasOptions").mockImplementation(async () => ({
slow: {
maxFeePerGas: new BigNumber(1),
maxPriorityFeePerGas: new BigNumber(2),
gasPrice: new BigNumber(3),
nextBaseFee: new BigNumber(4),
},
medium: {
maxFeePerGas: new BigNumber(5),
maxPriorityFeePerGas: new BigNumber(6),
gasPrice: new BigNumber(7),
nextBaseFee: new BigNumber(8),
},
fast: {
maxFeePerGas: new BigNumber(9),
maxPriorityFeePerGas: new BigNumber(10),
gasPrice: new BigNumber(11),
nextBaseFee: new BigNumber(12),
},
}));

const feeData = await LEDGER_API.getFeeData(currency, { type: 2 } as any);

expect(feeData).toEqual({
maxFeePerGas: new BigNumber(5),
maxPriorityFeePerGas: new BigNumber(6),
gasPrice: new BigNumber(7),
Expand Down
4 changes: 2 additions & 2 deletions libs/coin-modules/coin-evm/src/api/node/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const getFeeData: NodeApi["getFeeData"] = async (currency, transaction) =
throw new LedgerNodeUsedIncorrectly();
}

const { medium } = await getGasOptions({
const options = await getGasOptions({
currency: {
...currency,
ethereumLikeInfo: {
Expand All @@ -249,7 +249,7 @@ export const getFeeData: NodeApi["getFeeData"] = async (currency, transaction) =
},
});

return medium;
return options?.[transaction.feesStrategy as keyof typeof options] ?? options.medium;
};

/**
Expand Down

0 comments on commit e7db725

Please sign in to comment.