diff --git a/lib/eth/tx.rb b/lib/eth/tx.rb index 500255f3..765e91f9 100644 --- a/lib/eth/tx.rb +++ b/lib/eth/tx.rb @@ -210,7 +210,9 @@ def validate_params(fields) if fields[:nonce].nil? or fields[:nonce] < 0 raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!" end - if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT + if fields[:gas_limit].nil? or + fields[:gas_limit] < DEFAULT_GAS_LIMIT or + (fields[:gas_limit] > BLOCK_GAS_LIMIT and fields[:chain_id] == Chain::ETHEREUM) raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!" end unless fields[:value] >= 0 diff --git a/spec/eth/tx/eip1559_spec.rb b/spec/eth/tx/eip1559_spec.rb index 58dc5b6d..a83bd05b 100644 --- a/spec/eth/tx/eip1559_spec.rb +++ b/spec/eth/tx/eip1559_spec.rb @@ -102,6 +102,7 @@ priority_fee: 0, max_gas_fee: Unit::GWEI, gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::ETHEREUM, }) }.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!" expect { diff --git a/spec/eth/tx/eip2930_spec.rb b/spec/eth/tx/eip2930_spec.rb index 4eefb7e1..8ae81466 100644 --- a/spec/eth/tx/eip2930_spec.rb +++ b/spec/eth/tx/eip2930_spec.rb @@ -101,6 +101,7 @@ nonce: 0, gas_price: Unit::GWEI, gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::ETHEREUM, }) }.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!" expect { diff --git a/spec/eth/tx/legacy_spec.rb b/spec/eth/tx/legacy_spec.rb index 72459804..3a7795f7 100644 --- a/spec/eth/tx/legacy_spec.rb +++ b/spec/eth/tx/legacy_spec.rb @@ -128,8 +128,17 @@ nonce: 0, gas_price: Unit::GWEI, gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::ETHEREUM, }) }.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!" + expect { + Tx.new({ + nonce: 0, + gas_price: Unit::GWEI, + gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::OPTIMISM, + }) + }.not_to raise_error # Block gas limit is only enforced in Ethereum mainnet expect { Tx.new({ nonce: -1,