Skip to content

Commit

Permalink
Merge branch 'yuji/fix-ibc-gen-shielded' (#2311)
Browse files Browse the repository at this point in the history
* origin/yuji/fix-ibc-gen-shielded:
  fix e2e test
  add SDK changelog
  fix parsing token address
  add changelog
  non-namada token to ibc-gen-shielded
  • Loading branch information
Gianmarco Fraccaroli committed Dec 27, 2023
2 parents 0d90441 + ec2488d commit 2508bf0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/2308-fix-ibc-gen-shielded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- ibc-gen-shielded can set non-Namada token
([\#2308](https://github.com/anoma/namada/issues/2308))
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/2308-fix-ibc-gen-shielded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Non-Namada token can be given to ibc-gen-shielded
([\#2308](https://github.com/anoma/namada/issues/2308))
5 changes: 3 additions & 2 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,7 @@ pub mod args {
pub const TM_ADDRESS: Arg<String> = arg("tm-address");
pub const TOKEN_OPT: ArgOpt<WalletAddress> = TOKEN.opt();
pub const TOKEN: Arg<WalletAddress> = arg("token");
pub const TOKEN_STR: Arg<String> = arg("token");
pub const TRANSFER_SOURCE: Arg<WalletTransferSource> = arg("source");
pub const TRANSFER_TARGET: Arg<WalletTransferTarget> = arg("target");
pub const TRANSPARENT: ArgFlag = flag("transparent");
Expand Down Expand Up @@ -5532,7 +5533,7 @@ pub mod args {
query,
output_folder: self.output_folder,
target: chain_ctx.get(&self.target),
token: chain_ctx.get(&self.token),
token: self.token,
amount: self.amount,
port_id: self.port_id,
channel_id: self.channel_id,
Expand All @@ -5545,7 +5546,7 @@ pub mod args {
let query = Query::parse(matches);
let output_folder = OUTPUT_FOLDER_PATH.parse(matches);
let target = TRANSFER_TARGET.parse(matches);
let token = TOKEN.parse(matches);
let token = TOKEN_STR.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let port_id = PORT_ID.parse(matches);
let channel_id = CHANNEL_ID.parse(matches);
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,8 @@ pub struct GenIbcShieldedTransafer<C: NamadaTypes = SdkTypes> {
pub output_folder: Option<PathBuf>,
/// The target address
pub target: C::TransferTarget,
/// The token address
pub token: C::Address,
/// The token address which could be a non-namada address
pub token: String,
/// Transferred token amount
pub amount: InputAmount,
/// Port ID via which the token is received
Expand Down
12 changes: 7 additions & 5 deletions sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,14 @@ pub async fn format_denominated_amount(
/// Look up the IBC denomination from a IbcToken.
pub async fn query_ibc_denom<N: Namada>(
context: &N,
token: &Address,
token: impl AsRef<str>,
owner: Option<&Address>,
) -> String {
let hash = match token {
Address::Internal(InternalAddress::IbcToken(hash)) => hash.to_string(),
_ => return token.to_string(),
let hash = match Address::decode(token.as_ref()) {
Ok(Address::Internal(InternalAddress::IbcToken(hash))) => {
hash.to_string()
}
_ => return token.as_ref().to_string(),
};

if let Some(owner) = owner {
Expand All @@ -1246,5 +1248,5 @@ pub async fn query_ibc_denom<N: Namada>(
}
}

token.to_string()
token.as_ref().to_string()
}
3 changes: 2 additions & 1 deletion sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,8 @@ pub async fn build_ibc_transfer(
.map_err(|e| Error::from(QueryError::Wasm(e.to_string())))?;

let ibc_denom =
rpc::query_ibc_denom(context, &args.token, Some(&source)).await;
rpc::query_ibc_denom(context, &args.token.to_string(), Some(&source))
.await;
let token = PrefixedCoin {
denom: ibc_denom.parse().expect("Invalid IBC denom"),
// Set the IBC amount as an integer
Expand Down
13 changes: 9 additions & 4 deletions tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn run_ledger_ibc() -> Result<()> {
&port_id_b,
&channel_id_b,
)?;
check_shielded_balances(&port_id_b, &channel_id_b, &test_b)?;
check_shielded_balances(&port_id_b, &channel_id_b, &test_a, &test_b)?;

// Skip tests for closing a channel and timeout_on_close since the transfer
// channel cannot be closed
Expand Down Expand Up @@ -1021,6 +1021,8 @@ fn shielded_transfer(
// It will send 10 BTC from Chain A to PA(B) on Chain B
let rpc_b = get_actor_rpc(test_b, Who::Validator(0));
let output_folder = test_b.test_dir.path().to_string_lossy();
// PA(B) on Chain B will receive BTC on chain A
let token_addr = find_address(test_a, BTC)?;
let amount = Amount::native_whole(10).to_string_native();
let args = [
"ibc-gen-shielded",
Expand All @@ -1029,7 +1031,7 @@ fn shielded_transfer(
"--target",
AB_PAYMENT_ADDRESS,
"--token",
BTC,
&token_addr.to_string(),
"--amount",
&amount,
"--port-id",
Expand Down Expand Up @@ -1512,16 +1514,19 @@ fn check_balances_after_back(
fn check_shielded_balances(
dest_port_id: &PortId,
dest_channel_id: &ChannelId,
test_a: &Test,
test_b: &Test,
) -> Result<()> {
// Check the balance on Chain B
let rpc_b = get_actor_rpc(test_b, Who::Validator(0));
let rpc_b = get_actor_rpc(test_b, &Who::Validator(0));
// PA(B) on Chain B has received BTC on chain A
let token_addr = find_address(test_a, BTC)?.to_string();
let query_args = vec![
"balance",
"--owner",
AB_VIEWING_KEY,
"--token",
BTC,
&token_addr,
"--no-conversions",
"--node",
&rpc_b,
Expand Down

0 comments on commit 2508bf0

Please sign in to comment.