Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize prediction-market tests #1242

Merged
merged 35 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
15bee2c
Rename `tests.rs` to `old_tests.rs` to avoid naming conflicts
maltekliemann Jan 11, 2024
1b34302
Move `buy_complete_set` tests to new tests
maltekliemann Jan 11, 2024
8908952
Clean up `buy_complete_set` tests
maltekliemann Jan 11, 2024
3bd0f73
Extract `sell_complete_set_tests`
maltekliemann Jan 11, 2024
4be0484
Clean up `sell_complete_set` tests
maltekliemann Jan 11, 2024
62c5915
Extract `admin_move_market_to_closed` tests
maltekliemann Jan 11, 2024
edf6aea
Extract `create_market` tests
maltekliemann Jan 11, 2024
cbf78f6
Extract `admin_move_market_to_resolved` tests
maltekliemann Jan 11, 2024
8df142f
Remove superfluous test
maltekliemann Jan 11, 2024
8a73e99
Extract more `create_market` tests
maltekliemann Jan 11, 2024
4d04fdb
Extract `approve_market` tests
maltekliemann Jan 11, 2024
29bafe4
Extract `edit_market` tests
maltekliemann Jan 11, 2024
dd68842
Extract `edit_market` tests
maltekliemann Jan 11, 2024
4969d35
Merge branch 'main' into mkl-pm-tests
maltekliemann Jan 11, 2024
a3827ad
Add `on_market_close` tests
maltekliemann Jan 11, 2024
4352aa2
Extract `manually_close_market` tests
maltekliemann Jan 11, 2024
9cb5dfb
Extract `on_initialize` tests
maltekliemann Jan 12, 2024
0f4b1f9
Extract `report` tests
maltekliemann Jan 12, 2024
7717b4e
Extract `dispute` tests
maltekliemann Jan 12, 2024
87c1dc3
Extract `schedule_early_close` tests
maltekliemann Jan 12, 2024
18e62b0
Extract `dispute_early_close` tests
maltekliemann Jan 12, 2024
5efef55
Extract `reject_early_close` tests
maltekliemann Jan 13, 2024
cd7e813
Extract more `dispute` tests
maltekliemann Jan 13, 2024
fc57725
Extract `close_trusted_market` tests
maltekliemann Jan 13, 2024
0526b48
Extract `start_global_dispute` tests
maltekliemann Jan 13, 2024
27f420e
Extract `redeem_shares` tests and add missing tests
maltekliemann Jan 13, 2024
2bc4b41
Extract `on_resolution` and additional `redeem_shares` tests
maltekliemann Jan 13, 2024
c0e8a34
Move integration tests into new test module
maltekliemann Jan 13, 2024
fe30d80
Automatically set block to `1` at the start of test
maltekliemann Jan 13, 2024
c7298b8
Replace `crate::Config` with `Config`
maltekliemann Jan 20, 2024
b7a7144
Access constant through `Config`
maltekliemann Jan 20, 2024
6cf946f
Add TODOs for missing execution paths
maltekliemann Jan 21, 2024
a5f24ef
Fix formatting
maltekliemann Jan 21, 2024
d60c94a
Merge branch 'main' into mkl-pm-tests-retry
mergify[bot] Jan 22, 2024
5b0e022
Merge branch 'main' into mkl-pm-tests-retry
mergify[bot] Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions zrml/prediction-markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,28 @@ mod pallet {
/// Currently 10 blocks is 2 minutes (assuming block time is 12 seconds).
pub(crate) const MAX_RECOVERY_TIME_FRAMES: TimeFrame = 10;

pub(crate) type BalanceOf<T> = <T as zrml_market_commons::Config>::Balance;
pub(crate) type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub(crate) type NegativeImbalanceOf<T> =
<<T as Config>::Currency as Currency<AccountIdOf<T>>>::NegativeImbalance;
pub(crate) type TimeFrame = u64;
pub(crate) type AssetOf<T> = Asset<MarketIdOf<T>>;
pub(crate) type BalanceOf<T> = <T as zrml_market_commons::Config>::Balance;
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 MomentOf<T> =
<<T as zrml_market_commons::Config>::Timestamp as frame_support::traits::Time>::Moment;
pub type MarketOf<T> = Market<
pub(crate) type MarketOf<T> = Market<
AccountIdOf<T>,
BalanceOf<T>,
<T as frame_system::Config>::BlockNumber,
MomentOf<T>,
Asset<MarketIdOf<T>>,
AssetOf<T>,
>;
pub(crate) type MomentOf<T> =
<<T as zrml_market_commons::Config>::Timestamp as frame_support::traits::Time>::Moment;
pub(crate) type NegativeImbalanceOf<T> =
<<T as Config>::Currency as Currency<AccountIdOf<T>>>::NegativeImbalance;
pub(crate) type RejectReason<T> = BoundedVec<u8, <T as Config>::MaxRejectReasonLen>;
pub(crate) type ReportOf<T> = Report<AccountIdOf<T>, <T as frame_system::Config>::BlockNumber>;
pub type CacheSize = ConstU32<64>;
pub type EditReason<T> = BoundedVec<u8, <T as Config>::MaxEditReasonLen>;
pub type RejectReason<T> = BoundedVec<u8, <T as Config>::MaxRejectReasonLen>;
type InitialItemOf<T> = InitialItem<AccountIdOf<T>, BalanceOf<T>>;
pub(crate) type TimeFrame = u64;

macro_rules! impl_unreserve_bond {
($fn_name:ident, $bond_type:ident) => {
Expand Down Expand Up @@ -591,7 +593,7 @@ mod pallet {
#[transactional]
pub fn create_market(
origin: OriginFor<T>,
base_asset: Asset<MarketIdOf<T>>,
base_asset: AssetOf<T>,
creator_fee: Perbill,
oracle: T::AccountId,
period: MarketPeriod<T::BlockNumber, MomentOf<T>>,
Expand Down Expand Up @@ -643,7 +645,7 @@ mod pallet {
#[transactional]
pub fn edit_market(
origin: OriginFor<T>,
base_asset: Asset<MarketIdOf<T>>,
base_asset: AssetOf<T>,
market_id: MarketIdOf<T>,
oracle: T::AccountId,
period: MarketPeriod<T::BlockNumber, MomentOf<T>>,
Expand Down Expand Up @@ -1062,7 +1064,7 @@ mod pallet {
#[pallet::call_index(17)]
pub fn create_market_and_deploy_pool(
origin: OriginFor<T>,
base_asset: Asset<MarketIdOf<T>>,
base_asset: AssetOf<T>,
creator_fee: Perbill,
oracle: T::AccountId,
period: MarketPeriod<T::BlockNumber, MomentOf<T>>,
Expand Down Expand Up @@ -1902,13 +1904,7 @@ mod pallet {
SoldCompleteSet(MarketIdOf<T>, BalanceOf<T>, AccountIdOf<T>),
/// An amount of winning outcomes have been redeemed.
/// \[market_id, currency_id, amount_redeemed, payout, who\]
TokensRedeemed(
MarketIdOf<T>,
Asset<MarketIdOf<T>>,
BalanceOf<T>,
BalanceOf<T>,
AccountIdOf<T>,
),
TokensRedeemed(MarketIdOf<T>, AssetOf<T>, BalanceOf<T>, BalanceOf<T>, AccountIdOf<T>),
/// The global dispute was started. \[market_id\]
GlobalDisputeStarted(MarketIdOf<T>),
/// The recovery limit for timestamp based markets was reached due to a prolonged chain stall.
Expand Down Expand Up @@ -2090,7 +2086,7 @@ mod pallet {
#[require_transactional]
fn do_create_market(
who: T::AccountId,
base_asset: Asset<MarketIdOf<T>>,
base_asset: AssetOf<T>,
creator_fee: Perbill,
oracle: T::AccountId,
period: MarketPeriod<T::BlockNumber, MomentOf<T>>,
Expand Down Expand Up @@ -2148,10 +2144,7 @@ mod pallet {
Ok((ids_amount, market_id))
}

pub fn outcome_assets(
market_id: MarketIdOf<T>,
market: &MarketOf<T>,
) -> Vec<Asset<MarketIdOf<T>>> {
pub fn outcome_assets(market_id: MarketIdOf<T>, market: &MarketOf<T>) -> Vec<AssetOf<T>> {
match market.market_type {
MarketType::Categorical(categories) => {
let mut assets = Vec::new();
Expand Down Expand Up @@ -2886,7 +2879,7 @@ mod pallet {
}

fn construct_market(
base_asset: Asset<MarketIdOf<T>>,
base_asset: AssetOf<T>,
creator: T::AccountId,
creator_fee: Perbill,
oracle: T::AccountId,
Expand All @@ -2899,7 +2892,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: 4 additions & 1 deletion zrml/prediction-markets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ impl ExtBuilder {
}
.assimilate_storage(&mut t)
.unwrap();
t.into()

let mut test_ext: sp_io::TestExternalities = t.into();
test_ext.execute_with(|| System::set_block_number(1));
test_ext
}
}

Expand Down
Loading
Loading