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