Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Oct 9, 2024
1 parent 8ab6f12 commit be1a588
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 65 deletions.
4 changes: 2 additions & 2 deletions contracts/axelarnet-gateway/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum Error {
#[error("invalid token received")]
InvalidToken,
#[error("invalid routing destination")]
RoutingDestination,
InvalidRoutingDestination,
}

#[cw_serde]
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn call_contract(
RoutingDestination::Router if token.is_none() => {
route_to_router(storage, &Router::new(router), vec![msg])?
}
_ => bail!(Error::RoutingDestination),
_ => bail!(Error::InvalidRoutingDestination),
}
.add_event(event.into());

Expand Down
3 changes: 2 additions & 1 deletion contracts/axelarnet-gateway/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub enum ExecuteMsg {
},

/// Initiate a cross-chain contract call from Axelarnet to another chain.
/// The message will be routed to the destination chain's gateway via the router.
/// If the destination chain is registered with core, the message will be routed to core with an optional token.
/// Otherwise, the message will be routed to the destination chain's gateway via the router.
#[permission(Any)]
CallContract {
destination_chain: ChainName,
Expand Down
2 changes: 1 addition & 1 deletion contracts/axelarnet-gateway/tests/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,6 @@ fn contract_call_with_token_to_amplifier_chains_fails() {
payload,
),
ExecuteError,
ExecuteError::RoutingDestination,
ExecuteError::InvalidRoutingDestination,
);
}
61 changes: 61 additions & 0 deletions contracts/axelarnet-gateway/tests/utils/deps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use std::marker::PhantomData;
use std::ops::Deref;

use axelar_core_std::nexus::query::QueryMsg;
use axelar_core_std::query::AxelarQueryMsg;
use cosmwasm_std::testing::{MockApi, MockQuerier, MockQuerierCustomHandlerResult, MockStorage};
use cosmwasm_std::{ContractResult, Deps, DepsMut, Empty, OwnedDeps, QuerierWrapper, SystemResult};
use serde_json::json;

pub fn mock_axelar_dependencies(
) -> OwnedDeps<MockStorage, MockApi, MockQuerier<AxelarQueryMsg>, AxelarQueryMsg> {
OwnedDeps {
storage: MockStorage::default(),
api: MockApi::default(),
querier: MockQuerier::<AxelarQueryMsg>::new(&[("contract", &[])]),
custom_query_type: PhantomData,
}
}

pub fn axelar_query_handler(
tx_hash: [u8; 32],
nonce: u32,
is_chain_registered: bool,
) -> impl Fn(&AxelarQueryMsg) -> MockQuerierCustomHandlerResult {
move |query| {
let result = match query {
AxelarQueryMsg::Nexus(nexus_query) => match nexus_query {
QueryMsg::TxHashAndNonce {} => json!({
"tx_hash": tx_hash,
"nonce": nonce,
}),
QueryMsg::IsChainRegistered { chain: _ } => json!({
"is_registered": is_chain_registered
}),
_ => unreachable!("unexpected nexus query {:?}", nexus_query),
},
_ => unreachable!("unexpected query request {:?}", query),
}
.to_string()
.as_bytes()
.into();

SystemResult::Ok(ContractResult::Ok(result))
}
}

pub fn emptying_deps_mut<'a>(deps: &'a mut DepsMut<AxelarQueryMsg>) -> DepsMut<'a, Empty> {
DepsMut {
storage: deps.storage,
api: deps.api,
querier: QuerierWrapper::new(deps.querier.deref()),
}
}

pub fn emptying_deps<'a>(deps: &'a Deps<AxelarQueryMsg>) -> Deps<'a, Empty> {
Deps {
storage: deps.storage,
api: deps.api,
querier: QuerierWrapper::new(deps.querier.deref()),
}
}
63 changes: 2 additions & 61 deletions contracts/axelarnet-gateway/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,13 @@
// This circumvents that issue.
#![allow(dead_code)]

use std::marker::PhantomData;
use std::ops::Deref;

use axelar_core_std::nexus::query::QueryMsg;
use axelar_core_std::query::AxelarQueryMsg;
use cosmwasm_std::testing::{MockApi, MockQuerier, MockQuerierCustomHandlerResult, MockStorage};
use cosmwasm_std::{ContractResult, Deps, DepsMut, Empty, OwnedDeps, QuerierWrapper, SystemResult};
pub use deps::*;

Check warning on line 5 in contracts/axelarnet-gateway/tests/utils/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `deps::*`

Check failure on line 5 in contracts/axelarnet-gateway/tests/utils/mod.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `deps::*`
#[allow(unused_imports)]
pub use execute::*;
pub use instantiate::*;
use serde_json::json;

mod deps;
mod execute;
mod instantiate;
pub mod messages;
pub mod params;

pub fn mock_axelar_dependencies(
) -> OwnedDeps<MockStorage, MockApi, MockQuerier<AxelarQueryMsg>, AxelarQueryMsg> {
OwnedDeps {
storage: MockStorage::default(),
api: MockApi::default(),
querier: MockQuerier::<AxelarQueryMsg>::new(&[("contract", &[])]),
custom_query_type: PhantomData,
}
}

pub fn axelar_query_handler(
tx_hash: [u8; 32],
nonce: u32,
is_chain_registered: bool,
) -> impl Fn(&AxelarQueryMsg) -> MockQuerierCustomHandlerResult {
move |query| {
let result = match query {
AxelarQueryMsg::Nexus(nexus_query) => match nexus_query {
QueryMsg::TxHashAndNonce {} => json!({
"tx_hash": tx_hash,
"nonce": nonce,
}),
QueryMsg::IsChainRegistered { chain: _ } => json!({
"is_registered": is_chain_registered
}),
_ => unreachable!("unexpected nexus query {:?}", nexus_query),
},
_ => unreachable!("unexpected query request {:?}", query),
}
.to_string()
.as_bytes()
.into();

SystemResult::Ok(ContractResult::Ok(result))
}
}

pub fn emptying_deps_mut<'a>(deps: &'a mut DepsMut<AxelarQueryMsg>) -> DepsMut<'a, Empty> {
DepsMut {
storage: deps.storage,
api: deps.api,
querier: QuerierWrapper::new(deps.querier.deref()),
}
}

pub fn emptying_deps<'a>(deps: &'a Deps<AxelarQueryMsg>) -> Deps<'a, Empty> {
Deps {
storage: deps.storage,
api: deps.api,
querier: QuerierWrapper::new(deps.querier.deref()),
}
}

0 comments on commit be1a588

Please sign in to comment.