Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Open
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
773 changes: 585 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions contracts/callback-capturer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "callback-capturer"
version = "0.2.0"
version = "0.3.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2021"
publish = false
Expand All @@ -10,18 +10,19 @@ license = "Apache-2.0"
crate-type = ["cdylib", "rlib"]

[features]
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
simple-ica-controller = { version = "0.2.0", path = "../simple-ica-controller", features = ["library"] }
simple-ica = { version = "0.2.0", path = "../../packages/simple-ica" }
cw-utils = { version = "0.14.0" }
cw2 = { version = "0.14.0" }
cw-storage-plus = { version = "0.14.0" }
cosmwasm-schema = { version = "1.0.0" }
cosmwasm-std = { version = "1.0.0", features = ["staking", "stargate"] }
simple-ica-controller = { version = "0.3.0", path = "../simple-ica-controller", features = [
"library",
] }
simple-ica = { version = "0.3.0", path = "../../packages/simple-ica" }
cw-utils = { version = "2.0.0" }
cw2 = { version = "2.0.0" }
cw-storage-plus = { version = "2.0.0" }
cosmwasm-schema = { version = "2.0.0" }
cosmwasm-std = { version = "2.0.0", features = ["staking", "stargate"] }
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }
Expand Down
50 changes: 25 additions & 25 deletions contracts/callback-capturer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, QueryRequest, Response,
StdResult, WasmMsg,
to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, QueryRequest,
Response, StdResult, WasmMsg,
};

use cw2::set_contract_version;
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn execute_send_msgs(
};
let msg = WasmMsg::Execute {
contract_addr: cfg.simple_ica_controller.into(),
msg: to_binary(&ica_msg)?,
msg: to_json_binary(&ica_msg)?,
funds: vec![],
};

Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn execute_ibc_query(
};
let msg = WasmMsg::Execute {
contract_addr: cfg.simple_ica_controller.into(),
msg: to_binary(&ica_msg)?,
msg: to_json_binary(&ica_msg)?,
funds: vec![],
};

Expand All @@ -131,7 +131,7 @@ pub fn execute_check_remote_balance(
let ica_msg = simple_ica_controller::msg::ExecuteMsg::CheckRemoteBalance { channel_id };
let msg = WasmMsg::Execute {
contract_addr: cfg.simple_ica_controller.into(),
msg: to_binary(&ica_msg)?,
msg: to_json_binary(&ica_msg)?,
funds: vec![],
};

Expand All @@ -157,7 +157,7 @@ pub fn execute_send_funds(
};
let msg = WasmMsg::Execute {
contract_addr: cfg.simple_ica_controller.into(),
msg: to_binary(&ica_msg)?,
msg: to_json_binary(&ica_msg)?,
funds: info.funds,
};

Expand Down Expand Up @@ -188,8 +188,8 @@ pub fn execute_receive_ibc_response(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Admin {} => to_binary(&query_admin(deps)?),
QueryMsg::Result { id } => to_binary(&query_result(deps, id)?),
QueryMsg::Admin {} => to_json_binary(&query_admin(deps)?),
QueryMsg::Result { id } => to_json_binary(&query_result(deps, id)?),
}
}

Expand All @@ -208,25 +208,25 @@ pub fn query_result(deps: Deps, id: String) -> StdResult<ResultResponse> {
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};
use cosmwasm_std::{coins, BankMsg, BankQuery, SubMsg, WasmMsg};
use simple_ica::{IbcQueryResponse, StdAck};

