Skip to content

Commit dc1e556

Browse files
wip
1 parent 32c40b7 commit dc1e556

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

libs/coin-modules/coin-evm/src/logic/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export function getErc20Data(recipient: string, amount: bigint): Buffer {
9999
export function getCallData(intent: TransactionIntent<MemoNotSupported, BufferTxData>): Buffer {
100100
const data = intent.data?.value;
101101
if (Buffer.isBuffer(data) && data.length) return data;
102-
return isNative(intent.asset) ? Buffer.from([]) : getErc20Data(intent.recipient, intent.amount);
102+
return isNative(intent.asset) || !intent.recipient
103+
? Buffer.from([])
104+
: getErc20Data(intent.recipient, intent.amount);
103105
}
104106

105107
export async function prepareUnsignedTxParams(

libs/coin-modules/coin-evm/src/logic/validateIntent.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ import { EvmCoinConfig, setCoinConfig } from "../config";
2525
import ledgerExplorer from "../network/explorer/ledger";
2626
import ledgerGasTracker from "../network/gasTracker/ledger";
2727
import ledgerNode from "../network/node/ledger";
28+
import * as computeGasLimitModule from "./computeGasLimit";
2829
import { validateIntent } from "./validateIntent";
2930

31+
jest.mock("./computeGasLimit", () => ({
32+
...jest.requireActual("./computeGasLimit"),
33+
computeIntrinsicGasLimit: jest.fn(),
34+
}));
35+
3036
function 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 () => {

libs/coin-modules/coin-evm/src/logic/validateIntent.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ async function validateGas(
147147
callData,
148148
);
149149

150-
console.log("callData: ", callData);
151-
console.log("callData hex: ", "0x" + callData.toString("hex"));
152-
console.log("_intrinsicGasLimit: ", intrinsicGasLimit);
153-
console.log("intent: ", intent);
154-
console.log("calldata from intent: ", intent.data.value);
155-
156150
// Gas Limit
157151
if (typeof customGasLimit === "bigint") {
158152
if (customGasLimit === 0n) {

libs/coin-modules/coin-evm/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
"include": [
2020
"src/**/*"
2121
]
22-
}
22+
}

0 commit comments

Comments
 (0)