diff --git a/contracts/default-hook/Cargo.toml b/contracts/default-hook/Cargo.toml index 894b7b50..733cb685 100644 --- a/contracts/default-hook/Cargo.toml +++ b/contracts/default-hook/Cargo.toml @@ -36,4 +36,5 @@ hpl-ownable.workspace = true hpl-interface.workspace = true [dev-dependencies] +rstest.workspace = true anyhow.workspace = true diff --git a/contracts/default-hook/src/execute/hook.rs b/contracts/default-hook/src/execute/hook.rs index b0290912..f5b26688 100644 --- a/contracts/default-hook/src/execute/hook.rs +++ b/contracts/default-hook/src/execute/hook.rs @@ -94,6 +94,7 @@ mod test { testing::{mock_dependencies, mock_info}, Addr, Storage, }; + use rstest::rstest; use super::*; const ADDR1_VALUE: &str = "addr1"; @@ -105,13 +106,14 @@ mod test { .unwrap(); } - #[test] - fn test_set_hook() { + #[rstest] + #[case(Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"))] + #[case(Addr::unchecked("neutron1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnsyg35p"))] + fn test_set_hook(#[case] hook: Addr) { let mut deps = mock_dependencies(); mock_owner(deps.as_mut().storage, ADDR1_VALUE); let destination = 11155111; - let hook = Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"); let unauthorized = set_hook( deps.as_mut(), @@ -159,21 +161,26 @@ mod test { ); } - #[test] - fn test_set_hooks() { + #[rstest] + #[case(&[ + (5, Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el")), + (11155111, Addr::unchecked("osmo1mhnkm6fwaq53yzu7c0r3khhy60v04vse4c6gk5")) + ])] + #[case(&[ + (5, Addr::unchecked("neutron1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnsyg35p")), + (11155111, Addr::unchecked("neutron1mhnkm6fwaq53yzu7c0r3khhy60v04vseeuq66p")) + ])] + fn test_set_hooks(#[case] configs: &[(u32, Addr)]) { let mut deps = mock_dependencies(); mock_owner(deps.as_mut().storage, ADDR1_VALUE); - let hooks = vec![ - HookConfig { - destination: 5, - hook: Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"), - }, - HookConfig { - destination: 11155111, - hook: Addr::unchecked("osmo1mhnkm6fwaq53yzu7c0r3khhy60v04vse4c6gk5"), - }, - ]; + let hooks: Vec<_> = configs + .iter() + .map(|v| HookConfig { + destination: v.0, + hook: v.1.clone(), + }) + .collect(); let unauthorized = set_hooks(deps.as_mut(), mock_info(ADDR2_VALUE, &[]), hooks.clone()).unwrap_err(); diff --git a/contracts/default-hook/src/query.rs b/contracts/default-hook/src/query.rs index c7b5528c..2b7787bf 100644 --- a/contracts/default-hook/src/query.rs +++ b/contracts/default-hook/src/query.rs @@ -56,6 +56,7 @@ mod test { Addr, HexBinary, Uint256, }; use hpl_interface::hook::HookConfig; + use rstest::rstest; use super::*; @@ -100,8 +101,10 @@ mod test { ) } - #[test] - fn test_quote_dispatch() { + #[rstest] + #[case(Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"))] + #[case(Addr::unchecked("neutron1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnsyg35p"))] + fn test_quote_dispatch(#[case] hook: Addr) { let mut deps = mock_dependencies(); deps.querier.update_wasm( @@ -117,7 +120,6 @@ mod test { }, ); - let hook = Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"); let hook_config = HookConfig { hook, destination: 11155111, diff --git a/contracts/domain-routing-hook/Cargo.toml b/contracts/domain-routing-hook/Cargo.toml index a59a5eac..23696ed5 100644 --- a/contracts/domain-routing-hook/Cargo.toml +++ b/contracts/domain-routing-hook/Cargo.toml @@ -36,4 +36,5 @@ hpl-ownable.workspace = true hpl-interface.workspace = true [dev-dependencies] +rstest.workspace = true anyhow.workspace = true diff --git a/contracts/domain-routing-hook/src/query.rs b/contracts/domain-routing-hook/src/query.rs index c7b5528c..2b7787bf 100644 --- a/contracts/domain-routing-hook/src/query.rs +++ b/contracts/domain-routing-hook/src/query.rs @@ -56,6 +56,7 @@ mod test { Addr, HexBinary, Uint256, }; use hpl_interface::hook::HookConfig; + use rstest::rstest; use super::*; @@ -100,8 +101,10 @@ mod test { ) } - #[test] - fn test_quote_dispatch() { + #[rstest] + #[case(Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"))] + #[case(Addr::unchecked("neutron1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnsyg35p"))] + fn test_quote_dispatch(#[case] hook: Addr) { let mut deps = mock_dependencies(); deps.querier.update_wasm( @@ -117,7 +120,6 @@ mod test { }, ); - let hook = Addr::unchecked("osmo109ns4u04l44kqdkvp876hukd3hxz8zzm7809el"); let hook_config = HookConfig { hook, destination: 11155111, diff --git a/contracts/mock-msg-receiver/src/contract.rs b/contracts/mock-msg-receiver/src/contract.rs index d2dfa93c..71c7fb39 100644 --- a/contracts/mock-msg-receiver/src/contract.rs +++ b/contracts/mock-msg-receiver/src/contract.rs @@ -5,12 +5,15 @@ use cosmwasm_std::{ attr, to_binary, Deps, DepsMut, Env, Event, MessageInfo, QueryResponse, Response, StdResult, }; use cw2::set_contract_version; +use cw_storage_plus::Item; use hpl_interface::{ism, mailbox, types::bech32_encode}; use crate::{CONTRACT_NAME, CONTRACT_VERSION}; #[cw_serde] -pub struct InstantiateMsg {} +pub struct InstantiateMsg { + pub hrp: String, +} #[cw_serde] pub struct MigrateMsg {} @@ -18,15 +21,20 @@ pub struct MigrateMsg {} #[cw_serde] pub struct ExecuteMsg {} +pub const HRP_KEY: &str = "hrp"; +pub const HRP: Item = Item::new(HRP_KEY); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, _env: Env, _info: MessageInfo, - _msg: InstantiateMsg, + msg: InstantiateMsg, ) -> StdResult { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + HRP.save(deps.storage, &msg.hrp)?; + Ok(Response::new().add_attribute("method", "instantiate")) } @@ -38,7 +46,7 @@ pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult Ok(Response::default().add_event( Event::new("mailbox_msg_received").add_attributes(vec![ - attr("sender", bech32_encode("osmo", &msg.sender)?), + attr( + "sender", + bech32_encode(&HRP.load(deps.storage)?, &msg.sender)?, + ), attr("origin", msg.origin.to_string()), attr("body", std::str::from_utf8(&msg.body)?), ]), diff --git a/contracts/token-cw20/Cargo.toml b/contracts/token-cw20/Cargo.toml index 5e75f229..b99b4cb2 100644 --- a/contracts/token-cw20/Cargo.toml +++ b/contracts/token-cw20/Cargo.toml @@ -42,7 +42,7 @@ hpl-router.workspace = true hpl-interface.workspace = true [dev-dependencies] - +rstest.workspace = true anyhow.workspace = true k256.workspace = true sha3.workspace = true diff --git a/contracts/token-cw20/src/contract.rs b/contracts/token-cw20/src/contract.rs index d7ef069d..7d3a81b9 100644 --- a/contracts/token-cw20/src/contract.rs +++ b/contracts/token-cw20/src/contract.rs @@ -16,7 +16,7 @@ use hpl_interface::{ use crate::{ error::ContractError, msg::{InstantiateMsg, MigrateMsg, TokenOption}, - state::{MAILBOX, MODE, OWNER, TOKEN}, + state::{HRP, MAILBOX, MODE, OWNER, TOKEN}, CONTRACT_NAME, CONTRACT_VERSION, REPLY_ID_CREATE_DENOM, }; @@ -29,6 +29,7 @@ pub fn instantiate( ) -> Result { cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + HRP.save(deps.storage, &msg.hrp)?; MODE.save(deps.storage, &msg.mode)?; OWNER.save(deps.storage, &deps.api.addr_validate(&msg.owner)?)?; MAILBOX.save(deps.storage, &deps.api.addr_validate(&msg.mailbox)?)?; @@ -104,7 +105,7 @@ pub fn execute( ); let token_msg: token::Message = msg.body.into(); - let recipient = bech32_encode("osmo", &token_msg.recipient)?; + let recipient = bech32_encode(&HRP.load(deps.storage)?, &token_msg.recipient)?; let token = TOKEN.load(deps.storage)?; let mode = MODE.load(deps.storage)?; diff --git a/contracts/token-cw20/src/msg.rs b/contracts/token-cw20/src/msg.rs index 8bec5674..793b18e9 100644 --- a/contracts/token-cw20/src/msg.rs +++ b/contracts/token-cw20/src/msg.rs @@ -17,6 +17,7 @@ pub struct InstantiateMsg { pub token: Option, pub mode: TokenMode, + pub hrp: String, pub owner: String, pub mailbox: String, } diff --git a/contracts/token-cw20/src/state.rs b/contracts/token-cw20/src/state.rs index 468fb19b..d041e2f2 100644 --- a/contracts/token-cw20/src/state.rs +++ b/contracts/token-cw20/src/state.rs @@ -8,6 +8,9 @@ pub const TOKEN: Item = Item::new(TOKEN_KEY); pub const MODE_KEY: &str = "mode"; pub const MODE: Item = Item::new(MODE_KEY); +pub const HRP_KEY: &str = "hrp"; +pub const HRP: Item = Item::new(HRP_KEY); + pub const OWNER_KEY: &str = "owner"; pub const OWNER: Item = Item::new(OWNER_KEY); diff --git a/contracts/token-cw20/src/tests/contracts.rs b/contracts/token-cw20/src/tests/contracts.rs index 7e57c5fa..c72560dd 100644 --- a/contracts/token-cw20/src/tests/contracts.rs +++ b/contracts/token-cw20/src/tests/contracts.rs @@ -6,11 +6,14 @@ use hpl_interface::{ token::{self, TokenMode}, types::bech32_encode, }; +use rstest::rstest; use crate::{error::ContractError, msg::TokenOption, state::TOKEN, tests::TokenCW20}; -#[test] -fn test_router_role() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_router_role(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let owner = Addr::unchecked("owner"); @@ -29,6 +32,7 @@ fn test_router_role() -> anyhow::Result<()> { contract: token.to_string(), }), TokenMode::Bridged, + hrp, )?; // err @@ -43,8 +47,10 @@ fn test_router_role() -> anyhow::Result<()> { Ok(()) } -#[test] -fn test_outbound_transfer() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_outbound_transfer(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let router = Addr::unchecked("router"); @@ -123,6 +129,7 @@ fn test_outbound_transfer() -> anyhow::Result<()> { contract: token.to_string(), }), mode.clone(), + hrp, )?; if mode == TokenMode::Collateral { TOKEN.save(&mut warp.deps.storage, &token)?; @@ -149,8 +156,10 @@ fn test_outbound_transfer() -> anyhow::Result<()> { Ok(()) } -#[test] -fn test_inbound_transfer() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_inbound_transfer(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let router = Addr::unchecked("router"); @@ -169,7 +178,7 @@ fn test_inbound_transfer() -> anyhow::Result<()> { let mint_msg: CosmosMsg = WasmMsg::Execute { contract_addr: token.to_string(), msg: to_binary(&cw20::Cw20ExecuteMsg::Mint { - recipient: bech32_encode("osmo", user_remote.as_bytes())?.to_string(), + recipient: bech32_encode(hrp, user_remote.as_bytes())?.to_string(), amount: amount.into(), })?, funds: vec![], @@ -179,7 +188,7 @@ fn test_inbound_transfer() -> anyhow::Result<()> { let send_msg: CosmosMsg = WasmMsg::Execute { contract_addr: token.to_string(), msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer { - recipient: bech32_encode("osmo", user_remote.as_bytes())?.to_string(), + recipient: bech32_encode(hrp, user_remote.as_bytes())?.to_string(), amount: amount.into(), })?, funds: vec![], @@ -257,6 +266,7 @@ fn test_inbound_transfer() -> anyhow::Result<()> { contract: token.to_string(), }), mode.clone(), + hrp, )?; if mode == TokenMode::Collateral { TOKEN.save(&mut warp.deps.storage, &token)?; diff --git a/contracts/token-cw20/src/tests/mod.rs b/contracts/token-cw20/src/tests/mod.rs index 8686ac7a..01cd3649 100644 --- a/contracts/token-cw20/src/tests/mod.rs +++ b/contracts/token-cw20/src/tests/mod.rs @@ -40,6 +40,7 @@ impl TokenCW20 { mailbox: &Addr, token: Option, mode: TokenMode, + hrp: &str, ) -> Result { instantiate( self.deps.as_mut(), @@ -48,6 +49,7 @@ impl TokenCW20 { InstantiateMsg { token, mode, + hrp: hrp.to_string(), owner: owner.to_string(), mailbox: mailbox.to_string(), }, diff --git a/contracts/token-native/src/contract.rs b/contracts/token-native/src/contract.rs index 8a742b83..6c60ef15 100644 --- a/contracts/token-native/src/contract.rs +++ b/contracts/token-native/src/contract.rs @@ -17,7 +17,7 @@ use crate::{ error::ContractError, msg::{InstantiateMsg, MigrateMsg}, proto::{self, MsgBurn, MsgCreateDenom, MsgCreateDenomResponse, MsgMint, MsgSetDenomMetadata}, - state::{MAILBOX, MODE, OWNER, TOKEN}, + state::{HRP, MAILBOX, MODE, OWNER, TOKEN}, CONTRACT_NAME, CONTRACT_VERSION, REPLY_ID_CREATE_DENOM, }; @@ -30,6 +30,7 @@ pub fn instantiate( ) -> Result { cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + HRP.save(deps.storage, &msg.hrp)?; MODE.save(deps.storage, &msg.mode)?; OWNER.save(deps.storage, &deps.api.addr_validate(&msg.owner)?)?; MAILBOX.save(deps.storage, &deps.api.addr_validate(&msg.mailbox)?)?; @@ -116,7 +117,7 @@ pub fn execute( ); let token_msg: token::Message = msg.body.into(); - let recipient = bech32_encode("osmo", &token_msg.recipient)?; + let recipient = bech32_encode(&HRP.load(deps.storage)?, &token_msg.recipient)?; let token = TOKEN.load(deps.storage)?; let mode = MODE.load(deps.storage)?; diff --git a/contracts/token-native/src/msg.rs b/contracts/token-native/src/msg.rs index d1c75e9b..9776bce3 100644 --- a/contracts/token-native/src/msg.rs +++ b/contracts/token-native/src/msg.rs @@ -28,6 +28,7 @@ pub struct InstantiateMsg { pub metadata: Option, pub mode: TokenMode, + pub hrp: String, pub owner: String, pub mailbox: String, } diff --git a/contracts/token-native/src/state.rs b/contracts/token-native/src/state.rs index 60812942..7c542471 100644 --- a/contracts/token-native/src/state.rs +++ b/contracts/token-native/src/state.rs @@ -8,6 +8,9 @@ pub const TOKEN: Item = Item::new(TOKEN_KEY); pub const MODE_KEY: &str = "mode"; pub const MODE: Item = Item::new(MODE_KEY); +pub const HRP_KEY: &str = "hrp"; +pub const HRP: Item = Item::new(HRP_KEY); + pub const OWNER_KEY: &str = "owner"; pub const OWNER: Item = Item::new(OWNER_KEY); diff --git a/contracts/token-native/src/tests/contracts.rs b/contracts/token-native/src/tests/contracts.rs index db65129b..545b59cd 100644 --- a/contracts/token-native/src/tests/contracts.rs +++ b/contracts/token-native/src/tests/contracts.rs @@ -8,6 +8,7 @@ use hpl_interface::{ token::{self, TokenMode}, types::bech32_encode, }; +use rstest::rstest; use crate::{ error::ContractError, @@ -16,8 +17,10 @@ use crate::{ use super::TokenNative; -#[test] -fn test_init() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_init(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let owner = Addr::unchecked("owner"); @@ -26,6 +29,7 @@ fn test_init() -> anyhow::Result<()> { warp.init( &deployer, + hrp, &owner, &mailbox, "token-warp", @@ -36,8 +40,10 @@ fn test_init() -> anyhow::Result<()> { Ok(()) } -#[test] -fn test_router_role() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_router_role(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let owner = Addr::unchecked("owner"); @@ -48,7 +54,7 @@ fn test_router_role() -> anyhow::Result<()> { let mut warp = TokenNative::default(); - warp.init_hack(&deployer, &owner, &mailbox, denom, TokenMode::Bridged)?; + warp.init_hack(&deployer, &owner, &mailbox, hrp, denom, TokenMode::Bridged)?; // err let err = warp @@ -62,8 +68,10 @@ fn test_router_role() -> anyhow::Result<()> { Ok(()) } -#[test] -fn test_outbound_transfer() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_outbound_transfer(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let router = Addr::unchecked("router"); @@ -134,7 +142,7 @@ fn test_outbound_transfer() -> anyhow::Result<()> { ..Default::default() }; - warp.init_hack(&deployer, &owner, &mailbox, denom, mode)?; + warp.init_hack(&deployer, &owner, &mailbox, hrp, denom, mode)?; for (domain, router) in routers { warp.router_enroll(&owner, domain, router)?; @@ -156,8 +164,10 @@ fn test_outbound_transfer() -> anyhow::Result<()> { Ok(()) } -#[test] -fn test_inbound_transfer() -> anyhow::Result<()> { +#[rstest] +#[case("osmo")] +#[case("neutron")] +fn test_inbound_transfer(#[case] hrp: &str) -> anyhow::Result<()> { let deployer = Addr::unchecked("deployer"); let mailbox = Addr::unchecked("mailbox"); let router = Addr::unchecked("router"); @@ -183,7 +193,7 @@ fn test_inbound_transfer() -> anyhow::Result<()> { .into(); let send_msg: CosmosMsg = BankMsg::Send { - to_address: bech32_encode("osmo", user_remote.as_bytes())?.to_string(), + to_address: bech32_encode(hrp, user_remote.as_bytes())?.to_string(), amount: vec![coin(amount, denom)], } .into(); @@ -251,7 +261,7 @@ fn test_inbound_transfer() -> anyhow::Result<()> { ..Default::default() }; - warp.init_hack(&deployer, &owner, &mailbox, denom, mode)?; + warp.init_hack(&deployer, &owner, &mailbox, hrp, denom, mode)?; warp.router_enroll(&owner, origin_domain, router.as_bytes().into())?; let resp = warp.mailbox_handle( diff --git a/contracts/token-native/src/tests/mod.rs b/contracts/token-native/src/tests/mod.rs index ab3c14f9..7f569ac9 100644 --- a/contracts/token-native/src/tests/mod.rs +++ b/contracts/token-native/src/tests/mod.rs @@ -14,7 +14,7 @@ use crate::{ contract::{execute, instantiate, query}, error::ContractError, msg::{InstantiateMsg, Metadata}, - state::{MAILBOX, MODE, OWNER, TOKEN}, + state::{HRP, MAILBOX, MODE, OWNER, TOKEN}, }; mod contracts; @@ -34,9 +34,11 @@ impl Default for TokenNative { } impl TokenNative { + #[allow(clippy::too_many_arguments)] pub fn init( &mut self, sender: &Addr, + hrp: &str, owner: &Addr, mailbox: &Addr, denom: &str, @@ -51,6 +53,7 @@ impl TokenNative { denom: denom.to_string(), metadata, mode, + hrp: hrp.to_string(), owner: owner.to_string(), mailbox: mailbox.to_string(), }, @@ -62,10 +65,12 @@ impl TokenNative { _sender: &Addr, owner: &Addr, mailbox: &Addr, + hrp: &str, denom: &str, mode: TokenMode, ) -> anyhow::Result<()> { MODE.save(&mut self.deps.storage, &mode)?; + HRP.save(&mut self.deps.storage, &hrp.to_string())?; TOKEN.save(&mut self.deps.storage, &denom.to_string())?; OWNER.save(&mut self.deps.storage, owner)?; MAILBOX.save(&mut self.deps.storage, mailbox)?; diff --git a/integration-test/tests/contracts/cw/deploy.rs b/integration-test/tests/contracts/cw/deploy.rs index 64d19f98..e8bacf39 100644 --- a/integration-test/tests/contracts/cw/deploy.rs +++ b/integration-test/tests/contracts/cw/deploy.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::Empty; +use cosmwasm_schema::cw_serde; use test_tube::{Account, Runner, SigningAccount, Wasm}; use super::{ @@ -11,6 +11,7 @@ pub fn deploy_core<'a, R: Runner<'a>>( deployer: &SigningAccount, codes: &Codes, origin_domain: u32, + hrp: &str, test_ism: Ism, test_hook: Hook, ) -> eyre::Result { @@ -69,10 +70,17 @@ pub fn deploy_core<'a, R: Runner<'a>>( )?; // deploy test message receiver + #[cw_serde] + struct ReceiverInitMsg { + pub hrp: String, + } + let msg_receiver = wasm .instantiate( codes.test_mock_msg_receiver, - &Empty {}, + &ReceiverInitMsg { + hrp: hrp.to_string(), + }, None, None, &[], diff --git a/integration-test/tests/contracts/cw/mod.rs b/integration-test/tests/contracts/cw/mod.rs index 1b06afc3..5462a843 100644 --- a/integration-test/tests/contracts/cw/mod.rs +++ b/integration-test/tests/contracts/cw/mod.rs @@ -8,5 +8,5 @@ mod types; pub use deploy::deploy_core; pub use hook::{prepare_routing_hook, Hook}; pub use ism::{prepare_routing_ism, Ism}; -pub use setup::setup_env; +pub use setup::{setup_env, Env}; pub use store::store_code; diff --git a/integration-test/tests/contracts/cw/setup.rs b/integration-test/tests/contracts/cw/setup.rs index 4aa28e95..cda4b8f8 100644 --- a/integration-test/tests/contracts/cw/setup.rs +++ b/integration-test/tests/contracts/cw/setup.rs @@ -62,7 +62,7 @@ pub fn setup_env<'a, R: Runner<'a>>( let wasm = Wasm::new(app); let codes = store_code(&wasm, &deployer, artifacts)?; - let core = deploy_core(&wasm, &deployer, &codes, domain, ism, hook)?; + let core = deploy_core(&wasm, &deployer, &codes, domain, hrp, ism, hook)?; Ok(Env { validators: validators.iter().map(|v| (v.domain, v.clone())).collect(), diff --git a/integration-test/tests/contracts/eth/mod.rs b/integration-test/tests/contracts/eth/mod.rs index d35af76c..a6bb6f21 100644 --- a/integration-test/tests/contracts/eth/mod.rs +++ b/integration-test/tests/contracts/eth/mod.rs @@ -5,4 +5,4 @@ mod types; pub use bind::*; pub use deploy::deploy; -pub use setup::setup_env; +pub use setup::{setup_env, Env}; diff --git a/integration-test/tests/mailbox.rs b/integration-test/tests/mailbox.rs index d8c9bd0c..8e800c3b 100644 --- a/integration-test/tests/mailbox.rs +++ b/integration-test/tests/mailbox.rs @@ -5,10 +5,13 @@ mod event; mod validator; use cosmwasm_std::{attr, Attribute, Binary, HexBinary}; -use ethers::{prelude::parse_log, signers::Signer}; +use ethers::{ + prelude::parse_log, providers::Middleware, signers::Signer, types::TransactionReceipt, +}; use osmosis_test_tube::{Account, Module, OsmosisTestApp, Wasm}; use hpl_interface::types::{bech32_decode, bech32_encode, bech32_to_h256}; +use test_tube::Runner; use crate::{ constants::*, @@ -28,47 +31,74 @@ fn sorted(mut attrs: Vec) -> Vec { attrs } -#[tokio::test] -async fn test_mailbox_cw_to_evm() -> eyre::Result<()> { - // init Osmosis env - let osmo_app = OsmosisTestApp::new(); - let osmo = cw::setup_env( - &osmo_app, - |app, coins| app.init_account(coins).unwrap(), - None::<&str>, - "osmo", - DOMAIN_OSMO, - &[TestValidators::new(DOMAIN_EVM, 5, 3)], - )?; - - // init Anvil env - let anvil1 = eth::setup_env(DOMAIN_EVM).await?; - +async fn send_msg<'a, M, S, R>( + anvil: ð::Env, + cosmos: &cw::Env<'a, R>, +) -> eyre::Result +where + M: Middleware + 'static, + S: Signer + 'static, + R: Runner<'a>, +{ let mut receiver = [0u8; 32]; - receiver[12..].copy_from_slice(&anvil1.core.msg_receiver.address().0); - let _sender = bech32_decode(osmo.acc_tester.address().as_str())?; + receiver[12..].copy_from_slice(&anvil.core.msg_receiver.address().0); + let _sender = bech32_decode(cosmos.acc_tester.address().as_str())?; let msg_body = b"hello world"; // dispatch - let dispatch_res = Wasm::new(osmo.app).execute( - &osmo.core.mailbox, + let dispatch_res = Wasm::new(cosmos.app).execute( + &cosmos.core.mailbox, &hpl_interface::mailbox::ExecuteMsg::Dispatch { dest_domain: DOMAIN_EVM, recipient_addr: receiver.into(), msg_body: msg_body.into(), }, &[], - &osmo.acc_tester, + &cosmos.acc_tester, )?; let dispatch = parse_dispatch_from_res(&dispatch_res.events); let _dispatch_id = parse_dispatch_id_from_res(&dispatch_res.events); - let process_tx = anvil1 + let process_tx = anvil .core .mailbox .process(vec![].into(), Binary::from(dispatch.message).0.into()); - let _process_tx_res = process_tx.send().await?.await?.unwrap(); + let process_tx_res = process_tx.send().await?.await?.unwrap(); + + Ok(process_tx_res) +} + +#[tokio::test] +async fn test_mailbox_cw_to_evm() -> eyre::Result<()> { + // init Osmosis env + let osmo_app = OsmosisTestApp::new(); + let osmo = cw::setup_env( + &osmo_app, + |app, coins| app.init_account(coins).unwrap(), + None::<&str>, + "osmo", + DOMAIN_OSMO, + &[TestValidators::new(DOMAIN_EVM, 5, 3)], + )?; + + // TODO: leave this until Neutron supports test-tube properly + // // init Neutron env + // let ntrn_app = OsmosisTestApp::new(); + // let ntrn = cw::setup_env( + // &ntrn_app, + // |app, coins| app.init_account(coins).unwrap(), + // None::<&str>, + // "neutron", + // DOMAIN_NTRN, + // &[TestValidators::new(DOMAIN_EVM, 5, 3)], + // )?; + + // init Anvil env + let anvil1 = eth::setup_env(DOMAIN_EVM).await?; + + let _ = send_msg(&anvil1, &osmo).await?; + // let _ = send_msg(&anvil1, &ntrn).await?; Ok(()) } diff --git a/packages/interface/Cargo.toml b/packages/interface/Cargo.toml index 5c362bc5..8c51371f 100644 --- a/packages/interface/Cargo.toml +++ b/packages/interface/Cargo.toml @@ -33,4 +33,5 @@ thiserror.workspace = true cosmwasm-schema.workspace = true [dev-dependencies] +rstest.workspace = true cw-multi-test.workspace = true diff --git a/packages/interface/src/types/bech32.rs b/packages/interface/src/types/bech32.rs index 9bba749f..4470eaee 100644 --- a/packages/interface/src/types/bech32.rs +++ b/packages/interface/src/types/bech32.rs @@ -46,40 +46,72 @@ pub fn bech32_encode(hrp: &str, raw_addr: &[u8]) -> StdResult { #[cfg(test)] mod tests { + use rstest::rstest; + use crate::types::bech32_to_h256; use super::{bech32_decode, bech32_encode}; #[test] - fn test_decode_encode_full() { - let hrp = "osmo"; - let src_addr = "osmo1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjqkk0zfx"; - - let dec_addr = bech32_to_h256(src_addr).unwrap(); - let enc_addr = bech32_encode(hrp, &dec_addr).unwrap(); - - assert_eq!(src_addr, enc_addr.as_str()); + fn addr_conv() { + println!( + "{}", + bech32_encode( + "neutron", + &bech32_decode("osmo1mhnkm6fwaq53yzu7c0r3khhy60v04vse4c6gk5").unwrap(), + ) + .unwrap() + ); } - #[test] - fn test_decode_encode_full_padded() { - let hrp = "osmo"; - let src_addr = "osmo14n3a65fnqz9jve85l23al6m3pjugf0atvrfqh5"; - + #[rstest] + #[case( + "osmo", + "osmo1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjqkk0zfx" + )] + #[case("osmo", "osmo14n3a65fnqz9jve85l23al6m3pjugf0atvrfqh5")] + #[case( + "neutron", + "neutron1gajw625kz8el4ayk8fwpy7r6ew0m7zrg9jdd6grg85fle39shuxqezuz2c" + )] + #[case("neutron", "neutron1xle8l3h0wkcp6tsxmkc6n4vqyfkhwnukevwwsk")] + fn test_decode_encode(#[case] hrp: &str, #[case] src_addr: &str) { let dec_addr = bech32_to_h256(src_addr).unwrap(); let enc_addr = bech32_encode(hrp, &dec_addr).unwrap(); assert_eq!(src_addr, enc_addr.as_str()); } - #[test] - fn test_decode_encode_acc() { - let hrp = "osmo"; - let src_addr = "osmo14n3a65fnqz9jve85l23al6m3pjugf0atvrfqh5"; - + #[rstest] + #[case("osmo", "osmo1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnuqjrc5")] + #[case("neutron", "neutron1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnsyg35p")] + fn test_decode_encode_acc(#[case] hrp: &str, #[case] src_addr: &str) { let dec_addr = bech32_decode(src_addr).unwrap(); let enc_addr = bech32_encode(hrp, &dec_addr).unwrap(); assert_eq!(src_addr, enc_addr.as_str()); } + + #[rstest] + #[case(&[ + "cosmos1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qn5mpnwx", + "axelar1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qns4hm98", + "osmo1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnuqjrc5", + "neutron1d6a3j0kkpc8eac0j8h6ypyevfz8hd3qnsyg35p" + ])] + fn test_acc_cross(#[case] addrs: &[&str]) { + for (i, test_target_addr) in addrs.iter().enumerate() { + let mut test_addr_group = addrs.to_vec(); + test_addr_group.remove(i); + + let test_target_addr_bin = bech32_decode(test_target_addr).unwrap(); + + for test_addr in test_addr_group { + let hrp = test_addr.split('1').collect::>()[0]; + + let encoded = bech32_encode(hrp, &test_target_addr_bin).unwrap(); + assert_eq!(test_addr, encoded.as_str()); + } + } + } }