From 2ebd21912ec947228aa70c26175f4bc87b0e18f1 Mon Sep 17 00:00:00 2001 From: Malte Kliemann Date: Sat, 24 Feb 2024 12:32:27 +0100 Subject: [PATCH] Add missing tests for `create_market` --- .../src/tests/create_market.rs | 85 ++++++++++++++++++- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/zrml/prediction-markets/src/tests/create_market.rs b/zrml/prediction-markets/src/tests/create_market.rs index 151ab1407..059be2fa8 100644 --- a/zrml/prediction-markets/src/tests/create_market.rs +++ b/zrml/prediction-markets/src/tests/create_market.rs @@ -26,9 +26,88 @@ use zeitgeist_primitives::{ types::{BlockNumber, Bond, MarketBonds, Moment}, }; -// TODO(#1239) FeeTooHigh not verified -// TODO(#1239) InvalidMultihash not verified -// TODO(#1239) Creation fails if user can't afford the bonds +#[test_case( + MarketCreation::Advised, + ::AdvisoryBond::get() + ::OracleBond::get() - 1 +)] +#[test_case( + MarketCreation::Permissionless, + ::ValidityBond::get() + ::OracleBond::get() - 1 +)] +fn fails_if_user_cannot_afford_bonds_advised( + market_creation: MarketCreation, + balance: BalanceOf, +) { + ExtBuilder::default().build().execute_with(|| { + let creator = 999; + assert_ok!(AssetManager::deposit(Asset::Ztg, &creator, balance)); + assert_noop!( + PredictionMarkets::create_market( + RuntimeOrigin::signed(creator), + Asset::Ztg, + ::MaxCreatorFee::get(), + BOB, + MarketPeriod::Block(123..456), + get_deadlines(), + gen_metadata(2), + market_creation, + MarketType::Scalar(0..=1), + Some(MarketDisputeMechanism::SimpleDisputes), + ScoringRule::Lmsr, + ), + pallet_balances::Error::::InsufficientBalance + ); + }); +} + +#[test] +fn fails_on_fee_too_high() { + ExtBuilder::default().build().execute_with(|| { + let one_billionth = Perbill::from_rational(1u128, 1_000_000_000u128); + assert_noop!( + PredictionMarkets::create_market( + RuntimeOrigin::signed(ALICE), + Asset::Ztg, + ::MaxCreatorFee::get() + one_billionth, + BOB, + MarketPeriod::Block(123..456), + get_deadlines(), + gen_metadata(2), + MarketCreation::Permissionless, + MarketType::Scalar(0..=1), + Some(MarketDisputeMechanism::SimpleDisputes), + ScoringRule::Lmsr, + ), + Error::::FeeTooHigh + ); + }); +} + +#[test] +fn fails_on_invalid_multihash() { + ExtBuilder::default().build().execute_with(|| { + let mut metadata = [0xff; 50]; + metadata[0] = 0x15; + metadata[1] = 0x29; + let multihash = MultiHash::Sha3_384(metadata); + assert_noop!( + PredictionMarkets::create_market( + RuntimeOrigin::signed(ALICE), + Asset::Ztg, + ::MaxCreatorFee::get(), + BOB, + MarketPeriod::Block(123..456), + get_deadlines(), + multihash, + MarketCreation::Permissionless, + MarketType::Scalar(0..=1), + Some(MarketDisputeMechanism::SimpleDisputes), + ScoringRule::Lmsr, + ), + Error::::InvalidMultihash + ); + }); +} #[test_case(std::ops::RangeInclusive::new(7, 6); "empty range")] #[test_case(555..=555; "one element as range")]