diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-08-21 07:35:13 +0000 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-08-21 07:35:13 +0000 |
| commit | f608cce748d80d46f49ba25999e4334fd959b070 (patch) | |
| tree | 9fc73440b321933cfd6e6ead10ee18d93bc99c89 /tests/util/mod.rs | |
| parent | c05487949a5cb9808945b5bdd174e14fdd7e51ea (diff) | |
Refactor into lib+bin and start adding e2e tests
Diffstat (limited to 'tests/util/mod.rs')
| -rw-r--r-- | tests/util/mod.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/util/mod.rs b/tests/util/mod.rs new file mode 100644 index 0000000..3cc4c66 --- /dev/null +++ b/tests/util/mod.rs @@ -0,0 +1,29 @@ +#[path = "../../src/ganache.rs"] +mod ganache; + +use std::{str, process::Command}; +pub use ganache::*; + +/// Utility function for running the `hdwallet` command for integration tests. +pub fn exec(subcommand: &str, args: &[&str]) -> String { + try_exec(subcommand, args).unwrap() +} + +/// Try and execute a command, returning an error if there was one. +pub fn try_exec(subcommand: &str, args: &[&str]) -> Result<String, String> { + let output = Command::new("cargo") + .env("MNEMONIC", ganache::DETERMINISTIC_MNEMONIC) + .args(["run", "--", subcommand]) + .args(args) + .output() + .unwrap(); + if output.status.success() { + Ok(string_from_utf8(output.stdout)) + } else { + Err(string_from_utf8(output.stderr)) + } +} + +fn string_from_utf8(bytes: Vec<u8>) -> String { + str::from_utf8(&bytes).unwrap().trim().to_string() +}
\ No newline at end of file |
