Skip to content

Commit 6fc7a62

Browse files
feat(evm): pr reviews
1 parent 748c3ed commit 6fc7a62

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,41 @@ describe("common", () => {
1414
),
1515
},
1616
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>;
17+
const expectedResult = Buffer.from(intent.data.value);
1718

1819
const result = getCallData(intent);
19-
expect(result).toEqual(intent.data.value);
20+
expect(result).toEqual(expectedResult);
2021
});
2122

22-
it("should return empty buffer for native asset", () => {
23-
const intent = {
23+
it.each([
24+
{
2425
asset: {
2526
type: "native",
2627
},
27-
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>;
28-
29-
const result = getCallData(intent);
30-
expect(result).toEqual(Buffer.from([]));
31-
});
32-
33-
it("should return empty buffer for non native asset and no recipient", () => {
34-
const intent = {
28+
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>,
29+
{
3530
asset: {
3631
type: "erc20",
3732
},
38-
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>;
39-
40-
const result = getCallData(intent);
41-
expect(result).toEqual(Buffer.from([]));
42-
});
43-
44-
it("should return empty buffer for non native asset with recipient and no amount", () => {
45-
const intent = {
33+
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>,
34+
{
4635
asset: {
4736
type: "erc20",
4837
},
4938
recipient: "0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3",
50-
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>;
51-
39+
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>,
40+
{
41+
asset: {
42+
type: "erc20",
43+
},
44+
amount: 1n,
45+
} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>,
46+
])("should return empty buffer for invalid intent", intent => {
5247
const result = getCallData(intent);
5348
expect(result).toEqual(Buffer.from([]));
5449
});
5550

56-
it("should return calldata from contract for non native asset with a recipient", () => {
51+
it("should return calldata from contract for non native asset with a recipient and an amount", () => {
5752
const intent = {
5853
asset: {
5954
type: "erc20",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ 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) || !intent.recipient || !intent.amount
102+
return isNative(intent.asset) ||
103+
!intent.recipient ||
104+
intent.amount === undefined ||
105+
intent.amount === null
103106
? Buffer.from([])
104107
: getErc20Data(intent.recipient, intent.amount);
105108
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ describe("validateIntent", () => {
321321

322322
describe("gas", () => {
323323
describe("common", () => {
324+
beforeEach(() => {
325+
(computeGasLimitModule.computeIntrinsicGasLimit as jest.Mock).mockImplementation(
326+
jest.requireActual("./computeGasLimit").computeIntrinsicGasLimit,
327+
);
328+
// ... other setup
329+
});
330+
324331
describe.each([
325332
["a legacy intent", legacyIntent],
326333
["an eip1559 intent", eip1559Intent],

0 commit comments

Comments
 (0)