Skip to content

Commit

Permalink
Access constant through Config
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann committed Jan 20, 2024
1 parent c7298b8 commit b7a7144
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
3 changes: 2 additions & 1 deletion zrml/prediction-markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ mod pallet {
pub(crate) type CacheSize = ConstU32<64>;
pub(crate) type EditReason<T> = BoundedVec<u8, <T as Config>::MaxEditReasonLen>;
pub(crate) type InitialItemOf<T> = InitialItem<AccountIdOf<T>, BalanceOf<T>>;
pub(crate) type MarketBondsOf<T> = MarketBonds<AccountIdOf<T>, BalanceOf<T>>;
pub(crate) type MarketIdOf<T> = <T as zrml_market_commons::Config>::MarketId;
pub(crate) type MarketOf<T> = Market<
AccountIdOf<T>,
Expand Down Expand Up @@ -2923,7 +2924,7 @@ mod pallet {
scoring_rule: ScoringRule,
report: Option<ReportOf<T>>,
resolved_outcome: Option<OutcomeReport>,
bonds: MarketBonds<T::AccountId, BalanceOf<T>>,
bonds: MarketBondsOf<T>,
) -> Result<MarketOf<T>, DispatchError> {
let valid_base_asset = match base_asset {
Asset::Ztg => true,
Expand Down
5 changes: 3 additions & 2 deletions zrml/prediction-markets/src/tests/create_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<AccountIdTest, Balance>,
bonds: MarketBondsOf<Runtime>,
) {
ExtBuilder::default().build().execute_with(|| {
let creator = ALICE;
Expand Down
57 changes: 36 additions & 21 deletions zrml/prediction-markets/src/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 - <Runtime as Config>::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 - <Runtime as Config>::DisputeBond::get());
let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE);
assert_eq!(charlie_balance, 1_000 * BASE - CENT);
}
Expand All @@ -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, <Runtime as Config>::DisputeBond::get());

let market_ids_1 = MarketIdsPerDisputeBlock::<Runtime>::get(
dispute_at + <Runtime as zrml_authorized::Config>::CorrectionPeriod::get(),
Expand All @@ -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 - <Runtime as Config>::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 - <Runtime as Config>::DisputeBond::get());
let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE);
assert_eq!(charlie_balance, 1_000 * BASE - CENT);
}
Expand All @@ -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 - <Runtime as Config>::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 - <Runtime as Config>::DisputeBond::get());
let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE);
assert_eq!(charlie_balance, 1_000 * BASE - CENT);
}
Expand All @@ -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 + <Runtime as Config>::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 + <Runtime as Config>::OracleBond::get());
let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE);
assert_eq!(charlie_balance, 1_000 * BASE - CENT);
}
Expand All @@ -431,18 +440,18 @@ 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 + <Runtime as Config>::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 + <Runtime as Config>::OracleBond::get());
let charlie_balance = AssetManager::free_balance(base_asset, &CHARLIE);
assert_eq!(charlie_balance, 1_000 * BASE);
}
let charlie_reserved_2 = AssetManager::reserved_balance(Asset::Ztg, &CHARLIE);
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 - <Runtime as Config>::OracleBond::get());

// bob kinda gets away scot-free since Alice is held responsible
// for her designated reporter
Expand Down Expand Up @@ -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, <Runtime as Config>::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, <Runtime as Config>::DisputeBond::get());

assert_ok!(SimpleDisputes::suggest_outcome(
RuntimeOrigin::signed(DAVE),
Expand All @@ -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 - <Runtime as Config>::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 <Runtime as Config>::OutsiderBond and DisputeBond
assert_eq!(
Balances::free_balance(EVE),
eve_balance_before + DisputeBond::get() + OutsiderBond::get() + OracleBond::get()
eve_balance_before
+ <Runtime as Config>::DisputeBond::get()
+ <Runtime as Config>::OutsiderBond::get()
+ <Runtime as Config>::OracleBond::get()
);
// DAVE gets his outcome bond back
assert_eq!(Balances::free_balance(DAVE), dave_balance_before + outcome_bond);
Expand Down

0 comments on commit b7a7144

Please sign in to comment.