Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Nov 3, 2024
1 parent dfd4642 commit 08bb9c3
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 1 deletion.
160 changes: 159 additions & 1 deletion contracts/interchain-token-service/tests/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use interchain_token_service::{
TokenManagerType, TokenSupply,
};
use router_api::{Address, ChainName, ChainNameRaw, CrossChainId};
use utils::{params, TestMessage};
use serde_json::json;
use utils::{instantiate_contract, make_deps, params, TestMessage};

mod utils;

Expand Down Expand Up @@ -173,6 +174,163 @@ fn execute_hub_message_succeeds() {
goldie::assert_json!(responses);
}

#[test]
fn execute_message_deploy_interchain_token_should_translate_decimals_when_max_uints_are_different()
{
let mut deps = make_deps();
instantiate_contract(deps.as_mut()).unwrap();

let TestMessage {
router_message,
source_its_chain,
source_its_contract,
destination_its_chain,
destination_its_contract,
..
} = TestMessage::dummy();

utils::register_its_contract(
deps.as_mut(),
source_its_chain.clone(),
source_its_contract.clone(),
)
.unwrap();
utils::register_its_contract(
deps.as_mut(),
destination_its_chain.clone(),
destination_its_contract.clone(),
)
.unwrap();
utils::set_chain_config(
deps.as_mut(),
source_its_chain.clone(),
Uint256::MAX.try_into().unwrap(),
6,
)
.unwrap();
utils::set_chain_config(
deps.as_mut(),
destination_its_chain.clone(),
Uint256::from_u128(2)
.pow(64)
.strict_sub(Uint256::one())
.try_into()
.unwrap(),
6,
)
.unwrap();

let token_id = TokenId::new([1; 32]);
let message = DeployInterchainToken {
token_id,
name: "Test".try_into().unwrap(),
symbol: "TST".try_into().unwrap(),
decimals: 18,
minter: None,
}
.into();
let hub_message = HubMessage::SendToHub {
destination_chain: destination_its_chain.clone(),
message,
};
let response = assert_ok!(utils::execute_hub_message(
deps.as_mut(),
router_message.cc_id.clone(),
source_its_contract.clone(),
hub_message.clone(),
));
let source_token_instance = assert_ok!(utils::query_token_instance(
deps.as_ref(),
source_its_chain.clone(),
token_id
));
let destination_token_instance = assert_ok!(utils::query_token_instance(
deps.as_ref(),
destination_its_chain.clone(),
token_id
));

goldie::assert_json!(
json!({ "response": response, "source_token_instance": source_token_instance, "destination_token_instance": destination_token_instance })
);
}

#[test]
fn execute_message_deploy_interchain_token_should_translate_decimals_when_max_uints_are_the_same() {
let mut deps = make_deps();
instantiate_contract(deps.as_mut()).unwrap();

let TestMessage {
router_message,
source_its_chain,
source_its_contract,
destination_its_chain,
destination_its_contract,
..
} = TestMessage::dummy();

utils::register_its_contract(
deps.as_mut(),
source_its_chain.clone(),
source_its_contract.clone(),
)
.unwrap();
utils::register_its_contract(
deps.as_mut(),
destination_its_chain.clone(),
destination_its_contract.clone(),
)
.unwrap();
utils::set_chain_config(
deps.as_mut(),
source_its_chain.clone(),
Uint256::MAX.try_into().unwrap(),
6,
)
.unwrap();
utils::set_chain_config(
deps.as_mut(),
destination_its_chain.clone(),
Uint256::MAX.try_into().unwrap(),
6,
)
.unwrap();

let token_id = TokenId::new([1; 32]);
let message = DeployInterchainToken {
token_id,
name: "Test".try_into().unwrap(),
symbol: "TST".try_into().unwrap(),
decimals: 18,
minter: None,
}
.into();
let hub_message = HubMessage::SendToHub {
destination_chain: destination_its_chain.clone(),
message,
};
let response = assert_ok!(utils::execute_hub_message(
deps.as_mut(),
router_message.cc_id.clone(),
source_its_contract.clone(),
hub_message.clone(),
));
let source_token_instance = assert_ok!(utils::query_token_instance(
deps.as_ref(),
source_its_chain.clone(),
token_id
));
let destination_token_instance = assert_ok!(utils::query_token_instance(
deps.as_ref(),
destination_its_chain.clone(),
token_id
));

goldie::assert_json!(
json!({ "response": response, "source_token_instance": source_token_instance, "destination_token_instance": destination_token_instance })
);
}

#[test]
fn execute_its_when_not_gateway_sender_fails() {
let mut deps = mock_dependencies();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"destination_token_instance": {
"decimals": 6,
"supply": {
"tracked": "0"
}
},
"response": {
"attributes": [],
"data": null,
"events": [
{
"attributes": [
{
"key": "cc_id",
"value": "source-its-chain_message-id"
},
{
"key": "destination_chain",
"value": "dest-its-chain"
},
{
"key": "message_type",
"value": "DeployInterchainToken"
},
{
"key": "token_id",
"value": "0101010101010101010101010101010101010101010101010101010101010101"
},
{
"key": "name",
"value": "Test"
},
{
"key": "symbol",
"value": "TST"
},
{
"key": "decimals",
"value": "6"
}
],
"type": "message_received"
}
],
"messages": [
{
"gas_limit": null,
"id": 0,
"msg": {
"wasm": {
"execute": {
"contract_addr": "gateway",
"funds": [],
"msg": "eyJjYWxsX2NvbnRyYWN0Ijp7ImRlc3RpbmF0aW9uX2NoYWluIjoiZGVzdC1pdHMtY2hhaW4iLCJkZXN0aW5hdGlvbl9hZGRyZXNzIjoiZGVzdC1pdHMtY29udHJhY3QiLCJwYXlsb2FkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwNDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwNjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMGEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDczNmY3NTcyNjM2NTJkNjk3NDczMmQ2MzY4NjE2OTZlMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTYwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMGMwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDYwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTQwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwNDU0NjU3Mzc0MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAzNTQ1MzU0MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAifX0="
}
}
},
"reply_on": "never"
}
]
},
"source_token_instance": {
"decimals": 18,
"supply": "untracked"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"destination_token_instance": {
"decimals": 18,
"supply": {
"tracked": "0"
}
},
"response": {
"attributes": [],
"data": null,
"events": [
{
"attributes": [
{
"key": "cc_id",
"value": "source-its-chain_message-id"
},
{
"key": "destination_chain",
"value": "dest-its-chain"
},
{
"key": "message_type",
"value": "DeployInterchainToken"
},
{
"key": "token_id",
"value": "0101010101010101010101010101010101010101010101010101010101010101"
},
{
"key": "name",
"value": "Test"
},
{
"key": "symbol",
"value": "TST"
},
{
"key": "decimals",
"value": "18"
}
],
"type": "message_received"
}
],
"messages": [
{
"gas_limit": null,
"id": 0,
"msg": {
"wasm": {
"execute": {
"contract_addr": "gateway",
"funds": [],
"msg": "eyJjYWxsX2NvbnRyYWN0Ijp7ImRlc3RpbmF0aW9uX2NoYWluIjoiZGVzdC1pdHMtY2hhaW4iLCJkZXN0aW5hdGlvbl9hZGRyZXNzIjoiZGVzdC1pdHMtY29udHJhY3QiLCJwYXlsb2FkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwNDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwNjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMGEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDczNmY3NTcyNjM2NTJkNjk3NDczMmQ2MzY4NjE2OTZlMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTYwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTAxMDEwMTAx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