From b7a7144953cfc359f2171b26bd998cffb5e52ae5 Mon Sep 17 00:00:00 2001 From: Malte Kliemann Date: Sat, 20 Jan 2024 23:10:59 +0100 Subject: [PATCH] Access constant through `Config` --- zrml/prediction-markets/src/lib.rs | 3 +- .../src/tests/create_market.rs | 5 +- .../src/tests/integration.rs | 57 ++++++++++++------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index 1bc745796..73c1a1085 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -94,6 +94,7 @@ mod pallet { pub(crate) type CacheSize = ConstU32<64>; pub(crate) type EditReason = BoundedVec::MaxEditReasonLen>; pub(crate) type InitialItemOf = InitialItem, BalanceOf>; + pub(crate) type MarketBondsOf = MarketBonds, BalanceOf>; pub(crate) type MarketIdOf = ::MarketId; pub(crate) type MarketOf = Market< AccountIdOf, @@ -2923,7 +2924,7 @@ mod pallet { scoring_rule: ScoringRule, report: Option>, resolved_outcome: Option, - bonds: MarketBonds>, + bonds: MarketBondsOf, ) -> Result, DispatchError> { let valid_base_asset = match base_asset { Asset::Ztg => true, diff --git a/zrml/prediction-markets/src/tests/create_market.rs b/zrml/prediction-markets/src/tests/create_market.rs index 028d1c896..1541a90f2 100644 --- a/zrml/prediction-markets/src/tests/create_market.rs +++ b/zrml/prediction-markets/src/tests/create_market.rs @@ -19,10 +19,11 @@ use super::*; use test_case::test_case; +use crate::MarketBondsOf; use core::ops::RangeInclusive; use zeitgeist_primitives::{ constants::MILLISECS_PER_BLOCK, - types::{AccountIdTest, Balance, BlockNumber, Bond, MarketBonds, Moment}, + types::{BlockNumber, Bond, MarketBonds, Moment}, }; #[test_case(std::ops::RangeInclusive::new(7, 6); "empty range")] @@ -530,7 +531,7 @@ fn create_market_sets_the_correct_market_parameters_and_reserves_the_correct_amo creation: MarketCreation, scoring_rule: ScoringRule, status: MarketStatus, - bonds: MarketBonds, + bonds: MarketBondsOf, ) { ExtBuilder::default().build().execute_with(|| { let creator = ALICE; diff --git a/zrml/prediction-markets/src/tests/integration.rs b/zrml/prediction-markets/src/tests/integration.rs index e5f428931..7640e4acb 100644 --- a/zrml/prediction-markets/src/tests/integration.rs +++ b/zrml/prediction-markets/src/tests/integration.rs @@ -23,10 +23,7 @@ use zeitgeist_primitives::types::OutcomeReport; use crate::MarketIdsPerDisputeBlock; use orml_traits::MultiReservableCurrency; -use zeitgeist_primitives::{ - constants::{mock::OutsiderBond, MILLISECS_PER_BLOCK}, - types::ScalarPosition, -}; +use zeitgeist_primitives::{constants::MILLISECS_PER_BLOCK, types::ScalarPosition}; use zrml_global_disputes::{ types::{OutcomeInfo, Possession}, GlobalDisputesPalletApi, Outcomes, PossessionOf, @@ -353,10 +350,13 @@ fn authorized_correctly_resolves_disputed_market() { if base_asset == Asset::Ztg { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - CENT - DisputeBond::get()); + assert_eq!( + charlie_balance, + 1_000 * BASE - CENT - ::DisputeBond::get() + ); } else { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - DisputeBond::get()); + assert_eq!(charlie_balance, 1_000 * BASE - ::DisputeBond::get()); let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE); assert_eq!(charlie_balance, 1_000 * BASE - CENT); } @@ -378,7 +378,7 @@ fn authorized_correctly_resolves_disputed_market() { // check everyone's deposits let charlie_reserved = Balances::reserved_balance(CHARLIE); - assert_eq!(charlie_reserved, DisputeBond::get()); + assert_eq!(charlie_reserved, ::DisputeBond::get()); let market_ids_1 = MarketIdsPerDisputeBlock::::get( dispute_at + ::CorrectionPeriod::get(), @@ -387,10 +387,13 @@ fn authorized_correctly_resolves_disputed_market() { if base_asset == Asset::Ztg { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - CENT - DisputeBond::get()); + assert_eq!( + charlie_balance, + 1_000 * BASE - CENT - ::DisputeBond::get() + ); } else { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - DisputeBond::get()); + assert_eq!(charlie_balance, 1_000 * BASE - ::DisputeBond::get()); let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE); assert_eq!(charlie_balance, 1_000 * BASE - CENT); } @@ -402,10 +405,13 @@ fn authorized_correctly_resolves_disputed_market() { if base_asset == Asset::Ztg { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - CENT - DisputeBond::get()); + assert_eq!( + charlie_balance, + 1_000 * BASE - CENT - ::DisputeBond::get() + ); } else { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - DisputeBond::get()); + assert_eq!(charlie_balance, 1_000 * BASE - ::DisputeBond::get()); let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE); assert_eq!(charlie_balance, 1_000 * BASE - CENT); } @@ -414,10 +420,13 @@ fn authorized_correctly_resolves_disputed_market() { if base_asset == Asset::Ztg { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE - CENT + OracleBond::get()); + assert_eq!( + charlie_balance, + 1_000 * BASE - CENT + ::OracleBond::get() + ); } else { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE + OracleBond::get()); + assert_eq!(charlie_balance, 1_000 * BASE + ::OracleBond::get()); let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE); assert_eq!(charlie_balance, 1_000 * BASE - CENT); } @@ -431,10 +440,10 @@ fn authorized_correctly_resolves_disputed_market() { if base_asset == Asset::Ztg { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE + OracleBond::get()); + assert_eq!(charlie_balance, 1_000 * BASE + ::OracleBond::get()); } else { let charlie_balance = AssetManager::free_balance(Asset::Ztg, &CHARLIE); - assert_eq!(charlie_balance, 1_000 * BASE + OracleBond::get()); + assert_eq!(charlie_balance, 1_000 * BASE + ::OracleBond::get()); let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE); assert_eq!(charlie_balance, 1_000 * BASE); } @@ -442,7 +451,7 @@ fn authorized_correctly_resolves_disputed_market() { assert_eq!(charlie_reserved_2, 0); let alice_balance = AssetManager::free_balance(Asset::Ztg, &ALICE); - assert_eq!(alice_balance, 1_000 * BASE - OracleBond::get()); + assert_eq!(alice_balance, 1_000 * BASE - ::OracleBond::get()); // bob kinda gets away scot-free since Alice is held responsible // for her designated reporter @@ -496,12 +505,12 @@ fn outsider_reports_wrong_outcome() { )); let outsider_balance_before = Balances::free_balance(outsider); - check_reserve(&outsider, OutsiderBond::get()); + check_reserve(&outsider, ::OutsiderBond::get()); let dispute_at_0 = report_at + 1; run_to_block(dispute_at_0); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(EVE), 0,)); - check_reserve(&EVE, DisputeBond::get()); + check_reserve(&EVE, ::DisputeBond::get()); assert_ok!(SimpleDisputes::suggest_outcome( RuntimeOrigin::signed(DAVE), @@ -519,15 +528,21 @@ fn outsider_reports_wrong_outcome() { // on_resolution called run_blocks(market.deadlines.dispute_duration); - assert_eq!(Balances::free_balance(ALICE), alice_balance_before - OracleBond::get()); + assert_eq!( + Balances::free_balance(ALICE), + alice_balance_before - ::OracleBond::get() + ); check_reserve(&outsider, 0); assert_eq!(Balances::free_balance(outsider), outsider_balance_before); - // disputor EVE gets the OracleBond and OutsiderBond and DisputeBond + // disputor EVE gets the OracleBond and ::OutsiderBond and DisputeBond assert_eq!( Balances::free_balance(EVE), - eve_balance_before + DisputeBond::get() + OutsiderBond::get() + OracleBond::get() + eve_balance_before + + ::DisputeBond::get() + + ::OutsiderBond::get() + + ::OracleBond::get() ); // DAVE gets his outcome bond back assert_eq!(Balances::free_balance(DAVE), dave_balance_before + outcome_bond);