Prechádzať zdrojové kódy

cosmwasm: Fix formatting

Also remove the unstable options in rustfmt.toml.  We can re-enable them
once they are stabilized.
Chirantan Ekbote 3 rokov pred
rodič
commit
dedcea34af

+ 9 - 46
cosmwasm/contracts/cw20-wrapped/src/contract.rs

@@ -1,16 +1,6 @@
 use cosmwasm_std::{
-    to_binary,
-    Binary,
-    CosmosMsg,
-    Deps,
-    DepsMut,
-    Env,
-    MessageInfo,
-    Response,
-    StdError,
-    StdResult,
-    Uint128,
-    WasmMsg,
+    to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult,
+    Uint128, WasmMsg,
 };
 
 #[cfg(not(feature = "library"))]
@@ -19,40 +9,17 @@ use cosmwasm_std::entry_point;
 use cw2::set_contract_version;
 use cw20_base::{
     allowances::{
-        execute_burn_from,
-        execute_decrease_allowance,
-        execute_increase_allowance,
-        execute_send_from,
-        execute_transfer_from,
-        query_allowance,
-    },
-    contract::{
-        execute_mint,
-        execute_send,
-        execute_transfer,
-        query_balance,
-    },
-    state::{
-        MinterData,
-        TokenInfo,
-        TOKEN_INFO,
+        execute_burn_from, execute_decrease_allowance, execute_increase_allowance,
+        execute_send_from, execute_transfer_from, query_allowance,
     },
+    contract::{execute_mint, execute_send, execute_transfer, query_balance},
+    state::{MinterData, TokenInfo, TOKEN_INFO},
     ContractError,
 };
 
 use crate::{
-    msg::{
-        ExecuteMsg,
-        InstantiateMsg,
-        MigrateMsg,
-        QueryMsg,
-        WrappedAssetInfoResponse,
-    },
-    state::{
-        wrapped_asset_info,
-        wrapped_asset_info_read,
-        WrappedAssetInfo,
-    },
+    msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, WrappedAssetInfoResponse},
+    state::{wrapped_asset_info, wrapped_asset_info_read, WrappedAssetInfo},
 };
 use cw20::TokenInfoResponse;
 use std::string::String;
@@ -237,11 +204,7 @@ pub fn query_wrapped_asset_info(deps: Deps) -> StdResult<WrappedAssetInfoRespons
 #[cfg(test)]
 mod tests {
     use super::*;
-    use cosmwasm_std::testing::{
-        mock_dependencies,
-        mock_env,
-        mock_info,
-    };
+    use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
     use cw20::TokenInfoResponse;
 
     fn get_balance(deps: Deps, address: HumanAddr) -> Uint128 {

+ 2 - 9
cosmwasm/contracts/cw20-wrapped/src/msg.rs

@@ -1,15 +1,8 @@
 #![allow(clippy::field_reassign_with_default)]
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
-use cosmwasm_std::{
-    Addr,
-    Binary,
-    Uint128,
-};
+use cosmwasm_std::{Addr, Binary, Uint128};
 use cw20::Expiration;
 
 type HumanAddr = String;

+ 4 - 18
cosmwasm/contracts/cw20-wrapped/src/state.rs

@@ -1,20 +1,8 @@
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
-use cosmwasm_std::{
-    Binary,
-    CanonicalAddr,
-    Storage,
-};
-use cosmwasm_storage::{
-    singleton,
-    singleton_read,
-    ReadonlySingleton,
-    Singleton,
-};
+use cosmwasm_std::{Binary, CanonicalAddr, Storage};
+use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
 
 pub const KEY_WRAPPED_ASSET: &[u8] = b"wrappedAsset";
 
@@ -30,8 +18,6 @@ pub fn wrapped_asset_info(storage: &mut dyn Storage) -> Singleton<WrappedAssetIn
     singleton(storage, KEY_WRAPPED_ASSET)
 }
 
-pub fn wrapped_asset_info_read(
-    storage: &dyn Storage,
-) -> ReadonlySingleton<WrappedAssetInfo> {
+pub fn wrapped_asset_info_read(storage: &dyn Storage) -> ReadonlySingleton<WrappedAssetInfo> {
     singleton_read(storage, KEY_WRAPPED_ASSET)
 }

+ 6 - 32
cosmwasm/contracts/cw20-wrapped/tests/integration.rs

@@ -1,38 +1,14 @@
 use cosmwasm_std::{
     from_slice,
-    testing::{
-        mock_dependencies,
-        mock_env,
-        mock_info,
-        MockApi,
-        MockQuerier,
-        MockStorage,
-    },
-    Addr,
-    Api,
-    OwnedDeps,
-    Response,
-    Storage,
-    Uint128,
+    testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage},
+    Addr, Api, OwnedDeps, Response, Storage, Uint128,
 };
 use cosmwasm_storage::to_length_prefixed;
 use cw20::TokenInfoResponse;
 use cw20_wrapped_2::{
-    contract::{
-        execute,
-        instantiate,
-        query,
-    },
-    msg::{
-        ExecuteMsg,
-        InstantiateMsg,
-        QueryMsg,
-        WrappedAssetInfoResponse,
-    },
-    state::{
-        WrappedAssetInfo,
-        KEY_WRAPPED_ASSET,
-    },
+    contract::{execute, instantiate, query},
+    msg::{ExecuteMsg, InstantiateMsg, QueryMsg, WrappedAssetInfoResponse},
+    state::{WrappedAssetInfo, KEY_WRAPPED_ASSET},
     ContractError,
 };
 
@@ -42,9 +18,7 @@ static SENDER: &str = "addr3333";
 
 fn get_wrapped_asset_info<S: Storage>(storage: &S) -> WrappedAssetInfo {
     let key = to_length_prefixed(KEY_WRAPPED_ASSET);
-    let data = storage
-        .get(&key)
-        .expect("data should exist");
+    let data = storage.get(&key).expect("data should exist");
     from_slice(&data).expect("invalid data")
 }
 

+ 19 - 45
cosmwasm/contracts/mock-bridge-integration/src/contract.rs

@@ -1,42 +1,16 @@
 use cosmwasm_std::{
-    entry_point,
-    to_binary,
-    Binary,
-    CosmosMsg,
-    Deps,
-    DepsMut,
-    Env,
-    MessageInfo,
-    QueryRequest,
-    Reply,
-    Response,
-    StdError,
-    StdResult,
-    SubMsg,
-    WasmMsg,
-    WasmQuery,
+    entry_point, to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, QueryRequest,
+    Reply, Response, StdError, StdResult, SubMsg, WasmMsg, WasmQuery,
 };
 
 use crate::{
-    msg::{
-        ExecuteMsg,
-        InstantiateMsg,
-        MigrateMsg,
-        QueryMsg,
-    },
-    state::{
-        Config,
-        config,
-        config_read,
-    },
+    msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
+    state::{config, config_read, Config},
 };
 
 use token_bridge_terra_2::{
-    msg::{
-        ExecuteMsg as TokenBridgeExecuteMsg,
-        QueryMsg as TokenBridgeQueryMessage,
-    },
     msg::TransferInfoResponse,
+    msg::{ExecuteMsg as TokenBridgeExecuteMsg, QueryMsg as TokenBridgeQueryMessage},
 };
 
 #[cfg_attr(not(feature = "library"), entry_point)]
@@ -64,7 +38,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
     match msg {
         ExecuteMsg::CompleteTransferWithPayload { data } => {
             complete_transfer_with_payload(deps, env, info, &data)
-        },
+        }
     }
 }
 
