Skip to content

Commit

Permalink
Merge pull request #213 from icon-project/development/177-xcall-futur…
Browse files Browse the repository at this point in the history
…e-proof-messaging

feat: 177-xcall future proof messaging
  • Loading branch information
AntonAndell authored Mar 15, 2024
2 parents 96d156a + 3e87596 commit 617016e
Show file tree
Hide file tree
Showing 84 changed files with 5,796 additions and 1,325 deletions.
1,368 changes: 1,062 additions & 306 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ repository = "https://github.com/icon-project/ibc-integration.git"
version="0.2.0"

[workspace.dependencies]
cosmwasm-std = {version="1.2.2",default-features = false}
cosmwasm-std = {version="1.2.2",default-features = false,features = ["iterator", "staking"]}
cw-storage-plus = {git="https://github.com/icon-project/cw-storage-plus.git", branch="fix-raw"}
cosmwasm-schema = {version="1.2.2",default-features = false}
common = { git = "https://github.com/icon-project/IBC-Integration.git",branch="feat/cw-wasm-light-client" ,default-features = false}
schemars = {version="0.8.12",default-features = false}
cw2 = {version="1.0.1",default-features = false}
cosmwasm-storage = "1.2.2"
cosmwasm-schema = "1.2.2"
schemars = "0.8.12"
cw2 = "1.0.1"

prost = { version = "0.11.8", default-features = false,features=["prost-derive"]}

Expand All @@ -27,8 +27,15 @@ bytes = { version = "1.4.0", default-features = false }
thiserror = { version = "1.0.39" }
hex ={ version = "0.4.3", default-features = false }
debug_print = "1.0.0"


cw-xcall-lib = { path="contracts/cosmwasm-vm/cw-xcall-lib" }
cw-xcall={ path="contracts/cosmwasm-vm/cw-xcall" }
cw-xcall-ibc-connection = { git="https://github.com/icon-project/IBC-Integration.git", branch = "main" }
cw-mock-ibc-core = { git="https://github.com/icon-project/IBC-Integration.git", branch = "main"}
common = { git="https://github.com/icon-project/IBC-Integration.git", branch = "main" }
cw-common={ git="https://github.com/icon-project/IBC-Integration.git", branch = "main" }

cw-mock-dapp = {path="contracts/cosmwasm-vm/cw-mock-dapp"}
cw-mock-dapp-multi = { path="contracts/cosmwasm-vm/cw-mock-dapp-multi"}

[profile.release]
opt-level = 'z'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ build-java-docker:
docker-compose -f ./scripts/docker-compose.yml up java

build-wasm-docker:
@echo "Build java contracts"
@echo "Build wasm contracts"
docker-compose -f ./scripts/docker-compose.yml up wasm

gobuild:
Expand Down
34 changes: 34 additions & 0 deletions contracts/cosmwasm-vm/cw-integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "cw-integration"
version.workspace = true
authors.workspace = true
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cosmwasm-schema = {workspace=true}
cosmwasm-std = {workspace=true}
cw-storage-plus = {workspace=true}
cw-common={workspace=true}
common = { workspace=true, default-features = false }
ibc = { version = "0.32.0", default-features = false, features = ["parity-scale-codec", "mocks-no-std", "serde"]}
prost = { workspace=true}
strum="*"
strum_macros = "0.24"
cw-xcall-lib={package = "cw-xcall-lib",workspace=true}

[dev-dependencies]
hex = "0.4.3"
cw-multi-test = "0.15.1"
cw-xcall-ibc-connection = { workspace=true }
cw-mock-ibc-core = { workspace=true }
cw-mock-dapp = { workspace=true}
cw-mock-dapp-multi = { workspace=true }
## xcall connection uses the alpha tag need to update
xcall-lib={package="cw-xcall-lib", git="https://github.com/icon-project/xCall.git", tag="v0.1.0-alpha.5"}

cw-xcall = {workspace=true}
anyhow="*"


277 changes: 277 additions & 0 deletions contracts/cosmwasm-vm/cw-integration/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
use std::collections::HashMap;

