Skip to content

Commit

Permalink
use creator parameter in mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralt98 committed Oct 25, 2023
1 parent 2cdd654 commit 82d3ffc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
3 changes: 2 additions & 1 deletion zrml/parimutuel/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use zrml_market_commons::MarketCommonsPalletApi;

fn setup_market<T: Config>(market_type: MarketType) -> MarketIdOf<T> {
let market_id = 0u32.into();
let mut market = market_mock::<T>();
let market_creator = whitelisted_caller();
let mut market = market_mock::<T>(market_creator);
market.market_type = market_type;
market.status = MarketStatus::Active;
T::MarketCommons::push_market(market.clone()).unwrap();
Expand Down
17 changes: 8 additions & 9 deletions zrml/parimutuel/src/tests/buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use zrml_market_commons::{Error as MError, Markets};
fn buy_emits_event() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);

Expand All @@ -51,9 +51,8 @@ fn buy_emits_event() {
fn buy_balances_change_correctly() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
market.creator = MARKET_CREATOR;
Markets::<Runtime>::insert(market_id, market.clone());

let base_asset = market.base_asset;
Expand Down Expand Up @@ -89,7 +88,7 @@ fn buy_balances_change_correctly() {
fn buy_fails_if_asset_not_parimutuel_share() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market.clone());

Expand All @@ -109,7 +108,7 @@ fn buy_fails_if_asset_not_parimutuel_share() {
fn buy_fails_if_invalid_scoring_rule(scoring_rule: ScoringRule) {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
market.scoring_rule = scoring_rule;

Expand All @@ -134,7 +133,7 @@ fn buy_fails_if_invalid_scoring_rule(scoring_rule: ScoringRule) {
fn buy_fails_if_market_status_is_not_active(status: MarketStatus) {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = status;
market.scoring_rule = ScoringRule::Parimutuel;

Expand All @@ -153,7 +152,7 @@ fn buy_fails_if_market_status_is_not_active(status: MarketStatus) {
fn buy_fails_if_market_type_is_scalar() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
let range: RangeInclusive<u128> = 0..=100;
market.market_type = MarketType::Scalar(range);
market.status = MarketStatus::Active;
Expand All @@ -173,7 +172,7 @@ fn buy_fails_if_market_type_is_scalar() {
fn buy_fails_if_insufficient_balance() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market.clone());

Expand All @@ -193,7 +192,7 @@ fn buy_fails_if_insufficient_balance() {
fn buy_fails_if_below_minimum_bet_size() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market.clone());

Expand Down
18 changes: 9 additions & 9 deletions zrml/parimutuel/src/tests/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use zrml_market_commons::{Error as MError, Markets};
fn claim_rewards_emits_event() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);

Expand Down Expand Up @@ -70,7 +70,7 @@ fn claim_rewards_emits_event() {
fn claim_rewards_categorical_changes_balances_correctly() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);

Expand Down Expand Up @@ -162,7 +162,7 @@ fn claim_rewards_categorical_changes_balances_correctly() {
fn claim_rewards_fails_if_market_type_is_scalar() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
let range: RangeInclusive<u128> = 0..=100;
market.market_type = MarketType::Scalar(range);
market.resolved_outcome = Some(OutcomeReport::Scalar(50));
Expand All @@ -187,7 +187,7 @@ fn claim_rewards_fails_if_market_type_is_scalar() {
fn claim_rewards_fails_if_not_resolved(status: MarketStatus) {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = status;
Markets::<Runtime>::insert(market_id, market);

Expand All @@ -205,7 +205,7 @@ fn claim_rewards_fails_if_not_resolved(status: MarketStatus) {
fn claim_rewards_fails_if_scoring_rule_not_parimutuel(scoring_rule: ScoringRule) {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Resolved;
market.resolved_outcome = Some(OutcomeReport::Categorical(0u16));
market.scoring_rule = scoring_rule;
Expand All @@ -222,7 +222,7 @@ fn claim_rewards_fails_if_scoring_rule_not_parimutuel(scoring_rule: ScoringRule)
fn claim_rewards_fails_if_no_resolved_outcome() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Resolved;
market.resolved_outcome = None;
Markets::<Runtime>::insert(market_id, market);
Expand Down Expand Up @@ -250,7 +250,7 @@ fn claim_rewards_fails_if_market_does_not_exist() {
fn claim_rewards_categorical_fails_if_no_winner() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);

Expand Down Expand Up @@ -280,7 +280,7 @@ fn claim_rewards_categorical_fails_if_no_winner() {
fn claim_rewards_categorical_fails_if_no_winning_shares() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);
Expand Down Expand Up @@ -311,7 +311,7 @@ fn claim_rewards_categorical_fails_if_no_winning_shares() {
fn claim_refunds_works() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);
Expand Down
16 changes: 8 additions & 8 deletions zrml/parimutuel/src/tests/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use zrml_market_commons::Markets;
fn refund_fails_if_not_parimutuel_outcome() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.resolved_outcome = Some(OutcomeReport::Categorical(0u16));
market.status = MarketStatus::Resolved;
Expand All @@ -55,7 +55,7 @@ fn refund_fails_if_not_parimutuel_outcome() {
fn refund_fails_if_market_not_resolved(status: MarketStatus) {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = status;
Markets::<Runtime>::insert(market_id, market);
Expand All @@ -75,7 +75,7 @@ fn refund_fails_if_market_not_resolved(status: MarketStatus) {
fn refund_fails_if_invalid_scoring_rule(scoring_rule: ScoringRule) {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.resolved_outcome = Some(OutcomeReport::Categorical(0u16));
market.status = MarketStatus::Resolved;
Expand All @@ -95,7 +95,7 @@ fn refund_fails_if_invalid_scoring_rule(scoring_rule: ScoringRule) {
fn refund_fails_if_invalid_outcome_asset() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.resolved_outcome = Some(OutcomeReport::Categorical(0u16));
market.status = MarketStatus::Resolved;
Expand All @@ -113,7 +113,7 @@ fn refund_fails_if_invalid_outcome_asset() {
fn refund_fails_if_no_resolved_outcome() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = MarketStatus::Resolved;
market.resolved_outcome = None;
Expand All @@ -131,7 +131,7 @@ fn refund_fails_if_no_resolved_outcome() {
fn refund_fails_if_refund_not_allowed() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);
Expand All @@ -157,7 +157,7 @@ fn refund_fails_if_refund_not_allowed() {
fn refund_fails_if_refundable_balance_is_zero() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);
Expand Down Expand Up @@ -186,7 +186,7 @@ fn refund_fails_if_refundable_balance_is_zero() {
fn refund_emits_event() {
ExtBuilder::default().build().execute_with(|| {
let market_id = 0;
let mut market = market_mock::<Runtime>();
let mut market = market_mock::<Runtime>(MARKET_CREATOR);
market.market_type = MarketType::Categorical(10u16);
market.status = MarketStatus::Active;
Markets::<Runtime>::insert(market_id, market);
Expand Down
4 changes: 2 additions & 2 deletions zrml/parimutuel/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

#[cfg(any(feature = "runtime-benchmarks", test))]
pub(crate) fn market_mock<T>() -> crate::MarketOf<T>
pub(crate) fn market_mock<T>(creator: T::AccountId) -> crate::MarketOf<T>
where
T: crate::Config,
{
Expand All @@ -31,7 +31,7 @@ where
base_asset: Asset::Ztg,
creation: MarketCreation::Permissionless,
creator_fee: Perbill::zero(),
creator: T::PalletId::get().into_account_truncating(),
creator,
market_type: MarketType::Categorical(10u16),
dispute_mechanism: Some(MarketDisputeMechanism::Authorized),
metadata: Default::default(),
Expand Down

0 comments on commit 82d3ffc

Please sign in to comment.