Skip to content

Commit

Permalink
Adjust prediction markets tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sea212 committed Jan 16, 2024
1 parent a3339eb commit 0a76d86
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@
pub use super::*;
use crate::{
assets::Asset,
types::{Assets, Balance, Moment},
types::{Assets, Balance, Moment, Currencies},
};
use frame_support::{parameter_types, traits::LockIdentifier, PalletId};
use orml_traits::parameter_type_with_key;
use sp_arithmetic::Perbill;

// Assets
parameter_types! {
pub const AssetsAccountDeposit: Balance = 0;
pub const AssetsApprovalDeposit: Balance = 0;
pub const AssetsDeposit: Balance = 0;
pub const AssetsStringLimit: u32 = 256;
pub const AssetsMetadataDepositBase: Balance = 0;
pub const AssetsMetadataDepositPerByte: Balance = 0;
}

// Authorized
parameter_types! {
pub const AuthorizedPalletId: PalletId = PalletId(*b"zge/atzd");
Expand Down Expand Up @@ -164,6 +174,7 @@ parameter_types! {
pub const GetNativeCurrencyId: Assets = Asset::Ztg;
}

// Will be removed once asset-system is completely integerated
parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: Assets| -> Balance {
match currency_id {
Expand All @@ -173,6 +184,14 @@ parameter_type_with_key! {
};
}

parameter_type_with_key! {
pub ExistentialDepositsNew: |currency_id: Currencies| -> Balance {
match currency_id {
_ => 1
}
};
}

// System
parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand Down
6 changes: 5 additions & 1 deletion zrml/prediction-markets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zrml-simple-disputes = { workspace = true }
orml-asset-registry = { workspace = true, optional = true }
orml-currencies = { workspace = true, optional = true }
orml-tokens = { workspace = true, optional = true }
pallet-assets = { workspace = true }
pallet-balances = { workspace = true, optional = true }
pallet-randomness-collective-flip = { workspace = true, optional = true }
pallet-timestamp = { workspace = true, optional = true }
Expand All @@ -29,6 +30,7 @@ sp-api = { workspace = true, optional = true }
sp-io = { workspace = true, optional = true }
substrate-fixed = { workspace = true, optional = true }
xcm = { workspace = true, optional = true }
zrml-asset-router = { workspace = true, optional = true }
zrml-prediction-markets-runtime-api = { workspace = true, optional = true }
zrml-rikiddo = { workspace = true, optional = true }
zrml-swaps = { workspace = true, optional = true }
Expand All @@ -41,8 +43,10 @@ zrml-prediction-markets = { workspace = true, features = ["mock", "default"] }
[features]
default = ["std"]
mock = [
"orml-asset-registry/default",
"orml-currencies/default",
"orml-tokens/default",
"pallet-assets/default",
"pallet-balances",
"pallet-randomness-collective-flip/default",
"pallet-timestamp/default",
Expand All @@ -52,11 +56,11 @@ mock = [
"sp-io/default",
"substrate-fixed",
"zeitgeist-primitives/mock",
"zrml-asset-router/default",
"zrml-prediction-markets-runtime-api/default",
"zrml-rikiddo/default",
"zrml-swaps/default",
"xcm/default",
"orml-asset-registry/default",
]
parachain = []
runtime-benchmarks = [
Expand Down
125 changes: 108 additions & 17 deletions zrml/prediction-markets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@

use crate as prediction_markets;
use frame_support::{
construct_runtime, ord_parameter_types, parameter_types,
traits::{Everything, NeverEnsureOrigin, OnFinalize, OnInitialize},
construct_runtime, ord_parameter_types, parameter_types,
traits::{Everything, NeverEnsureOrigin, OnFinalize, OnInitialize, AsEnsureOriginWithArg},
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use frame_system::{EnsureRoot, EnsureSignedBy, EnsureSigned};
#[cfg(feature = "parachain")]
use orml_asset_registry::AssetMetadata;
use sp_arithmetic::per_things::Percent;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
traits::{ConstU32, BlakeTwo256, IdentityLookup},
DispatchError, DispatchResult,
};
use parity_scale_codec::Compact;
use std::cell::RefCell;
use substrate_fixed::{types::extra::U33, FixedI128, FixedU128};
use zeitgeist_primitives::{
Expand All @@ -44,7 +45,7 @@ use zeitgeist_primitives::{
BalanceFractionalDecimals, BlockHashCount, BlocksPerYear, CloseEarlyBlockPeriod,
CloseEarlyDisputeBond, CloseEarlyProtectionBlockPeriod,
CloseEarlyProtectionTimeFramePeriod, CloseEarlyRequestBond, CloseEarlyTimeFramePeriod,
CorrectionPeriod, CourtPalletId, ExistentialDeposit, ExistentialDeposits, ExitFee,
CorrectionPeriod, CourtPalletId, ExistentialDeposit, ExistentialDepositsNew, ExitFee,
GdVotingPeriod, GetNativeCurrencyId, GlobalDisputeLockId, GlobalDisputesPalletId,
InflationPeriod, LiquidityMiningPalletId, LockId, MaxAppeals, MaxApprovals, MaxAssets,
MaxCategories, MaxCourtParticipants, MaxCreatorFee, MaxDelegations, MaxDisputeDuration,
Expand All @@ -55,12 +56,12 @@ use zeitgeist_primitives::{
MinOutcomeVoteAmount, MinSubsidy, MinSubsidyPeriod, MinWeight, MinimumPeriod, OutcomeBond,
OutcomeFactor, OutsiderBond, PmPalletId, RemoveKeysLimit, RequestInterval,
SimpleDisputesPalletId, SwapsPalletId, TreasuryPalletId, VotePeriod, VotingOutcomeFee,
BASE, CENT, MILLISECS_PER_BLOCK,
BASE, CENT, MILLISECS_PER_BLOCK, AssetsApprovalDeposit, AssetsAccountDeposit, AssetsDeposit, AssetsMetadataDepositBase, AssetsMetadataDepositPerByte, AssetsStringLimit,
},
traits::DeployPoolApi,
types::{
AccountIdTest, Amount, Asset, Assets, Balance, BasicCurrencyAdapter, BlockNumber,
BlockTest, Hash, Index, MarketId, Moment, PoolId, UncheckedExtrinsicTest,
AccountIdTest, Amount, Assets, Currencies, Balance, BasicCurrencyAdapter, BlockNumber,
BlockTest, Hash, Index, MarketId, Moment, PoolId, UncheckedExtrinsicTest, CampaignAsset, CustomAsset, MarketAsset, CustomAssetId, CampaignAssetId
},
};
use zrml_rikiddo::types::{EmaMarketVolume, FeeSigmoid, RikiddoSigmoidMV};
Expand Down Expand Up @@ -157,18 +158,26 @@ parameter_types! {
pub const DisputeBond: Balance = 109 * CENT;
}

type CustomAssetsInstance = pallet_assets::Instance1;
type CampaignAssetsInstance = pallet_assets::Instance2;
type MarketAssetsInstance = pallet_assets::Instance3;

construct_runtime!(
pub enum Runtime
where
Block = BlockTest<Runtime>,
NodeBlock = BlockTest<Runtime>,
UncheckedExtrinsic = UncheckedExtrinsicTest<Runtime>,
{
AssetRouter: zrml_asset_router::{Pallet},
Authorized: zrml_authorized::{Event<T>, Pallet, Storage},
Balances: pallet_balances::{Call, Config<T>, Event<T>, Pallet, Storage},
CampaignAssets: pallet_assets::<Instance2>::{Call, Pallet, Storage, Event<T>},
CustomAssets: pallet_assets::<Instance1>::{Call, Pallet, Storage, Event<T>},
Court: zrml_court::{Event<T>, Pallet, Storage},
AssetManager: orml_currencies::{Call, Pallet, Storage},
LiquidityMining: zrml_liquidity_mining::{Config<T>, Event<T>, Pallet},
MarketAssets: pallet_assets::<Instance3>::{Call, Pallet, Storage, Event<T>},
MarketCommons: zrml_market_commons::{Pallet, Storage},
PredictionMarkets: prediction_markets::{Event<T>, Pallet, Storage},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
Expand Down Expand Up @@ -263,18 +272,18 @@ impl frame_system::Config for Runtime {

impl orml_currencies::Config for Runtime {
type GetNativeCurrencyId = GetNativeCurrencyId;
type MultiCurrency = Tokens;
type MultiCurrency = AssetRouter;
type NativeCurrency = BasicCurrencyAdapter<Runtime, Balances>;
type WeightInfo = ();
}

impl orml_tokens::Config for Runtime {
type Amount = Amount;
type Balance = Balance;
type CurrencyId = Assets;
type CurrencyId = Currencies;
type DustRemovalWhitelist = Everything;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposits = ExistentialDeposits;
type ExistentialDeposits = ExistentialDepositsNew;
type MaxLocks = ();
type MaxReserves = MaxReserves;
type CurrencyHooks = ();
Expand All @@ -285,7 +294,7 @@ impl orml_tokens::Config for Runtime {
#[cfg(feature = "parachain")]
crate::orml_asset_registry::impl_mock_registry! {
MockRegistry,
Assets,
Currencies,
Balance,
zeitgeist_primitives::types::CustomMetadata
}
Expand Down Expand Up @@ -315,6 +324,88 @@ ord_parameter_types! {
pub const AuthorizedDisputeResolutionUser: AccountIdTest = ALICE;
}

impl pallet_assets::Config<CampaignAssetsInstance> for Runtime {
type ApprovalDeposit = AssetsApprovalDeposit;
type AssetAccountDeposit = AssetsAccountDeposit;
type AssetDeposit = AssetsDeposit;
type AssetId = CampaignAsset;
type AssetIdParameter = Compact<CampaignAssetId>;
type Balance = Balance;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<AccountIdTest>;
type Freezer = ();
type MetadataDepositBase = AssetsMetadataDepositBase;
type MetadataDepositPerByte = AssetsMetadataDepositPerByte;
type RemoveItemsLimit = ConstU32<50>;
type RuntimeEvent = RuntimeEvent;
type StringLimit = AssetsStringLimit;
type WeightInfo = ();
}

impl pallet_assets::Config<CustomAssetsInstance> for Runtime {
type ApprovalDeposit = AssetsApprovalDeposit;
type AssetAccountDeposit = AssetsAccountDeposit;
type AssetDeposit = AssetsDeposit;
type AssetId = CustomAsset;
type AssetIdParameter = Compact<CustomAssetId>;
type Balance = Balance;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<AccountIdTest>;
type Freezer = ();
type MetadataDepositBase = AssetsMetadataDepositBase;
type MetadataDepositPerByte = AssetsMetadataDepositPerByte;
type RemoveItemsLimit = ConstU32<50>;
type RuntimeEvent = RuntimeEvent;
type StringLimit = AssetsStringLimit;
type WeightInfo = ();
}

impl pallet_assets::Config<MarketAssetsInstance> for Runtime {
type ApprovalDeposit = AssetsApprovalDeposit;
type AssetAccountDeposit = AssetsAccountDeposit;
type AssetDeposit = AssetsDeposit;
type AssetId = MarketAsset;
type AssetIdParameter = MarketAsset;
type Balance = Balance;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<AccountIdTest>;
type Freezer = ();
type MetadataDepositBase = AssetsMetadataDepositBase;
type MetadataDepositPerByte = AssetsMetadataDepositPerByte;
type RemoveItemsLimit = ConstU32<50>;
type RuntimeEvent = RuntimeEvent;
type StringLimit = AssetsStringLimit;
type WeightInfo = ();
}

impl zrml_asset_router::Config for Runtime {
type AssetType = Assets;
type Balance = Balance;
type CurrencyType = Currencies;
type Currencies = Tokens;
type CampaignAssetType = CampaignAsset;
type CampaignAssets = CampaignAssets;
type CustomAssetType = CustomAsset;
type CustomAssets = CustomAssets;
type MarketAssetType = MarketAsset;
type MarketAssets = MarketAssets;
}

impl zrml_authorized::Config for Runtime {
type AuthorizedDisputeResolutionOrigin =
EnsureSignedBy<AuthorizedDisputeResolutionUser, AccountIdTest>;
Expand Down Expand Up @@ -488,7 +579,7 @@ impl ExtBuilder {
#[cfg(feature = "parachain")]
orml_tokens::GenesisConfig::<Runtime> {
balances: (0..69)
.map(|idx| (idx, Assets::ForeignAsset(100), INITIAL_BALANCE))
.map(|idx| (idx, Currencies::ForeignAsset(100), INITIAL_BALANCE))
.collect(),
}
.assimilate_storage(&mut t)
Expand All @@ -502,7 +593,7 @@ impl ExtBuilder {
orml_asset_registry_mock::GenesisConfig {
metadata: vec![
(
Assets::ForeignAsset(100),
Currencies::ForeignAsset(100),
AssetMetadata {
decimals: 18,
name: "ACALA USD".as_bytes().to_vec(),
Expand All @@ -513,7 +604,7 @@ impl ExtBuilder {
},
),
(
Assets::ForeignAsset(420),
Currencies::ForeignAsset(420),
AssetMetadata {
decimals: 18,
name: "FANCY_TOKEN".as_bytes().to_vec(),
Expand Down Expand Up @@ -558,8 +649,8 @@ pub fn set_timestamp_for_on_initialize(time: Moment) {

sp_api::mock_impl_runtime_apis! {
impl zrml_prediction_markets_runtime_api::PredictionMarketsApi<BlockTest<Runtime>, MarketId, Hash> for Runtime {
fn market_outcome_share_id(_: MarketId, _: u16) -> Asset<MarketId> {
Asset::PoolShare(1)
fn market_outcome_share_id(_: MarketId, _: u16) -> Assets {
Assets::PoolShare(1)
}
}
}
Expand Down
Loading

0 comments on commit 0a76d86

Please sign in to comment.