to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult, Uint256,
create_orderbook_response_handler, create_spot_multi_market_handler, get_default_subaccount_id_for_checked_address, inj_mock_deps,
test_market_ids, HandlesMarketIdQuery, InjectiveQueryWrapper, MarketId, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket,
cosmwasm::wasm::v1::{AcceptedMessageKeysFilter, ContractExecutionAuthorization, ContractGrant, MaxCallsLimit},
use injective_test_tube::{Account, Authz, Bank, Exchange, InjectiveTestApp, Module, SigningAccount, Wasm};
create_mock_spot_market("eth", FPDecimal::must_from_str("0.001"), FPDecimal::must_from_str("0.001"), 0),
create_mock_spot_market("inj", FPDecimal::must_from_str("0.001"), FPDecimal::must_from_str("0.001"), 1),
querier.spot_market_orderbook_response_handler = create_orderbook_response_handler(orderbooks);
querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_error_multiplier_handler()
querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_ok_multiplier_handler()
create_mock_spot_market("atom", FPDecimal::must_from_str("0.001"), FPDecimal::must_from_str("10000"), 1),
querier.spot_market_orderbook_response_handler = create_orderbook_response_handler(orderbooks);
querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_error_multiplier_handler()
querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_ok_multiplier_handler()
fn create_mock_spot_market(base: &str, min_price_tick_size: FPDecimal, min_quantity_tick_size: FPDecimal, idx: u32) -> SpotMarket {
pub fn launch_realistic_inj_usdt_spot_market(exchange: &Exchange<InjectiveTestApp>, signer: &SigningAccount) -> String {
pub fn launch_realistic_weth_usdt_spot_market(exchange: &Exchange<InjectiveTestApp>, signer: &SigningAccount) -> String {
pub fn launch_realistic_atom_usdt_spot_market(exchange: &Exchange<InjectiveTestApp>, signer: &SigningAccount) -> String {
pub fn launch_realistic_usdt_usdc_spot_market(exchange: &Exchange<InjectiveTestApp>, signer: &SigningAccount) -> String {
pub fn launch_realistic_ninja_inj_spot_market(exchange: &Exchange<InjectiveTestApp>, signer: &SigningAccount) -> String {
create_realistic_limit_order(app, trader2, market_id, OrderSide::Buy, "1978", "1.23", Decimals::Eighteen, Decimals::Six);
pub fn create_realistic_inj_usdt_sell_orders_from_spreadsheet(app: &InjectiveTestApp, market_id: &str, trader1: &SigningAccount) {
create_realistic_limit_order(app, trader1, market_id, OrderSide::Sell, "8.89", "197.89", Decimals::Six, Decimals::Six);
create_realistic_limit_order(app, trader2, market_id, OrderSide::Sell, "8.93", "181.02", Decimals::Six, Decimals::Six);
create_realistic_limit_order(app, trader3, market_id, OrderSide::Sell, "8.99", "203.12", Decimals::Six, Decimals::Six);
create_realistic_limit_order(app, trader1, market_id, OrderSide::Sell, "9.01", "421.11", Decimals::Six, Decimals::Six);
pub fn create_realistic_usdt_usdc_both_side_orders(app: &InjectiveTestApp, market_id: &str, trader1: &SigningAccount) {
pub fn create_ninja_inj_both_side_orders(app: &InjectiveTestApp, market_id: &str, trader1: &SigningAccount) {
let (price_to_send, quantity_to_send) = scale_price_quantity_spot_market(price, quantity, &(base_decimals as i32), &(quote_decimals as i32));
subaccount_id: get_default_subaccount_id_for_checked_address(&Addr::unchecked(trader.address())).to_string(),
pub fn init_self_relaying_contract_and_get_address(wasm: &Wasm<InjectiveTestApp>, owner: &SigningAccount, initial_balance: &[Coin]) -> String {
let release_wasm_path = format!("{}/../../artifacts/swap_contract.wasm", env!("CARGO_MANIFEST_DIR"));
let release_wasm = std::fs::read(release_wasm_path).expect("build the optimized release artifact before running TestTube tests");
pub fn must_init_account_with_funds(app: &InjectiveTestApp, initial_funds: &[Coin]) -> SigningAccount {
let mut initial_funds_coin: Vec<Coin> = initial_funds.iter().map(|ic| ic.coin.clone()).collect();
let mut initial_funds_decimals = initial_funds.iter().map(|ic| ic.decimals).collect::<Vec<u32>>();
let account = app.init_account_decimals(&initial_funds_coin, &initial_funds_decimals).unwrap();
pub fn query_all_bank_balances(bank: &Bank<InjectiveTestApp>, address: &str) -> Vec<injective_std::types::cosmos::base::v1beta1::Coin> {
pub fn query_bank_balance(bank: &Bank<InjectiveTestApp>, denom: &str, address: &str) -> FPDecimal {
AcceptedMessageKeysFilter::encode(&AcceptedMessageKeysFilter { keys: vec![message] }, &mut filter_buf).unwrap();
use crate::testing::test_utils::{human_to_dec, human_to_proto, scale_price_quantity_spot_market, Decimals};
fn it_panics_when_converting_decimal_below_zero_with_18_decimals_with_too_high_precision_to_proto() {
let (scaled_price, scaled_quantity) = scale_price_quantity_spot_market(price, quantity, &(base_decimals as i32), &(quote_decimals as i32));
let (scaled_price, scaled_quantity) = scale_price_quantity_spot_market(price, quantity, &(base_decimals as i32), &(quote_decimals as i32));
let (scaled_price, scaled_quantity) = scale_price_quantity_spot_market(price, quantity, &(base_decimals as i32), &(quote_decimals as i32));
let (scaled_price, scaled_quantity) = scale_price_quantity_spot_market(price, quantity, &(base_decimals as i32), &(quote_decimals as i32));
pub fn are_fpdecimals_approximately_equal(first: FPDecimal, second: FPDecimal, max_diff: FPDecimal) -> bool {
pub fn assert_fee_is_as_expected(raw_fees: &mut [FPCoin], expected_fees: &mut [FPCoin], max_diff: FPDecimal) {