use cosmwasm_std::{
coins,
testing::{mock_dependencies, mock_info, MockApi, MockQuerier, MockStorage},
Addr, Attribute, Empty, Event, IbcEndpoint, MessageInfo, OwnedDeps,
};
use cw_common::ibc_types::IbcEventType;
use cw_multi_test::{App, AppResponse, Contract, ContractWrapper, Executor};
use cw_xcall_ibc_connection::state::IbcConfig;

pub const PORT: &str = "xcall";
pub const COUNTERPARTY_NID: &str = "0x3.icon";

#[derive(Debug, PartialEq, Eq, Hash)]
pub enum TestApps {
Dapp,
XcallApp,
IbcCore,
XcallIbcConnection,
}

pub struct TestContext {
pub app: App,
pub contracts: HashMap<TestApps, Addr>,
pub sender: Addr,
pub admin: Option<String>,
pub caller: Option<String>,
}

impl TestContext {
pub fn get_dapp(&self) -> Addr {
return self.contracts.get(&TestApps::Dapp).unwrap().clone();
}
pub fn get_ibc_core(&self) -> Addr {
return self.contracts.get(&TestApps::IbcCore).unwrap().clone();
}

pub fn get_xcall_app(&self) -> Addr {
return self.contracts.get(&TestApps::XcallApp).unwrap().clone();
}
pub fn get_xcall_ibc_connection(&self) -> Addr {
return self
.contracts
.get(&TestApps::XcallIbcConnection)
.unwrap()
.clone();
}

pub fn set_dapp(&mut self, addr: Addr) -> Option<Addr> {
self.contracts.insert(TestApps::Dapp, addr)
}
pub fn set_ibc_core(&mut self, addr: Addr) -> Option<Addr> {
self.contracts.insert(TestApps::IbcCore, addr)
}

pub fn set_xcall_app(&mut self, addr: Addr) -> Option<Addr> {
self.contracts.insert(TestApps::XcallApp, addr)
}
pub fn set_xcall_ibc_connection(&mut self, addr: Addr) -> Option<Addr> {
self.contracts.insert(TestApps::XcallIbcConnection, addr)
}

pub fn list_contracts(&self) {
println!("IbcHost {}", self.get_ibc_core());
println!("IbcConnection {}", self.get_xcall_ibc_connection());
println!("Xcall {}", self.get_xcall_app());
println!("Dapp {}", self.get_dapp())
}
}

pub fn create_mock_info(creator: &str, denom: &str, amount: u128) -> MessageInfo {
let funds = coins(amount, denom);
mock_info(creator, &funds)
}

pub fn deps() -> OwnedDeps<MockStorage, MockApi, MockQuerier, Empty> {
mock_dependencies()
}

pub fn mock_ibc_config() -> IbcConfig {
let src = IbcEndpoint {
port_id: "xcall".to_string(),
channel_id: "our-channel-id".to_string(),
};

let dst = IbcEndpoint {
port_id: "xcall".to_string(),
channel_id: "their-channel-id".to_string(),
};

IbcConfig::new(src, dst)
}

pub fn mock_dapp_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
cw_mock_dapp::execute,
cw_mock_dapp::instantiate,
cw_mock_dapp::query,
);
Box::new(contract)
}

pub fn mock_dapp_multi_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
cw_mock_dapp_multi::execute,
cw_mock_dapp_multi::instantiate,
cw_mock_dapp_multi::query,
);
Box::new(contract)
}

pub fn init_mock_dapp_multi_contract(mut ctx: TestContext) -> TestContext {
let code_id = ctx.app.store_code(mock_dapp_multi_contract());
let contract_addr = ctx
.app
.instantiate_contract(
code_id,
ctx.sender.clone(),
&cw_mock_dapp_multi::types::InstantiateMsg {
address: ctx.get_xcall_app().to_string(),
},
&[],
"MockApp",
Some(ctx.sender.clone().to_string()),
)
.unwrap();
ctx.set_dapp(contract_addr);

ctx
}

