@@ -25,8 +25,14 @@ import { EvmCoinConfig, setCoinConfig } from "../config";
2525import ledgerExplorer from "../network/explorer/ledger";
2626import ledgerGasTracker from "../network/gasTracker/ledger";
2727import ledgerNode from "../network/node/ledger";
28+ import * as computeGasLimitModule from "./computeGasLimit";
2829import { validateIntent } from "./validateIntent";
2930
31+ jest.mock("./computeGasLimit", () => ({
32+ ...jest.requireActual("./computeGasLimit"),
33+ computeIntrinsicGasLimit: jest.fn(),
34+ }));
35+
3036function legacyIntent(
3137 intent: Omit<Partial<TransactionIntent>, "type">,
3238): TransactionIntent<MemoNotSupported, BufferTxData> {
@@ -106,7 +112,7 @@ describe("validateIntent", () => {
106112 jest.spyOn(ledgerNode, "getTransactionCount").mockResolvedValue(30);
107113 });
108114 afterEach(() => {
109- jest.restoreAllMocks ();
115+ jest.clearAllMocks ();
110116 });
111117
112118 describe("fee ratio", () => {
@@ -122,7 +128,10 @@ describe("validateIntent", () => {
122128 ])("%s with too high fees on a %s asset", async (_s, assetType, expectedWarnings) => {
123129 const res = await validateIntent(
124130 {} as CryptoCurrency,
125- eip1559Intent({ amount: 1n, asset: { type: assetType } }),
131+ eip1559Intent({
132+ amount: 1n,
133+ asset: { type: assetType },
134+ }),
126135 [{ value: 50n, asset: { type: "native" } }],
127136 {
128137 value: 2n,
@@ -479,13 +488,18 @@ describe("validateIntent", () => {
479488 });
480489
481490 it("detects gas limit being too low in a tx with an error", async () => {
491+ const intrinsicGasLimit = 21000n;
492+ (computeGasLimitModule.computeIntrinsicGasLimit as jest.Mock).mockReturnValue(
493+ intrinsicGasLimit,
494+ );
495+
482496 const res = await validateIntent(
483497 {} as CryptoCurrency,
484498 createIntent({}),
485499 [{ value: 50n, asset: { type: "native" } }],
486500 {
487501 value: 0n,
488- parameters: { gasLimit: 20000n }, // min should be 21000
502+ parameters: { gasLimit: intrinsicGasLimit - 1n }, // min should be 21000
489503 },
490504 );
491505
@@ -494,16 +508,23 @@ describe("validateIntent", () => {
494508 gasLimit: new GasLessThanEstimate(),
495509 }),
496510 );
511+
512+ expect(computeGasLimitModule.computeIntrinsicGasLimit).toHaveBeenCalledTimes(1);
497513 });
498514
499515 it("detects custom gas limit being too low in a tx with an error", async () => {
516+ const intrinsicGasLimit = 21000n;
517+ (computeGasLimitModule.computeIntrinsicGasLimit as jest.Mock).mockReturnValue(
518+ intrinsicGasLimit,
519+ );
520+
500521 const res = await validateIntent(
501522 {} as CryptoCurrency,
502523 createIntent({}),
503524 [{ value: 50n, asset: { type: "native" } }],
504525 {
505526 value: 0n,
506- parameters: { customGasLimit: 20000n }, // min should be 21000
527+ parameters: { customGasLimit: intrinsicGasLimit - 1n },
507528 },
508529 );
509530
@@ -512,6 +533,8 @@ describe("validateIntent", () => {
512533 gasLimit: new GasLessThanEstimate(),
513534 }),
514535 );
536+
537+ expect(computeGasLimitModule.computeIntrinsicGasLimit).toHaveBeenCalledTimes(1);
515538 });
516539
517540 it("detects customGasLimit being lower than gasLimit with a warning", async () => {
0 commit comments