From 6cf946fadb56e9d2d6b1d8efe749a4b00e6a54e0 Mon Sep 17 00:00:00 2001 From: Malte Kliemann Date: Sun, 21 Jan 2024 18:49:07 +0100 Subject: [PATCH] Add TODOs for missing execution paths --- .../src/tests/admin_move_market_to_closed.rs | 4 +- .../tests/admin_move_market_to_resolved.rs | 2 + .../src/tests/approve_market.rs | 5 +- .../src/tests/buy_complete_set.rs | 2 + .../src/tests/close_trusted_market.rs | 3 + .../src/tests/create_market.rs | 27 +---- .../tests/create_market_and_deploy_pool.rs | 5 +- zrml/prediction-markets/src/tests/dispute.rs | 4 + .../src/tests/dispute_early_close.rs | 4 + .../src/tests/edit_market.rs | 91 +------------- .../src/tests/manually_close_market.rs | 3 + zrml/prediction-markets/src/tests/mod.rs | 1 + .../src/tests/redeem_shares.rs | 4 + .../src/tests/reject_early_close.rs | 3 + .../src/tests/reject_market.rs | 3 + zrml/prediction-markets/src/tests/report.rs | 11 ++ .../src/tests/request_edit.rs | 111 ++++++++++++++++++ .../src/tests/schedule_early_close.rs | 7 ++ .../src/tests/sell_complete_set.rs | 2 + .../src/tests/start_global_dispute.rs | 7 ++ 20 files changed, 186 insertions(+), 113 deletions(-) create mode 100644 zrml/prediction-markets/src/tests/request_edit.rs diff --git a/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs b/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs index fc9fa8bd3..b28662cfb 100644 --- a/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs +++ b/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs @@ -17,7 +17,7 @@ // along with Zeitgeist. If not, see . use super::*; -use crate::MarketIdsPerCloseBlock; +use crate::{MarketIdsPerCloseBlock, MomentOf}; use test_case::test_case; use zeitgeist_primitives::constants::MILLISECS_PER_BLOCK; @@ -52,7 +52,7 @@ fn admin_move_market_to_closed_successfully_closes_market_and_sets_end_blocknumb fn admin_move_market_to_closed_successfully_closes_market_and_sets_end_timestamp() { ExtBuilder::default().build().execute_with(|| { let start_block = 7; - set_timestamp_for_on_initialize(start_block * MILLISECS_PER_BLOCK as u64); + set_timestamp_for_on_initialize(start_block * MILLISECS_PER_BLOCK as MomentOf); run_blocks(start_block); let start = >::now(); diff --git a/zrml/prediction-markets/src/tests/admin_move_market_to_resolved.rs b/zrml/prediction-markets/src/tests/admin_move_market_to_resolved.rs index 6b84bd4a8..d4a8a8cca 100644 --- a/zrml/prediction-markets/src/tests/admin_move_market_to_resolved.rs +++ b/zrml/prediction-markets/src/tests/admin_move_market_to_resolved.rs @@ -91,6 +91,8 @@ fn admin_move_market_to_resolved_resolves_reported_market() { }); } +// TODO(#1239) resolves disputed market + #[test_case(MarketStatus::Active)] #[test_case(MarketStatus::Closed)] #[test_case(MarketStatus::Resolved)] diff --git a/zrml/prediction-markets/src/tests/approve_market.rs b/zrml/prediction-markets/src/tests/approve_market.rs index e2bcb14f3..d5a0db67c 100644 --- a/zrml/prediction-markets/src/tests/approve_market.rs +++ b/zrml/prediction-markets/src/tests/approve_market.rs @@ -21,6 +21,9 @@ use super::*; use crate::MarketIdsForEdit; use sp_runtime::DispatchError; +// TODO(#1239) Be more granular with regards to origins +// TODO(#1239) Approve fails if market status is not proposed + #[test] fn it_allows_advisory_origin_to_approve_markets() { ExtBuilder::default().build().execute_with(|| { @@ -34,7 +37,7 @@ fn it_allows_advisory_origin_to_approve_markets() { let market = MarketCommons::market(&0); assert_eq!(market.unwrap().status, MarketStatus::Proposed); - // Make sure it fails from the random joe + // Make sure it fails for the random joe assert_noop!( PredictionMarkets::approve_market(RuntimeOrigin::signed(BOB), 0), DispatchError::BadOrigin diff --git a/zrml/prediction-markets/src/tests/buy_complete_set.rs b/zrml/prediction-markets/src/tests/buy_complete_set.rs index 6a1035d3e..c9b2f3311 100644 --- a/zrml/prediction-markets/src/tests/buy_complete_set.rs +++ b/zrml/prediction-markets/src/tests/buy_complete_set.rs @@ -19,6 +19,8 @@ use super::*; use test_case::test_case; +// TODO(#1239) buy_complete_set fails if market doesn't exist + #[test] fn buy_complete_set_works() { let test = |base_asset: AssetOf| { diff --git a/zrml/prediction-markets/src/tests/close_trusted_market.rs b/zrml/prediction-markets/src/tests/close_trusted_market.rs index 8f8cb6de6..8fcdcb2f9 100644 --- a/zrml/prediction-markets/src/tests/close_trusted_market.rs +++ b/zrml/prediction-markets/src/tests/close_trusted_market.rs @@ -22,6 +22,9 @@ use test_case::test_case; use crate::MarketIdsPerCloseBlock; use sp_runtime::traits::Zero; +// TODO(#1239) MarketDoesNotExist + +// TODO(#1239) Split test #[test] fn close_trusted_market_works() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/create_market.rs b/zrml/prediction-markets/src/tests/create_market.rs index 1541a90f2..151ab1407 100644 --- a/zrml/prediction-markets/src/tests/create_market.rs +++ b/zrml/prediction-markets/src/tests/create_market.rs @@ -26,6 +26,10 @@ 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(std::ops::RangeInclusive::new(7, 6); "empty range")] #[test_case(555..=555; "one element as range")] fn create_scalar_market_fails_on_invalid_range(range: RangeInclusive) { @@ -184,6 +188,7 @@ fn create_market_fails_on_max_oracle_duration() { }); } +// TODO(#1239) split this test #[cfg(feature = "parachain")] #[test] fn create_market_with_foreign_assets() { @@ -292,28 +297,6 @@ fn it_does_not_create_market_with_too_many_categories() { }); } -#[test] -fn create_categorical_market_fails_if_market_begin_is_equal_to_end() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - PredictionMarkets::create_market( - RuntimeOrigin::signed(ALICE), - Asset::Ztg, - Perbill::zero(), - BOB, - MarketPeriod::Block(3..3), - get_deadlines(), - gen_metadata(0), - MarketCreation::Permissionless, - MarketType::Categorical(3), - Some(MarketDisputeMechanism::Authorized), - ScoringRule::Lmsr, - ), - Error::::InvalidMarketPeriod, - ); - }); -} - #[test_case(MarketPeriod::Block(3..3); "empty range blocks")] #[test_case(MarketPeriod::Timestamp(3..3); "empty range timestamp")] #[test_case( diff --git a/zrml/prediction-markets/src/tests/create_market_and_deploy_pool.rs b/zrml/prediction-markets/src/tests/create_market_and_deploy_pool.rs index 87824af68..73264f96d 100644 --- a/zrml/prediction-markets/src/tests/create_market_and_deploy_pool.rs +++ b/zrml/prediction-markets/src/tests/create_market_and_deploy_pool.rs @@ -17,9 +17,12 @@ // along with Zeitgeist. If not, see . use super::*; - use zeitgeist_primitives::types::{Bond, MarketBonds}; +// TODO(#1239) Issue: Separate integration tests and other; use mocks for unit testing +// TODO(#1239) do_buy_complete_set failure +// TODO(#1239) deploy_pool failure + #[test] fn create_market_and_deploy_pool_works() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/dispute.rs b/zrml/prediction-markets/src/tests/dispute.rs index c1f0f81d0..947f2caee 100644 --- a/zrml/prediction-markets/src/tests/dispute.rs +++ b/zrml/prediction-markets/src/tests/dispute.rs @@ -22,6 +22,10 @@ use test_case::test_case; use crate::MarketIdsPerDisputeBlock; use zeitgeist_primitives::types::{Bond, OutcomeReport}; +// TODO(#1239) fails if market doesn't exist +// TODO(#1239) fails if market is trusted +// TODO(#1239) fails if user can't afford the bond + #[test] fn it_allows_to_dispute_the_outcome_of_a_market() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/dispute_early_close.rs b/zrml/prediction-markets/src/tests/dispute_early_close.rs index 2f7438eaf..8e2f7fdf1 100644 --- a/zrml/prediction-markets/src/tests/dispute_early_close.rs +++ b/zrml/prediction-markets/src/tests/dispute_early_close.rs @@ -21,6 +21,10 @@ use super::*; use crate::MarketIdsPerCloseBlock; use zeitgeist_primitives::types::{Bond, EarlyClose, EarlyCloseState}; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) MarketIsNotActive +// TODO(#1239) dispute bond failure + #[test] fn dispute_early_close_emits_event() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/edit_market.rs b/zrml/prediction-markets/src/tests/edit_market.rs index 8a03bbc74..731b93d2c 100644 --- a/zrml/prediction-markets/src/tests/edit_market.rs +++ b/zrml/prediction-markets/src/tests/edit_market.rs @@ -19,94 +19,11 @@ use super::*; use crate::MarketIdsForEdit; -use sp_runtime::DispatchError; -#[test] -fn it_allows_request_edit_origin_to_request_edits_for_markets() { - ExtBuilder::default().build().execute_with(|| { - simple_create_categorical_market( - Asset::Ztg, - MarketCreation::Advised, - 2..4, - ScoringRule::Lmsr, - ); - - // make sure it's in status proposed - let market = MarketCommons::market(&0); - assert_eq!(market.unwrap().status, MarketStatus::Proposed); - - let edit_reason = vec![0_u8; ::MaxEditReasonLen::get() as usize]; - // Make sure it fails from the random joe - assert_noop!( - PredictionMarkets::request_edit(RuntimeOrigin::signed(BOB), 0, edit_reason.clone()), - DispatchError::BadOrigin - ); - - // Now it should work from SUDO - assert_ok!(PredictionMarkets::request_edit( - RuntimeOrigin::signed(SUDO), - 0, - edit_reason.clone() - )); - System::assert_last_event( - Event::MarketRequestedEdit( - 0, - edit_reason.try_into().expect("Conversion to BoundedVec failed"), - ) - .into(), - ); - - assert!(MarketIdsForEdit::::contains_key(0)); - }); -} - -#[test] -fn request_edit_fails_on_bad_origin() { - ExtBuilder::default().build().execute_with(|| { - frame_system::Pallet::::set_block_number(1); - // Creates an advised market. - simple_create_categorical_market( - Asset::Ztg, - MarketCreation::Advised, - 2..4, - ScoringRule::Lmsr, - ); - - // make sure it's in status proposed - let market = MarketCommons::market(&0); - assert_eq!(market.unwrap().status, MarketStatus::Proposed); - - let edit_reason = vec![0_u8; ::MaxEditReasonLen::get() as usize]; - // Make sure it fails from the random joe - assert_noop!( - PredictionMarkets::request_edit(RuntimeOrigin::signed(BOB), 0, edit_reason), - DispatchError::BadOrigin - ); - }); -} - -#[test] -fn edit_request_fails_if_edit_reason_is_too_long() { - ExtBuilder::default().build().execute_with(|| { - // Creates an advised market. - simple_create_categorical_market( - Asset::Ztg, - MarketCreation::Advised, - 0..2, - ScoringRule::Lmsr, - ); - - let market = MarketCommons::market(&0); - assert_eq!(market.unwrap().status, MarketStatus::Proposed); - - let edit_reason = vec![0_u8; ::MaxEditReasonLen::get() as usize + 1]; - - assert_noop!( - PredictionMarkets::request_edit(RuntimeOrigin::signed(SUDO), 0, edit_reason), - Error::::EditReasonLengthExceedsMaxEditReasonLen - ); - }); -} +// TODO(#1239) MarketEditNotRequested +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) InvalidMarketStatus +// TODO(#1239) All failures that need to be ensured for `create_market` #[test] fn only_creator_can_edit_market() { diff --git a/zrml/prediction-markets/src/tests/manually_close_market.rs b/zrml/prediction-markets/src/tests/manually_close_market.rs index 0d39626cd..9c61a8d33 100644 --- a/zrml/prediction-markets/src/tests/manually_close_market.rs +++ b/zrml/prediction-markets/src/tests/manually_close_market.rs @@ -21,6 +21,9 @@ use super::*; use crate::{LastTimeFrame, MarketIdsPerCloseTimeFrame}; use zeitgeist_primitives::constants::MILLISECS_PER_BLOCK; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) MarketPeriodEndNotAlreadyReachedYet + #[test] fn manually_close_market_after_long_stall() { // We check that `on_market_close` works correctly even if a block takes much longer than 12sec diff --git a/zrml/prediction-markets/src/tests/mod.rs b/zrml/prediction-markets/src/tests/mod.rs index 454cda81c..0f17d3fe3 100644 --- a/zrml/prediction-markets/src/tests/mod.rs +++ b/zrml/prediction-markets/src/tests/mod.rs @@ -36,6 +36,7 @@ mod on_resolution; mod redeem_shares; mod reject_early_close; mod reject_market; +mod request_edit; mod report; mod schedule_early_close; mod sell_complete_set; diff --git a/zrml/prediction-markets/src/tests/redeem_shares.rs b/zrml/prediction-markets/src/tests/redeem_shares.rs index 3bb4cd650..a76618a4d 100644 --- a/zrml/prediction-markets/src/tests/redeem_shares.rs +++ b/zrml/prediction-markets/src/tests/redeem_shares.rs @@ -21,6 +21,10 @@ use test_case::test_case; use zeitgeist_primitives::types::{OutcomeReport, ScalarPosition}; +// TODO(#1239) MarketIsNotResolved +// TODO(#1239) NoWinningBalance +// TODO(#1239) MarketDoesNotExist + #[test] fn it_allows_to_redeem_shares() { let test = |base_asset: AssetOf| { diff --git a/zrml/prediction-markets/src/tests/reject_early_close.rs b/zrml/prediction-markets/src/tests/reject_early_close.rs index 22b518da9..77cd26a85 100644 --- a/zrml/prediction-markets/src/tests/reject_early_close.rs +++ b/zrml/prediction-markets/src/tests/reject_early_close.rs @@ -21,6 +21,9 @@ use super::*; use crate::MarketIdsPerCloseBlock; use zeitgeist_primitives::types::EarlyCloseState; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) NoEarlyCloseScheduled + #[test] fn reject_early_close_emits_event() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/reject_market.rs b/zrml/prediction-markets/src/tests/reject_market.rs index d618465a7..38eded944 100644 --- a/zrml/prediction-markets/src/tests/reject_market.rs +++ b/zrml/prediction-markets/src/tests/reject_market.rs @@ -20,6 +20,9 @@ use super::*; use crate::{MarketIdsForEdit, MarketIdsPerCloseBlock}; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) Fails if market is not proposed + #[test] fn it_allows_the_advisory_origin_to_reject_markets() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/report.rs b/zrml/prediction-markets/src/tests/report.rs index 13f0bbccd..4d28e8cea 100644 --- a/zrml/prediction-markets/src/tests/report.rs +++ b/zrml/prediction-markets/src/tests/report.rs @@ -20,6 +20,13 @@ use super::*; use zeitgeist_primitives::{constants::MILLISECS_PER_BLOCK, types::OutcomeReport}; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) MarketAlreadyReported +// TODO(#1239) Trusted markets resolve immediately +// TODO(#1239) NotAllowedToReport with timestamps +// TODO(#1239) Reports are allowed after the oracle duration +// TODO(#1239) Outsider can't report if they can't pay for the bond + #[test] fn it_allows_to_report_the_outcome_of_a_market() { ExtBuilder::default().build().execute_with(|| { @@ -90,6 +97,8 @@ fn report_fails_before_grace_period_is_over() { }); } +// TODO(#1239) This test is misnamed - this does NOT ensure that reports outside of the oracle duration are +// not allowed. #[test] fn it_allows_only_oracle_to_report_the_outcome_of_a_market_during_oracle_duration_blocks() { ExtBuilder::default().build().execute_with(|| { @@ -172,6 +181,7 @@ fn it_allows_only_oracle_to_report_the_outcome_of_a_market_during_oracle_duratio }); } +// TODO(#1239) Use test_case! #[test] fn report_fails_on_mismatched_outcome_for_categorical_market() { ExtBuilder::default().build().execute_with(|| { @@ -278,6 +288,7 @@ fn it_allows_anyone_to_report_an_unreported_market() { }); } +// TODO(#1239) Use `test_case` #[test] fn report_fails_on_market_state_proposed() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/request_edit.rs b/zrml/prediction-markets/src/tests/request_edit.rs new file mode 100644 index 000000000..8851e82de --- /dev/null +++ b/zrml/prediction-markets/src/tests/request_edit.rs @@ -0,0 +1,111 @@ +// Copyright 2022-2024 Forecasting Technologies LTD. +// Copyright 2021-2022 Zeitgeist PM LLC. +// +// This file is part of Zeitgeist. +// +// Zeitgeist is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. +// +// Zeitgeist is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Zeitgeist. If not, see . + +use super::*; +use crate::MarketIdsForEdit; +use sp_runtime::DispatchError; + +// TODO(#1239) request_edit fails if market is not proposed +// TODO(#1239) request_edit fails if edit already in progress + +#[test] +fn it_allows_request_edit_origin_to_request_edits_for_markets() { + ExtBuilder::default().build().execute_with(|| { + simple_create_categorical_market( + Asset::Ztg, + MarketCreation::Advised, + 2..4, + ScoringRule::Lmsr, + ); + + // make sure it's in status proposed + let market = MarketCommons::market(&0); + assert_eq!(market.unwrap().status, MarketStatus::Proposed); + + let edit_reason = vec![0_u8; ::MaxEditReasonLen::get() as usize]; + // Make sure it fails from the random joe + assert_noop!( + PredictionMarkets::request_edit(RuntimeOrigin::signed(BOB), 0, edit_reason.clone()), + DispatchError::BadOrigin + ); + + // Now it should work from SUDO + assert_ok!(PredictionMarkets::request_edit( + RuntimeOrigin::signed(SUDO), + 0, + edit_reason.clone() + )); + System::assert_last_event( + Event::MarketRequestedEdit( + 0, + edit_reason.try_into().expect("Conversion to BoundedVec failed"), + ) + .into(), + ); + + assert!(MarketIdsForEdit::::contains_key(0)); + }); +} + +#[test] +fn request_edit_fails_on_bad_origin() { + ExtBuilder::default().build().execute_with(|| { + frame_system::Pallet::::set_block_number(1); + // Creates an advised market. + simple_create_categorical_market( + Asset::Ztg, + MarketCreation::Advised, + 2..4, + ScoringRule::Lmsr, + ); + + // make sure it's in status proposed + let market = MarketCommons::market(&0); + assert_eq!(market.unwrap().status, MarketStatus::Proposed); + + let edit_reason = vec![0_u8; ::MaxEditReasonLen::get() as usize]; + // Make sure it fails from the random joe + assert_noop!( + PredictionMarkets::request_edit(RuntimeOrigin::signed(BOB), 0, edit_reason), + DispatchError::BadOrigin + ); + }); +} + +#[test] +fn edit_request_fails_if_edit_reason_is_too_long() { + ExtBuilder::default().build().execute_with(|| { + // Creates an advised market. + simple_create_categorical_market( + Asset::Ztg, + MarketCreation::Advised, + 0..2, + ScoringRule::Lmsr, + ); + + let market = MarketCommons::market(&0); + assert_eq!(market.unwrap().status, MarketStatus::Proposed); + + let edit_reason = vec![0_u8; ::MaxEditReasonLen::get() as usize + 1]; + + assert_noop!( + PredictionMarkets::request_edit(RuntimeOrigin::signed(SUDO), 0, edit_reason), + Error::::EditReasonLengthExceedsMaxEditReasonLen + ); + }); +} diff --git a/zrml/prediction-markets/src/tests/schedule_early_close.rs b/zrml/prediction-markets/src/tests/schedule_early_close.rs index d565d8bc7..cb8d83145 100644 --- a/zrml/prediction-markets/src/tests/schedule_early_close.rs +++ b/zrml/prediction-markets/src/tests/schedule_early_close.rs @@ -24,6 +24,13 @@ use zeitgeist_primitives::{ types::{EarlyClose, EarlyCloseState}, }; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) RequesterNotCreator +// TODO(#1239) MarketIsNotActive +// TODO(#1239) OnlyAuthorizedCanScheduleEarlyClose +// TODO(#1239) Correct repatriations +// TODO(#1239) reserve_named failure + #[test] fn schedule_early_close_emits_event() { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/prediction-markets/src/tests/sell_complete_set.rs b/zrml/prediction-markets/src/tests/sell_complete_set.rs index 23de1bd8f..6814481c9 100644 --- a/zrml/prediction-markets/src/tests/sell_complete_set.rs +++ b/zrml/prediction-markets/src/tests/sell_complete_set.rs @@ -19,6 +19,8 @@ use super::*; use test_case::test_case; +// TODO(#1239) MarketDoesNotExist + #[test_case(ScoringRule::Lmsr)] #[test_case(ScoringRule::Orderbook)] fn sell_complete_set_works(scoring_rule: ScoringRule) { diff --git a/zrml/prediction-markets/src/tests/start_global_dispute.rs b/zrml/prediction-markets/src/tests/start_global_dispute.rs index 573dcf8a3..2b84d8ed7 100644 --- a/zrml/prediction-markets/src/tests/start_global_dispute.rs +++ b/zrml/prediction-markets/src/tests/start_global_dispute.rs @@ -20,6 +20,13 @@ use super::*; use zeitgeist_primitives::types::OutcomeReport; +// TODO(#1239) MarketDoesNotExist +// TODO(#1239) NoDisputeMechanism +// TODO(#1239) InvalidMarketStatus +// TODO(#1239) GlobalDisputeExistsAlready +// TODO(#1239) MarketIsNotReported +// TODO(#1239) MarketDisputeMechanismNotFailed + #[test] fn start_global_dispute_fails_on_wrong_mdm() { ExtBuilder::default().build().execute_with(|| {