Skip to content

Commit

Permalink
Merge branch 'main' into refactor/interchain_token_service_message_in…
Browse files Browse the repository at this point in the history
…terceptors
  • Loading branch information
fish-sammy committed Nov 8, 2024
2 parents 9150d87 + 08bec3c commit 6529fca
Show file tree
Hide file tree
Showing 11 changed files with 492 additions and 315 deletions.
38 changes: 12 additions & 26 deletions contracts/interchain-token-service/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use cosmwasm_std::{Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Respons
use error_stack::{Report, ResultExt};
use execute::{freeze_chain, unfreeze_chain};

use crate::events::Event;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state;
use crate::state::Config;
Expand All @@ -26,10 +25,10 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub enum Error {
#[error("failed to execute a cross-chain message")]
Execute,
#[error("failed to register an its edge contract")]
RegisterItsContract,
#[error("failed to deregsiter an its edge contract")]
DeregisterItsContract,
#[error("failed to register chains")]
RegisterChains,
#[error("failed to update chain")]
UpdateChain,
#[error("failed to freeze chain")]
FreezeChain,
#[error("failed to unfreeze chain")]
Expand Down Expand Up @@ -79,17 +78,9 @@ pub fn instantiate(

state::save_config(deps.storage, &Config { axelarnet_gateway })?;

for (chain, address) in msg.its_contracts.iter() {
state::save_its_contract(deps.storage, chain, address)?;
}

killswitch::init(deps.storage, killswitch::State::Disengaged)?;

Ok(Response::new().add_events(
msg.its_contracts
.into_iter()
.map(|(chain, address)| Event::ItsContractRegistered { chain, address }.into()),
))
Ok(Response::new())
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand All @@ -106,13 +97,14 @@ pub fn execute(
payload,
}) => execute::execute_message(deps, cc_id, source_address, payload)
.change_context(Error::Execute),
ExecuteMsg::RegisterItsContract { chain, address } => {
execute::register_its_contract(deps, chain, address)
.change_context(Error::RegisterItsContract)
ExecuteMsg::RegisterChains { chains } => {
execute::register_chains(deps, chains).change_context(Error::RegisterChains)
}
ExecuteMsg::DeregisterItsContract { chain } => {
execute::deregister_its_contract(deps, chain)
.change_context(Error::DeregisterItsContract)
ExecuteMsg::UpdateChain {
chain,
its_edge_contract,
} => {
execute::update_chain(deps, chain, its_edge_contract).change_context(Error::UpdateChain)
}
ExecuteMsg::FreezeChain { chain } => {
freeze_chain(deps, chain).change_context(Error::FreezeChain)
Expand All @@ -126,12 +118,6 @@ pub fn execute(
ExecuteMsg::EnableExecution => {
execute::enable_execution(deps).change_context(Error::EnableExecution)
}
ExecuteMsg::SetChainConfig {
chain,
max_uint,
max_target_decimals,
} => execute::set_chain_config(deps, chain, max_uint, max_target_decimals)
.change_context(Error::SetChainConfig),
}?
.then(Ok)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod test {
use super::Error;
use crate::contract::execute::interceptors;
use crate::state::{self, TokenDeploymentType};
use crate::{DeployInterchainToken, InterchainTransfer, TokenInstance};
use crate::{msg, DeployInterchainToken, InterchainTransfer, TokenInstance};

#[test]
fn apply_scaling_factor_to_amount_when_source_decimals_are_bigger() {
Expand Down Expand Up @@ -352,8 +352,12 @@ mod test {
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(1_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down Expand Up @@ -399,8 +403,12 @@ mod test {
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down Expand Up @@ -446,8 +454,12 @@ mod test {
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down Expand Up @@ -493,8 +505,12 @@ mod test {
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(100_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(100_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down Expand Up @@ -540,8 +556,12 @@ mod test {
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(100_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(100_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down Expand Up @@ -573,15 +593,23 @@ mod test {
state::save_chain_config(
&mut storage,
&source_chain,
Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: source_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(1_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down Expand Up @@ -625,15 +653,23 @@ mod test {
state::save_chain_config(
&mut storage,
&source_chain,
Uint256::from(1_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: source_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();
state::save_chain_config(
&mut storage,
&destination_chain,
Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
6,
msg::ChainConfig {
chain: destination_chain.clone(),
its_edge_contract: "itsedgecontract".to_string().try_into().unwrap(),
max_uint: Uint256::from(1_000_000_000_000_000u128).try_into().unwrap(),
max_target_decimals: 6,
},
)
.unwrap();

Expand Down
Loading

0 comments on commit 6529fca

Please sign in to comment.