pub fn init_mock_dapp_contract(mut ctx: TestContext) -> TestContext {
let code_id = ctx.app.store_code(mock_dapp_contract());
let contract_addr = ctx
.app
.instantiate_contract(
code_id,
ctx.sender.clone(),
&cw_mock_dapp::types::InstantiateMsg {
address: "someaddr".to_string(),
},
&[],
"MockApp",
Some(ctx.sender.clone().to_string()),
)
.unwrap();
ctx.set_dapp(contract_addr);

ctx
}

pub fn init_mock_ibc_core_contract(mut ctx: TestContext) -> TestContext {
let ibc_core_code_id = ctx.app.store_code(mock_ibc_core_contract());
let ibc_core_addr = ctx
.app
.instantiate_contract(
ibc_core_code_id,
ctx.sender.clone(),
&cw_common::core_msg::InstantiateMsg {},
&[],
"IBCCore",
Some(ctx.sender.clone().to_string()),
)
.unwrap();

ctx.set_ibc_core(ibc_core_addr);
ctx
}

pub fn ibc_connection_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
cw_xcall_ibc_connection::execute,
cw_xcall_ibc_connection::instantiate,
cw_xcall_ibc_connection::query,
)
.with_reply(cw_xcall_ibc_connection::reply);
Box::new(contract)
}

pub fn mock_ibc_core_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
cw_mock_ibc_core::contract::execute,
cw_mock_ibc_core::contract::instantiate,
cw_mock_ibc_core::contract::query,
)
.with_reply(cw_mock_ibc_core::contract::reply);
Box::new(contract)
}

pub fn xcall_app_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(cw_xcall::execute, cw_xcall::instantiate, cw_xcall::query)
.with_reply(cw_xcall::reply);
Box::new(contract)
}

pub fn init_xcall_app_contract(mut ctx: TestContext) -> TestContext {
let xcall_app_contractcode_id = ctx.app.store_code(xcall_app_contract());
let xcall_app_contract_addr = ctx
.app
.instantiate_contract(
xcall_app_contractcode_id,
ctx.sender.clone(),
&cw_xcall::msg::InstantiateMsg {
network_id: "nid".to_string(),
denom: "uarch".to_string(),
},
&[],
"XCallApp",
Some(ctx.sender.clone().to_string()),
)
.unwrap();

ctx.set_xcall_app(xcall_app_contract_addr);
ctx
}

pub fn init_xcall_ibc_connection_contract(mut ctx: TestContext) -> TestContext {
let ibc_connection_contract_code_id = ctx.app.store_code(ibc_connection_contract());
let ibc_connection_contract_addr = ctx
.app
.instantiate_contract(
ibc_connection_contract_code_id,
ctx.sender.clone(),
&cw_xcall_ibc_connection::msg::InstantiateMsg {
ibc_host: ctx.get_ibc_core(),
denom: "uarch".to_string(),
port_id: PORT.to_string(),
xcall_address: ctx.get_xcall_app(),
},
&[],
"IBCConnection",
Some(ctx.sender.clone().to_string()),
)
.unwrap();

ctx.set_xcall_ibc_connection(ibc_connection_contract_addr);
ctx
}

pub fn setup_context() -> TestContext {
let router = App::default();
let sender = Addr::unchecked("sender");

TestContext {
app: router,
contracts: HashMap::new(),
sender,
admin: None,
caller: None,
}
}

pub fn get_event(res: &AppResponse, event: &str) -> Option<HashMap<String, String>> {
let event = res
.events
.iter()
.filter(|e| e.ty == event)
.collect::<Vec<&Event>>();
if !event.is_empty() {
let map = to_attribute_map(&event[0].attributes);
return Some(map);
}
None
}

pub fn get_event_name(event_type: IbcEventType) -> String {
format!("wasm-{}", event_type.as_str())
}

pub fn to_attribute_map(attrs: &Vec<Attribute>) -> HashMap<String, String> {
let mut map = HashMap::new();
for attr in attrs {
map.insert(attr.key.clone(), attr.value.clone());
}
map
}
Loading

0 comments on commit 617016e

Please sign in to comment.