diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index a266169a..1e6dbe42 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -48,6 +48,8 @@ pub struct GethInstance { ipc: Option, data_dir: Option, p2p_port: Option, + genesis: Option, + clique_private_key: Option, } impl GethInstance { @@ -81,6 +83,16 @@ impl GethInstance { &self.data_dir } + /// Returns the genesis configuration used to conifugre this instance + pub fn genesis(&self) -> &Option { + &self.genesis + } + + /// Returns the private key used to configure clique on this instance + pub fn clique_private_key(&self) -> &Option { + &self.clique_private_key + } + /// Takes the stderr contained in the child process. /// /// This leaves a `None` in its place, so calling methods that require a stderr to be present @@ -186,9 +198,9 @@ pub struct Geth { data_dir: Option, chain_id: Option, insecure_unlock: bool, - pub genesis: Option, + genesis: Option, mode: GethMode, - pub clique_private_key: Option, + clique_private_key: Option, } impl Geth { @@ -515,7 +527,15 @@ impl Geth { child.stderr = Some(reader.into_inner()); - GethInstance { pid: child, port, ipc: self.ipc_path, data_dir: self.data_dir, p2p_port } + GethInstance { + pid: child, + port, + ipc: self.ipc_path, + data_dir: self.data_dir, + p2p_port, + genesis: self.genesis, + clique_private_key: self.clique_private_key, + } } } @@ -569,4 +589,64 @@ mod tests { assert!(p2p_port.is_none()); } + + #[test] + fn clique_private_key_configured() { + let temp_dir = tempfile::tempdir().unwrap(); + let temp_dir_path = temp_dir.path().to_path_buf(); + + let private_key = SigningKey::random(&mut rand::thread_rng()); + let geth = Geth::new() + .set_clique_private_key(private_key) + .chain_id(1337u64) + .data_dir(temp_dir_path) + .spawn(); + + let clique_private_key = geth.clique_private_key().clone(); + + drop(geth); + temp_dir.close().unwrap(); + + assert!(clique_private_key.is_some()); + } + + #[test] + fn clique_genesis_configured() { + let temp_dir = tempfile::tempdir().unwrap(); + let temp_dir_path = temp_dir.path().to_path_buf(); + + let private_key = SigningKey::random(&mut rand::thread_rng()); + let geth = Geth::new() + .set_clique_private_key(private_key) + .chain_id(1337u64) + .data_dir(temp_dir_path) + .spawn(); + + let genesis = geth.genesis().clone(); + + drop(geth); + temp_dir.close().unwrap(); + + assert!(genesis.is_some()); + } + + #[test] + fn clique_p2p_configured() { + let temp_dir = tempfile::tempdir().unwrap(); + let temp_dir_path = temp_dir.path().to_path_buf(); + + let private_key = SigningKey::random(&mut rand::thread_rng()); + let geth = Geth::new() + .set_clique_private_key(private_key) + .chain_id(1337u64) + .data_dir(temp_dir_path) + .spawn(); + + let p2p_port = geth.p2p_port(); + + drop(geth); + temp_dir.close().unwrap(); + + assert!(p2p_port.is_some()); + } }