Skip to content

Commit

Permalink
feat: add extra method for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hoomp3 committed Jan 29, 2024
1 parent cd971bc commit 2bff8e6
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 67 deletions.
4 changes: 1 addition & 3 deletions contracts/oracle_router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use cosmwasm_std::{
};
use shade_oracles::{
core::{
validate_admin, AdminPermissions,
pad_execute_result, pad_query_result,
ssp::ItemStorage,
pad_execute_result, pad_query_result, ssp::ItemStorage, validate_admin, AdminPermissions,
Contract,
},
create_attr_action,
Expand Down
7 changes: 2 additions & 5 deletions contracts/shadeswap_spot_oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ use shade_oracles::interfaces::common::config::{CommonConfig, CommonConfigRespon
use shade_oracles::interfaces::common::{OraclePrice, PriceResponse, PricesResponse};
use shade_oracles::protocols::shadeswap::ShadeSwapQuerier;
use shade_oracles::{
common::querier::{query_prices as query_router_prices},
core::pad_query_result,
interfaces::dex::generic::*,
ssp::ItemStorage,
BLOCK_SIZE,
common::querier::query_prices as query_router_prices, core::pad_query_result,
interfaces::dex::generic::*, ssp::ItemStorage, BLOCK_SIZE,
};
use snip20::helpers::query_token_info;

Expand Down
7 changes: 2 additions & 5 deletions contracts/siennaswap_reserves_oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ use shade_oracles::interfaces::common::config::{CommonConfig, CommonConfigRespon
use shade_oracles::interfaces::common::{OraclePrice, PriceResponse, PricesResponse};
use shade_oracles::protocols::siennaswap::SiennaSwapQuerier;
use shade_oracles::{
common::querier::{query_prices as query_router_prices},
core::pad_query_result,
interfaces::dex::generic::*,
ssp::ItemStorage,
BLOCK_SIZE,
common::querier::query_prices as query_router_prices, core::pad_query_result,
interfaces::dex::generic::*, ssp::ItemStorage, BLOCK_SIZE,
};
use snip20::helpers::query_token_info;

Expand Down
7 changes: 2 additions & 5 deletions contracts/siennaswap_spot_oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ use shade_oracles::interfaces::common::config::{CommonConfig, CommonConfigRespon
use shade_oracles::interfaces::common::{OraclePrice, PriceResponse, PricesResponse};
use shade_oracles::protocols::siennaswap::SiennaSwapQuerier;
use shade_oracles::{
common::querier::{query_prices as query_router_prices},
core::pad_query_result,
interfaces::dex::generic::*,
ssp::ItemStorage,
BLOCK_SIZE,
common::querier::query_prices as query_router_prices, core::pad_query_result,
interfaces::dex::generic::*, ssp::ItemStorage, BLOCK_SIZE,
};
use snip20::helpers::query_token_info;

Expand Down
8 changes: 5 additions & 3 deletions contracts/testnet_snip20_faucet/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use cosmwasm_schema::cw_serde;
use cosmwasm_std::{entry_point, Addr, StdError, Uint128};
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use secret_storage_plus::{Item, Map};
use shade_toolkit::{ExecuteCallback, Query, pad_query_result, pad_execute_result, BLOCK_SIZE, RawContract, Contract};
use snip20::helpers::{query_token_info};
use snip20::msg::{QueryAnswer, ExecuteMsg as Snip20ExecuteMsg, QueryMsg as Snip20QueryMsg};
use shade_toolkit::{
pad_execute_result, pad_query_result, Contract, ExecuteCallback, Query, RawContract, BLOCK_SIZE,
};
use snip20::helpers::query_token_info;
use snip20::msg::{ExecuteMsg as Snip20ExecuteMsg, QueryAnswer, QueryMsg as Snip20QueryMsg};

#[cw_serde]
pub struct InstantiateMsg {
Expand Down
2 changes: 1 addition & 1 deletion packages/mocks/src/shade_stkd_scrt/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use shade_oracles::{
protocols::shade_staking_derivatives::{StakingDerivativeQueryMsg, StakingInfoResponse},
ssp::Item,
};
use snip20::helpers::{TokenInfo};
use snip20::helpers::TokenInfo;
use snip20::msg::QueryAnswer;

#[cw_serde]
Expand Down
5 changes: 4 additions & 1 deletion packages/multi_helpers/src/helpers/admin_auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use shade_toolkit::{implement_harness, interfaces::admin_auth::{InstantiateMsg, RegistryAction, ExecuteMsg}};
use super::*;
use shade_toolkit::{
implement_harness,
interfaces::admin_auth::{ExecuteMsg, InstantiateMsg, RegistryAction},
};

implement_harness!(Admin, admin);
create_test_helper!(AdminAuthHelper);
Expand Down
17 changes: 16 additions & 1 deletion packages/multi_helpers/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::*;
use cosmwasm_std::{Addr, StdError};
use serde::de::DeserializeOwned;
use shade_toolkit::{
multi::{nanoid::nanoid, AnyResult, MultiTestable, Tester},
multi_test::{App, AppResponse},
multi::{MultiTestable, AnyResult, Tester},
};
use std::{
fmt::{Debug, Display},
Expand All @@ -16,6 +16,15 @@ pub mod snip20;

pub type AppResult = AnyResult<AppResponse>;

/// Alphabet used by nanoid for generating addresses. Has the characters '-' and '_' removed and upper case characters so that generated address is normalized.
/// Very low probability of collisions - https://alex7kom.github.io/nano-nanoid-cc.
/// Using address length of 40.
pub const SAFE_NANOID: [char; 36] = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
];
pub const SAFE_NANOID_LENGTH: usize = 40;

pub struct Asserter;

impl Asserter {
Expand Down Expand Up @@ -84,6 +93,12 @@ impl User {
pub fn str(&self) -> String {
self.address.to_string()
}
pub fn gen() -> User {
User::new(format!(
"secret{}",
nanoid!(SAFE_NANOID_LENGTH, &SAFE_NANOID)
))
}
}

impl From<Addr> for User {
Expand Down
5 changes: 4 additions & 1 deletion packages/multi_helpers/src/helpers/query_auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use shade_toolkit::{implement_harness, interfaces::query_auth::{InstantiateMsg, ExecuteMsg}};
use shade_toolkit::{
implement_harness,
interfaces::query_auth::{ExecuteMsg, InstantiateMsg},
};

use super::*;
use ::query_auth as query_auth_crate;
Expand Down
4 changes: 2 additions & 2 deletions packages/multi_helpers/src/helpers/snip20.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::*;
use ::snip20;
use ::snip20::{helpers::TokenInfo, msg::*};
use cosmwasm_std::from_binary;
use shade_oracles::{
asset::{Asset, RawAsset},
better_secret_math::U256,
};
use shade_toolkit::implement_harness;
use ::snip20::{helpers::TokenInfo, msg::*};
use ::snip20 as snip20;

implement_harness!(Snip20, snip20);
create_test_helper!(Snip20Helper);
Expand Down
2 changes: 1 addition & 1 deletion packages/multi_test/src/helpers/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use multi_test_helpers::admin_auth::AdminAuthHelper;
use shade_oracles::interfaces::providers::mock::{BandExecuteMsg, BandMockPrice, MockPrice};
use shade_oracles::interfaces::providers::{self, Provider, RawProvider};
use shade_toolkit::multi::Tester;
use shade_toolkit::{multi_test::App, multi::AnyResult, Contract};
use shade_toolkit::{multi::AnyResult, multi_test::App, Contract};

create_test_helper!(MockProviderHelper);
impl MockProviderHelper {
Expand Down
4 changes: 1 addition & 3 deletions packages/multi_test/src/helpers/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ impl OracleRouterHelper {
mod test {
use super::*;
use multi_test_helpers::Asserter;
use shade_oracles::{
unit_test_interface::prices::PricesFixture,
};
use shade_oracles::unit_test_interface::prices::PricesFixture;
use shade_toolkit::interfaces::admin_auth::AdminPermissions;

/// Tests set protection, remove key protection, update protection, query protected keys.
Expand Down
6 changes: 3 additions & 3 deletions packages/multi_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use shade_oracles::{
use shade_toolkit::multi_test::{App, AppResponse};

use shade_toolkit::{
multi::{AnyResult, MultiTestable, Tester},
{
{Contract, RawContract}, Query,
Query, {Contract, RawContract},
},
multi::{MultiTestable, AnyResult, Tester},
};
};
use std::collections::HashMap;
7 changes: 2 additions & 5 deletions packages/shade_oracles/src/common/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ use better_secret_math::U256;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Api, CosmosMsg, QuerierWrapper, StdError, StdResult, Storage, Uint256};
use secret_storage_plus::Map;
use snip20::{
helpers::query_token_info,
msg::ExecuteMsg as Snip20ExecuteMsg
};
use shade_toolkit::{Contract, InstantiateCallback, ExecuteCallback, RawContract};
use shade_toolkit::{Contract, ExecuteCallback, InstantiateCallback, RawContract};
use snip20::{helpers::query_token_info, msg::ExecuteMsg as Snip20ExecuteMsg};

#[derive(Eq)]
#[cw_serde]
Expand Down
12 changes: 6 additions & 6 deletions packages/shade_oracles/src/common/querier.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{interfaces::{
use crate::interfaces::{
common::{OracleQuery, PriceResponse, PricesResponse},
router::msg::{ConfigResponse as RouterConfigResponse, QueryMsg as RouterQueryMsg},
}};
};
use cosmwasm_std::{QuerierWrapper, StdError, StdResult};
use shade_toolkit::{Contract, Query, interfaces::admin_auth::{
AdminPermissions,
validate_admin,
}};
use shade_toolkit::{
interfaces::admin_auth::{validate_admin, AdminPermissions},
Contract, Query,
};

pub fn query_price(
oracle: &Contract,
Expand Down
6 changes: 3 additions & 3 deletions packages/shade_oracles/src/interfaces/common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ pub use state::*;
mod state {
use std::collections::HashSet;

use secret_borsh_storage::BorshItem;
use shade_toolkit::interfaces::admin_auth::{ValidateAdminPermissionResponse, QueryMsg};
use super::*;
use crate::{
error::CommonOracleError,
interfaces::router::msg::{
ConfigResponse as RouterConfigResponse, QueryMsg as RouterQueryMsg,
},
querier::{query_price, require_admin, require_admin_or_bot, require_bot},
};
use super::*;
use secret_borsh_storage::BorshItem;
use shade_toolkit::interfaces::admin_auth::{QueryMsg, ValidateAdminPermissionResponse};

impl CommonConfig {
pub const SUPPORTED_KEYS: BorshItem<'static, HashSet<String>> =
Expand Down
2 changes: 1 addition & 1 deletion packages/shade_oracles/src/interfaces/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::cmp::min;

use super::*;
use crate::BLOCK_SIZE;
use better_secret_math::U256;
use better_secret_math::traits::PriceMath;
use better_secret_math::U256;
use shade_toolkit::Query;

pub mod config;
Expand Down
2 changes: 1 addition & 1 deletion packages/shade_oracles/src/interfaces/dex/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::interfaces::common::{PriceResponse, PricesResponse};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Addr;
use secret_storage_plus::{Item, ItemStorage, Map};
use shade_toolkit::{RawContract, Contract};
use shade_toolkit::{Contract, RawContract};

pub mod msg {

Expand Down
2 changes: 1 addition & 1 deletion packages/shade_oracles/src/interfaces/index/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Decimal256, Uint256, Uint64};
use shade_toolkit::{RawContract, Contract};
use shade_toolkit::{Contract, RawContract};

use super::{AssetSymbol, AssetWeights, Peg};

Expand Down
4 changes: 1 addition & 3 deletions packages/shade_oracles/src/interfaces/providers/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::*;
use shade_toolkit::interfaces::admin_auth::{
AdminPermissions, validate_admin
};
use shade_toolkit::interfaces::admin_auth::{validate_admin, AdminPermissions};

#[cw_serde]
pub struct BandInstantiateMsg {
Expand Down
3 changes: 1 addition & 2 deletions packages/shade_oracles/src/interfaces/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Api, QuerierWrapper, Timestamp, Uint128, Uint256, Uint64};
use cosmwasm_std::{StdError, StdResult};
use shade_toolkit::{
{ExecuteCallback, InstantiateCallback, Query},
Contract, RawContract, ResponseStatus
Contract, RawContract, ResponseStatus, {ExecuteCallback, InstantiateCallback, Query},
};

use self::mock::ConfigResponse;
Expand Down
2 changes: 1 addition & 1 deletion packages/shade_oracles/src/interfaces/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod querier {
use super::msg::ConfigResponse;
use super::msg::*;
use cosmwasm_std::{QuerierWrapper, StdResult};
use shade_toolkit::{Query, Contract};
use shade_toolkit::{Contract, Query};

pub fn get_admin_auth(
router: &Contract,
Expand Down
2 changes: 1 addition & 1 deletion packages/shade_oracles/src/interfaces/router/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Uint256;
use shade_toolkit::{RawContract, Contract};
use shade_toolkit::{Contract, RawContract};

use super::registry::ProtectedKeyInfo;

Expand Down
15 changes: 6 additions & 9 deletions packages/shade_oracles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use cosmwasm_std::{
Addr, Api, MessageInfo, QuerierWrapper, StdError, StdResult, Storage, Timestamp, Uint128,
Uint256,
};
use shade_toolkit::{
Contract, RawContract,
Query,
};
use shade_toolkit::{Contract, Query, RawContract};

pub mod unit_test_interface;

Expand All @@ -25,15 +22,15 @@ pub mod storage {
}
#[cfg(feature = "core")]
pub mod core {
pub use shade_toolkit::{
BLOCK_SIZE, Contract, RawContract, ResponseStatus, pad_execute_result, pad_query_result,
Query, ExecuteCallback, InstantiateCallback,
interfaces::admin_auth::{validate_admin, AdminPermissions}
};
pub use better_secret_math;
pub use schemars;
pub use secret_storage_plus as ssp;
pub use serde;
pub use shade_toolkit::{
interfaces::admin_auth::{validate_admin, AdminPermissions},
pad_execute_result, pad_query_result, Contract, ExecuteCallback, InstantiateCallback,
Query, RawContract, ResponseStatus, BLOCK_SIZE,
};
pub use thiserror;
}

Expand Down

0 comments on commit 2bff8e6

Please sign in to comment.