@@ -90,31 +64,31 @@ fn complete_transfer_with_payload(
         CosmosMsg::Wasm(WasmMsg::Execute {
             contract_addr: cfg.token_bridge_contract,
             msg: to_binary(&TokenBridgeExecuteMsg::CompleteTransferWithPayload {
-                data: data.clone(), relayer: info.sender.to_string()
+                data: data.clone(),
+                relayer: info.sender.to_string(),
             })?,
             funds: vec![],
         }),
         1,
-    ),];
+    )];
 
     let transfer_info = parse_transfer_vaa(deps.as_ref(), data)?;
 
     Ok(Response::new()
         .add_submessages(messages)
         .add_attribute("action", "complete_transfer_with_payload")
-        .add_attribute("transfer_payload", Binary::from(transfer_info.payload).to_base64()))
+        .add_attribute(
+            "transfer_payload",
+            Binary::from(transfer_info.payload).to_base64(),
+        ))
 }
 
-fn parse_transfer_vaa(
-    deps: Deps,
-    data: &Binary,
-) -> StdResult<TransferInfoResponse> {
+fn parse_transfer_vaa(deps: Deps, data: &Binary) -> StdResult<TransferInfoResponse> {
     let cfg = config_read(deps.storage).load()?;
-    let transfer_info: TransferInfoResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
-        contract_addr: cfg.token_bridge_contract,
-        msg: to_binary(&TokenBridgeQueryMessage::TransferInfo {
-            vaa: data.clone(),
-        })?,
-    }))?;
+    let transfer_info: TransferInfoResponse =
+        deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
+            contract_addr: cfg.token_bridge_contract,
+            msg: to_binary(&TokenBridgeQueryMessage::TransferInfo { vaa: data.clone() })?,
+        }))?;
     Ok(transfer_info)
 }

+ 3 - 8
cosmwasm/contracts/mock-bridge-integration/src/msg.rs

@@ -1,9 +1,6 @@
 use cosmwasm_std::Binary;
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
 type HumanAddr = String;
 
@@ -15,9 +12,7 @@ pub struct InstantiateMsg {
 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
 #[serde(rename_all = "snake_case")]
 pub enum ExecuteMsg {
-    CompleteTransferWithPayload {
-        data: Binary,
-    },
+    CompleteTransferWithPayload { data: Binary },
 }
 
 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
@@ -28,4 +23,4 @@ pub struct MigrateMsg {}
 #[serde(rename_all = "snake_case")]
 pub enum QueryMsg {
     WrappedRegistry { chain: u16, address: Binary },
-}
+}

+ 3 - 11
cosmwasm/contracts/mock-bridge-integration/src/state.rs

@@ -1,16 +1,8 @@
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
 use cosmwasm_std::Storage;
-use cosmwasm_storage::{
-    singleton,
-    singleton_read,
-    ReadonlySingleton,
-    Singleton,
-};
+use cosmwasm_storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
 
 type HumanAddr = String;
 
