terra: Fix clippy warnings

This commit is contained in:
Chirantan Ekbote 2022-09-30 19:07:27 +09:00 committed by Evan Gray
parent 68ae3ff6cd
commit f7cc16aa91
25 changed files with 125 additions and 147 deletions

View File

@ -208,7 +208,7 @@ mod tests {
use cw20::TokenInfoResponse;
fn get_balance(deps: Deps, address: HumanAddr) -> Uint128 {
query_balance(deps, address.into()).unwrap().balance
query_balance(deps, address).unwrap().balance
}
fn do_init(mut deps: DepsMut, creator: &HumanAddr) {
@ -261,7 +261,7 @@ mod tests {
let env = mock_env();
let info = mock_info(creator, &[]);
let res = execute(deps.branch(), env, info, msg.clone()).unwrap();
let res = execute(deps.branch(), env, info, msg).unwrap();
assert_eq!(0, res.messages.len());
assert_eq!(get_balance(deps.as_ref(), mint_to.clone(),), amount);
@ -293,10 +293,7 @@ mod tests {
do_init(deps.as_mut(), &minter);
let amount = Uint128::new(222_222_222);
let msg = ExecuteMsg::Mint {
recipient: recipient.clone(),
amount,
};
let msg = ExecuteMsg::Mint { recipient, amount };
let other_address = HumanAddr::from("other");
let env = mock_env();
@ -326,7 +323,7 @@ mod tests {
let env = mock_env();
let info = mock_info(&owner, &[]);
let res = execute(deps.as_mut(), env, info, msg.clone()).unwrap();
let res = execute(deps.as_mut(), env, info, msg).unwrap();
assert_eq!(0, res.messages.len());
assert_eq!(get_balance(deps.as_ref(), owner), Uint128::new(222_000_000));
assert_eq!(get_balance(deps.as_ref(), recipient), amount_transfer);
@ -344,12 +341,12 @@ mod tests {
let recipient = HumanAddr::from("recipient");
let amount_transfer = Uint128::new(222_222);
let msg = ExecuteMsg::Transfer {
recipient: recipient.clone(),
recipient,
amount: amount_transfer,
};
let env = mock_env();
let info = mock_info(&owner, &[]);
let _ = execute(deps.as_mut(), env, info, msg.clone()).unwrap_err(); // Will panic if no error
let _ = execute(deps.as_mut(), env, info, msg).unwrap_err(); // Will panic if no error
}
}

View File

@ -7,7 +7,7 @@ use cw20::Expiration;
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {
pub name: String,
pub symbol: String,
@ -18,19 +18,19 @@ pub struct InstantiateMsg {
pub init_hook: Option<InitHook>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InitHook {
pub msg: Binary,
pub contract_addr: HumanAddr,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InitMint {
pub recipient: HumanAddr,
pub amount: Uint128,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}
@ -94,7 +94,7 @@ pub enum ExecuteMsg {
UpdateMetadata { name: String, symbol: String },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
// Generic information about the wrapped asset
@ -113,7 +113,7 @@ pub enum QueryMsg {
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WrappedAssetInfoResponse {
pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address in the original chain

View File

@ -7,7 +7,7 @@ use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset";
// Created at initialization and reference original asset and bridge address
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WrappedAssetInfo {
pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address on the original chain

View File

@ -59,7 +59,7 @@ fn do_mint(
) {
let mint_msg = ExecuteMsg::Mint {
recipient: recipient.to_string(),
amount: amount.clone(),
amount: *amount,
};
let info = mock_info(INITIALIZER, &[]);
let handle_response: Response = execute(deps.as_mut(), mock_env(), info, mint_msg).unwrap();
@ -74,7 +74,7 @@ fn do_transfer(
) {
let transfer_msg = ExecuteMsg::Transfer {
recipient: recipient.to_string(),
amount: amount.clone(),
amount: *amount,
};
let env = mock_env();
let info = mock_info(sender.as_str(), &[]);
@ -116,8 +116,8 @@ fn check_token_details(deps: &OwnedDeps<MockStorage, MockApi, MockQuerier>, supp
#[test]
fn init_works() {
let mut deps = do_init();
check_token_details(&mut deps, Uint128::new(0));
let deps = do_init();
check_token_details(&deps, Uint128::new(0));
}
#[test]
@ -126,7 +126,7 @@ fn query_works() {
let query_response = query(deps.as_ref(), mock_env(), QueryMsg::WrappedAssetInfo {}).unwrap();
assert_eq!(
from_slice::<WrappedAssetInfoResponse>(&query_response.as_slice()).unwrap(),
from_slice::<WrappedAssetInfoResponse>(query_response.as_slice()).unwrap(),
WrappedAssetInfoResponse {
asset_chain: 1,
asset_address: vec![1; 32].into(),
@ -172,6 +172,6 @@ fn transfer_works() {
do_mint(&mut deps, &sender, &Uint128::new(123_123_123));
do_transfer(&mut deps, &sender, &recipient, &Uint128::new(123_123_000));
check_balance(&mut deps, &sender, &Uint128::new(123));
check_balance(&mut deps, &recipient, &Uint128::new(123_123_000));
check_balance(&deps, &sender, &Uint128::new(123));
check_balance(&deps, &recipient, &Uint128::new(123_123_000));
}

View File

@ -304,11 +304,7 @@ where
// update the approval list (remove any for the same spender before adding)
let spender_addr = deps.api.addr_validate(spender)?;
token.approvals = token
.approvals
.into_iter()
.filter(|apr| apr.spender != spender_addr)
.collect();
token.approvals.retain(|apr| apr.spender != spender_addr);
// only difference between approve and revoke
if add {

View File

@ -7,7 +7,7 @@ use cw721::{
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct Cw721Contract(pub Addr);
#[allow(dead_code)]

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use cosmwasm_std::Binary;
use cw721::Expiration;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {
/// Name of the NFT contract
pub name: String,
@ -57,7 +57,7 @@ pub enum ExecuteMsg<T> {
Burn { token_id: String },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct MintMsg<T> {
/// Unique ID of the NFT
pub token_id: String,
@ -71,7 +71,7 @@ pub struct MintMsg<T> {
pub extension: T,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
/// Return the owner of the given token, error if token does not exist
@ -148,7 +148,7 @@ pub enum QueryMsg {
}
/// Shows who can mint these tokens
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
pub struct MinterResponse {
pub minter: String,
}

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
pub use cosmwasm_std::to_binary;
use cosmwasm_std::Empty;
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug, Default)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
pub struct Trait {
pub display_type: Option<String>,
pub trait_type: String,

View File

@ -36,13 +36,13 @@ pub struct InstantiateMsg {
pub init_hook: Option<InitHook>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InitHook {
pub msg: Binary,
pub contract_addr: HumanAddr,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
/// Generic information about the wrapped asset
@ -120,7 +120,7 @@ pub enum QueryMsg {
Minter {},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WrappedAssetInfoResponse {
pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address in the original chain

View File

@ -7,7 +7,7 @@ use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset";
// Created at initialization and reference original asset and bridge address
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WrappedAssetInfo {
pub asset_chain: u16, // Asset chain id
pub asset_address: Binary, // Asset smart contract address on the original chain

View File

@ -53,7 +53,7 @@ pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
}
fn complete_transfer_with_payload(
mut deps: DepsMut,
deps: DepsMut,
_env: Env,
info: MessageInfo,
data: &Binary,

View File

@ -4,22 +4,22 @@ use serde::{Deserialize, Serialize};
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {
pub token_bridge_contract: HumanAddr,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
CompleteTransferWithPayload { data: Binary },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
WrappedRegistry { chain: u16, address: Binary },

View File

@ -9,7 +9,7 @@ type HumanAddr = String;
pub static CONFIG_KEY: &[u8] = b"config";
// Guardian set information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Config {
pub token_bridge_contract: HumanAddr,
}

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {
// governance contract details
pub gov_chain: u16,
@ -14,7 +14,7 @@ pub struct InstantiateMsg {
pub wrapped_asset_code_id: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
RegisterAssetHook {
@ -34,24 +34,24 @@ pub enum ExecuteMsg {
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
WrappedRegistry { chain: u16, address: Binary },
AllWrappedAssets {},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct WrappedRegistryResponse {
pub address: HumanAddr,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum WormholeQueryMsg {
VerifyVAA { vaa: Binary, block_time: u64 },

View File

@ -21,7 +21,7 @@ pub static TOKEN_ID_HASHES_KEY: &[u8] = b"token_id_hashes";
pub static SPL_CACHE_KEY: &[u8] = b"spl_cache";
// Guardian set information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ConfigInfo {
// governance contract details
pub gov_chain: u16,
@ -31,7 +31,7 @@ pub struct ConfigInfo {
pub wrapped_asset_code_id: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct SplCacheItem {
pub name: [u8; 32],
pub symbol: [u8; 32],
@ -124,7 +124,7 @@ impl TokenBridgeMessage {
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[repr(transparent)]
pub struct BoundedVec<T, const N: usize> {
vec: Vec<T>,
@ -159,7 +159,7 @@ impl<T, const N: usize> BoundedVec<T, N> {
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferInfo {
pub nft_address: [u8; 32],
pub nft_chain: u16,

View File

@ -1,35 +1,15 @@
static WASM: &[u8] = include_bytes!("../../../target/wasm32-unknown-unknown/release/wormhole.wasm");
use cosmwasm_std::{
from_slice,
Coin,
Env,
HumanAddr,
InitResponse,
};
use cosmwasm_std::{from_slice, Coin, Env, HumanAddr, InitResponse};
use cosmwasm_storage::to_length_prefixed;
use cosmwasm_vm::{
testing::{
init,
mock_env,
mock_instance,
MockApi,
MockQuerier,
MockStorage,
},
Api,
Instance,
Storage,
testing::{init, mock_env, mock_instance, MockApi, MockQuerier, MockStorage},
Api, Instance, Storage,
};
use wormhole::{
msg::InitMsg,
state::{
ConfigInfo,
GuardianAddress,
GuardianSetInfo,
CONFIG_KEY,
},
state::{ConfigInfo, GuardianAddress, GuardianSetInfo, CONFIG_KEY},
};
use hex;

View File

@ -22,10 +22,13 @@ use wormhole::{
state::{vaa_archive_add, vaa_archive_check, GovernancePacket, ParsedVAA},
};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
coin, entry_point, to_binary, BankMsg, Binary, CanonicalAddr, Coin, CosmosMsg, Decimal, Deps,
DepsMut, Empty, Env, MessageInfo, Order, QuerierWrapper, QueryRequest, Reply, Response,
StdError, StdResult, SubMsg, Uint128, WasmMsg, WasmQuery,
coin, to_binary, BankMsg, Binary, CanonicalAddr, Coin, CosmosMsg, Decimal, Deps, DepsMut,
Empty, Env, MessageInfo, Order, QuerierWrapper, QueryRequest, Reply, Response, StdError,
StdResult, SubMsg, Uint128, WasmMsg, WasmQuery,
};
use crate::{
@ -259,7 +262,7 @@ pub fn coins_after_tax(deps: DepsMut, coins: Vec<Coin>) -> StdResult<Vec<Coin>>
let mut res = vec![];
for coin in coins {
let asset = Asset {
amount: coin.amount.clone(),
amount: coin.amount,
info: AssetInfo::NativeToken {
denom: coin.denom.clone(),
},
@ -285,7 +288,7 @@ fn parse_vaa(deps: Deps, block_time: u64, data: &Binary) -> StdResult<ParsedVAA>
pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> {
match msg {
ExecuteMsg::RegisterAssetHook { asset_id } => {
handle_register_asset(deps, env, info, &asset_id.as_slice())
handle_register_asset(deps, env, info, asset_id.as_slice())
}
ExecuteMsg::InitiateTransfer {
asset,
@ -391,13 +394,13 @@ fn handle_register_asset(
let mut bucket = wrapped_asset(deps.storage);
let result = bucket.load(asset_id);
let result = result.map_err(|_| ContractError::RegistrationForbidden.std())?;
if result != HumanAddr::from(WRAPPED_ASSET_UPDATING) {
if result != WRAPPED_ASSET_UPDATING {
return ContractError::AssetAlreadyRegistered.std_err();
}
bucket.save(asset_id, &info.sender.to_string())?;
let contract_address: CanonicalAddr = deps.api.addr_canonicalize(&info.sender.as_str())?;
let contract_address: CanonicalAddr = deps.api.addr_canonicalize(info.sender.as_str())?;
wrapped_asset_address(deps.storage).save(contract_address.as_slice(), &asset_id.to_vec())?;
Ok(Response::new()
@ -431,7 +434,7 @@ fn handle_attest_meta(
}
let cfg = config_read(deps.storage).load()?;
let asset_id = build_asset_id(meta.token_chain, &meta.token_address.as_slice());
let asset_id = build_asset_id(meta.token_chain, meta.token_address.as_slice());
// If a CW20 wrapped already exists and this message has a newer sequence ID
// we allow updating the metadata. If not, we create a brand new token.
@ -532,7 +535,7 @@ fn handle_create_asset_meta_token(
nonce,
})?,
// forward coins sent to this message
funds: coins_after_tax(deps, info.funds.clone())?,
funds: coins_after_tax(deps, info.funds)?,
}))
.add_attribute("meta.token_chain", CHAIN_ID.to_string())
.add_attribute("meta.token", asset_address)
@ -570,7 +573,7 @@ fn handle_create_asset_meta_native_token(
nonce,
})?,
// forward coins sent to this message
funds: coins_after_tax(deps, info.funds.clone())?,
funds: coins_after_tax(deps, info.funds)?,
}))
.add_attribute("meta.token_chain", CHAIN_ID.to_string())
.add_attribute("meta.symbol", symbol)
@ -662,8 +665,8 @@ fn submit_vaa(deps: DepsMut, env: Env, info: MessageInfo, data: &Binary) -> StdR
}
}
fn handle_governance_payload(deps: DepsMut, env: Env, data: &Vec<u8>) -> StdResult<Response> {
let gov_packet = GovernancePacket::deserialize(&data)?;
fn handle_governance_payload(deps: DepsMut, env: Env, data: &[u8]) -> StdResult<Response> {
let gov_packet = GovernancePacket::deserialize(data)?;
let module = get_string_from_32(&gov_packet.module);
if module != "TokenBridge" {
@ -684,7 +687,7 @@ fn handle_governance_payload(deps: DepsMut, env: Env, data: &Vec<u8>) -> StdResu
}
fn handle_upgrade_contract(_deps: DepsMut, env: Env, data: &Vec<u8>) -> StdResult<Response> {
let UpgradeContract { new_contract } = UpgradeContract::deserialize(&data)?;
let UpgradeContract { new_contract } = UpgradeContract::deserialize(data)?;
Ok(Response::new()
.add_message(CosmosMsg::Wasm(WasmMsg::Migrate {
@ -699,7 +702,7 @@ fn handle_register_chain(deps: DepsMut, _env: Env, data: &Vec<u8>) -> StdResult<
let RegisterChain {
chain_id,
chain_address,
} = RegisterChain::deserialize(&data)?;
} = RegisterChain::deserialize(data)?;
let existing = bridge_contracts_read(deps.storage).load(&chain_id.to_be_bytes());
if existing.is_ok() {
@ -716,6 +719,7 @@ fn handle_register_chain(deps: DepsMut, _env: Env, data: &Vec<u8>) -> StdResult<
.add_attribute("chain_address", hex::encode(chain_address)))
}
#[allow(clippy::too_many_arguments)]
fn handle_complete_transfer(
deps: DepsMut,
env: Env,
@ -726,7 +730,7 @@ fn handle_complete_transfer(
data: &Vec<u8>,
relayer_address: &HumanAddr,
) -> StdResult<Response> {
let transfer_info = TransferInfo::deserialize(&data)?;
let transfer_info = TransferInfo::deserialize(data)?;
let marker_byte = transfer_info.token_address.as_slice()[0];
if transfer_info.token_chain == CHAIN_ID {
match marker_byte {
@ -766,6 +770,7 @@ fn handle_complete_transfer(
}
}
#[allow(clippy::too_many_arguments)]
fn handle_complete_transfer_token(
deps: DepsMut,
_env: Env,
@ -777,9 +782,9 @@ fn handle_complete_transfer_token(
relayer_address: &HumanAddr,
) -> StdResult<Response> {
let transfer_info = match transfer_type {
TransferType::WithoutPayload => TransferInfo::deserialize(&data)?,
TransferType::WithoutPayload => TransferInfo::deserialize(data)?,
TransferType::WithPayload { payload: _ } => {
TransferWithPayloadInfo::deserialize(&data)?.as_transfer_info()
TransferWithPayloadInfo::deserialize(data)?.as_transfer_info()
}
};
@ -826,7 +831,7 @@ fn handle_complete_transfer_token(
// Check if this asset is already deployed
let contract_addr = wrapped_asset_read(deps.storage).load(&asset_id).ok();
return if let Some(contract_addr) = contract_addr {
if let Some(contract_addr) = contract_addr {
// Asset already deployed, just mint
let mut messages = vec![CosmosMsg::Wasm(WasmMsg::Execute {
@ -858,7 +863,7 @@ fn handle_complete_transfer_token(
.add_attribute("fee", fee.to_string()))
} else {
Err(StdError::generic_err("Wrapped asset not deployed. To deploy, invoke CreateWrapped with the associated AssetMeta"))
};
}
} else {
let token_address = transfer_info.token_address.as_slice().get_address(0);
@ -911,6 +916,7 @@ fn handle_complete_transfer_token(
}
}
#[allow(clippy::too_many_arguments)]
fn handle_complete_transfer_token_native(
mut deps: DepsMut,
_env: Env,
@ -922,9 +928,9 @@ fn handle_complete_transfer_token_native(
relayer_address: &HumanAddr,
) -> StdResult<Response> {
let transfer_info = match transfer_type {
TransferType::WithoutPayload => TransferInfo::deserialize(&data)?,
TransferType::WithoutPayload => TransferInfo::deserialize(data)?,
TransferType::WithPayload { payload: () } => {
TransferWithPayloadInfo::deserialize(&data)?.as_transfer_info()
TransferWithPayloadInfo::deserialize(data)?.as_transfer_info()
}
};
@ -964,7 +970,7 @@ fn handle_complete_transfer_token_native(
}
// Wipe the native byte marker and extract the serialized denom.
let mut token_address = transfer_info.token_address.clone();
let mut token_address = transfer_info.token_address;
let token_address = token_address.as_mut_slice();
token_address[0] = 0;
@ -999,6 +1005,7 @@ fn handle_complete_transfer_token_native(
.add_attribute("fee", fee.to_string()))
}
#[allow(clippy::too_many_arguments)]
fn handle_initiate_transfer(
deps: DepsMut,
env: Env,
@ -1038,6 +1045,7 @@ fn handle_initiate_transfer(
}
}
#[allow(clippy::too_many_arguments)]
fn handle_initiate_transfer_token(
mut deps: DepsMut,
env: Env,
@ -1067,7 +1075,7 @@ fn handle_initiate_transfer_token(
let mut submessages: Vec<SubMsg> = vec![];
// we'll only need this for payload 3 transfers
let sender_address = deps.api.addr_canonicalize(&info.sender.to_string())?;
let sender_address = deps.api.addr_canonicalize(info.sender.as_ref())?;
let sender_address = extend_address_to_32_array(&sender_address);
match wrapped_asset_address_read(deps.storage).load(asset_canonical.as_slice()) {
@ -1134,7 +1142,7 @@ fn handle_initiate_transfer_token(
nonce,
})?,
// forward coins sent to this message
funds: coins_after_tax(deps.branch(), info.funds.clone())?,
funds: coins_after_tax(deps.branch(), info.funds)?,
}));
}
Err(_) => {
@ -1206,7 +1214,7 @@ fn handle_initiate_transfer_token(
TransferType::WithoutPayload => {
let transfer_info = TransferInfo {
amount: (0, amount.u128()),
token_address: asset_address.clone(),
token_address: asset_address,
token_chain: asset_chain,
recipient,
recipient_chain,
@ -1220,7 +1228,7 @@ fn handle_initiate_transfer_token(
TransferType::WithPayload { payload } => {
let transfer_info = TransferWithPayloadInfo {
amount: (0, amount.u128()),
token_address: asset_address.clone(),
token_address: asset_address,
token_chain: asset_chain,
recipient,
recipient_chain,
@ -1255,7 +1263,7 @@ fn handle_initiate_transfer_token(
.add_attribute(
"transfer.sender",
hex::encode(extend_address_to_32(
&deps.api.addr_canonicalize(&info.sender.as_str())?,
&deps.api.addr_canonicalize(info.sender.as_str())?,
)),
)
.add_attribute("transfer.recipient_chain", recipient_chain.to_string())
@ -1275,6 +1283,7 @@ fn format_native_denom_symbol(denom: &str) -> String {
denom.to_uppercase()[1..3].to_string() + "T"
}
#[allow(clippy::too_many_arguments)]
fn handle_initiate_transfer_native_token(
deps: DepsMut,
env: Env,
@ -1333,7 +1342,7 @@ fn handle_initiate_transfer_native_token(
}
}
TransferType::WithPayload { payload } => {
let sender_address = deps.api.addr_canonicalize(&info.sender.to_string())?;
let sender_address = deps.api.addr_canonicalize(info.sender.as_ref())?;
let sender_address = extend_address_to_32_array(&sender_address);
let transfer_info = TransferWithPayloadInfo {
amount: (0, amount.u128()),
@ -1351,14 +1360,14 @@ fn handle_initiate_transfer_native_token(
}
};
let sender = deps.api.addr_canonicalize(&info.sender.as_str())?;
let sender = deps.api.addr_canonicalize(info.sender.as_str())?;
messages.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: cfg.wormhole_contract,
msg: to_binary(&WormholeExecuteMsg::PostMessage {
message: Binary::from(token_bridge_message.serialize()),
nonce,
})?,
funds: coins_after_tax(deps, info.funds.clone())?,
funds: coins_after_tax(deps, info.funds)?,
}));
Ok(Response::new()
@ -1465,8 +1474,8 @@ pub fn build_native_id(denom: &str) -> Vec<u8> {
asset_address
}
fn is_governance_emitter(cfg: &ConfigInfo, emitter_chain: u16, emitter_address: &Vec<u8>) -> bool {
cfg.gov_chain == emitter_chain && cfg.gov_address == emitter_address.clone()
fn is_governance_emitter(cfg: &ConfigInfo, emitter_chain: u16, emitter_address: &[u8]) -> bool {
cfg.gov_chain == emitter_chain && cfg.gov_address == emitter_address
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -5,7 +5,7 @@ use terraswap::asset::{Asset, AssetInfo};
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {
// governance contract details
pub gov_chain: u16,
@ -59,24 +59,24 @@ pub enum ExecuteMsg {
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
WrappedRegistry { chain: u16, address: Binary },
TransferInfo { vaa: Binary },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct WrappedRegistryResponse {
pub address: HumanAddr,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct TransferInfoResponse {
pub amount: Uint128,

View File

@ -21,7 +21,7 @@ pub static BRIDGE_DEPOSITS: &[u8] = b"bridge_deposits";
pub static NATIVE_COUNTER: &[u8] = b"native_counter";
// Guardian set information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ConfigInfo {
// governance contract details
pub gov_chain: u16,
@ -83,7 +83,7 @@ type Serialized128 = String;
/// Structure to keep track of an active CW20 transfer, required to pass state through to the reply
/// handler for submessages during a transfer.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferState {
pub account: String,
pub message: Vec<u8>,
@ -167,7 +167,7 @@ impl TokenBridgeMessage {
// 98 u16 recipient_chain
// 100 u256 fee
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferInfo {
pub amount: (u128, u128),
pub token_address: [u8; 32],
@ -219,7 +219,7 @@ impl TransferInfo {
// 100 [u8; 32] sender_address
// 132 [u8] payload
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct TransferWithPayloadInfo {
pub amount: (u128, u128),
pub token_address: [u8; 32],
@ -275,7 +275,7 @@ impl TransferWithPayloadInfo {
pub fn as_transfer_info(&self) -> TransferInfo {
TransferInfo {
amount: self.amount,
token_address: self.token_address.clone(),
token_address: self.token_address,
token_chain: self.token_chain,
recipient: self.recipient,
recipient_chain: self.recipient_chain,

View File

@ -6,7 +6,7 @@ use crate::state::{GuardianAddress, GuardianSetInfo};
type HumanAddr = String;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {
pub gov_chain: u16,
pub gov_address: Binary,
@ -15,18 +15,18 @@ pub struct InstantiateMsg {
pub guardian_set_expirity: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
SubmitVAA { vaa: Binary },
PostMessage { message: Binary, nonce: u32 },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MigrateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
GuardianSetInfo {},
@ -35,14 +35,14 @@ pub enum QueryMsg {
QueryAddressHex { address: HumanAddr },
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct GuardianSetInfoResponse {
pub guardian_set_index: u32, // Current guardian set index
pub addresses: Vec<GuardianAddress>, // List of querdian addresses
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct WrappedRegistryResponse {
pub address: HumanAddr,
@ -54,7 +54,7 @@ pub struct GetStateResponse {
pub fee: Coin,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct GetAddressHexResponse {
pub hex: String,

View File

@ -37,7 +37,7 @@ pub struct ConfigInfo {
}
// Validator Action Approval(VAA) data
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct ParsedVAA {
pub version: u8,
pub guardian_set_index: u32,
@ -150,7 +150,7 @@ impl ParsedVAA {
}
// Guardian address
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct GuardianAddress {
pub bytes: Binary, // 20-byte addresses
}
@ -169,7 +169,7 @@ impl GuardianAddress {
}
// Guardian set information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct GuardianSetInfo {
pub addresses: Vec<GuardianAddress>,
// List of guardian addresses
@ -187,7 +187,7 @@ impl GuardianSetInfo {
}
// Wormhole contract generic information
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct WormholeInfo {
// Period for which a guardian set stays active after it has been replaced
pub guardian_set_expirity: u64,
@ -220,8 +220,7 @@ pub fn sequence_set(storage: &mut dyn Storage, emitter: &[u8], sequence: u64) ->
pub fn sequence_read(storage: &dyn Storage, emitter: &[u8]) -> u64 {
bucket_read(storage, SEQUENCE_KEY)
.load(emitter)
.or::<u64>(Ok(0))
.unwrap()
.unwrap_or(0)
}
pub fn vaa_archive_add(storage: &mut dyn Storage, hash: &[u8]) -> StdResult<()> {
@ -231,8 +230,7 @@ pub fn vaa_archive_add(storage: &mut dyn Storage, hash: &[u8]) -> StdResult<()>
pub fn vaa_archive_check(storage: &dyn Storage, hash: &[u8]) -> bool {
bucket_read(storage, GUARDIAN_SET_KEY)
.load(hash)
.or::<bool>(Ok(false))
.unwrap()
.unwrap_or(false)
}
pub fn wrapped_asset(storage: &mut dyn Storage) -> Bucket<HumanAddr> {

View File

@ -185,7 +185,7 @@ fn get_address_test() -> StdResult<()> {
#[test]
#[should_panic]
fn get_address_test_panic() -> () {
fn get_address_test_panic() {
// panics because of junk in first 12 bytes
let ones_32: &[u8] = &[1; 32];
ones_32.get_address(0);
@ -193,7 +193,7 @@ fn get_address_test_panic() -> () {
#[test]
#[should_panic]
fn get_address_test_panic_2() -> () {
fn get_address_test_panic_2() {
// panics because not enough bytes (need at least 32)
let short_address: &[u8] = &[0; 31];
short_address.get_address(0);

View File

@ -11,8 +11,6 @@ use wormhole::{
state::{ConfigInfo, GuardianAddress, GuardianSetInfo, CONFIG_KEY},
};
use hex;
static INITIALIZER: &str = "initializer";
static GOV_ADDR: &[u8] = b"GOVERNANCE_ADDRESS";
@ -54,10 +52,10 @@ fn do_init(guardians: &[GuardianAddress]) -> OwnedDeps<MockStorage, MockApi, Moc
#[test]
fn init_works() {
let guardians = [GuardianAddress::from(GuardianAddress {
let guardians = [GuardianAddress {
bytes: hex::decode("beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe")
.expect("Decoding failed")
.into(),
})];
}];
let _deps = do_init(&guardians);
}

View File

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use cw0::Expiration;
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum Cw721QueryMsg {
/// Return the owner of the given token, error if token does not exist
@ -94,18 +94,18 @@ pub struct OperatorsResponse {
pub operators: Vec<Approval>,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
pub struct NumTokensResponse {
pub count: u64,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
pub struct ContractInfoResponse {
pub name: String,
pub symbol: String,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
pub struct NftInfoResponse<T> {
/// Universal resource identifier for this NFT
/// Should point to a JSON file that conforms to the ERC721
@ -123,7 +123,7 @@ pub struct AllNftInfoResponse<T> {
pub info: NftInfoResponse<T>,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
pub struct TokensResponse {
/// Contains all token_ids in lexicographical ordering
/// If there are more than `limit`, use `start_from` in future queries

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use cosmwasm_std::{to_binary, Binary, CosmosMsg, StdResult, WasmMsg};
/// Cw721ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Cw721ReceiveMsg {
pub sender: String,