Fee storage type changed to optional

This commit is contained in:
Yuriy Savchenko 2021-03-14 18:45:28 +02:00 committed by Leopold Schabel
parent 097093e1f1
commit 06242ffc74
4 changed files with 12 additions and 12 deletions

View File

@ -50,7 +50,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
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<S: Storage, A: Api, Q: Querier>(
}
// 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<S: Storage, A: Api, Q: Querier>(
pub fn handle_set_fee<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
env: Env,
fee: Coin,
fee: Option<Coin>,
) -> StdResult<HandleResponse> {
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),
}
)
}

View File

@ -31,7 +31,7 @@ pub enum HandleMsg {
is_active: bool,
},
SetFee {
fee: Coin,
fee: Option<Coin>,
},
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<Coin>,
}

View File

@ -36,7 +36,7 @@ pub struct ConfigInfo {
pub is_active: bool,
// Asset locking fee
pub fee: Coin,
pub fee: Option<Coin>,
}
// Validator Action Approval(VAA) data

View File

@ -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(())