Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Interchain API for tests / execution #474

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
109 changes: 99 additions & 10 deletions framework/Cargo.lock

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

2 changes: 1 addition & 1 deletion framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protobuf = { version = "2", features = ["with-bytes"] }
clap = { version = "4.0.32", features = ["derive"] }
semver = "1.0"
cw-orch = { version = "0.25.0" }
cw-orch-interchain = { version = "0.4.0" }
cw-orch-interchain = { version = "0.5.0" }
tokio = { version = "1.4", features = ["full"] }

polytone = { package = "abstract-polytone", version = "2.0.0" }
Expand Down
1 change: 1 addition & 0 deletions framework/packages/abstract-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use crate::{
};

/// Client to interact with Abstract accounts and modules
#[derive(Clone)]
pub struct AbstractClient<Chain: CwEnv> {
pub(crate) abstr: Abstract<Chain>,
}
Expand Down
69 changes: 69 additions & 0 deletions framework/packages/abstract-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,83 @@ pub use source::AccountSource;
mod interchain {
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) mod remote_account;
mod remote_application;
use std::collections::HashMap;

use cw_orch_interchain::{IbcQueryHandler, InterchainEnv, InterchainError};
pub use remote_account::RemoteAccount;
pub use remote_application::RemoteApplication;

use crate::{client::AbstractClientResult, AbstractClient, Environment};

// TODO: Why are we not returning ibc tx analysis after await
/// IbcTxAnalysis after waiting for interchain action
pub struct IbcTxAnalysisV2<Chain: cw_orch::environment::CwEnv>(
pub cw_orch_interchain::types::IbcTxAnalysis<Chain>,
);

/// Client to interact with Abstract and setup interchain capabilities
pub struct AbstractInterchainClient<Chain: IbcQueryHandler> {
/// All clients registered within this Interchain Client
pub clients: HashMap<String, AbstractClient<Chain>>,
}

impl<Chain: IbcQueryHandler> AbstractInterchainClient<Chain> {
/// Deploys and connects Abstract instances across all chains specified
pub fn build<Interchain: InterchainEnv<Chain>>(
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
interchain: &Interchain,
) -> AbstractClientResult<Self> {
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
// We deploy Abstract on all chains
let clients = interchain
.chains()
.map_err(Into::into)?
.iter()
.map(|chain| AbstractClient::builder(chain.clone()).build())
.collect::<Result<Vec<_>, _>>()?;

// We connect all chains together
for i in 0..clients.len() {
for j in i + 1..clients.len() {
clients[i].connect_to(&clients[j], interchain)?;
}
}

Ok(AbstractInterchainClient {
clients: clients
.into_iter()
.map(|c| (c.environment().chain_id(), c))
.collect(),
})
}

/// Loads Abstract from all the environments specified inside `interchain_env`
/// Use `get_abstract` to get a single abstract instance
pub fn new<Interchain: InterchainEnv<Chain>>(
interchain: &Interchain,
) -> AbstractClientResult<Self> {
let clients = interchain
.chains()
.map_err(Into::into)?
.iter()
.map(|chain| AbstractClient::new(chain.clone()))
.collect::<Result<Vec<_>, _>>()?;

Ok(AbstractInterchainClient {
clients: clients
.into_iter()
.map(|c| (c.environment().chain_id(), c))
.collect(),
})
}

/// Getter for an abstract client within this object
pub fn get_abstract(&self, chain_id: &str) -> AbstractClientResult<AbstractClient<Chain>> {
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
self.clients
.get(chain_id)
.cloned()
.ok_or(InterchainError::ChainNotFound(chain_id.to_string()))
.map_err(Into::into)
}
}
}
#[cfg(feature = "interchain")]
pub use interchain::*;
1 change: 1 addition & 0 deletions framework/packages/abstract-interface/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl State {
}
}

