diff --git a/CHANGELOG.md b/CHANGELOG.md index 95e41ac6752..3f38594c7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ ### Added +- [#7555](https://github.com/ChainSafe/forest/issues/7555): Added `--as-default` to `forest-wallet import`. - [#7414](https://github.com/ChainSafe/forest/issues/7414): New `drand_http_fetch_total` metric, counting the drand rounds that had to be fetched over HTTP rather than served from the in-memory cache. ### Changed diff --git a/scripts/devnet-forest-miner/docker-compose.yml b/scripts/devnet-forest-miner/docker-compose.yml index 70f2bf95839..9684d02a779 100644 --- a/scripts/devnet-forest-miner/docker-compose.yml +++ b/scripts/devnet-forest-miner/docker-compose.yml @@ -176,8 +176,7 @@ services: set -euxo pipefail export TOKEN=$$(cat ${FOREST_DATA_DIR}/token.jwt) export FULLNODE_API_INFO=$$TOKEN:/dns/forest/tcp/${FOREST_RPC_PORT}/http - ADDR=$$(forest-wallet --remote-wallet import ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key) - forest-wallet --remote-wallet set-default "$$ADDR" + forest-wallet --remote-wallet import --as-default ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key # Lotus Miner: the block producer. Its full-node API points at FOREST, so it # drives block production through Forest's RPC (this is the swap vs ../devnet). diff --git a/scripts/devnet/docker-compose.yml b/scripts/devnet/docker-compose.yml index 3fe711a5ba2..b5c9302e279 100644 --- a/scripts/devnet/docker-compose.yml +++ b/scripts/devnet/docker-compose.yml @@ -292,8 +292,7 @@ services: set -euxo pipefail export TOKEN=$$(cat ${FOREST_DATA_DIR}/token.jwt) export FULLNODE_API_INFO=$$TOKEN:/dns/forest/tcp/${FOREST_RPC_PORT}/http - ADDR=$$(forest-wallet --remote-wallet import ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key) - forest-wallet --remote-wallet set-default "$$ADDR" + forest-wallet --remote-wallet import --as-default ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key volumes: # Shared proof parameter files. It is re-used by both Lotus and Forest. diff --git a/src/dev/subcommands/tests_cmd/wallet.rs b/src/dev/subcommands/tests_cmd/wallet.rs index 654670e6180..0b5d491915c 100644 --- a/src/dev/subcommands/tests_cmd/wallet.rs +++ b/src/dev/subcommands/tests_cmd/wallet.rs @@ -28,6 +28,14 @@ fn tests() -> Vec { block_on(export_import_roundtrip(Backend::Remote)); Ok(()) }), + Trial::test("import_as_default_local", || { + block_on(import_as_default(Backend::Local)); + Ok(()) + }), + Trial::test("import_as_default_remote", || { + block_on(import_as_default(Backend::Remote)); + Ok(()) + }), Trial::test("market_add_balance_message_on_chain", || { block_on(market_add_balance_message_on_chain()); Ok(()) @@ -91,6 +99,27 @@ async fn export_import_roundtrip(backend: Backend) { ); } +async fn import_as_default(backend: Backend) { + let addr = wallet(backend, &["new"]).unwrap(); + let exported = export_to_temp_file(&addr, backend).unwrap(); + let path = exported + .path() + .to_str() + .expect("temp path is not valid UTF-8"); + + let deleted = wallet(backend, &["delete", &addr]).unwrap(); + eprintln!("delete output ({}): {deleted}", backend.label()); + + let imported = wallet(backend, &["import", "--as-default", path]).unwrap(); + assert_eq!( + imported, + addr, + "round-trip mismatch on {} backend: {imported} != {addr}", + backend.label(), + ); + assert_eq!(wallet(backend, &["default"]).unwrap(), imported); +} + async fn market_add_balance_message_on_chain() { const ATTO_FIL: &str = "23"; let result = rpc_call_with_retry( diff --git a/src/wallet/subcommands/wallet_cmd.rs b/src/wallet/subcommands/wallet_cmd.rs index ffbbc98f984..745156aaef6 100644 --- a/src/wallet/subcommands/wallet_cmd.rs +++ b/src/wallet/subcommands/wallet_cmd.rs @@ -230,6 +230,9 @@ pub enum WalletCommands { Import { /// The path to the private key path: Option, + /// Set the imported address as default + #[arg(long)] + as_default: bool, }, /// List addresses of the wallet List { @@ -374,7 +377,7 @@ impl WalletCommands { println!("deleted {address}."); Ok(()) } - Self::Import { path } => { + Self::Import { path, as_default } => { let key = match path { Some(path) => std::fs::read_to_string(path)?, _ => { @@ -405,6 +408,9 @@ impl WalletCommands { .context("invalid key format")?; let key = backend.wallet_import(key_info).await?; + if as_default { + backend.wallet_set_default(Address::from_str(&key)?).await?; + } println!("{key}"); Ok(())