From beea682c28cea561e6e0f2283d36eb12b1f6c25c Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Mon, 13 May 2024 22:13:02 -0400 Subject: [PATCH] test: added UT Signed-off-by: Logan Nguyen --- packages/relay/src/formatters.ts | 2 +- packages/relay/tests/lib/formatters.spec.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/relay/src/formatters.ts b/packages/relay/src/formatters.ts index 6161ae00b3..de5df597c4 100644 --- a/packages/relay/src/formatters.ts +++ b/packages/relay/src/formatters.ts @@ -147,7 +147,7 @@ const formatContractResult = (cr: any) => { const commonFields = { blockHash: toHash32(cr.block_hash), blockNumber: nullableNumberTo0x(cr.block_number), - chainId: cr.chain_id === '0x' ? undefined : cr.chain_id, + chainId: cr.chain_id === EMPTY_HEX ? undefined : cr.chain_id, from: cr.from.substring(0, 42), gas: nanOrNumberTo0x(cr.gas_used), gasPrice: toNullIfEmptyHex(cr.gas_price), diff --git a/packages/relay/tests/lib/formatters.spec.ts b/packages/relay/tests/lib/formatters.spec.ts index 78b190bf02..ef61d5c63a 100644 --- a/packages/relay/tests/lib/formatters.spec.ts +++ b/packages/relay/tests/lib/formatters.spec.ts @@ -252,6 +252,11 @@ describe('Formatters', () => { expect(formattedResult.yParity).to.equal('0x0'); expect(formattedResult.value).to.equal('0x0'); }); + + it('Should not include chainId field for legacy EIP155 transaction (tx.chainId=0x0)', () => { + const formattedResult: any = formatContractResult({ ...contractResult, chain_id: '0x' }); + expect(formattedResult.chainId).to.be.undefined; + }); }); describe('prepend0x', () => {