From 5e8858dc9dae2be6c2e13b2e454fe034acbd5465 Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Mon, 13 May 2024 18:46:18 -0400 Subject: [PATCH] fix: removed chainId field for legacy EIP155 transactions Signed-off-by: Logan Nguyen --- packages/relay/src/formatters.ts | 2 +- .../tests/acceptance/rpc_batch1.spec.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/relay/src/formatters.ts b/packages/relay/src/formatters.ts index b00ebddb93..6161ae00b3 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, + chainId: cr.chain_id === '0x' ? undefined : cr.chain_id, from: cr.from.substring(0, 42), gas: nanOrNumberTo0x(cr.gas_used), gasPrice: toNullIfEmptyHex(cr.gas_price), diff --git a/packages/server/tests/acceptance/rpc_batch1.spec.ts b/packages/server/tests/acceptance/rpc_batch1.spec.ts index 4d9733d0b2..8cf4234f5b 100644 --- a/packages/server/tests/acceptance/rpc_batch1.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch1.spec.ts @@ -957,6 +957,26 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () { expect(balanceChange.toString()).to.eq(Number(ONE_TINYBAR).toString()); }); + it('should return transaction result with no chainId field for legacy EIP155 transactions (with no chainId i.e. chainId=0x0)', async function () { + const transaction = { + ...defaultLegacyTransactionData, + to: parentContractAddress, + nonce: await relay.getAccountNonce(accounts[2].address, requestId), + gasPrice: await relay.gasPrice(requestId), + }; + const signedTx = await accounts[2].wallet.signTransaction(transaction); + const transactionHash = await relay.sendRawTransaction(signedTx, requestId); + + const transactionResult = await relay.call( + RelayCalls.ETH_ENDPOINTS.ETH_GET_TRANSACTION_BY_HASH, + [transactionHash], + requestId, + ); + + const result = Object.prototype.hasOwnProperty.call(transactionResult, 'chainId'); + expect(result).to.be.false; + }); + it('should fail "eth_sendRawTransaction" for Legacy transactions (with gas price too low)', async function () { const transaction = { ...defaultLegacyTransactionData,