From a2a5d4e44d3a0f4d1314c1fdab339966d7679d7b Mon Sep 17 00:00:00 2001 From: _dssei_ Date: Mon, 8 Apr 2024 12:10:14 -0700 Subject: [PATCH] formatting --- contracts/sei-tester/src/contract.rs | 11 +++- .../tests/sei_tester_integration_tests.rs | 13 +++-- packages/sei-cosmwasm/src/querier.rs | 22 +++++--- packages/sei-cosmwasm/src/query.rs | 3 +- packages/sei-integration-tests/src/helper.rs | 35 ++++++------ packages/sei-integration-tests/src/module.rs | 53 +++++++++++-------- 6 files changed, 88 insertions(+), 49 deletions(-) diff --git a/contracts/sei-tester/src/contract.rs b/contracts/sei-tester/src/contract.rs index 99181d4..3c8edef 100644 --- a/contracts/sei-tester/src/contract.rs +++ b/contracts/sei-tester/src/contract.rs @@ -11,9 +11,16 @@ use crate::{ state::{PARALLEL_VALS, USER_SUMS, VALUES}, types::{OrderData, PositionEffect}, }; -use protobuf::Message; -use sei_cosmwasm::{BulkOrderPlacementsResponse, Cancellation, DenomAuthorityMetadataResponse, DenomUnit, DenomsFromCreatorResponse, DepositInfo, DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse, Metadata, MsgPlaceOrdersResponse, OracleTwapsResponse, Order, OrderSimulationResponse, OrderType, PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry, SudoMsg, EvmAddressResponse, SeiAddressResponse}; use ethaddr::Address; +use protobuf::Message; +use sei_cosmwasm::{BulkOrderPlacementsResponse, Cancellation, DenomAuthorityMetadataResponse, + DenomUnit, DenomsFromCreatorResponse, DepositInfo, DexTwapsResponse, + EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse, + GetOrderByIdResponse, GetOrdersResponse, Metadata, MsgPlaceOrdersResponse, + OracleTwapsResponse, Order, OrderSimulationResponse, OrderType, + PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry, + SudoMsg, EvmAddressResponse, SeiAddressResponse}; + const PLACE_ORDER_REPLY_ID: u64 = 1; // version info for migration info diff --git a/contracts/sei-tester/tests/sei_tester_integration_tests.rs b/contracts/sei-tester/tests/sei_tester_integration_tests.rs index afe9c18..07d342c 100644 --- a/contracts/sei-tester/tests/sei_tester_integration_tests.rs +++ b/contracts/sei-tester/tests/sei_tester_integration_tests.rs @@ -1,11 +1,17 @@ -use cosmwasm_std::{Addr, Api, BalanceResponse, coin, Coin, CosmosMsg, Decimal, Empty, from_json, GovMsg, IbcMsg, IbcQuery, QueryRequest, StdError, Storage, testing::{MockApi, MockStorage}, Uint128}; +use cosmwasm_std::{Addr, Api, BalanceResponse, coin, Coin, CosmosMsg, Decimal, Empty, from_json, + GovMsg, IbcMsg, IbcQuery, QueryRequest, StdError, Storage, + testing::{MockApi, MockStorage}, Uint128}; use cosmwasm_std::{BlockInfo, Uint64}; use cw_multi_test::{ App, BankKeeper, ContractWrapper, DistributionKeeper, Executor, FailingModule, Router, StakeKeeper, WasmKeeper, }; -use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order, OrderSimulationResponse, OrderStatus, OrderType, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute}; +use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, + EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, + GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order, + OrderSimulationResponse, OrderStatus, OrderType, PositionDirection, + SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute}; use sei_integration_tests::{ helper::{get_balance, mock_app}, module::{SeiModule, EVM_ADDRESS, SEI_ADDRESS}, @@ -1003,5 +1009,6 @@ fn test_sei_address_query() { let err = res.expect_err("Expected an error because the EVM address is invalid"); assert_eq!(err.to_string(), - "Generic error: Querier contract error: Generic error: Failed to parse Ethereum address"); + "Generic error: Querier contract error: Generic error: Failed to parse Ethereum \ + address"); } \ No newline at end of file diff --git a/packages/sei-cosmwasm/src/querier.rs b/packages/sei-cosmwasm/src/querier.rs index 51d5ff7..8ac0dfb 100644 --- a/packages/sei-cosmwasm/src/querier.rs +++ b/packages/sei-cosmwasm/src/querier.rs @@ -1,7 +1,13 @@ use cosmwasm_std::{Addr, QuerierWrapper, StdResult, Uint128}; use cw20::{BalanceResponse, TokenInfoResponse}; -use crate::query::{DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse, EpochResponse, Erc20AllowanceResponse, Erc721ApprovedResponse, Erc721IsApprovedForAllResponse, Erc721NameSymbolResponse, Erc721OwnerResponse, Erc721UriResponse, ErcPayloadResponse, EvmAddressResponse, SeiAddressResponse, ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse, SeiQuery, SeiQueryWrapper, StaticCallResponse}; +use crate::query::{DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse, + EpochResponse, Erc20AllowanceResponse, Erc721ApprovedResponse, + Erc721IsApprovedForAllResponse, Erc721NameSymbolResponse, Erc721OwnerResponse, + Erc721UriResponse, ErcPayloadResponse, EvmAddressResponse, SeiAddressResponse, + ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, + GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse, SeiQuery, + SeiQueryWrapper, StaticCallResponse}; use crate::route::SeiRoute; use crate::Order; @@ -430,9 +436,10 @@ impl<'a> SeiQuerier<'a> { /// Queries the EVM (Ethereum Virtual Machine) address associated with a given Sei address. /// - /// This function takes a `sei_address` as a parameter, which is a `String` representing the SEI address. - /// It returns a `StdResult`, which is a standard result type in the `cosmwasm_std` library. - /// The `EvmAddressResponse` struct contains the EVM address and a boolean indicating whether the EVM address is associated. + /// This function takes a `sei_address` as a parameter, which is a `String` representing the + /// SEI address. It returns a `StdResult`, which is a standard result type + /// in the `cosmwasm_std` library. The `EvmAddressResponse` struct contains the EVM address and + /// a boolean indicating whether the EVM address is associated. /// /// # Arguments /// @@ -440,9 +447,10 @@ impl<'a> SeiQuerier<'a> { /// /// # Returns /// - /// * `StdResult` - A standard result that wraps the `EvmAddressResponse` struct. - /// `EvmAddressResponse` contains the EVM address and a boolean indicating whether the EVM address is associated. - /// If the Sei address is not associated with any EVM address, the EVM address will be an empty string. + /// * `StdResult` - A standard result that wraps the `EvmAddressResponse` + /// struct. `EvmAddressResponse` contains the EVM address and a boolean indicating whether the + /// EVM address is associated. If the Sei address is not associated with any EVM address, + /// the EVM address will be an empty string. /// /// /// # Errors diff --git a/packages/sei-cosmwasm/src/query.rs b/packages/sei-cosmwasm/src/query.rs index 9ab013e..0c81147 100644 --- a/packages/sei-cosmwasm/src/query.rs +++ b/packages/sei-cosmwasm/src/query.rs @@ -261,7 +261,8 @@ pub struct EvmAddressResponse { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct SeiAddressResponse { - /// The SEI address associated to EVM address. Empty if the EVM address is not associated with any SEI address. + /// The SEI address associated to EVM address. Empty if the EVM address is not associated with + /// any SEI address. pub sei_address: String, /// A boolean value indicating whether the SEI address is associated to EVM address. diff --git a/packages/sei-integration-tests/src/helper.rs b/packages/sei-integration-tests/src/helper.rs index f3075c3..c584155 100644 --- a/packages/sei-integration-tests/src/helper.rs +++ b/packages/sei-integration-tests/src/helper.rs @@ -1,4 +1,9 @@ -use cosmwasm_std::{testing::{MockApi, MockQuerier, MockStorage}, Api, BalanceResponse, BankQuery, BlockInfo, Empty, GovMsg, IbcMsg, IbcQuery, MemoryStorage, Storage, Timestamp, from_json}; +use cosmwasm_std::{ + from_json, + testing::{MockApi, MockQuerier, MockStorage}, + Api, BalanceResponse, BankQuery, BlockInfo, Empty, GovMsg, IbcMsg, IbcQuery, MemoryStorage, + Storage, Timestamp, +}; use cw_multi_test::{ App, AppBuilder, BankKeeper, DistributionKeeper, FailingModule, Module, Router, StakeKeeper, WasmKeeper, @@ -47,20 +52,20 @@ pub fn mock_app( FailingModule, FailingModule, > -where - F: FnOnce( - &mut Router< - BankKeeper, - SeiModule, - WasmKeeper, - StakeKeeper, - DistributionKeeper, - FailingModule, - FailingModule, - >, - &dyn Api, - &mut dyn Storage, - ), + where + F: FnOnce( + &mut Router< + BankKeeper, + SeiModule, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + FailingModule, + FailingModule, + >, + &dyn Api, + &mut dyn Storage, + ), { let appbuilder: AppBuilder< BankKeeper, diff --git a/packages/sei-integration-tests/src/module.rs b/packages/sei-integration-tests/src/module.rs index 38bd141..824b1d8 100644 --- a/packages/sei-integration-tests/src/module.rs +++ b/packages/sei-integration-tests/src/module.rs @@ -1,8 +1,19 @@ use anyhow::Result as AnyResult; -use cosmwasm_std::{Addr, Api, BankMsg, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Decimal, Querier, Storage, Uint128, Uint64, to_json_binary, from_json}; +use cosmwasm_std::{ + from_json, + to_json_binary, + Addr, Api, BankMsg, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Decimal, Querier, Storage, + Uint128, Uint64, +}; use cw_multi_test::{AppResponse, BankSudo, CosmosRouter, Module, SudoMsg}; use schemars::JsonSchema; -use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, Epoch, EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleTwap, OracleTwapsResponse, Order, OrderResponse, OrderSimulationResponse, OrderStatus, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SudoMsg as SeiSudoMsg}; +use sei_cosmwasm::{ + Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, Epoch, + EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, + GetOrdersResponse, OracleTwap, OracleTwapsResponse, Order, OrderResponse, + OrderSimulationResponse, OrderStatus, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery, + SeiQueryWrapper, SudoMsg as SeiSudoMsg +}; use serde::de::DeserializeOwned; use std::{ collections::HashMap, @@ -81,14 +92,14 @@ impl Module for SeiModule { &self, api: &dyn Api, storage: &mut dyn Storage, - router: &dyn CosmosRouter, + router: &dyn CosmosRouter, block: &BlockInfo, sender: Addr, msg: Self::ExecT, ) -> AnyResult - where - ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, - QueryC: CustomQuery + DeserializeOwned + 'static, + where + ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, + QueryC: CustomQuery + DeserializeOwned + 'static, { match msg { SeiMsg::PlaceOrders { @@ -204,13 +215,13 @@ impl Module for SeiModule { &self, _api: &dyn Api, _storage: &mut dyn Storage, - _router: &dyn CosmosRouter, + _router: &dyn CosmosRouter, _block: &BlockInfo, msg: Self::SudoT, ) -> AnyResult - where - ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, - QueryC: CustomQuery + DeserializeOwned + 'static, + where + ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, + QueryC: CustomQuery + DeserializeOwned + 'static, { match msg { SeiSudoMsg::Settlement { @@ -484,7 +495,7 @@ fn get_dex_twaps( let order_response: GetOrdersResponse = from_json( &query_get_orders_helper(storage, contract_address, Addr::unchecked("")).unwrap(), ) - .unwrap(); + .unwrap(); let mut orders = order_response.orders.clone(); orders.sort_by(|a, b| b.id.cmp(&a.id)); @@ -555,7 +566,7 @@ fn get_order_simulation( let orders: GetOrdersResponse = from_json( &query_get_orders_helper(storage, contract_address, Addr::unchecked("")).unwrap(), ) - .unwrap(); + .unwrap(); let valid_orders = if order.position_direction == PositionDirection::Long { PositionDirection::Short @@ -568,7 +579,7 @@ fn get_order_simulation( if (order_response.position_direction == PositionDirection::Long && order.price <= order_response.price) || (order_response.position_direction == PositionDirection::Short - && order.price >= order_response.price) + && order.price >= order_response.price) { executed_quantity += order_response.quantity; } @@ -698,14 +709,14 @@ fn execute_create_denom_helper( fn execute_mint_tokens_helper( api: &dyn Api, storage: &mut dyn Storage, - router: &dyn CosmosRouter, + router: &dyn CosmosRouter, block: &BlockInfo, sender: Addr, amount: Coin, ) -> AnyResult -where - ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, - QueryC: CustomQuery + DeserializeOwned + 'static, + where + ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, + QueryC: CustomQuery + DeserializeOwned + 'static, { let owner = storage.get(amount.denom.as_bytes()); if owner.is_none() || owner.unwrap() != sender.to_string().as_bytes() { @@ -728,14 +739,14 @@ where fn execute_burn_tokens_helper( api: &dyn Api, storage: &mut dyn Storage, - router: &dyn CosmosRouter, + router: &dyn CosmosRouter, block: &BlockInfo, sender: Addr, amount: Coin, ) -> AnyResult -where - ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, - QueryC: CustomQuery + DeserializeOwned + 'static, + where + ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static, + QueryC: CustomQuery + DeserializeOwned + 'static, { let owner = storage.get(amount.denom.as_bytes()); if owner.is_none() || owner.unwrap() != sender.to_string().as_bytes() {