Skip to content

Commit

Permalink
fix: removed chainId field for legacy EIP155 transactions
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
  • Loading branch information
quiet-node committed May 13, 2024
1 parent 88b6eea commit 5e8858d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/relay/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
20 changes: 20 additions & 0 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5e8858d

Please sign in to comment.