From 06242ffc746e625960cf3a99366a2f40eb746ac7 Mon Sep 17 00:00:00 2001 From: Yuriy Savchenko Date: Sun, 14 Mar 2021 18:45:28 +0200 Subject: [PATCH] Fee storage type changed to optional --- terra/contracts/wormhole/src/contract.rs | 14 +++++++------- terra/contracts/wormhole/src/msg.rs | 4 ++-- terra/contracts/wormhole/src/state.rs | 2 +- terra/contracts/wormhole/tests/integration.rs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/terra/contracts/wormhole/src/contract.rs b/terra/contracts/wormhole/src/contract.rs index dedf7edd7..40ee4d768 100644 --- a/terra/contracts/wormhole/src/contract.rs +++ b/terra/contracts/wormhole/src/contract.rs @@ -50,7 +50,7 @@ pub fn init( wrapped_asset_code_id: msg.wrapped_asset_code_id, owner: deps.api.canonical_address(&env.message.sender)?, is_active: true, - fee: Coin::new(0, ""), // No fee by default + fee: None, // No fee by default }; config(&mut deps.storage).save(&state)?; @@ -450,8 +450,8 @@ fn handle_lock_assets( } // Check fee - if state.fee.amount > Uint128::zero() { - if !has_coins(env.message.sent_funds.as_ref(), &state.fee) { + if let Some(fee) = state.fee { + if !has_coins(env.message.sent_funds.as_ref(), &fee) { return ContractError::FeeTooLow.std_err(); } } @@ -551,7 +551,7 @@ pub fn handle_set_active( pub fn handle_set_fee( deps: &mut Extern, env: Env, - fee: Coin, + fee: Option, ) -> StdResult { let mut state = config_read(&deps.storage).load()?; @@ -1365,7 +1365,7 @@ mod tests { let fee = Coin::new(1000, "luna"); let result = submit_msg_with_sender( &mut deps, - HandleMsg::SetFee { fee: fee.clone() }, + HandleMsg::SetFee { fee: Some(fee.clone()) }, &HumanAddr::from(CREATOR_ADDR), ); assert!(result.is_ok()); @@ -1374,7 +1374,7 @@ mod tests { let state = config_read(&deps.storage) .load() .expect("Cannot load config storage"); - assert_eq!(state.fee, fee); + assert_eq!(state.fee, Some(fee.clone())); // Check error on lock let result = submit_msg(&mut deps, MSG_LOCK.clone()); @@ -1404,7 +1404,7 @@ mod tests { result, GetStateResponse { is_active: true, - fee, + fee: Some(fee), } ) } diff --git a/terra/contracts/wormhole/src/msg.rs b/terra/contracts/wormhole/src/msg.rs index 8c526c474..c3cff2259 100644 --- a/terra/contracts/wormhole/src/msg.rs +++ b/terra/contracts/wormhole/src/msg.rs @@ -31,7 +31,7 @@ pub enum HandleMsg { is_active: bool, }, SetFee { - fee: Coin, + fee: Option, }, TransferFee { amount: Coin, @@ -65,5 +65,5 @@ pub struct WrappedRegistryResponse { #[serde(rename_all = "snake_case")] pub struct GetStateResponse { pub is_active: bool, - pub fee: Coin, + pub fee: Option, } diff --git a/terra/contracts/wormhole/src/state.rs b/terra/contracts/wormhole/src/state.rs index f523edbe1..fc5d21f61 100644 --- a/terra/contracts/wormhole/src/state.rs +++ b/terra/contracts/wormhole/src/state.rs @@ -36,7 +36,7 @@ pub struct ConfigInfo { pub is_active: bool, // Asset locking fee - pub fee: Coin, + pub fee: Option, } // Validator Action Approval(VAA) data diff --git a/terra/contracts/wormhole/tests/integration.rs b/terra/contracts/wormhole/tests/integration.rs index ab50202c7..20c1a7101 100644 --- a/terra/contracts/wormhole/tests/integration.rs +++ b/terra/contracts/wormhole/tests/integration.rs @@ -1,6 +1,6 @@ static WASM: &[u8] = include_bytes!("../../../target/wasm32-unknown-unknown/release/wormhole.wasm"); -use cosmwasm_std::{from_slice, Env, HumanAddr, InitResponse, Coin}; +use cosmwasm_std::{from_slice, Env, HumanAddr, InitResponse}; use cosmwasm_storage::to_length_prefixed; use cosmwasm_vm::testing::{init, mock_env, mock_instance, MockApi, MockQuerier, MockStorage}; use cosmwasm_vm::{Api, Instance, Storage}; @@ -71,7 +71,7 @@ fn do_init( wrapped_asset_code_id: 999, owner, is_active: true, - fee: Coin::new(0, ""), + fee: None, } ); Ok(())