#[test]
fn send_message_enforces_permissions() {
let mut deps = mock_dependencies();

let alice = "alice";
let bob = "bob";
let carl = "carl";
let ica = "simple_ica";
let alice = deps.api.addr_make("alice");
let bob = deps.api.addr_make("bob");
let carl = deps.api.addr_make("carl");
let ica = deps.api.addr_make("simple_ica");
let channel = "channel-23";

// instantiate the contract
let instantiate_msg = InstantiateMsg {
simple_ica_controller: ica.to_string(),
};
let info = mock_info(alice, &[]);
let info = message_info(&alice, &[]);
instantiate(deps.as_mut(), mock_env(), info, instantiate_msg).unwrap();

// try to send without permissions
Expand All @@ -242,16 +242,16 @@ mod tests {
};

// bob cannot execute them
let info = mock_info(bob, &[]);
let info = message_info(&bob, &[]);
let err = execute(deps.as_mut(), mock_env(), info, execute_msg.clone()).unwrap_err();
assert_eq!(err, ContractError::Unauthorized {});

// but alice can (original owner)
let info = mock_info(alice, &[]);
let info = message_info(&alice, &[]);
let res = execute(deps.as_mut(), mock_env(), info, execute_msg).unwrap();
let expected = vec![SubMsg::new(WasmMsg::Execute {
contract_addr: ica.to_string(),
msg: to_binary(&simple_ica_controller::msg::ExecuteMsg::SendMsgs {
msg: to_json_binary(&simple_ica_controller::msg::ExecuteMsg::SendMsgs {
channel_id: channel.to_string(),
msgs,
callback_id: Some("test".to_string()),
Expand All @@ -266,17 +266,17 @@ mod tests {
fn query_and_callback_work() {
let mut deps = mock_dependencies();

let alice = "alice";
let bob = "bob";
let ica = "simple_ica";
let alice = deps.api.addr_make("alice");
let bob = deps.api.addr_make("bob");
let ica = deps.api.addr_make("simple_ica");
let channel = "channel-23";
let callback = "my-balance";

// instantiate the contract
let instantiate_msg = InstantiateMsg {
simple_ica_controller: ica.to_string(),
};
let info = mock_info(alice, &[]);
let info = message_info(&alice, &[]);
instantiate(deps.as_mut(), mock_env(), info, instantiate_msg).unwrap();

// try to send without permissions
Expand All @@ -292,11 +292,11 @@ mod tests {
};

// alice can execute
let info = mock_info(alice, &[]);
let info = message_info(&alice, &[]);
let res = execute(deps.as_mut(), mock_env(), info, execute_msg).unwrap();
let expected = vec![SubMsg::new(WasmMsg::Execute {
contract_addr: ica.to_string(),
msg: to_binary(&simple_ica_controller::msg::ExecuteMsg::IbcQuery {
msg: to_json_binary(&simple_ica_controller::msg::ExecuteMsg::IbcQuery {
channel_id: channel.to_string(),
msgs: queries,
callback_id: Some(callback.to_string()),
Expand All @@ -308,12 +308,12 @@ mod tests {

// we get a callback
let ack = StdAck::Result(
to_binary(&IbcQueryResponse {
to_json_binary(&IbcQueryResponse {
results: vec![b"{}".into()],
})
.unwrap(),
);
let info = mock_info(ica, &[]);
let info = message_info(&ica, &[]);
let msg = ExecuteMsg::ReceiveIcaResponse(ReceiveIcaResponseMsg {
id: callback.to_string(),
msg: ack.clone(),
Expand Down
14 changes: 6 additions & 8 deletions contracts/simple-ica-controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "simple-ica-controller"
version = "0.2.0"
version = "0.3.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2021"
publish = false
Expand All @@ -24,19 +24,17 @@ overflow-checks = true

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
simple-ica = { version = "0.2.0", path = "../../packages/simple-ica"}
cosmwasm-std = { version = "1.0.0", features = ["iterator", "ibc3"] }
cw-storage-plus = { version = "0.14.0" }
cw-utils = { version = "0.14.0" }
simple-ica = { version = "0.3.0", path = "../../packages/simple-ica" }
cosmwasm-std = { version = "2.0.0", features = ["iterator", "stargate"] }
cw-storage-plus = { version = "2.0.0" }
cw-utils = { version = "2.0.0" }
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }

[dev-dependencies]
cosmwasm-schema = { version = "1.0.0" }
cosmwasm-schema = { version = "2.0.0" }
24 changes: 13 additions & 11 deletions contracts/simple-ica-controller/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, CosmosMsg, Deps, DepsMut, Empty, Env, IbcMsg, MessageInfo, Order, QueryRequest,
to_json_binary, CosmosMsg, Deps, DepsMut, Empty, Env, IbcMsg, MessageInfo, Order, QueryRequest,
QueryResponse, Response, StdError, StdResult,
};

Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn execute_send_msgs(
};
let msg = IbcMsg::SendPacket {
channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(),
};

Expand All @@ -121,7 +121,7 @@ pub fn execute_ibc_query(
};
let msg = IbcMsg::SendPacket {
channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(),
};

Expand Down Expand Up @@ -149,7 +149,7 @@ pub fn execute_check_remote_balance(
let packet = PacketMsg::Balances {};
let msg = IbcMsg::SendPacket {
channel_id,
data: to_binary(&packet)?,
data: to_json_binary(&packet)?,
timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(),
};

Expand Down Expand Up @@ -199,6 +199,7 @@ pub fn execute_send_funds(
to_address: remote_addr,
amount,
timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(),
memo: None,
};

let res = Response::new()
Expand All @@ -210,11 +211,11 @@ pub fn execute_send_funds(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<QueryResponse> {
match msg {
QueryMsg::Admin {} => to_binary(&query_admin(deps)?),
QueryMsg::Account { channel_id } => to_binary(&query_account(deps, channel_id)?),
QueryMsg::ListAccounts {} => to_binary(&query_list_accounts(deps)?),
QueryMsg::Admin {} => to_json_binary(&query_admin(deps)?),
QueryMsg::Account { channel_id } => to_json_binary(&query_account(deps, channel_id)?),
QueryMsg::ListAccounts {} => to_json_binary(&query_list_accounts(deps)?),
QueryMsg::LatestQueryResult { channel_id } => {
to_binary(&query_latest_ibc_query_result(deps, channel_id)?)
to_json_binary(&query_latest_ibc_query_result(deps, channel_id)?)
}
}
}
Expand Down Expand Up @@ -249,19 +250,20 @@ fn query_admin(deps: Deps) -> StdResult<AdminResponse> {
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};

const CREATOR: &str = "creator";

#[test]
fn instantiate_works() {
let mut deps = mock_dependencies();
let creator = deps.api.addr_make(CREATOR);
let msg = InstantiateMsg {};
let info = mock_info(CREATOR, &[]);
let info = message_info(&creator, &[]);
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
assert_eq!(0, res.messages.len());

let admin = query_admin(deps.as_ref()).unwrap();
assert_eq!(CREATOR, admin.admin.as_str());
assert_eq!(creator.to_string(), admin.admin);
}
}
Loading