Skip to content

Commit

Permalink
make cargo test compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthamastro committed Jan 25, 2024
1 parent 0a89e49 commit 31f6869
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion check-all-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ cargo build --features try-runtime || exit
cargo build --features runtime-benchmarks || exit
./target/debug/polkadex-node benchmark pallet --pallet "*" --extrinsic "*" --steps 2 --repeat 1 || exit
cargo clippy -- -D warnings || exit
cargo test || exit
RUSTFLAGS="-D warnings" cargo test || exit
4 changes: 3 additions & 1 deletion pallets/liquidity-mining/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pallet-balances = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
sp-application-crypto = { workspace = true }
sp-io = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }

[features]
default = [ "std" ]
Expand All @@ -52,7 +53,8 @@ std = [
"pallet-timestamp/std",
"sp-io/std",
"sp-application-crypto/std",
"sp-io/std"
"sp-io/std",
"sp-core/std"
]
runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
Expand Down
1 change: 0 additions & 1 deletion pallets/liquidity-mining/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

//! Tests for pallet-ocex
use crate::*;
use frame_support::{
pallet_prelude::Weight,
parameter_types,
Expand Down
39 changes: 12 additions & 27 deletions pallets/liquidity-mining/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
//! Tests for pallet-lmp.
use crate::mock::*;
use frame_support::{assert_noop, assert_ok, testing_prelude::bounded_vec};
use frame_system::EventRecord;
use frame_support::{assert_noop, assert_ok};
use orderbook_primitives::{constants::UNIT_BALANCE, types::TradingPair};
use polkadex_primitives::AssetId;
use sp_core::crypto::AccountId32;
use std::{collections::BTreeMap, ops::DivAssign, process::exit};
use std::{collections::BTreeMap, ops::DivAssign};

#[test]
fn test_register_pool_happy_path() {
Expand Down Expand Up @@ -95,7 +94,7 @@ fn test_register_pool_error_unknown_pool() {
})
}

use crate::pallet::{Pools, SnapshotFlag};
use crate::pallet::{Pools};
use frame_support::traits::fungibles::Inspect;
use rust_decimal::{prelude::FromPrimitive, Decimal};

Expand Down Expand Up @@ -129,16 +128,16 @@ fn test_register_pool_error_register_pool_fails() {
),
pallet_ocex_lmp::pallet::Error::<Test>::ProxyAlreadyRegistered
);
let (pool, share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
let (_pool, share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
// Check if Asset is registered or not
assert!(!Assets::asset_exists(share_id)); //Verify this with @gautham
})
}
use frame_support::traits::{
fungible::Mutate,
fungibles::{Create, Mutate as MutateNonNative},
fungibles::{ Mutate as MutateNonNative},
};
use log::log;