@@ -28,4 +20,4 @@ pub fn config(storage: &mut dyn Storage) -> Singleton<Config> {
 
 pub fn config_read(storage: &dyn Storage) -> ReadonlySingleton<Config> {
     singleton_read(storage, CONFIG_KEY)
-}
+}

+ 4 - 24
cosmwasm/contracts/token-bridge/_tests/integration.rs

@@ -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;

+ 20 - 95
cosmwasm/contracts/token-bridge/src/contract.rs

@@ -1,121 +1,47 @@
-use cw20::{
-    BalanceResponse,
-    TokenInfoResponse,
-};
-use cw20_base::msg::{
-    ExecuteMsg as TokenMsg,
-    QueryMsg as TokenQuery,
-};
+use cw20::{BalanceResponse, TokenInfoResponse};
+use cw20_base::msg::{ExecuteMsg as TokenMsg, QueryMsg as TokenQuery};
 use cw20_wrapped_2::msg::{
-    ExecuteMsg as WrappedMsg,
-    InitHook,
-    InstantiateMsg as WrappedInit,
-    QueryMsg as WrappedQuery,
+    ExecuteMsg as WrappedMsg, InitHook, InstantiateMsg as WrappedInit, QueryMsg as WrappedQuery,
     WrappedAssetInfoResponse,
 };
 use std::{
-    cmp::{
-        max,
-        min,
-    },
+    cmp::{max, min},
     str::FromStr,
 };
-use terraswap::asset::{
-    Asset,
-    AssetInfo,
-};
+use terraswap::asset::{Asset, AssetInfo};
 
 use wormhole::{
     byte_utils::{
-        extend_address_to_32,
-        extend_address_to_32_array,
-        extend_string_to_32,
-        get_string_from_32,
+        extend_address_to_32, extend_address_to_32_array, extend_string_to_32, get_string_from_32,
         ByteUtils,
     },
     error::ContractError,
-    msg::{
-        ExecuteMsg as WormholeExecuteMsg,
-        QueryMsg as WormholeQueryMsg,
-    },
-    state::{
-        vaa_archive_add,
-        vaa_archive_check,
-        GovernancePacket,
-        ParsedVAA,
-    },
+    msg::{ExecuteMsg as WormholeExecuteMsg, QueryMsg as WormholeQueryMsg},
+    state::{vaa_archive_add, vaa_archive_check, GovernancePacket, ParsedVAA},
 };
 
 #[allow(unused_imports)]
 use cosmwasm_std::entry_point;
 
 use cosmwasm_std::{
-    coin,
-    to_binary,
-    BankMsg,
-    Binary,
-    CanonicalAddr,
-    CosmosMsg,
-    Deps,
-    DepsMut,
-    Empty,
-    Env,
-    MessageInfo,
-    QueryRequest,
-    Reply,
-    Response,
-    StdError,
-    StdResult,
-    SubMsg,
-    Uint128,
-    WasmMsg,
+    coin, to_binary, BankMsg, Binary, CanonicalAddr, CosmosMsg, Deps, DepsMut, Empty, Env,
+    MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg,
     WasmQuery,
 };
 
 use crate::{
     msg::{
-        ExecuteMsg,
-        ExternalIdResponse,
-        InstantiateMsg,
-        IsVaaRedeemedResponse,
-        MigrateMsg,
-        QueryMsg,
-        TransferInfoResponse,
-        WrappedRegistryResponse,
+        ExecuteMsg, ExternalIdResponse, InstantiateMsg, IsVaaRedeemedResponse, MigrateMsg,
+        QueryMsg, TransferInfoResponse, WrappedRegistryResponse,
     },
     state::{
-        bridge_contracts,
-        bridge_contracts_read,
-        bridge_deposit,
-        config,
-        config_read,
-        config_read_legacy,
-        is_wrapped_asset,
-        is_wrapped_asset_read,
-        receive_native,
-        send_native,
-        wrapped_asset,
-        wrapped_asset_read,
-        wrapped_asset_seq,
-        wrapped_asset_seq_read,
-        wrapped_transfer_tmp,
-        Action,
-        AssetMeta,
-        ConfigInfo,
-        ConfigInfoLegacy,
-        RegisterChain,
-        TokenBridgeMessage,
-        TransferInfo,
-        TransferState,
-        TransferWithPayloadInfo,
-        UpgradeContract,
-    },
-    token_address::{
-        ContractId,
-        ExternalTokenId,
-        TokenId,
-        WrappedCW20,
+        bridge_contracts, bridge_contracts_read, bridge_deposit, config, config_read,
+        is_wrapped_asset, is_wrapped_asset_read, receive_native, send_native, wrapped_asset,
+        wrapped_asset_read, wrapped_asset_seq, wrapped_asset_seq_read, wrapped_transfer_tmp,
+        Action, AssetMeta, ConfigInfo, RegisterChain, TokenBridgeMessage, TransferInfo,
+        TransferState, TransferWithPayloadInfo, UpgradeContract,
     },
+    token_address::{ContractId, ExternalTokenId, TokenId, WrappedCW20},
 };
 
 type HumanAddr = String;
