diff --git a/cosmwasm/Cargo.lock b/cosmwasm/Cargo.lock index 79d93cddf1..8c4d2a5462 100644 --- a/cosmwasm/Cargo.lock +++ b/cosmwasm/Cargo.lock @@ -2,6 +2,31 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "abstract-cw-multi-test" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c77f8d4bac08f74fbc4fce8943cb2d35e742682b6cae8cb65555d6cd3830feb" +dependencies = [ + "anyhow", + "bech32 0.11.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw20-ics20", + "derivative", + "hex", + "itertools 0.12.1", + "log", + "prost 0.12.6", + "schemars", + "serde", + "serde_json", + "sha2 0.10.8", + "thiserror", +] + [[package]] name = "accountant" version = "0.1.0" @@ -122,6 +147,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bitflags" version = "1.3.2" @@ -327,7 +358,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c21fde95ccd20044a23c0ac6fd8c941f3e8c158169dc94b5aa6491a2d9551a8d" dependencies = [ "base64 0.21.7", - "bech32", + "bech32 0.9.1", "bnum", "cosmwasm-crypto", "cosmwasm-derive", @@ -560,6 +591,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cw-controllers" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57de8d3761e46be863e3ac1eba8c8a976362a48c6abf240df1e26c3e421ee9e8" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw-multi-test" version = "0.13.4" @@ -581,17 +627,17 @@ dependencies = [ [[package]] name = "cw-multi-test" -version = "0.20.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc392a5cb7e778e3f90adbf7faa43c4db7f35b6623224b08886d796718edb875" +checksum = "91fc33b1d65c102d72f46548c64dca423c337e528d6747d0c595316aa65f887b" dependencies = [ "anyhow", - "bech32", + "bech32 0.11.0", "cosmwasm-std", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "derivative", - "itertools 0.12.1", + "itertools 0.13.0", "prost 0.12.6", "schemars", "serde", @@ -687,6 +733,19 @@ dependencies = [ "serde", ] +[[package]] +name = "cw20" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526e39bb20534e25a1cd0386727f0038f4da294e5e535729ba3ef54055246abd" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-utils 1.0.3", + "schemars", + "serde", +] + [[package]] name = "cw20-base" version = "0.13.4" @@ -697,12 +756,31 @@ dependencies = [ "cw-storage-plus 0.13.4", "cw-utils 0.13.4", "cw2 0.13.4", - "cw20", + "cw20 0.13.4", "schemars", "serde", "thiserror", ] +[[package]] +name = "cw20-ics20" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76221201da08fed611c857ea3aa21c031a4a7dc771a8b1750559ca987335dc02" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-controllers", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", + "cw2 1.1.2", + "cw20 1.1.2", + "schemars", + "semver", + "serde", + "thiserror", +] + [[package]] name = "cw20-wrapped-2" version = "0.1.0" @@ -710,7 +788,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw2 0.13.4", - "cw20", + "cw20 0.13.4", "cw20-base", "schemars", "serde", @@ -1179,7 +1257,7 @@ dependencies = [ "cosmwasm-std", "cw-storage-plus 0.13.4", "cw-utils 1.0.3", - "cw20", + "cw20 0.13.4", "cw20-base", "cw20-wrapped-2", "hex", @@ -1237,6 +1315,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -2158,7 +2245,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw2 0.13.4", - "cw20", + "cw20 0.13.4", "protobuf", "schemars", "serde", @@ -2206,7 +2293,7 @@ version = "0.1.0" dependencies = [ "cosmwasm-std", "cosmwasm-storage", - "cw20", + "cw20 0.13.4", "cw20-base", "cw20-wrapped-2", "hex", @@ -2697,17 +2784,21 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" name = "wormchain-ibc-receiver" version = "0.1.0" dependencies = [ + "abstract-cw-multi-test", "anyhow", "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test 0.20.1", - "cw-storage-plus 0.13.4", + "cw-storage-plus 1.2.0", + "hex", "semver", "serde", "serde-json-wasm 0.4.1", "serde_wormhole", "thiserror", + "wormchain-ibc-receiver", "wormhole-bindings", + "wormhole-cosmwasm", + "wormhole-ibc", "wormhole-vaas-serde", ] @@ -2715,10 +2806,10 @@ dependencies = [ name = "wormhole-bindings" version = "0.1.0" dependencies = [ + "abstract-cw-multi-test", "anyhow", "cosmwasm-schema", "cosmwasm-std", - "cw-multi-test 0.20.1", "k256 0.11.6", "schemars", "serde", @@ -2748,14 +2839,19 @@ dependencies = [ "anyhow", "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 0.13.4", + "cw-multi-test 1.2.0", + "cw-storage-plus 1.2.0", "hex", "schemars", "semver", "serde", + "serde-json-wasm 0.4.1", "serde_wormhole", "thiserror", + "wormchain-ibc-receiver", + "wormhole-bindings", "wormhole-cosmwasm", + "wormhole-ibc", "wormhole-vaas-serde", ] diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/Cargo.toml b/cosmwasm/contracts/wormchain-ibc-receiver/Cargo.toml index 1da6bdefa9..674770848a 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/Cargo.toml +++ b/cosmwasm/contracts/wormchain-ibc-receiver/Cargo.toml @@ -10,11 +10,12 @@ crate-type = ["cdylib", "rlib"] [features] backtraces = ["cosmwasm-std/backtraces"] library = [] +test-interface = [] [dependencies] -cosmwasm-std = { version = "1.0.0", features = ["ibc3"] } -cosmwasm-schema = "1" -cw-storage-plus = "0.13.2" +cosmwasm-std = { version = "1.5.8", features = ["ibc3"] } +cosmwasm-schema = "1.5.8" +cw-storage-plus = "1.2.0" anyhow = "1" semver = "1.0.16" thiserror = "1.0.31" @@ -23,7 +24,17 @@ wormhole-sdk = { workspace = true, features = ["schemars"] } serde_wormhole.workspace = true [dev-dependencies] -cw-multi-test = { version = "0.20" } +abstract-cw-multi-test = "1.0.1" serde-json-wasm = "0.4" wormhole-bindings = { version = "0.1.0", features = ["fake"] } serde = { version = "1.0.137", default-features = false, features = ["derive"] } + +hex = "0.4.3" +wormhole-ibc = { path = "../wormhole-ibc", features = ["test-interface"] } +wormhole-cosmwasm = { version = "0.1.0", default-features = false, features = [ + "library", + "full", +] } +wormchain-ibc-receiver = { path = "../wormchain-ibc-receiver", features = [ + "test-interface", +] } diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs index 16613f483d..b4a50b9987 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs @@ -2,7 +2,7 @@ use crate::error::ContractError; use crate::msg::{AllChannelChainsResponse, ChannelChainResponse, ExecuteMsg, QueryMsg}; use crate::state::{CHANNEL_CHAIN, VAA_ARCHIVE}; use anyhow::{bail, ensure, Context}; -use cosmwasm_std::{entry_point, to_binary, Binary, Deps, Empty, Event, StdResult}; +use cosmwasm_std::{entry_point, to_json_binary, Binary, Deps, Empty, Event, StdResult}; use cosmwasm_std::{DepsMut, Env, MessageInfo, Order, Response}; use serde_wormhole::RawMessage; use std::str; @@ -132,10 +132,10 @@ fn handle_vaa(deps: DepsMut, vaa: Binary) -> anyhow::Result StdResult { match msg { QueryMsg::ChannelChain { channel_id } => { - query_channel_chain(deps, channel_id).and_then(|resp| to_binary(&resp)) + query_channel_chain(deps, channel_id).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllChannelChains {} => { - query_all_channel_chains(deps).and_then(|resp| to_binary(&resp)) + query_all_channel_chains(deps).and_then(|resp| to_json_binary(&resp)) } } } diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs index 8b24b75968..d3111fdf30 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs @@ -1,6 +1,6 @@ use anyhow::{bail, ensure}; use cosmwasm_std::{ - entry_point, from_slice, to_binary, Attribute, Binary, ContractResult, DepsMut, Env, + entry_point, from_json, to_json_binary, Attribute, Binary, ContractResult, DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, StdError, StdResult, @@ -91,7 +91,7 @@ fn handle_packet_receive(msg: IbcPacketReceiveMsg) -> Result { receive_publish(channel_id, publish_attrs) @@ -135,7 +135,7 @@ fn receive_publish( } // send the ack and emit the message with the attributes from the wormhole message - let acknowledgement = to_binary(&ContractResult::<()>::Ok(()))?; + let acknowledgement = to_json_binary(&ContractResult::<()>::Ok(()))?; Ok(IbcReceiveResponse::new() .set_ack(acknowledgement) .add_attribute("action", "receive_publish") @@ -146,7 +146,7 @@ fn receive_publish( // this encode an error or error message into a proper acknowledgement to the recevier fn encode_ibc_error(msg: impl Into) -> Binary { // this cannot error, unwrap to keep the interface simple - to_binary(&ContractResult::<()>::Err(msg.into())).unwrap() + to_json_binary(&ContractResult::<()>::Err(msg.into())).unwrap() } /// 5. Acknowledging a packet. Called when the other chain successfully receives a packet from us. diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/interface.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/interface.rs new file mode 100644 index 0000000000..2c35862407 --- /dev/null +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/interface.rs @@ -0,0 +1,96 @@ +use crate::{ + contract::{execute, instantiate, query}, + ibc::{ + ibc_channel_close, ibc_channel_connect, ibc_channel_open, ibc_packet_ack, + ibc_packet_receive, ibc_packet_timeout, + }, +}; +use abstract_cw_multi_test::{ + ibc::IbcSimpleModule, no_init, App, AppBuilder, BankKeeper, ContractWrapper, + DistributionKeeper, Executor, MockAddressGenerator, MockApiBech32, StakeKeeper, WasmKeeper, +}; +use cosmwasm_std::{Addr, Empty, MemoryStorage, StdError}; +use wormhole_bindings::{fake::WormholeKeeper, WormholeQuery}; + +pub type MockIbcApp = ( + App< + BankKeeper, + MockApiBech32, + MemoryStorage, + WormholeKeeper, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcSimpleModule, + >, + Addr, + Addr, +); + +pub fn create_receiver_app(hrp: &'static str) -> MockIbcApp { + let mut app = AppBuilder::new_custom() + .with_ibc(IbcSimpleModule::default()) + .with_wasm(WasmKeeper::new().with_address_generator(MockAddressGenerator)) + .with_api(MockApiBech32::new(hrp)) + .with_custom(wormhole_bindings::fake::WormholeKeeper::default()) + .build(no_init); + + let user = app.api().addr_make("user"); + + let contract_wrap = ContractWrapper::new( + |deps, env, info, msg| { + execute(deps, env, info, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, info, msg| { + instantiate(deps.into_empty(), env, info, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + query(deps.into_empty(), env, msg) + // .map(|res| Binary::from(res.0)) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + ) + .with_ibc( + |deps, env, msg| { + ibc_channel_open(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_channel_connect(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_channel_close(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_packet_receive(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_packet_ack(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_packet_timeout(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + ); + + let receiver_code_id = app.store_code(Box::new(contract_wrap)); + + let contract_addr = app + .instantiate_contract( + receiver_code_id, + user.clone(), + &Empty {}, + &[], + "receiver_contract", + None, + ) + .unwrap(); + + (app, user, contract_addr) +} diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/lib.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/lib.rs index 31d3febfdc..10ce0188db 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/lib.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/lib.rs @@ -6,3 +6,6 @@ pub mod state; #[cfg(test)] pub mod tests; + +#[cfg(all(test, feature = "test-interface"))] +pub mod interface; diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/ibc_tests.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/ibc_tests.rs new file mode 100644 index 0000000000..74ce412448 --- /dev/null +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/ibc_tests.rs @@ -0,0 +1,46 @@ +use crate::{ibc as receiver_contract_ibc, interface::create_receiver_app}; +use abstract_cw_multi_test::ibc::relayer::{create_channel, create_connection}; +use anyhow::Error; +use cosmwasm_std::IbcOrder; +use wormhole_ibc::interface::create_sender_app; + +#[test] +pub fn ibc_channel_happy_path() -> anyhow::Result<(), Error> { + let (mut wormchain, wormchain_user, receiver_contract) = create_receiver_app("worm"); + let (mut sei, sei_user, sender_contract) = create_sender_app("sei"); + + let receiver_port = wormchain + .wrap() + .query_wasm_contract_info(receiver_contract.clone())? + .ibc_port + .unwrap_or(format!("wasm.{}", receiver_contract.clone())); + + let sender_port = sei + .wrap() + .query_wasm_contract_info(sender_contract.clone())? + .ibc_port + .unwrap_or(format!("wasm.{}", sender_contract.clone())); + + println!( + "receiver_ibc_port: {:?}, sender_port: {}", + receiver_port, sender_port + ); + + let (sei_connection_id, _) = create_connection(&mut sei, &mut wormchain)?; + + println!("sei_connection: {:?}", sei_connection_id); + + let new_channel = create_channel( + &mut sei, + &mut wormchain, + sei_connection_id, + sender_port, + receiver_port, + receiver_contract_ibc::IBC_APP_VERSION.to_string(), + IbcOrder::Unordered, + )?; + + println!("channel_creation: {:?}", new_channel); + + Ok(()) +} diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/integration_tests.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/integration_tests.rs index c195fed1a8..07d0246c70 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/integration_tests.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/integration_tests.rs @@ -3,9 +3,9 @@ use crate::{ msg::{AllChannelChainsResponse, ExecuteMsg, QueryMsg}, tests::test_utils::{create_gov_vaa_body, create_transfer_vaa_body, sign_vaa_body}, }; +use abstract_cw_multi_test::{no_init, AppBuilder, ContractWrapper, Executor, WasmKeeper}; use anyhow::Error; use cosmwasm_std::{testing::MockApi, Addr, Binary, Empty, StdError}; -use cw_multi_test::{no_init, AppBuilder, ContractWrapper, Executor, WasmKeeper}; use wormhole_bindings::{fake::WormholeKeeper, WormholeQuery}; use wormhole_sdk::{ ibc_receiver::{Action, GovernancePacket}, @@ -13,8 +13,8 @@ use wormhole_sdk::{ Chain, GOVERNANCE_EMITTER, }; -type WormholeApp = cw_multi_test::App< - cw_multi_test::BankKeeper, +type WormholeApp = abstract_cw_multi_test::App< + abstract_cw_multi_test::BankKeeper, MockApi, cosmwasm_std::MemoryStorage, WormholeKeeper, diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/mod.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/mod.rs index 7e5f6c1060..6d7f19d74f 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/mod.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/tests/mod.rs @@ -1,2 +1,3 @@ +pub mod ibc_tests; pub mod integration_tests; pub mod test_utils; diff --git a/cosmwasm/contracts/wormhole-ibc/Cargo.toml b/cosmwasm/contracts/wormhole-ibc/Cargo.toml index 805cb8cdb8..3ad968473c 100644 --- a/cosmwasm/contracts/wormhole-ibc/Cargo.toml +++ b/cosmwasm/contracts/wormhole-ibc/Cargo.toml @@ -10,12 +10,16 @@ crate-type = ["cdylib", "rlib"] [features] backtraces = ["cosmwasm-std/backtraces"] library = [] +test-interface = [] [dependencies] -wormhole-cosmwasm = { version = "0.1.0", default-features = false, features = ["library", "full"] } -cosmwasm-std = { version = "1.0.0", features = ["ibc3"] } -cw-storage-plus = "0.13.2" -cosmwasm-schema = "1" +wormhole-cosmwasm = { version = "0.1.0", default-features = false, features = [ + "library", + "full", +] } +cosmwasm-std = { version = "1.5.8", features = ["ibc3"] } +cw-storage-plus = "1.2.0" +cosmwasm-schema = "1.5.8" anyhow = "1" schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } @@ -26,3 +30,11 @@ wormhole-sdk = { workspace = true, features = ["schemars"] } [dev-dependencies] hex = "0.4.3" +cw-multi-test = { version = "1.2.0" } +serde-json-wasm = "0.4" +wormhole-bindings = { version = "0.1.0", features = ["fake"] } +serde = { version = "1.0.137", default-features = false, features = ["derive"] } +wormchain-ibc-receiver = { path = "../wormchain-ibc-receiver", features = [ + "test-interface", +] } +wormhole-ibc = { path = "../wormhole-ibc", features = ["test-interface"] } diff --git a/cosmwasm/contracts/wormhole-ibc/src/contract.rs b/cosmwasm/contracts/wormhole-ibc/src/contract.rs index 68384d2758..de5b48eaef 100644 --- a/cosmwasm/contracts/wormhole-ibc/src/contract.rs +++ b/cosmwasm/contracts/wormhole-ibc/src/contract.rs @@ -19,7 +19,7 @@ use crate::{ }; use anyhow::{bail, ensure, Context}; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, Event, IbcMsg, MessageInfo, Response, StdResult, + to_json_binary, Binary, Deps, DepsMut, Env, Event, IbcMsg, MessageInfo, Response, StdResult, }; use cw_wormhole::msg::{ExecuteMsg as WormholeExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; @@ -157,7 +157,7 @@ fn post_message_ibc( }; let ibc_msg = IbcMsg::SendPacket { channel_id, - data: to_binary(&packet)?, + data: to_json_binary(&packet)?, timeout: packet_timeout, }; diff --git a/cosmwasm/contracts/wormhole-ibc/src/interface.rs b/cosmwasm/contracts/wormhole-ibc/src/interface.rs new file mode 100644 index 0000000000..c2fc8557ed --- /dev/null +++ b/cosmwasm/contracts/wormhole-ibc/src/interface.rs @@ -0,0 +1,118 @@ +use crate::{ + contract::{execute, instantiate, query}, + ibc::{ + ibc_channel_close, ibc_channel_connect, ibc_channel_open, ibc_packet_ack, + ibc_packet_receive, ibc_packet_timeout, + }, +}; +use abstract_cw_multi_test::{ + ibc::{ + relayer::{create_channel, create_connection}, + types::{Connection, MockIbcQuery}, + IbcPacketRelayingMsg, IbcSimpleModule, + }, + no_init, AcceptingModule, App, AppBuilder, BankKeeper, ContractWrapper, DistributionKeeper, + Executor, IbcAcceptingModule, MockAddressGenerator, MockApiBech32, StakeKeeper, WasmKeeper, +}; +use cosmwasm_std::{Addr, StdError}; +use cw_wormhole::state::{GuardianAddress, GuardianSetInfo}; +use hex::decode; +use wormhole_bindings::{fake::WormholeKeeper, WormholeQuery}; + +static GOV_ADDR: &[u8] = b"GOVERNANCE_ADDRESS"; + +pub fn create_sender_app( + hrp: &'static str, +) -> ( + App< + BankKeeper, + MockApiBech32, + MemoryStorage, + WormholeKeeper, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcSimpleModule, + >, + Addr, + Addr, +) { + let mut app = AppBuilder::new_custom() + .with_ibc(IbcSimpleModule::default()) + .with_wasm(WasmKeeper::new().with_address_generator(MockAddressGenerator)) + .with_api(MockApiBech32::new(hrp)) + .with_custom(wormhole_bindings::fake::WormholeKeeper::default()) + .build(no_init); + + let user = app.api().addr_make("user"); + + let contract_code_id = app.store_code(Box::new( + ContractWrapper::new( + |deps, env, info, msg| { + execute(deps.into_empty(), env, info, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, info, msg| { + instantiate(deps.into_empty(), env, info, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + query(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + ) + .with_ibc( + |deps, env, msg| { + ibc_channel_open(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_channel_connect(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_channel_close(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_packet_receive(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_packet_ack(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + |deps, env, msg| { + ibc_packet_timeout(deps.into_empty(), env, msg) + .map_err(|anyhow_err| StdError::generic_err(anyhow_err.to_string())) + }, + ), + )); + + let contract_addr = app + .instantiate_contract( + contract_code_id, + user.clone(), + &cw_wormhole::msg::InstantiateMsg { + gov_chain: 0, + gov_address: GOV_ADDR.into(), + initial_guardian_set: GuardianSetInfo { + addresses: vec![GuardianAddress { + bytes: decode("beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe") + .expect("Decoding failed") + .into(), + }], + expiration_time: 100, + }, + guardian_set_expirity: 50, + chain_id: 18, + fee_denom: "uluna".to_string(), + }, + &[], + "wormhole_ibc", + None, + ) + .expect("contract should instantiate correctly"); + + (app, user, contract_addr) +} diff --git a/cosmwasm/contracts/wormhole-ibc/src/lib.rs b/cosmwasm/contracts/wormhole-ibc/src/lib.rs index 1130f05ec2..b5542914c8 100644 --- a/cosmwasm/contracts/wormhole-ibc/src/lib.rs +++ b/cosmwasm/contracts/wormhole-ibc/src/lib.rs @@ -2,3 +2,6 @@ pub mod contract; pub mod ibc; pub mod msg; pub mod state; + +#[cfg(all(test, feature = "test-interface"))] +pub mod interface; diff --git a/cosmwasm/packages/wormhole-bindings/Cargo.toml b/cosmwasm/packages/wormhole-bindings/Cargo.toml index 823c2e6421..1d84983f2a 100644 --- a/cosmwasm/packages/wormhole-bindings/Cargo.toml +++ b/cosmwasm/packages/wormhole-bindings/Cargo.toml @@ -5,15 +5,15 @@ authors = ["Wormhole Project Contributors"] edition = "2021" [features] -fake = ["dep:cw-multi-test", "dep:k256", "dep:serde_wormhole"] +fake = ["dep:abstract-cw-multi-test", "dep:k256", "dep:serde_wormhole"] [dependencies] anyhow = "1" -cosmwasm-schema = "1" -cosmwasm-std = "1" +cosmwasm-schema = "1.5.8" +cosmwasm-std = "1.5.8" schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } serde_wormhole = { workspace = true, optional = true } -cw-multi-test = { version = "0.20.0", optional = true } +abstract-cw-multi-test = { version = "1.0.1", optional = true } k256 = { version = "0.11", optional = true, features = ["ecdsa", "keccak256"] } wormhole-sdk.workspace = true diff --git a/cosmwasm/packages/wormhole-bindings/src/fake.rs b/cosmwasm/packages/wormhole-bindings/src/fake.rs index c97771addf..a51f7addbe 100644 --- a/cosmwasm/packages/wormhole-bindings/src/fake.rs +++ b/cosmwasm/packages/wormhole-bindings/src/fake.rs @@ -1,8 +1,10 @@ use std::{cell::RefCell, collections::BTreeSet, fmt::Debug, rc::Rc}; +use abstract_cw_multi_test::{AppResponse, CosmosRouter, Module}; use anyhow::{anyhow, bail, ensure, Context}; -use cosmwasm_std::{to_binary, Addr, Api, Binary, BlockInfo, CustomQuery, Empty, Querier, Storage}; -use cw_multi_test::{AppResponse, CosmosRouter, Module}; +use cosmwasm_std::{ + to_json_binary, Addr, Api, Binary, BlockInfo, CustomQuery, Empty, Querier, Storage, +}; use k256::ecdsa::{recoverable, signature::Signer, SigningKey}; use schemars::JsonSchema; use serde::de::DeserializeOwned; @@ -171,7 +173,7 @@ impl WormholeKeeper { match request { WormholeQuery::VerifyVaa { vaa } => self .verify_vaa(&vaa, block.height) - .and_then(|e| to_binary(&e).map_err(From::from)), + .and_then(|e| to_json_binary(&e).map_err(From::from)), WormholeQuery::VerifyMessageSignature { prefix, data, @@ -179,10 +181,10 @@ impl WormholeKeeper { signature, } => self .verify_signature(&prefix, &data, guardian_set_index, &signature, block.height) - .and_then(|e| to_binary(&e).map_err(From::from)), + .and_then(|e| to_json_binary(&e).map_err(From::from)), WormholeQuery::CalculateQuorum { guardian_set_index } => self .calculate_quorum(guardian_set_index, block.height) - .and_then(|q| to_binary(&q).map_err(From::from)), + .and_then(|q| to_json_binary(&q).map_err(From::from)), } }