Add a way to get the coinbase address

This commit is contained in:
Omar Abdulla
2025-07-14 22:48:45 +03:00
parent 61540741e1
commit 02547b62ee
3 changed files with 62 additions and 9 deletions
+26
View File
@@ -374,6 +374,19 @@ impl EthereumNode for Instance {
.map(|block| block.header.gas_limit as _)
})?
}
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
fn coinbase(&self) -> anyhow::Result<Address> {
let provider = self.provider();
BlockingExecutor::execute(async move {
provider
.await?
.get_block_by_number(BlockNumberOrTag::Latest)
.await?
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.map(|block| block.header.beneficiary)
})?
}
}
impl Node for Instance {
@@ -529,4 +542,17 @@ mod tests {
let gas_limit = gas_limit.expect("Failed to get the gas limit");
assert_eq!(gas_limit, u32::MAX as u128)
}
#[test]
fn can_get_coinbase_from_node() {
// Arrange
let (node, _temp_dir) = new_node();
// Act
let coinbase = node.coinbase();
// Assert
let coinbase = coinbase.expect("Failed to get the gas limit");
assert_eq!(coinbase, Address::new([0xFF; 20]))
}
}
+26
View File
@@ -450,6 +450,19 @@ impl EthereumNode for KitchensinkNode {
.map(|block| block.header.gas_limit)
})?
}
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
fn coinbase(&self) -> anyhow::Result<Address> {
let provider = self.provider();
BlockingExecutor::execute(async move {
provider
.await?
.get_block_by_number(BlockNumberOrTag::Latest)
.await?
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.map(|block| block.header.beneficiary)
})?
}
}
impl Node for KitchensinkNode {
@@ -1202,4 +1215,17 @@ mod tests {
let gas_limit = gas_limit.expect("Failed to get the gas limit");
assert_eq!(gas_limit, 52430300000000000000)
}
#[test]
fn can_get_coinbase_from_node() {
// Arrange
let (node, _temp_dir) = new_node();
// Act
let coinbase = node.coinbase();
// Assert
let coinbase = coinbase.expect("Failed to get the gas limit");
assert_eq!(coinbase, Address::ZERO)
}
}