@@ -160,7 +86,7 @@ pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Respons
     //     wormhole_contract,
     //     wrapped_asset_code_id,
     // } = config_read_legacy(deps.storage).load()?;
-    
+
     // // 3. store new state with terra2 values hardcoded
     // let chain_id = 18;
     // let native_denom = "uluna".to_string();
@@ -317,7 +243,6 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
         ExecuteMsg::SubmitVaa { data } => submit_vaa(deps, env, info, &data),
 
         // The following actions are disabled in "shutdown" mode
-
         #[cfg(feature = "full")]
         ExecuteMsg::RegisterAssetHook {
             chain,
@@ -383,7 +308,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
 
         // When in "shutdown" mode, we reject any other action
         #[cfg(not(feature = "full"))]
-        _ => Err(StdError::generic_err("Invalid during shutdown mode"))
+        _ => Err(StdError::generic_err("Invalid during shutdown mode")),
     }
 }
 

+ 5 - 17
cosmwasm/contracts/token-bridge/src/msg.rs

@@ -1,21 +1,9 @@
-use cosmwasm_std::{
-    Binary,
-    Uint128,
-};
+use cosmwasm_std::{Binary, Uint128};
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
-use terraswap::asset::{
-    Asset,
-    AssetInfo,
-};
-
-use crate::token_address::{
-    ExternalTokenId,
-    TokenId,
-};
+use serde::{Deserialize, Serialize};
+use terraswap::asset::{Asset, AssetInfo};
+
+use crate::token_address::{ExternalTokenId, TokenId};
 
 type HumanAddr = String;
 

+ 3 - 19
cosmwasm/contracts/token-bridge/src/state.rs

@@ -1,24 +1,9 @@
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
-use cosmwasm_std::{
-    Addr,
-    StdError,
-    StdResult,
-    Storage,
-    Uint128,
-};
+use cosmwasm_std::{Addr, StdError, StdResult, Storage, Uint128};
 use cosmwasm_storage::{
-    bucket,
-    bucket_read,
-    singleton,
-    singleton_read,
-    Bucket,
-    ReadonlyBucket,
-    ReadonlySingleton,
+    bucket, bucket_read, singleton, singleton_read, Bucket, ReadonlyBucket, ReadonlySingleton,
     Singleton,
 };
 
@@ -325,7 +310,6 @@ impl TransferWithPayloadInfo {
             sender_address,
             payload,
         })
