Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Oct 17, 2024
1 parent 90b2d70 commit c79f4b0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/axelarnet-gateway/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum Error {
InvalidToken,
#[error("invalid routing destination")]
InvalidRoutingDestination,
#[error("failed converting the nexus message for the router")]
#[error("failed to convert the nexus message for the router")]
InvalidNexusMessageForRouter,
}

Expand Down
17 changes: 17 additions & 0 deletions contracts/axelarnet-gateway/tests/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,20 @@ fn contract_call_with_token_to_amplifier_chains_fails() {
ExecuteError::InvalidRoutingDestination,
);
}

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

utils::instantiate_contract(deps.as_mut()).unwrap();

let response = assert_ok!(utils::route_from_nexus(
deps.as_mut(),
vec![
messages::dummy_from_nexus(&vec![1, 2, 3]),
messages::dummy_from_nexus(&vec![4, 5, 6]),
]
));

goldie::assert_json!(response.messages)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"id": 0,
"msg": {
"wasm": {
"execute": {
"contract_addr": "router",
"msg": "eyJyb3V0ZV9tZXNzYWdlcyI6W3siY2NfaWQiOnsic291cmNlX2NoYWluIjoiRXRoZXJldW0iLCJtZXNzYWdlX2lkIjoic291cmNlLWNoYWluLTAifSwic291cmNlX2FkZHJlc3MiOiJzb3VyY2UtYWRkcmVzcyIsImRlc3RpbmF0aW9uX2NoYWluIjoiZGVzdGluYXRpb24tY2hhaW4iLCJkZXN0aW5hdGlvbl9hZGRyZXNzIjoiZGVzdGluYXRpb24tYWRkcmVzcyIsInBheWxvYWRfaGFzaCI6ImYxODg1ZWRhNTRiN2EwNTMzMThjZDQxZTIwOTMyMjBkYWIxNWQ2NTM4MWIxMTU3YTM2MzNhODNiZmQ1YzkyMzkifSx7ImNjX2lkIjp7InNvdXJjZV9jaGFpbiI6IkV0aGVyZXVtIiwibWVzc2FnZV9pZCI6InNvdXJjZS1jaGFpbi0wIn0sInNvdXJjZV9hZGRyZXNzIjoic291cmNlLWFkZHJlc3MiLCJkZXN0aW5hdGlvbl9jaGFpbiI6ImRlc3RpbmF0aW9uLWNoYWluIiwiZGVzdGluYXRpb25fYWRkcmVzcyI6ImRlc3RpbmF0aW9uLWFkZHJlc3MiLCJwYXlsb2FkX2hhc2giOiIyZTZhNWViY2NjODgxMGZlZTMzMjRjMGQ0NDUwMDExODg3ODdkMGQzYWM4YWJhMmNkODliNzc1MjdkMTk4YmIwIn1dfQ==",
"funds": []
}
}
},
"gas_limit": null,
"reply_on": "never"
}
]
12 changes: 12 additions & 0 deletions contracts/axelarnet-gateway/tests/utils/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ pub fn route_to_router(
GatewayExecuteMsg::RouteMessages(msgs),
)
}

pub fn route_from_nexus(
deps: DepsMut,
msgs: Vec<nexus::execute::Message>,
) -> Result<Response<nexus::execute::Message>, ContractError> {
contract::execute(
deps,
mock_env(),
mock_info("nexus", &[]),
GatewayExecuteMsg::RouteMessagesFromNexus(msgs),
)
}
16 changes: 16 additions & 0 deletions contracts/axelarnet-gateway/tests/utils/messages.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use axelar_core_std::nexus;
use cw_storage_plus::Prefixer;

Check failure on line 2 in contracts/axelarnet-gateway/tests/utils/messages.rs

View workflow job for this annotation

GitHub Actions / Lints

unused import: `cw_storage_plus::Prefixer`

Check warning on line 2 in contracts/axelarnet-gateway/tests/utils/messages.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `cw_storage_plus::Prefixer`
use router_api::{CrossChainId, Message};
use sha3::Digest;

Expand All @@ -22,3 +24,17 @@ pub fn dummy_to_router(payload: &impl AsRef<[u8]>) -> Message {
payload_hash: sha3::Keccak256::digest(payload).into(),
}
}

pub fn dummy_from_nexus(payload: &impl AsRef<[u8]>) -> nexus::execute::Message {
nexus::execute::Message {
source_chain: "Ethereum".parse().unwrap(),
source_address: "source-address".parse().unwrap(),
destination_chain: "destination-chain".parse().unwrap(),
destination_address: "destination-address".parse().unwrap(),
payload_hash: sha3::Keccak256::digest(payload).into(),
source_tx_id: "source-chain".as_bytes().to_vec().try_into().unwrap(),
source_tx_index: 0,
id: "source-chain-0".to_string(),
token: None,
}
}

0 comments on commit c79f4b0

Please sign in to comment.