use pallet_ocex_lmp::pallet::PriceOracle;
use sp_runtime::{traits::One, ArithmeticError::Underflow};
#[test]
Expand All @@ -157,7 +156,6 @@ fn test_add_liquidity_happy_path() {
let mut price = Decimal::from_u128(UNIT_BALANCE * 5).unwrap();
price.div_assign(Decimal::from(UNIT_BALANCE));
let tick = Decimal::from_u128(UNIT_BALANCE * 1).unwrap();
let trading_account = AccountId32::new([1; 32]);
let market_maker = AccountId32::new([2; 32]);
let user_who_wants_to_add_liq = AccountId32::new([3; 32]);
let mut map = BTreeMap::new();
Expand Down Expand Up @@ -309,7 +307,7 @@ fn test_remove_liquidity_happy_path_and_error() {
market_maker.clone(),
UNIT_BALANCE * 6
));
let (pool, share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
let (_pool, share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
// * Check shares of user
assert_eq!(Assets::balance(share_id, &user_who_wants_to_add_liq), 0);
assert_noop!(
Expand Down Expand Up @@ -411,7 +409,7 @@ fn test_claim_rewards_by_lp_happy_path_and_error() {
let reward_account =
<crate::mock::Test as pallet_ocex_lmp::Config>::LMPRewardsPalletId::get()
.into_account_truncating();
Balances::mint_into(&reward_account, 300 * UNIT_BALANCE);
Balances::mint_into(&reward_account, 300 * UNIT_BALANCE).unwrap();
let market_maker = AccountId32::new([2; 32]);
let trader = AccountId32::new([1; 32]);
let mut score_map: BTreeMap<AccountId32, (u128, bool)> = BTreeMap::new();
Expand Down Expand Up @@ -457,7 +455,7 @@ fn test_claim_rewards_by_mm_happy_path_and_error() {
let reward_account =
<crate::mock::Test as pallet_ocex_lmp::Config>::LMPRewardsPalletId::get()
.into_account_truncating();
Balances::mint_into(&reward_account, 300 * UNIT_BALANCE);
Balances::mint_into(&reward_account, 300 * UNIT_BALANCE).unwrap();
let market_maker = AccountId32::new([2; 32]);
let trader = AccountId32::new([1; 32]);
let mut score_map: BTreeMap<AccountId32, (u128, bool)> = BTreeMap::new();
Expand Down Expand Up @@ -505,7 +503,7 @@ fn test_initiate_withdrawal() {
let epoch = 1;
let num_of_request = 1;
let market_maker = AccountId32::new([2; 32]);
let (pool, share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
let (pool, _share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
let trader = AccountId32::new([1; 32]);
let asset1 = 10 * UNIT_BALANCE;
let asset2 = 10 * UNIT_BALANCE;
Expand Down Expand Up @@ -583,7 +581,6 @@ fn add_liquidity() {
let mut price = Decimal::from_u128(UNIT_BALANCE * 5).unwrap();
price.div_assign(Decimal::from(UNIT_BALANCE));
let tick = Decimal::from_u128(UNIT_BALANCE * 1).unwrap();
let trading_account = AccountId32::new([1; 32]);
let market_maker = AccountId32::new([2; 32]);
let user_who_wants_to_add_liq = AccountId32::new([3; 32]);
let mut map = BTreeMap::new();
Expand All @@ -598,7 +595,6 @@ fn add_liquidity() {
UNIT_BALANCE * 6,
UNIT_BALANCE * 40
));
let (pool, share_id) = LiqudityMining::create_pool_account(&market_maker, trading_pair);
let share_issued = Decimal::from(6);
let price = Decimal::from(5);
let total_inventory_in_quote = Decimal::from(40);
Expand All @@ -614,27 +610,16 @@ fn add_liquidity() {

fn mint_base_quote_asset_for_user(user: AccountId32) {
let quote_asset = AssetId::Asset(1);
Balances::mint_into(&user, UNIT_BALANCE * 100);
Balances::mint_into(&user, UNIT_BALANCE * 100).unwrap();
Assets::create(
RuntimeOrigin::signed(user.clone()),
parity_scale_codec::Compact(quote_asset.asset_id().unwrap()),
AccountId32::new([1; 32]),
One::one(),
);
).unwrap();
assert_ok!(Assets::mint_into(quote_asset.asset_id().unwrap(), &user, UNIT_BALANCE * 100));
}

fn crete_base_and_quote_asset() {
let quote_asset = AssetId::Asset(1);
Balances::mint_into(&AccountId32::new([1; 32]), UNIT_BALANCE);
assert_ok!(Assets::create(
RuntimeOrigin::signed(AccountId32::new([1; 32])),
parity_scale_codec::Compact(quote_asset.asset_id().unwrap()),
AccountId32::new([1; 32]),
One::one()
));
}

fn register_test_pool(public_fund_allowed: bool) {
let name = [1; 10];
let base_asset = AssetId::Polkadex;
Expand Down
12 changes: 6 additions & 6 deletions pallets/ocex/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::{storage::store_trie_root, *};
use frame_support::{assert_noop, assert_ok};
use polkadex_primitives::{assets::AssetId, withdrawal::Withdrawal, Signature, UNIT_BALANCE};
use rust_decimal::prelude::{FromPrimitive, ToPrimitive, Zero};
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
use sp_std::collections::btree_map::BTreeMap;
use std::str::FromStr;
// The testing primitives are very useful for avoiding having to work with signatures
Expand Down Expand Up @@ -2325,7 +2325,7 @@ use orderbook_primitives::{
};
use sp_runtime::traits::{BlockNumberProvider, One};

use orderbook_primitives::types::{UserActionBatch, UserActions};
use orderbook_primitives::types::{UserActionBatch};
use trie_db::TrieMut;

#[test]
Expand Down Expand Up @@ -2671,7 +2671,7 @@ fn test_set_lmp_epoch_config_invalid_market_weightage() {
}

#[test]
fn test_set_lmp_epoch_config_invalid_invalid_LMPConfig() {
fn test_set_lmp_epoch_config_invalid_invalid_lmpconfig() {
new_test_ext().execute_with(|| {
let total_liquidity_mining_rewards: Option<u128> = Some(1000 * UNIT_BALANCE);
let total_trading_rewards: Option<u128> = Some(1000 * UNIT_BALANCE);
Expand Down Expand Up @@ -2766,7 +2766,7 @@ fn test_do_claim_lmp_rewards_happy_path() {
let trading_pair = TradingPair { base: base_asset, quote: quote_asset };
let reward_account =
<mock::Test as pallet::Config>::LMPRewardsPalletId::get().into_account_truncating();
Balances::mint_into(&reward_account, 300 * UNIT_BALANCE);
Balances::mint_into(&reward_account, 300 * UNIT_BALANCE).unwrap();
assert_ok!(OCEX::do_claim_lmp_rewards(main_account.clone(), epoch, trading_pair));
assert_eq!(Balances::free_balance(&main_account), 200999999999900u128);
})
Expand Down Expand Up @@ -2822,11 +2822,11 @@ pub fn add_lmp_config() {
OCEX::start_new_epoch();
}

use frame_support::traits::{fungible::Mutate, fungibles::Create};
use frame_support::traits::{fungible::Mutate};

fn crete_base_and_quote_asset() {
let quote_asset = AssetId::Asset(1);
Balances::mint_into(&AccountId32::new([1; 32]), UNIT_BALANCE);
Balances::mint_into(&AccountId32::new([1; 32]), UNIT_BALANCE).unwrap();
assert_ok!(Assets::create(
RuntimeOrigin::signed(AccountId32::new([1; 32])),
parity_scale_codec::Compact(quote_asset.asset_id().unwrap()),
Expand Down

0 comments on commit 31f6869

Please sign in to comment.