Introduce a geth platform

This commit is contained in:
Omar Abdulla
2025-09-17 19:54:50 +03:00
parent 9e4f2e95f1
commit ac0f4e0cf2
8 changed files with 199 additions and 134 deletions
+101 -7
View File
@@ -3,12 +3,27 @@
//! This crate defines the testing configuration and
//! provides a helper utility to execute tests.
use std::{
pin::Pin,
thread::{self, JoinHandle},
};
use alloy::genesis::Genesis;
use anyhow::Context as _;
use revive_dt_common::types::*;
use revive_dt_compiler::{DynSolidityCompiler, SolidityCompiler, revive_resolc, solc};
use revive_dt_compiler::{
DynSolidityCompiler, SolidityCompiler, revive_resolc,
solc::{self, Solc},
};
use revive_dt_config::*;
use revive_dt_format::traits::ResolverApi;
use revive_dt_node::{Node, geth, kitchensink::KitchensinkNode};
use revive_dt_node::{
Node,
geth::{self, GethNode},
kitchensink::KitchensinkNode,
};
use revive_dt_node_interaction::EthereumNode;
use tracing::info;
pub mod driver;
@@ -48,6 +63,7 @@ impl Platform for Kitchensink {
}
/// A trait that describes the interface for the platforms that are supported by the tool.
#[allow(clippy::type_complexity)]
pub trait DynPlatform {
/// Returns the identifier of this platform. This is a combination of the node and the compiler
/// used.
@@ -87,14 +103,92 @@ pub trait DynPlatform {
+ Sync
+ Clone
+ 'static,
) -> Box<dyn EthereumNode>;
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>>;
/// Creates a new compiler for the provided platform
fn new_compiler(
fn new_compiler<'a>(
&self,
context: impl AsRef<SolcConfiguration>
+ AsRef<ResolcConfiguration>
+ AsRef<WorkingDirectoryConfiguration>,
version: impl Into<Option<VersionOrRequirement>>,
) -> Box<dyn DynSolidityCompiler>;
+ AsRef<WorkingDirectoryConfiguration>
+ 'a,
version: impl Into<Option<VersionOrRequirement>> + 'a,
) -> Pin<Box<dyn Future<Output = anyhow::Result<Box<dyn DynSolidityCompiler>>> + 'a>>;
}
pub struct GethEvmPlatform;
impl DynPlatform for GethEvmPlatform {
fn platform_identifier(&self) -> PlatformIdentifier {
PlatformIdentifier::GethEvmSolc
}
fn node_identifier(&self) -> NodeIdentifier {
NodeIdentifier::Geth
}
fn vm_identifier(&self) -> VmIdentifier {
VmIdentifier::Evm
}
fn compiler_identifier(&self) -> CompilerIdentifier {
CompilerIdentifier::Solc
}
fn new_node(
&self,
context: impl AsRef<WorkingDirectoryConfiguration>
+ AsRef<ConcurrencyConfiguration>
+ AsRef<GenesisConfiguration>
+ AsRef<WalletConfiguration>
+ AsRef<GethConfiguration>
+ AsRef<KitchensinkConfiguration>
+ AsRef<ReviveDevNodeConfiguration>
+ AsRef<EthRpcConfiguration>
+ Send
+ Sync
+ Clone
+ 'static,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || {
let node = GethNode::new(context);
let node = spawn_node::<GethNode>(node, genesis)?;
Ok(Box::new(node) as Box<_>)
}))
}
fn new_compiler<'a>(
&self,
context: impl AsRef<SolcConfiguration>
+ AsRef<ResolcConfiguration>
+ AsRef<WorkingDirectoryConfiguration>
+ 'a,
version: impl Into<Option<VersionOrRequirement>> + 'a,
) -> Pin<Box<dyn Future<Output = anyhow::Result<Box<dyn DynSolidityCompiler>>> + 'a>> {
Box::pin(async move {
let compiler = Solc::new(context, version).await;
compiler.map(|compiler| Box::new(compiler) as Box<dyn DynSolidityCompiler>)
})
}
}
fn spawn_node<T: Node + EthereumNode + Send + Sync>(
mut node: T,
genesis: Genesis,
) -> anyhow::Result<T> {
info!(
id = node.id(),
connection_string = node.connection_string(),
"Spawning node"
);
node.spawn(genesis)
.context("Failed to spawn node process")?;
info!(
id = node.id(),
connection_string = node.connection_string(),
"Spawned node"
);
Ok(node)
}