#[derive(Clone)]
pub struct Abstract<Chain: CwEnv> {
pub ans_host: AnsHost<Chain>,
pub version_control: VersionControl<Chain>,
Expand Down
2 changes: 2 additions & 0 deletions framework/packages/abstract-interface/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{Abstract, AbstractInterfaceError, IbcClient, IbcHost, VersionControl};
use abstract_std::{IBC_CLIENT, IBC_HOST};
use cw_orch::prelude::*;

#[derive(Clone)]
pub struct AbstractIbc<Chain: CwEnv> {
pub client: IbcClient<Chain>,
pub host: IbcHost<Chain>,
Expand Down
3 changes: 2 additions & 1 deletion modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ chrono = { version = "0.4.31", default-features = false }
clap = { version = "4.0.32", features = ["derive"] }
semver = "1.0"
cw-orch = { version = "0.25.0" }
cw-orch-interchain = { version = "0.4.0" }
cw-orch-interchain = { version = "0.5.0" }
# cw-orch-osmosis-test-tube = { version = "0.2.0" }
tokio = { version = "1.4", features = ["full"] }

Expand Down Expand Up @@ -110,6 +110,7 @@ abstract-polytone-note = { git = "https://github.com/AbstractSDK/polytone.git",
abstract-cw-orch-polytone = { git = "https://github.com/AbstractSDK/polytone.git", branch = "bump/cw2" }
abstract-cw-plus-interface = { git = "https://github.com/AbstractSDK/cw-plus.git", branch = "buckram/update-interface-package" }


# Backup release profile, will result in warnings during optimization
[profile.release]
rpath = false
Expand Down
59 changes: 59 additions & 0 deletions modules/contracts/apps/ping-pong/tests/better_interchain_api.rs
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use abstract_client::{AbstractClient, AbstractInterchainClient};
use cw_orch::anyhow;
use cw_orch::prelude::*;
use cw_orch_interchain::prelude::*;
pub const JUNO: &str = "juno-1";
pub const STARGAZE: &str = "stargaze-1";

#[test]
fn abstract_load_api() -> anyhow::Result<()> {
// Start by deploying abstract completely
let mock_interchain =
MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]);
let interchain_abstract = AbstractInterchainClient::build(&mock_interchain)?;

// Then we load abstract from state and make sure this is the same instance
let juno_abstract = AbstractClient::new(mock_interchain.get_chain(JUNO)?)?;
let stargaze_abstract = AbstractClient::new(mock_interchain.get_chain(STARGAZE)?)?;

let loaded_interchain_abstract = AbstractInterchainClient::new(&mock_interchain)?;

assert_eq!(
interchain_abstract
.get_abstract(JUNO)?
.version_control()
.address()?,
juno_abstract.version_control().address()?
);

assert_eq!(
interchain_abstract
.get_abstract(JUNO)?
.version_control()
.address()?,
loaded_interchain_abstract
.get_abstract(JUNO)?
.version_control()
.address()?,
);

assert_eq!(
interchain_abstract
.get_abstract(STARGAZE)?
.version_control()
.address()?,
stargaze_abstract.version_control().address()?
);
assert_eq!(
interchain_abstract
.get_abstract(STARGAZE)?
.version_control()
.address()?,
loaded_interchain_abstract
.get_abstract(STARGAZE)?
.version_control()
.address()?,
);

Ok(())
}
13 changes: 6 additions & 7 deletions modules/contracts/apps/ping-pong/tests/ping_pong_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use abstract_app::objects::namespace::Namespace;
use abstract_app::objects::AccountId;

use abstract_app::std::ABSTRACT_EVENT_TYPE;
use abstract_client::{AbstractClient, Application, Environment, RemoteAccount};
use abstract_client::{
AbstractClient, AbstractInterchainClient, Application, Environment, RemoteAccount,
};

use abstract_app::std::objects::account::AccountTrace;
use abstract_app::std::objects::TruncatedChainId;
Expand Down Expand Up @@ -31,13 +33,10 @@ impl<'a> PingPong<'a, MockBech32, MockBech32InterchainEnv> {
fn setup(
mock_interchain: &'a MockBech32InterchainEnv,
) -> anyhow::Result<PingPong<'a, MockBech32, MockBech32InterchainEnv>> {
let mock_juno = mock_interchain.get_chain(JUNO).unwrap();
let mock_stargaze = mock_interchain.get_chain(STARGAZE).unwrap();
let interchain_abstract = AbstractInterchainClient::build(mock_interchain)?;

let abs_juno = AbstractClient::builder(mock_juno.clone()).build()?;
let abs_stargaze = AbstractClient::builder(mock_stargaze.clone()).build()?;

abs_juno.connect_to(&abs_stargaze, mock_interchain)?;
let abs_juno = interchain_abstract.get_abstract(JUNO)?;
let abs_stargaze = interchain_abstract.get_abstract(STARGAZE)?;

let namespace = Namespace::from_id(APP_ID)?;
// Publish and install on both chains
Expand Down