-
     }
 
     pub fn serialize(&self) -> Vec<u8> {

+ 30 - 34
cosmwasm/contracts/token-bridge/src/testing/tests.rs

@@ -1,19 +1,11 @@
 use std::convert::TryInto;
 
-use cosmwasm_std::{
-    Binary,
-    StdResult,
-};
+use cosmwasm_std::{Binary, StdResult};
 
 use wormhole::state::ParsedVAA;
 
 use crate::{
-    state::{
-        Action,
-        TokenBridgeMessage,
-        TransferInfo,
-        TransferWithPayloadInfo,
-    },
+    state::{Action, TokenBridgeMessage, TransferInfo, TransferWithPayloadInfo},
     token_address::ExternalTokenId,
 };
 
@@ -53,7 +45,10 @@ fn binary_check() -> StdResult<()> {
 fn build_native_and_asset_ids() -> StdResult<()> {
     let external_id_uluna = ExternalTokenId::from_bank_token(&"uluna".to_string())?;
 
-    let expected_external_id: [u8; 32] = [1, 250, 108, 111, 188, 54, 216, 194, 69, 176, 168, 82, 164, 62, 181, 214, 68, 232, 180, 196, 119, 178, 123, 250, 185, 83, 124, 16, 148, 89, 57, 218];
+    let expected_external_id: [u8; 32] = [
+        1, 250, 108, 111, 188, 54, 216, 194, 69, 176, 168, 82, 164, 62, 181, 214, 68, 232, 180,
+        196, 119, 178, 123, 250, 185, 83, 124, 16, 148, 89, 57, 218,
+    ];
     assert_eq!(
         &external_id_uluna.serialize(),
         &expected_external_id,
@@ -69,7 +64,10 @@ fn build_native_and_asset_ids() -> StdResult<()> {
         .unwrap();
     let external_id_weth = ExternalTokenId::from_foreign_token(token_address);
 
-    let expected_asset_id: [u8; 32] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 42, 170, 57, 178, 35, 254, 141, 10, 14, 92, 79, 39, 234, 217, 8, 60, 117, 108, 194];
+    let expected_asset_id: [u8; 32] = [
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 42, 170, 57, 178, 35, 254, 141, 10, 14, 92, 79,
+        39, 234, 217, 8, 60, 117, 108, 194,
+    ];
     assert_eq!(
         &external_id_weth.serialize(),
         &expected_asset_id,
@@ -140,27 +138,26 @@ fn deserialize_transfer_vaa() -> StdResult<()> {
 
 #[test]
 fn deserialize_transfer_with_payload_vaa() -> StdResult<()> {
-
-// ┌──────────────────────────────────────────────────────────────────────────────┐
-// │ Wormhole VAA v1         │ nonce: 2080370133       │ time: 0                  │
-// │ guardian set #0         │ #4568529024235897313    │ consistency: 32          │
-// ├──────────────────────────────────────────────────────────────────────────────┤
-// │ Signature:                                                                   │
-// │   #0: 2565e7ae10421624fd81118855acda893e752aeeef31c13fbfc417591ada...        │
-// ├──────────────────────────────────────────────────────────────────────────────┤
-// │ Emitter: 11111111111111111111111111111115 (Solana)                           │
-// ╞══════════════════════════════════════════════════════════════════════════════╡
-// │ Token transfer with payload (aka payload 3)                                  │
-// │ Amount: 1.0                                                                  │
-// │ Token: terra1qqqqqqqqqqqqqqqqqqqqqqqqqp6h2umyswfh6y (Terra)                  │
-// │ Recipient: terra13nkgqrfymug724h8pprpexqj9h629sa3ncw7sh (Terra)              │
-// │ From: 1399a4e782b935d2bb36b97586d3df8747b07dc66902d807eed0ae99e00ed256       │
-// ╞══════════════════════════════════════════════════════════════════════════════╡
-// │ Custom payload:                                                              │
-// │ Length: 30 (0x1e) bytes                                                      │
-// │ 0000:   41 6c 6c 20  79 6f 75 72  20 62 61 73  65 20 61 72   All your base ar│
-// │ 0010:   65 20 62 65  6c 6f 6e 67  20 74 6f 20  75 73         e belong to us  │
-// └──────────────────────────────────────────────────────────────────────────────┘
+    // ┌──────────────────────────────────────────────────────────────────────────────┐
+    // │ Wormhole VAA v1         │ nonce: 2080370133       │ time: 0                  │
+    // │ guardian set #0         │ #4568529024235897313    │ consistency: 32          │
+    // ├──────────────────────────────────────────────────────────────────────────────┤
+    // │ Signature:                                                                   │
+    // │   #0: 2565e7ae10421624fd81118855acda893e752aeeef31c13fbfc417591ada...        │
+    // ├──────────────────────────────────────────────────────────────────────────────┤
+    // │ Emitter: 11111111111111111111111111111115 (Solana)                           │
+    // ╞══════════════════════════════════════════════════════════════════════════════╡
+    // │ Token transfer with payload (aka payload 3)                                  │
+    // │ Amount: 1.0                                                                  │
+    // │ Token: terra1qqqqqqqqqqqqqqqqqqqqqqqqqp6h2umyswfh6y (Terra)                  │
+    // │ Recipient: terra13nkgqrfymug724h8pprpexqj9h629sa3ncw7sh (Terra)              │
+    // │ From: 1399a4e782b935d2bb36b97586d3df8747b07dc66902d807eed0ae99e00ed256       │
+    // ╞══════════════════════════════════════════════════════════════════════════════╡
+    // │ Custom payload:                                                              │
+    // │ Length: 30 (0x1e) bytes                                                      │
+    // │ 0000:   41 6c 6c 20  79 6f 75 72  20 62 61 73  65 20 61 72   All your base ar│
+    // │ 0010:   65 20 62 65  6c 6f 6e 67  20 74 6f 20  75 73         e belong to us  │
+    // └──────────────────────────────────────────────────────────────────────────────┘
 
     let signed_vaa = "\
         010000000001002565e7ae10421624fd81118855acda893e752aeeef31c13fbf\
@@ -223,7 +220,6 @@ fn deserialize_transfer_with_payload_vaa() -> StdResult<()> {
         "info.recipient_chain != expected"
     );
 
-
     let transfer_payload = "All your base are belong to us";
     let transfer_payload = transfer_payload.as_bytes();
     assert_eq!(

+ 4 - 18
cosmwasm/contracts/token-bridge/src/token_address.rs

@@ -1,25 +1,11 @@
-use cosmwasm_std::{
-    Addr,
-    StdError,
-    StdResult,
-    Storage,
-};
+use cosmwasm_std::{Addr, StdError, StdResult, Storage};
 
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
-use sha3::{
-    Digest,
-    Keccak256,
-};
+use serde::{Deserialize, Serialize};
+use sha3::{Digest, Keccak256};
 
 use crate::state::{
-    bank_token_hashes,
-    bank_token_hashes_read,
-    config_read,
-    native_c20_hashes,
+    bank_token_hashes, bank_token_hashes_read, config_read, native_c20_hashes,
     native_c20_hashes_read,
 };
 

+ 2 - 2
cosmwasm/contracts/wormhole/src/byte_utils.rs

@@ -46,9 +46,9 @@ impl ByteUtils for &[u8] {
         // 32 bytes are reserved for addresses, but wasmd uses both 32 and 20 bytes
         // https://github.com/CosmWasm/wasmd/blob/ac92fdcf37388cc8dc24535f301f64395f8fb3da/x/wasm/types/types.go#L325
         if self.get_u128_be(index) >> 32 == 0 {
-            return CanonicalAddr::from(&self[index + 12..index + 32])    
+            return CanonicalAddr::from(&self[index + 12..index + 32]);
         }
-        return CanonicalAddr::from(&self[index..index + 32])
+        return CanonicalAddr::from(&self[index..index + 32]);
     }
     fn get_bytes32(&self, index: usize) -> &[u8] {
         &self[index..index + 32]

+ 12 - 54
cosmwasm/contracts/wormhole/src/contract.rs

@@ -1,75 +1,33 @@
 use cosmwasm_std::{
-    has_coins,
-    to_binary,
-    BankMsg,
-    Binary,
-    Coin,
-    CosmosMsg,
-    Deps,
-    DepsMut,
-    Env,
-    MessageInfo,
-    Response,
-    StdError,
-    StdResult,
-    Storage,
-    WasmMsg,
+    has_coins, to_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
+    Response, StdError, StdResult, Storage, WasmMsg,
 };
 
 #[cfg(not(feature = "library"))]
 use cosmwasm_std::entry_point;
 
 use crate::{
-    byte_utils::{
-        extend_address_to_32,
-        ByteUtils,
-    },
+    byte_utils::{extend_address_to_32, ByteUtils},
     error::ContractError,
     msg::{
-        ExecuteMsg,
-        GetAddressHexResponse,
-        GetStateResponse,
-        GuardianSetInfoResponse,
-        InstantiateMsg,
-        MigrateMsg,
-        QueryMsg,
+        ExecuteMsg, GetAddressHexResponse, GetStateResponse, GuardianSetInfoResponse,
+        InstantiateMsg, MigrateMsg, QueryMsg,
     },
     state::{
-        config,
-        config_read,
-        guardian_set_get,
-        guardian_set_set,
-        sequence_read,
-        sequence_set,
-        vaa_archive_add,
-        vaa_archive_check,
-        ConfigInfo,
-        ContractUpgrade,
-        GovernancePacket,
-        GuardianAddress,
-        GuardianSetInfo,
-        GuardianSetUpgrade,
-        ParsedVAA,
-        SetFee,
-        TransferFee,
+        config, config_read, guardian_set_get, guardian_set_set, sequence_read, sequence_set,
+        vaa_archive_add, vaa_archive_check, ConfigInfo, ContractUpgrade, GovernancePacket,
+        GuardianAddress, GuardianSetInfo, GuardianSetUpgrade, ParsedVAA, SetFee, TransferFee,
     },
 };
 
 use k256::{
     ecdsa::{
-        recoverable::{
-            Id as RecoverableId,
-            Signature as RecoverableSignature,
-        },
-        Signature,
-        VerifyingKey,
+        recoverable::{Id as RecoverableId, Signature as RecoverableSignature},
+        Signature, VerifyingKey,
     },
     EncodedPoint,
 };
-use sha3::{
-    Digest,
-    Keccak256,
-};
+use sha3::{Digest, Keccak256};
 
 use generic_array::GenericArray;
 use std::convert::TryFrom;
@@ -139,7 +97,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
 
         // When in "shutdown" mode, we reject any other action
         #[cfg(not(feature = "full"))]
-        _ => Err(StdError::generic_err("Invalid during shutdown mode"))
+        _ => Err(StdError::generic_err("Invalid during shutdown mode")),
     }
 }
 

+ 4 - 14
cosmwasm/contracts/wormhole/src/msg.rs

@@ -1,17 +1,8 @@
-use cosmwasm_std::{
-    Binary,
-    Coin,
-};
+use cosmwasm_std::{Binary, Coin};
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
-use crate::state::{
-    GuardianAddress,
-    GuardianSetInfo,
-};
+use crate::state::{GuardianAddress, GuardianSetInfo};
 
 type HumanAddr = String;
 
@@ -39,8 +30,7 @@ pub enum ExecuteMsg {
 
 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
 #[serde(rename_all = "snake_case")]
-pub struct MigrateMsg {
-}
+pub struct MigrateMsg {}
 
 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
 #[serde(rename_all = "snake_case")]

+ 7 - 32
cosmwasm/contracts/wormhole/src/state.rs

@@ -1,37 +1,15 @@
 use schemars::JsonSchema;
-use serde::{
-    Deserialize,
-    Serialize,
-};
+use serde::{Deserialize, Serialize};
 
-use cosmwasm_std::{
-    Binary,
-    CanonicalAddr,
-    Coin,
-    StdResult,
-    Storage,
-    Uint128,
-};
+use cosmwasm_std::{Binary, CanonicalAddr, Coin, StdResult, Storage, Uint128};
 use cosmwasm_storage::{
-    bucket,
-    bucket_read,
-    singleton,
-    singleton_read,
-    Bucket,
-    ReadonlyBucket,
-    ReadonlySingleton,
+    bucket, bucket_read, singleton, singleton_read, Bucket, ReadonlyBucket, ReadonlySingleton,
     Singleton,
 };
 
-use crate::{
-    byte_utils::ByteUtils,
-    error::ContractError,
-};
+use crate::{byte_utils::ByteUtils, error::ContractError};
 
-use sha3::{
-    Digest,
-    Keccak256,
-};
+use sha3::{Digest, Keccak256};
 
 type HumanAddr = String;
 
@@ -335,7 +313,7 @@ impl GovernancePacket {
 }
 
 // action 1
-pub struct ContractUpgrade  {
+pub struct ContractUpgrade {
     pub new_contract: u64,
 }
 
@@ -348,9 +326,7 @@ pub struct GuardianSetUpgrade {
 impl ContractUpgrade {
     pub fn deserialize(data: &[u8]) -> StdResult<Self> {
         let new_contract = data.get_u64(24);
-        Ok(ContractUpgrade {
-            new_contract,
-        })
+        Ok(ContractUpgrade { new_contract })
     }
 }
 
@@ -421,4 +397,3 @@ impl TransferFee {
         Ok(TransferFee { amount, recipient })
     }
 }
-

+ 1 - 1
cosmwasm/contracts/wormhole/src/testing/mod.rs

@@ -1 +1 @@
-mod tests;
+mod tests;

+ 65 - 52
cosmwasm/contracts/wormhole/src/testing/tests.rs

@@ -4,22 +4,16 @@ use crate::state::{GuardianAddress, GuardianSetInfo, ParsedVAA};
 
 #[test]
 fn quardian_set_quorum() {
-    let num_guardians_trials: Vec<usize> = vec![
-        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 20, 25, 100,
-    ];
+    let num_guardians_trials: Vec<usize> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 20, 25, 100];
 
-    let expected_quorums: Vec<usize> = vec![
-        1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 14, 17, 67,
-    ];
+    let expected_quorums: Vec<usize> = vec![1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 14, 17, 67];
 
     let make_guardian_set = |n: usize| -> GuardianSetInfo {
         let mut addresses = Vec::with_capacity(n);
         for _ in 0..n {
-            addresses.push(
-                GuardianAddress {
-                    bytes: Vec::new().into(),
-                }
-            );
+            addresses.push(GuardianAddress {
+                bytes: Vec::new().into(),
+            });
         }
         GuardianSetInfo {
             addresses,
@@ -48,38 +42,52 @@ fn deserialize_round_1() -> StdResult<()> {
     assert_eq!(parsed.version, version, "parsed.version != expected");
 
     let guardian_set_index = 9u32;
-    assert_eq!(parsed.guardian_set_index, guardian_set_index, "parsed.guardian_set_index != expected");
+    assert_eq!(
+        parsed.guardian_set_index, guardian_set_index,
+        "parsed.guardian_set_index != expected"
+    );
 
     let timestamp = 2837u32;
     assert_eq!(parsed.timestamp, timestamp, "parsed.timestamp != expected");
 
     let nonce = 5u32;
     assert_eq!(parsed.nonce, nonce, "parsed.nonce != expected");
-    
+
     let len_signers = 1u8;
-    assert_eq!(parsed.len_signers, len_signers, "parsed.len_signers != expected");
-    
+    assert_eq!(
+        parsed.len_signers, len_signers,
+        "parsed.len_signers != expected"
+    );
+
     let emitter_chain = 2u16;
-    assert_eq!(parsed.emitter_chain, emitter_chain, "parsed.emitter_chain != expected");
+    assert_eq!(
+        parsed.emitter_chain, emitter_chain,
+        "parsed.emitter_chain != expected"
+    );
 
     let emitter_address = "0001020304000000000000000000000000000000000000000000000000000000";
     let emitter_address = hex::decode(emitter_address).unwrap();
-    assert_eq!(parsed.emitter_address, emitter_address, "parsed.emitter_address != expected");
+    assert_eq!(
+        parsed.emitter_address, emitter_address,
+        "parsed.emitter_address != expected"
+    );
 
     let sequence = 10u64;
     assert_eq!(parsed.sequence, sequence, "parsed.sequence != expected");
 
     let consistency_level = 2u8;
-    assert_eq!(parsed.consistency_level, consistency_level, "parsed.consistency_level != expected");
+    assert_eq!(
+        parsed.consistency_level, consistency_level,
+        "parsed.consistency_level != expected"
+    );
 
     let payload = vec![97u8, 98u8, 99u8, 100u8];
     assert_eq!(parsed.payload, payload, "parsed.payload != expected");
 
     let hash = vec![
-        164u8,  44u8,  82u8, 103u8,  33u8, 170u8, 183u8, 178u8,
-        188u8, 204u8,  35u8,  53u8,  78u8, 148u8, 160u8, 153u8,
-        122u8, 252u8,  84u8, 211u8,  26u8, 204u8, 128u8, 215u8,
-         37u8, 232u8, 222u8, 186u8, 222u8, 186u8,  98u8,  94u8,
+        164u8, 44u8, 82u8, 103u8, 33u8, 170u8, 183u8, 178u8, 188u8, 204u8, 35u8, 53u8, 78u8, 148u8,
+        160u8, 153u8, 122u8, 252u8, 84u8, 211u8, 26u8, 204u8, 128u8, 215u8, 37u8, 232u8, 222u8,
+        186u8, 222u8, 186u8, 98u8, 94u8,
     ];
     assert_eq!(parsed.hash, hash, "parsed.hash != expected");
 
@@ -105,58 +113,63 @@ fn deserialize_round_2() -> StdResult<()> {
     assert_eq!(parsed.version, version, "parsed.version != expected");
 
     let guardian_set_index = 0u32;
-    assert_eq!(parsed.guardian_set_index, guardian_set_index, "parsed.guardian_set_index != expected");
+    assert_eq!(
+        parsed.guardian_set_index, guardian_set_index,
+        "parsed.guardian_set_index != expected"
+    );
 
     let timestamp = 0u32;
     assert_eq!(parsed.timestamp, timestamp, "parsed.timestamp != expected");
 
     let nonce = 0u32;
     assert_eq!(parsed.nonce, nonce, "parsed.nonce != expected");
-    
+
     let len_signers = 1u8;
-    assert_eq!(parsed.len_signers, len_signers, "parsed.len_signers != expected");
-    
+    assert_eq!(
+        parsed.len_signers, len_signers,
+        "parsed.len_signers != expected"
+    );
+
     let emitter_chain = 1u16;
-    assert_eq!(parsed.emitter_chain, emitter_chain, "parsed.emitter_chain != expected");
+    assert_eq!(
+        parsed.emitter_chain, emitter_chain,
+        "parsed.emitter_chain != expected"
+    );
 
     let emitter_address = "000000000000000000000000000000000000000000000000000000000000ffff";
     let emitter_address = hex::decode(emitter_address).unwrap();
-    assert_eq!(parsed.emitter_address, emitter_address, "parsed.emitter_address != expected");
-    
+    assert_eq!(
+        parsed.emitter_address, emitter_address,
+        "parsed.emitter_address != expected"
+    );
+
     let sequence = 0u64;
     assert_eq!(parsed.sequence, sequence, "parsed.sequence != expected");
 
     let consistency_level = 0u8;
-    assert_eq!(parsed.consistency_level, consistency_level, "parsed.consistency_level != expected");
+    assert_eq!(
+        parsed.consistency_level, consistency_level,
+        "parsed.consistency_level != expected"
+    );
 
     let payload = vec![
-          1u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   5u8, 245u8, 225u8,
-          0u8,   1u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8, 117u8, 117u8, 115u8,
-        100u8,   0u8,   3u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8, 247u8,
-        247u8, 221u8, 232u8,  72u8, 231u8,  69u8,  10u8,   2u8,
-        156u8, 208u8, 169u8, 189u8, 155u8, 218u8, 228u8, 181u8,
-         20u8, 125u8, 179u8,   0u8,   3u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,   0u8,
-          0u8,   0u8,  15u8,  66u8,  64u8,
+        1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
+        0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 5u8, 245u8, 225u8, 0u8, 1u8, 0u8,
+        0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
+        0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 117u8, 117u8, 115u8, 100u8, 0u8, 3u8, 0u8, 0u8,
+        0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 247u8, 247u8, 221u8, 232u8, 72u8, 231u8,
+        69u8, 10u8, 2u8, 156u8, 208u8, 169u8, 189u8, 155u8, 218u8, 228u8, 181u8, 20u8, 125u8,
+        179u8, 0u8, 3u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
+        0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 15u8, 66u8, 64u8,
     ];
     assert_eq!(parsed.payload, payload, "parsed.payload != expected");
 
     let hash = vec![
-        114u8, 108u8, 111u8,  78u8, 204u8,  83u8, 150u8, 170u8,
-        240u8,  15u8, 193u8, 176u8, 165u8,  87u8, 174u8, 230u8,
-         94u8, 222u8, 106u8, 206u8, 179u8, 203u8, 193u8, 187u8,
-          1u8, 148u8,  17u8,  40u8, 248u8, 214u8, 147u8,  68u8,
+        114u8, 108u8, 111u8, 78u8, 204u8, 83u8, 150u8, 170u8, 240u8, 15u8, 193u8, 176u8, 165u8,
+        87u8, 174u8, 230u8, 94u8, 222u8, 106u8, 206u8, 179u8, 203u8, 193u8, 187u8, 1u8, 148u8,
+        17u8, 40u8, 248u8, 214u8, 147u8, 68u8,
     ];
     assert_eq!(parsed.hash, hash, "parsed.hash != expected");
 
     Ok(())
-}
+}

+ 3 - 18
cosmwasm/contracts/wormhole/tests/integration.rs

@@ -1,29 +1,14 @@
 use cosmwasm_std::{
     from_slice,
-    testing::{
-        mock_dependencies,
-        mock_env,
-        mock_info,
-        MockApi,
-        MockQuerier,
-        MockStorage,
-    },
-    Coin,
-    OwnedDeps,
-    Response,
-    Storage,
+    testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage},
+    Coin, OwnedDeps, Response, Storage,
 };
 use cosmwasm_storage::to_length_prefixed;
 
 use wormhole::{
     contract::instantiate,
     msg::InstantiateMsg,
-    state::{
-        ConfigInfo,
-        GuardianAddress,
-        GuardianSetInfo,
-        CONFIG_KEY,
-    },
+    state::{ConfigInfo, GuardianAddress, GuardianSetInfo, CONFIG_KEY},
 };
 
 use hex;

+ 5 - 3
cosmwasm/rustfmt.toml

@@ -1,11 +1,13 @@
+# Unstable options are commented out below. We should re-enable them once they are stabilized.
+
 # Merge similar crates together to avoid multiple use statements.
-imports_granularity = "Crate"
+# imports_granularity = "Crate"
 
 # Consistency in formatting makes tool based searching/editing better.
-empty_item_single_line = false
+# empty_item_single_line = false
 
 # Easier editing when arbitrary mixed use statements do not collapse.
-imports_layout = "Vertical"
+# imports_layout = "Vertical"
 
 # Default rustfmt formatting of match arms with branches is awful.
 match_arm_leading_pipes = "Preserve"