From 60559385141be193484e03e6f259e5191985db94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Grze=C5=9Bkiewicz?= Date: Mon, 23 Sep 2024 13:31:08 +0200 Subject: [PATCH] fix(api_server): fix blob_gas length (#2673) Discovered during testing Gateway integration (our own asserts from query.rs started being triggered by our eth api implementation :D ) --------- Co-authored-by: perekopskiy --- core/node/api_server/src/web3/namespaces/eth.rs | 9 +++++---- core/tests/ts-integration/tests/api/web3.test.ts | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/node/api_server/src/web3/namespaces/eth.rs b/core/node/api_server/src/web3/namespaces/eth.rs index fda5ff6f06be..0bc0bce30d73 100644 --- a/core/node/api_server/src/web3/namespaces/eth.rs +++ b/core/node/api_server/src/web3/namespaces/eth.rs @@ -690,15 +690,16 @@ impl EthNamespace { base_fee_per_gas.len() ]); + // `base_fee_per_gas` for next L2 block cannot be calculated, appending last fee as a placeholder. + base_fee_per_gas.push(*base_fee_per_gas.last().unwrap()); + // We do not support EIP-4844, but per API specification we should return 0 for pre EIP-4844 blocks. let base_fee_per_blob_gas = vec![U256::zero(); base_fee_per_gas.len()]; - let blob_gas_used_ratio = vec![0.0; base_fee_per_gas.len()]; + let blob_gas_used_ratio = vec![0.0; gas_used_ratio.len()]; - // `base_fee_per_gas` for next L2 block cannot be calculated, appending last fee as a placeholder. - base_fee_per_gas.push(*base_fee_per_gas.last().unwrap()); Ok(FeeHistory { inner: web3::FeeHistory { - oldest_block: zksync_types::web3::BlockNumber::Number(oldest_block.into()), + oldest_block: web3::BlockNumber::Number(oldest_block.into()), base_fee_per_gas, gas_used_ratio, reward, diff --git a/core/tests/ts-integration/tests/api/web3.test.ts b/core/tests/ts-integration/tests/api/web3.test.ts index 79789e744471..6f1b6c3aa6b8 100644 --- a/core/tests/ts-integration/tests/api/web3.test.ts +++ b/core/tests/ts-integration/tests/api/web3.test.ts @@ -843,6 +843,10 @@ describe('web3 API compatibility tests', () => { expect(parseInt(response.oldestBlock)).toEqual(receipt.blockNumber - 1); expect(response.baseFeePerGas).toHaveLength(3); + expect(response.baseFeePerBlobGas).toHaveLength(3); + expect(response.gasUsedRatio).toHaveLength(2); + expect(response.blobGasUsedRatio).toHaveLength(2); + expect(response.l2PubdataPrice).toHaveLength(2); for (let i = 0; i < 2; i += 1) { const expectedBaseFee = (await alice.provider.getBlock(receipt.blockNumber - 1 + i)).baseFeePerGas; expect(BigInt(response.baseFeePerGas[i])).toEqual(expectedBaseFee);