chore: add more attributes to anvil&co
This commit is contained in:
parent
5521276e67
commit
fc58c5d118
|
@ -85,6 +85,7 @@ impl Drop for AnvilInstance {
|
|||
/// drop(anvil); // this will kill the instance
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[must_use = "This Builder struct does nothing unless it is `spawn`ed"]
|
||||
pub struct Anvil {
|
||||
program: Option<PathBuf>,
|
||||
port: Option<u16>,
|
||||
|
@ -135,35 +136,30 @@ impl Anvil {
|
|||
///
|
||||
/// By default, it's expected that `anvil` is in `$PATH`, see also
|
||||
/// [`std::process::Command::new()`]
|
||||
#[must_use]
|
||||
pub fn path<T: Into<PathBuf>>(mut self, path: T) -> Self {
|
||||
self.program = Some(path.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the port which will be used when the `anvil` instance is launched.
|
||||
#[must_use]
|
||||
pub fn port<T: Into<u16>>(mut self, port: T) -> Self {
|
||||
self.port = Some(port.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the chain_id the `anvil` instance will use.
|
||||
#[must_use]
|
||||
pub fn chain_id<T: Into<u64>>(mut self, chain_id: T) -> Self {
|
||||
self.chain_id = Some(chain_id.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the mnemonic which will be used when the `anvil` instance is launched.
|
||||
#[must_use]
|
||||
pub fn mnemonic<T: Into<String>>(mut self, mnemonic: T) -> Self {
|
||||
self.mnemonic = Some(mnemonic.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the block-time in seconds which will be used when the `anvil` instance is launched.
|
||||
#[must_use]
|
||||
pub fn block_time<T: Into<u64>>(mut self, block_time: T) -> Self {
|
||||
self.block_time = Some(block_time.into());
|
||||
self
|
||||
|
@ -172,7 +168,6 @@ impl Anvil {
|
|||
/// Sets the `fork-block-number` which will be used in addition to [`Self::fork`].
|
||||
///
|
||||
/// **Note:** if set, then this requires `fork` to be set as well
|
||||
#[must_use]
|
||||
pub fn fork_block_number<T: Into<u64>>(mut self, fork_block_number: T) -> Self {
|
||||
self.fork_block_number = Some(fork_block_number.into());
|
||||
self
|
||||
|
@ -182,21 +177,18 @@ impl Anvil {
|
|||
/// at a given block. Input should be the HTTP location and port of the other client,
|
||||
/// e.g. `http://localhost:8545`. You can optionally specify the block to fork from
|
||||
/// using an @ sign: `http://localhost:8545@1599200`
|
||||
#[must_use]
|
||||
pub fn fork<T: Into<String>>(mut self, fork: T) -> Self {
|
||||
self.fork = Some(fork.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an argument to pass to the `anvil`.
|
||||
#[must_use]
|
||||
pub fn arg<T: Into<String>>(mut self, arg: T) -> Self {
|
||||
self.args.push(arg.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds multiple arguments to pass to the `anvil`.
|
||||
#[must_use]
|
||||
pub fn args<I, S>(mut self, args: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
|
@ -209,14 +201,17 @@ impl Anvil {
|
|||
}
|
||||
|
||||
/// Sets the timeout which will be used when the `anvil` instance is launched.
|
||||
#[must_use]
|
||||
pub fn timeout<T: Into<u64>>(mut self, timeout: T) -> Self {
|
||||
self.timeout = Some(timeout.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Consumes the builder and spawns `anvil` with stdout redirected
|
||||
/// to /dev/null.
|
||||
/// Consumes the builder and spawns `anvil`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If spawning the instance fails at any point.
|
||||
#[track_caller]
|
||||
pub fn spawn(self) -> AnvilInstance {
|
||||
let mut cmd = if let Some(ref prg) = self.program {
|
||||
Command::new(prg)
|
||||
|
|
|
@ -78,6 +78,7 @@ impl Drop for GanacheInstance {
|
|||
/// drop(ganache); // this will kill the instance
|
||||
/// ```
|
||||
#[derive(Clone, Default)]
|
||||
#[must_use = "This Builder struct does nothing unless it is `spawn`ed"]
|
||||
pub struct Ganache {
|
||||
port: Option<u16>,
|
||||
block_time: Option<u64>,
|
||||
|
@ -102,21 +103,18 @@ impl Ganache {
|
|||
}
|
||||
|
||||
/// Sets the port which will be used when the `ganache-cli` instance is launched.
|
||||
#[must_use]
|
||||
pub fn port<T: Into<u16>>(mut self, port: T) -> Self {
|
||||
self.port = Some(port.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the mnemonic which will be used when the `ganache-cli` instance is launched.
|
||||
#[must_use]
|
||||
pub fn mnemonic<T: Into<String>>(mut self, mnemonic: T) -> Self {
|
||||
self.mnemonic = Some(mnemonic.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the block-time which will be used when the `ganache-cli` instance is launched.
|
||||
#[must_use]
|
||||
pub fn block_time<T: Into<u64>>(mut self, block_time: T) -> Self {
|
||||
self.block_time = Some(block_time.into());
|
||||
self
|
||||
|
@ -126,21 +124,18 @@ impl Ganache {
|
|||
/// at a given block. Input should be the HTTP location and port of the other client,
|
||||
/// e.g. `http://localhost:8545`. You can optionally specify the block to fork from
|
||||
/// using an @ sign: `http://localhost:8545@1599200`
|
||||
#[must_use]
|
||||
pub fn fork<T: Into<String>>(mut self, fork: T) -> Self {
|
||||
self.fork = Some(fork.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an argument to pass to the `ganache-cli`.
|
||||
#[must_use]
|
||||
pub fn arg<T: Into<String>>(mut self, arg: T) -> Self {
|
||||
self.args.push(arg.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds multiple arguments to pass to the `ganache-cli`.
|
||||
#[must_use]
|
||||
pub fn args<I, S>(mut self, args: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
|
@ -152,9 +147,12 @@ impl Ganache {
|
|||
self
|
||||
}
|
||||
|
||||
/// Consumes the builder and spawns `ganache-cli` with stdout redirected
|
||||
/// to /dev/null. This takes ~2 seconds to execute as it blocks while
|
||||
/// waiting for `ganache-cli` to launch.
|
||||
/// Consumes the builder and spawns `ganache-cli`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If spawning the instance fails at any point.
|
||||
#[track_caller]
|
||||
pub fn spawn(self) -> GanacheInstance {
|
||||
let mut cmd = Command::new("ganache-cli");
|
||||
cmd.stdout(std::process::Stdio::piped());
|
||||
|
|
|
@ -189,6 +189,7 @@ impl Default for PrivateNetOptions {
|
|||
/// drop(geth); // this will kill the instance
|
||||
/// ```
|
||||
#[derive(Clone, Default)]
|
||||
#[must_use = "This Builder struct does nothing unless it is `spawn`ed"]
|
||||
pub struct Geth {
|
||||
program: Option<PathBuf>,
|
||||
port: Option<u16>,
|
||||
|
@ -234,7 +235,6 @@ impl Geth {
|
|||
///
|
||||
/// By default, it's expected that `geth` is in `$PATH`, see also
|
||||
/// [`std::process::Command::new()`]
|
||||
#[must_use]
|
||||
pub fn path<T: Into<PathBuf>>(mut self, path: T) -> Self {
|
||||
self.program = Some(path.into());
|
||||
self
|
||||
|
@ -245,14 +245,12 @@ impl Geth {
|
|||
///
|
||||
/// The address derived from this private key will be used to set the `miner.etherbase` field
|
||||
/// on the node.
|
||||
#[must_use]
|
||||
pub fn set_clique_private_key<T: Into<SigningKey>>(mut self, private_key: T) -> Self {
|
||||
self.clique_private_key = Some(private_key.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the port which will be used when the `geth-cli` instance is launched.
|
||||
#[must_use]
|
||||
pub fn port<T: Into<u16>>(mut self, port: T) -> Self {
|
||||
self.port = Some(port.into());
|
||||
self
|
||||
|
@ -262,7 +260,6 @@ impl Geth {
|
|||
///
|
||||
/// This will put the geth instance into non-dev mode, discarding any previously set dev-mode
|
||||
/// options.
|
||||
#[must_use]
|
||||
pub fn p2p_port(mut self, port: u16) -> Self {
|
||||
match self.mode {
|
||||
GethMode::Dev(_) => {
|
||||
|
@ -280,21 +277,18 @@ impl Geth {
|
|||
///
|
||||
/// This will put the geth instance in `dev` mode, discarding any previously set options that
|
||||
/// cannot be used in dev mode.
|
||||
#[must_use]
|
||||
pub fn block_time<T: Into<u64>>(mut self, block_time: T) -> Self {
|
||||
self.mode = GethMode::Dev(DevOptions { block_time: Some(block_time.into()) });
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the chain id for the geth instance.
|
||||
#[must_use]
|
||||
pub fn chain_id<T: Into<u64>>(mut self, chain_id: T) -> Self {
|
||||
self.chain_id = Some(chain_id.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Allow geth to unlock accounts when rpc apis are open.
|
||||
#[must_use]
|
||||
pub fn insecure_unlock(mut self) -> Self {
|
||||
self.insecure_unlock = true;
|
||||
self
|
||||
|
@ -304,7 +298,6 @@ impl Geth {
|
|||
///
|
||||
/// This will put the geth instance into non-dev mode, discarding any previously set dev-mode
|
||||
/// options.
|
||||
#[must_use]
|
||||
pub fn disable_discovery(mut self) -> Self {
|
||||
self.inner_disable_discovery();
|
||||
self
|
||||
|
@ -321,14 +314,12 @@ impl Geth {
|
|||
}
|
||||
|
||||
/// Manually sets the IPC path for the socket manually.
|
||||
#[must_use]
|
||||
pub fn ipc_path<T: Into<PathBuf>>(mut self, path: T) -> Self {
|
||||
self.ipc_path = Some(path.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the data directory for geth.
|
||||
#[must_use]
|
||||
pub fn data_dir<T: Into<PathBuf>>(mut self, path: T) -> Self {
|
||||
self.data_dir = Some(path.into());
|
||||
self
|
||||
|
@ -340,21 +331,22 @@ impl Geth {
|
|||
/// set to the same value as `data_dir`.
|
||||
///
|
||||
/// This is destructive and will overwrite any existing data in the data directory.
|
||||
#[must_use]
|
||||
pub fn genesis(mut self, genesis: Genesis) -> Self {
|
||||
self.genesis = Some(genesis);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the port for authenticated RPC connections.
|
||||
#[must_use]
|
||||
pub fn authrpc_port(mut self, port: u16) -> Self {
|
||||
self.authrpc_port = Some(port);
|
||||
self
|
||||
}
|
||||
|
||||
/// Consumes the builder and spawns `geth` with stdout redirected to /dev/null.
|
||||
#[must_use]
|
||||
/// Consumes the builder and spawns `geth`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If spawning the instance fails at any point.
|
||||
#[track_caller]
|
||||
pub fn spawn(mut self) -> GethInstance {
|
||||
let bin_path = match self.program.as_ref() {
|
||||
|
|
|
@ -42,7 +42,6 @@ async fn test_derive_eip712() {
|
|||
const PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/DeriveEip712Test.sol");
|
||||
Solc::find_or_install_svm_version("0.6.0").unwrap(); // install solc
|
||||
let result = Solc::default().compile_source(PATH).unwrap();
|
||||
eprintln!("{result:#?}");
|
||||
let (abi, bytecode, _) = result
|
||||
.find("DeriveEip712Test")
|
||||
.expect("failed to get DeriveEip712Test contract")
|
||||
|
|
Loading…
Reference in New Issue