Skip to content

Commit

Permalink
Add TODOs for missing execution paths
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann committed Jan 21, 2024
1 parent b7a7144 commit 6cf946f
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use super::*;
use crate::MarketIdsPerCloseBlock;
use crate::{MarketIdsPerCloseBlock, MomentOf};
use test_case::test_case;
use zeitgeist_primitives::constants::MILLISECS_PER_BLOCK;

Expand Down Expand Up @@ -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<Runtime>);
run_blocks(start_block);
let start = <zrml_market_commons::Pallet<Runtime>>::now();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion zrml/prediction-markets/src/tests/approve_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions zrml/prediction-markets/src/tests/buy_complete_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>| {
Expand Down
3 changes: 3 additions & 0 deletions zrml/prediction-markets/src/tests/close_trusted_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
27 changes: 5 additions & 22 deletions zrml/prediction-markets/src/tests/create_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u128>) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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::<Runtime>::InvalidMarketPeriod,
);
});
}

#[test_case(MarketPeriod::Block(3..3); "empty range blocks")]
#[test_case(MarketPeriod::Timestamp(3..3); "empty range timestamp")]
#[test_case(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

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(|| {
Expand Down
4 changes: 4 additions & 0 deletions zrml/prediction-markets/src/tests/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
4 changes: 4 additions & 0 deletions zrml/prediction-markets/src/tests/dispute_early_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
91 changes: 4 additions & 87 deletions zrml/prediction-markets/src/tests/edit_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; <Runtime as Config>::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::<Runtime>::contains_key(0));
});
}

#[test]
fn request_edit_fails_on_bad_origin() {
ExtBuilder::default().build().execute_with(|| {
frame_system::Pallet::<Runtime>::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; <Runtime as Config>::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; <Runtime as Config>::MaxEditReasonLen::get() as usize + 1];

assert_noop!(
PredictionMarkets::request_edit(RuntimeOrigin::signed(SUDO), 0, edit_reason),
Error::<Runtime>::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() {
Expand Down
3 changes: 3 additions & 0 deletions zrml/prediction-markets/src/tests/manually_close_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions zrml/prediction-markets/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions zrml/prediction-markets/src/tests/redeem_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>| {
Expand Down
3 changes: 3 additions & 0 deletions zrml/prediction-markets/src/tests/reject_early_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
3 changes: 3 additions & 0 deletions zrml/prediction-markets/src/tests/reject_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
11 changes: 11 additions & 0 deletions zrml/prediction-markets/src/tests/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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(|| {
Expand Down
Loading

0 comments on commit 6cf946f

Please sign in to comment.