mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-15 16:01:02 +00:00
Expose APIs for getting the info of a specific block
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
//! This crate implements all node interactions.
|
//! This crate implements all node interactions.
|
||||||
|
|
||||||
|
use alloy::eips::BlockNumberOrTag;
|
||||||
use alloy::primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, ChainId, U256};
|
use alloy::primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, ChainId, U256};
|
||||||
use alloy::rpc::types::trace::geth::{DiffMode, GethTrace};
|
use alloy::rpc::types::trace::geth::{DiffMode, GethTrace};
|
||||||
use alloy::rpc::types::{TransactionReceipt, TransactionRequest};
|
use alloy::rpc::types::{TransactionReceipt, TransactionRequest};
|
||||||
@@ -27,20 +28,20 @@ pub trait EthereumNode {
|
|||||||
|
|
||||||
// TODO: This is currently a u128 due to Kitchensink needing more than 64 bits for its gas limit
|
// TODO: This is currently a u128 due to Kitchensink needing more than 64 bits for its gas limit
|
||||||
// when we implement the changes to the gas we need to adjust this to be a u64.
|
// when we implement the changes to the gas we need to adjust this to be a u64.
|
||||||
/// Returns the gas limit of the last block.
|
/// Returns the gas limit of the specified block.
|
||||||
fn block_gas_limit(&self) -> Result<u128>;
|
fn block_gas_limit(&self, number: BlockNumberOrTag) -> Result<u128>;
|
||||||
|
|
||||||
/// Returns the coinbase of the last block.
|
/// Returns the coinbase of the specified block.
|
||||||
fn block_coinbase(&self) -> Result<Address>;
|
fn block_coinbase(&self, number: BlockNumberOrTag) -> Result<Address>;
|
||||||
|
|
||||||
/// Returns the difficulty of the last block.
|
/// Returns the difficulty of the specified block.
|
||||||
fn block_difficulty(&self) -> Result<U256>;
|
fn block_difficulty(&self, number: BlockNumberOrTag) -> Result<U256>;
|
||||||
|
|
||||||
/// Returns the hash of the last block.
|
/// Returns the hash of the specified block.
|
||||||
fn block_hash(&self) -> Result<BlockHash>;
|
fn block_hash(&self, number: BlockNumberOrTag) -> Result<BlockHash>;
|
||||||
|
|
||||||
/// Returns the timestamp of the last block,
|
/// Returns the timestamp of the specified block,
|
||||||
fn block_timestamp(&self) -> Result<BlockTimestamp>;
|
fn block_timestamp(&self, number: BlockNumberOrTag) -> Result<BlockTimestamp>;
|
||||||
|
|
||||||
/// Returns the number of the last block.
|
/// Returns the number of the last block.
|
||||||
fn last_block_number(&self) -> Result<BlockNumber>;
|
fn last_block_number(&self) -> Result<BlockNumber>;
|
||||||
|
|||||||
+15
-15
@@ -363,12 +363,12 @@ impl EthereumNode for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_gas_limit(&self) -> anyhow::Result<u128> {
|
fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.gas_limit as _)
|
.map(|block| block.header.gas_limit as _)
|
||||||
@@ -376,12 +376,12 @@ impl EthereumNode for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_coinbase(&self) -> anyhow::Result<Address> {
|
fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.beneficiary)
|
.map(|block| block.header.beneficiary)
|
||||||
@@ -389,12 +389,12 @@ impl EthereumNode for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_difficulty(&self) -> anyhow::Result<U256> {
|
fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.difficulty)
|
.map(|block| block.header.difficulty)
|
||||||
@@ -402,12 +402,12 @@ impl EthereumNode for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_hash(&self) -> anyhow::Result<BlockHash> {
|
fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.hash)
|
.map(|block| block.header.hash)
|
||||||
@@ -415,12 +415,12 @@ impl EthereumNode for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_timestamp(&self) -> anyhow::Result<BlockTimestamp> {
|
fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.timestamp)
|
.map(|block| block.header.timestamp)
|
||||||
@@ -583,7 +583,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let gas_limit = node.block_gas_limit();
|
let gas_limit = node.block_gas_limit(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let gas_limit = gas_limit.expect("Failed to get the gas limit");
|
let gas_limit = gas_limit.expect("Failed to get the gas limit");
|
||||||
@@ -596,7 +596,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let coinbase = node.block_coinbase();
|
let coinbase = node.block_coinbase(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let coinbase = coinbase.expect("Failed to get the coinbase");
|
let coinbase = coinbase.expect("Failed to get the coinbase");
|
||||||
@@ -609,7 +609,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let block_difficulty = node.block_difficulty();
|
let block_difficulty = node.block_difficulty(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let block_difficulty = block_difficulty.expect("Failed to get the block difficulty");
|
let block_difficulty = block_difficulty.expect("Failed to get the block difficulty");
|
||||||
@@ -622,7 +622,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let block_hash = node.block_hash();
|
let block_hash = node.block_hash(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let _ = block_hash.expect("Failed to get the block hash");
|
let _ = block_hash.expect("Failed to get the block hash");
|
||||||
@@ -634,7 +634,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let block_timestamp = node.block_timestamp();
|
let block_timestamp = node.block_timestamp(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let _ = block_timestamp.expect("Failed to get the block timestamp");
|
let _ = block_timestamp.expect("Failed to get the block timestamp");
|
||||||
|
|||||||
@@ -439,12 +439,12 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_gas_limit(&self) -> anyhow::Result<u128> {
|
fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.gas_limit)
|
.map(|block| block.header.gas_limit)
|
||||||
@@ -452,12 +452,12 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_coinbase(&self) -> anyhow::Result<Address> {
|
fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.beneficiary)
|
.map(|block| block.header.beneficiary)
|
||||||
@@ -465,12 +465,12 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_difficulty(&self) -> anyhow::Result<U256> {
|
fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.difficulty)
|
.map(|block| block.header.difficulty)
|
||||||
@@ -478,12 +478,12 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_hash(&self) -> anyhow::Result<BlockHash> {
|
fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.hash)
|
.map(|block| block.header.hash)
|
||||||
@@ -491,12 +491,12 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||||
fn block_timestamp(&self) -> anyhow::Result<BlockTimestamp> {
|
fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
|
||||||
let provider = self.provider();
|
let provider = self.provider();
|
||||||
BlockingExecutor::execute(async move {
|
BlockingExecutor::execute(async move {
|
||||||
provider
|
provider
|
||||||
.await?
|
.await?
|
||||||
.get_block_by_number(BlockNumberOrTag::Latest)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
||||||
.map(|block| block.header.timestamp)
|
.map(|block| block.header.timestamp)
|
||||||
@@ -1256,7 +1256,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let gas_limit = node.block_gas_limit();
|
let gas_limit = node.block_gas_limit(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let gas_limit = gas_limit.expect("Failed to get the gas limit");
|
let gas_limit = gas_limit.expect("Failed to get the gas limit");
|
||||||
@@ -1269,7 +1269,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let coinbase = node.block_coinbase();
|
let coinbase = node.block_coinbase(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let coinbase = coinbase.expect("Failed to get the coinbase");
|
let coinbase = coinbase.expect("Failed to get the coinbase");
|
||||||
@@ -1282,7 +1282,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let block_difficulty = node.block_difficulty();
|
let block_difficulty = node.block_difficulty(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let block_difficulty = block_difficulty.expect("Failed to get the block difficulty");
|
let block_difficulty = block_difficulty.expect("Failed to get the block difficulty");
|
||||||
@@ -1295,7 +1295,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let block_hash = node.block_hash();
|
let block_hash = node.block_hash(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let _ = block_hash.expect("Failed to get the block hash");
|
let _ = block_hash.expect("Failed to get the block hash");
|
||||||
@@ -1307,7 +1307,7 @@ mod tests {
|
|||||||
let (node, _temp_dir) = new_node();
|
let (node, _temp_dir) = new_node();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let block_timestamp = node.block_timestamp();
|
let block_timestamp = node.block_timestamp(BlockNumberOrTag::Latest);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
let _ = block_timestamp.expect("Failed to get the block timestamp");
|
let _ = block_timestamp.expect("Failed to get the block timestamp");
|
||||||
|
|||||||
Reference in New Issue
Block a user