Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,47 @@ fn invoke_log(sandbox: &TestEnv, id: &str) {
r#"Log: {"vec":[{"string":"hello {}"},{"symbol":"world"}]}"#,
));
}

#[tokio::test]
async fn invoke_auth_uses_hd_path_for_addr_alias() {
let sandbox = &TestEnv::new();

// Fund path 1 of the "test" seed (path 0 is funded by default)
sandbox
.new_assert_cmd("keys")
.arg("fund")
.arg("test")
.arg("--hd-path=1")
.assert()
.success();

let addr_1 = sandbox
.new_assert_cmd("keys")
.arg("address")
.arg("test")
.arg("--hd-path=1")
.assert()
.stdout_as_str();

let id = &deploy_hello(sandbox).await;
extend_contract(sandbox, id).await;

// --hd-path=1 must propagate to --addr alias resolution AND the auth signer.
// The contract's auth function returns the Address it was called with, so
// the output must be addr_1 (path 1), not path 0.
sandbox
.new_assert_cmd("contract")
.arg("invoke")
.arg("--source")
.arg("test")
.arg("--hd-path=1")
.arg("--id")
.arg(id)
.arg("--")
.arg("auth")
.arg("--addr=test")
.arg("--world=world")
.assert()
.stdout(format!("\"{addr_1}\"\n"))
.success();
}
8 changes: 6 additions & 2 deletions cmd/soroban-cli/src/commands/contract/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ fn resolve_address(addr_or_alias: &str, config: &config::Args) -> Result<String,
let account = match sc_address {
UnresolvedScAddress::Resolved(addr) => addr.to_string(),
addr @ UnresolvedScAddress::Alias(_) => {
let addr = addr.resolve(&config.locator, &config.get_network()?.network_passphrase)?;
let addr = addr.resolve(
&config.locator,
&config.get_network()?.network_passphrase,
config.hd_path(),
)?;
match addr {
xdr::ScAddress::Account(account) => account.to_string(),
contract @ xdr::ScAddress::Contract(_) => contract.to_string(),
Expand All @@ -467,7 +471,7 @@ fn resolve_address(addr_or_alias: &str, config: &config::Args) -> Result<String,
async fn resolve_signer(addr_or_alias: &str, config: &config::Args) -> Option<Signer> {
let secret = config.locator.get_secret_key(addr_or_alias).ok()?;
let print = Print::new(false);
let signer = secret.signer(None, print).await.ok()?;
let signer = secret.signer(config.hd_path(), print).await.ok()?;
Some(signer)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Args {
pub async fn source_signer(&self) -> Result<Signer, Error> {
let print = Print::new(true);
let secret = &self.source_account.resolve_secret(&self.locator)?;
Ok(secret.signer(None, print).await?)
Ok(secret.signer(self.hd_path(), print).await?)
}

pub fn key_pair(&self) -> Result<ed25519_dalek::SigningKey, Error> {
Expand Down
3 changes: 2 additions & 1 deletion cmd/soroban-cli/src/config/sc_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl UnresolvedScAddress {
self,
locator: &locator::Args,
network_passphrase: &str,
hd_path: Option<usize>,
) -> Result<xdr::ScAddress, Error> {
let alias = match self {
UnresolvedScAddress::Resolved(addr) => return Ok(addr),
Expand All @@ -64,7 +65,7 @@ impl UnresolvedScAddress {
xdr::Hash(contract.0),
))),
(_, Ok(key)) => Ok(xdr::ScAddress::Account(
key.muxed_account(None)?.account_id(),
key.muxed_account(hd_path)?.account_id(),
)),
_ => Err(Error::AccountAliasNotFound(alias)),
}
Expand Down
Loading