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

fix: review sov-ibc-transfer implementation and apply fixes #133

Merged
merged 12 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 23 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion clients/sov-celestia/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ workspace = true

[dependencies]
# external dependencies
base64 = { workspace = true, features = ["alloc"] }
bytes = { workspace = true }
hex = { version = "0.4.3" }
jmt = { workspace = true }
Expand Down
11 changes: 5 additions & 6 deletions mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ workspace = true
# external dependencies
anyhow = { workspace = true }
async-trait = { version = "0.1.74", default-features = false }
base64 = { workspace = true }
borsh = { workspace = true }
jmt = { workspace = true }
prost = { workspace = true }
Expand All @@ -32,10 +31,10 @@ tracing = "0.1.36"
typed-builder = "0.18.0"

# internal dependencies
sov-ibc = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "acdfdf72" }
sov-ibc-transfer = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "acdfdf72" }
sov-consensus-state-tracker = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "acdfdf72" }
sov-celestia-client = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "acdfdf72", features = ["test-util"] }
sov-ibc = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "300e4c16" }
sov-ibc-transfer = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "300e4c16" }
sov-consensus-state-tracker = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "300e4c16" }
sov-celestia-client = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "300e4c16", features = ["test-util"] }

# ibc dependencies
ibc-core = { workspace = true }
Expand All @@ -46,7 +45,7 @@ ibc-query = { workspace = true }
ibc-testkit = { workspace = true }

# cosmos dependencies
basecoin = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "90886ab" }
basecoin = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "adfebf9" }
tendermint = { workspace = true }
tendermint-testgen = { workspace = true }

Expand Down
13 changes: 8 additions & 5 deletions mocks/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;

use ibc_app_transfer::types::Memo;
use ibc_core::host::types::identifiers::ChainId;
use ibc_testkit::fixtures::core::signer::dummy_bech32_account;
use serde::de::DeserializeOwned;
use sov_bank::{get_token_id, GasTokenConfig, TokenId};
use sov_bank::{get_token_id, TokenConfig, TokenId, GAS_TOKEN_ID};
#[cfg(feature = "celestia-da")]
use sov_consensus_state_tracker::CelestiaService;
#[cfg(feature = "mock-da")]
Expand Down Expand Up @@ -45,11 +46,12 @@ pub struct TestSetupConfig<S: Spec, Da: DaService> {

impl<S: Spec, Da: DaService> TestSetupConfig<S, Da> {
/// Returns list of tokens in the bank configuration
pub fn gas_token_config(&self) -> GasTokenConfig<S> {
pub fn gas_token_config(&self) -> TokenConfig<S> {
self.rollup_genesis_config
.bank_config
.gas_token_config
.clone()
.into()
}

/// Returns the address of the relayer. We use the last address in the list
Expand Down Expand Up @@ -104,10 +106,8 @@ pub async fn default_config_with_celestia_da() -> TestSetupConfig<DefaultSpec, C
#[derive(TypedBuilder, Clone, Debug)]
pub struct TransferTestConfig {
/// The token name on the rollup.
#[builder(default = GAS_TOKEN_ID.to_bech32().to_string())]
pub sov_denom: String,
/// The token ID on the rollup.
#[builder(default = None)]
pub sov_token_id: Option<TokenId>,
/// An arbitrary user address on the rollup.
pub sov_address: Address,
/// The token name on the Cosmos chain.
Expand All @@ -119,6 +119,9 @@ pub struct TransferTestConfig {
/// The amount to transfer.
#[builder(default = 100)]
pub amount: u64,
/// The memo to attach to the transfer.
#[builder(default = "".into())]
pub memo: Memo,
}

/// Reads toml file as a specific type.
Expand Down
17 changes: 2 additions & 15 deletions mocks/src/relayer/msgs/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

use std::str::FromStr;

use base64::engine::general_purpose;
use base64::Engine;
use basecoin::modules::ibc::AnyClientState;
use ibc_app_transfer::types::msgs::transfer::MsgTransfer;
use ibc_app_transfer::types::packet::PacketData;
use ibc_app_transfer::types::{Coin, Memo, PrefixedDenom};
use ibc_app_transfer::types::{Coin, PrefixedDenom};
use ibc_core::channel::types::msgs::MsgRecvPacket;
use ibc_core::channel::types::packet::Packet;
use ibc_core::channel::types::timeout::TimeoutHeight;
Expand Down Expand Up @@ -100,25 +98,14 @@ where

/// Builds a Cosmos chain token transfer message; serialized to Any
pub fn build_msg_transfer_for_cos(&self, config: &TransferTestConfig) -> MsgTransfer {
let memo = match config.sov_token_id {
Some(token_id) => {
let mut token_id_buf = String::new();

general_purpose::STANDARD_NO_PAD.encode_string(token_id, &mut token_id_buf);

token_id_buf.into()
}
None => Memo::from_str("").unwrap(),
};

let packet_data = PacketData {
token: Coin {
denom: PrefixedDenom::from_str(&config.cos_denom).unwrap(),
amount: config.amount.into(),
},
sender: Signer::from(config.cos_address.clone()),
receiver: Signer::from(config.sov_address.to_string()),
memo,
memo: config.memo.clone(),
};

MsgTransfer {
Expand Down
15 changes: 5 additions & 10 deletions mocks/src/relayer/msgs/rollup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Contains rollup specific message builders for the relayer.
use std::str::FromStr;

use base64::engine::general_purpose;
use base64::Engine;
use ibc_app_transfer::types::msgs::transfer::MsgTransfer;
use ibc_app_transfer::types::packet::PacketData;
use ibc_app_transfer::types::{Coin, PrefixedDenom};
Expand Down Expand Up @@ -101,22 +99,19 @@ where
CallMessage::Core(msg_update_client.to_any())
}

/// Builds a sdk token transfer message wrapped in a `CallMessage` with the given amount
/// Note: keep the amount value lower than the initial balance of the sender address
/// Builds a `MsgTransfer` with the given configuration
///
/// Note: keep the amount value lower than the initial balance of the sender
/// address
pub fn build_msg_transfer_for_sov(&self, config: &TransferTestConfig) -> MsgTransfer {
let mut token_id_buf = String::new();

general_purpose::STANDARD_NO_PAD
.encode_string(config.sov_token_id.unwrap(), &mut token_id_buf);

let packet_data = PacketData {
token: Coin {
denom: PrefixedDenom::from_str(&config.sov_denom).unwrap(),
amount: config.amount.into(),
},
sender: Signer::from(config.sov_address.to_string()),
receiver: Signer::from(config.cos_address.clone()),
memo: token_id_buf.into(),
memo: config.memo.clone(),
};

MsgTransfer {
Expand Down
Loading
Loading