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

Outcome assertion added #8

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions contract/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ pub enum Error {
idx: String,
source: std::num::TryFromIntError,
},
#[error("Supported only 2 outcomes, received {total_outcomes}")]
UnsupportedOutcomes { total_outcomes: usize },
}
5 changes: 5 additions & 0 deletions contract/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ fn add_market(
});
}

let total_outcomes = outcomes.len();
if !total_outcomes == 2 {
return Err(Error::UnsupportedOutcomes { total_outcomes });
}

let funds = funds.require_funds(&denom)?;
let id = LAST_MARKET_ID
.may_load(deps.storage)?
Expand Down
34 changes: 34 additions & 0 deletions contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,40 @@ fn house_always_wins() {
assert!(house_balance > Uint128::zero());
}

#[test]
fn market_with_only_one_outcome() {
let app = Predict::new();
let params = AddMarketParams {
title: "Test market".to_owned(),
description: "Test description".to_owned(),
arbitrator: app.arbitrator.clone().to_string(),
outcomes: vec![OutcomeDef {
label: "Yes".to_owned(),
initial_amount: Collateral(100u16.into()),
}],
denom: DENOM.to_owned(),
deposit_fee: "0.01".parse().unwrap(),
withdrawal_fee: "0.01".parse().unwrap(),
withdrawal_stop_date: app.app.borrow().block_info().time.plus_days(1),
deposit_stop_date: app.app.borrow().block_info().time.plus_days(2),
house: app.house.clone().into_string(),
};
app.app
.borrow_mut()
.execute_contract(
app.admin.clone(),
app.contract.clone(),
&ExecuteMsg::AddMarket {
params: params.into(),
},
&[Coin {
denom: DENOM.to_owned(),
amount: 100u16.into(),
}],
)
.unwrap();
}

proptest! {
#[test]
fn test_cpmm_buy_sell(pool_one in 1..1000u32, pool_two in 1..1000u32, buy in 2..50u32) {
Expand Down