Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
test: fix tests and dev features (#2293)
Browse files Browse the repository at this point in the history
* fix(solc): features part 2

* chore: add more attributes to anvil&co

* update tests

* fix: close temp dirs

* test: merge geth clique tests

* refactor tempdir handling

* only manually clean dirs on unix

* ignore multiple geths in windows

* ci: add 3 retries to nextest runs
  • Loading branch information
DaniPopes authored Apr 13, 2023
1 parent 9a5b31a commit 5c0de28
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 166 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ jobs:
run: |
cargo nextest run \
${{ matrix.flags.flags }} \
-E "!(deps(ethers-etherscan) & kind(test))"
-E "!(deps(ethers-etherscan) & kind(test))" \
--retries 3
etherscan-tests:
name: etherscan tests
Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ethers-solc.workspace = true
ethers-providers = { workspace = true, features = ["ws"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { workspace = true, features = ["macros"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[features]
default = ["abigen"]
Expand Down
2 changes: 2 additions & 0 deletions ethers-core/src/macros/ethers_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ mod tests {
}

#[test]
#[ignore = "TODO: flaky and slow"]
fn test_names() {
fn assert_names(s: &ProjectEnvironment, ethers: bool, dependencies: &[EthersCrate]) {
write_manifest(s, ethers, dependencies);
Expand Down Expand Up @@ -424,6 +425,7 @@ mod tests {
}

#[test]
#[ignore = "TODO: flaky and slow"]
fn test_lock_file() {
let (s, _dir) = test_project();
write_manifest(&s, true, &[]);
Expand Down
2 changes: 1 addition & 1 deletion ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ mod tests {
fn serde_to_string_match() {
for chain in Chain::iter() {
let chain_serde = serde_json::to_string(&chain).unwrap();
let chain_string = format!("\"{}\"", chain);
let chain_string = format!("\"{chain}\"");
assert_eq!(chain_serde, chain_string);
}
}
Expand Down
19 changes: 7 additions & 12 deletions ethers-core/src/utils/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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>,
Expand All @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions ethers-core/src/utils/ganache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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
Expand All @@ -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>,
Expand All @@ -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());
Expand Down
Loading

0 comments on commit 5c0de28

Please sign in to comment.