Skip to content

Commit

Permalink
Maker/Taker Sell Persist/Restore testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu-maeda committed Jan 23, 2024
1 parent 1e83731 commit 913ad6f
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 77 deletions.
6 changes: 3 additions & 3 deletions src/comms/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod tests {
.register_peer_message_fallback_tx(peer_message_fallback_tx)
.unwrap();

let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();

let url = Url::from_str("ws://example.com").unwrap();

Expand Down Expand Up @@ -213,7 +213,7 @@ mod tests {
.register_peer_message_fallback_tx(peer_message_fallback_tx)
.unwrap();

let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();

let url = Url::from_str("ws://example.com").unwrap();

Expand Down Expand Up @@ -282,7 +282,7 @@ mod tests {
.register_peer_message_tx(Uuid::new_v4(), event_tx)
.unwrap();

let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();

let url = Url::from_str("ws://example.com").unwrap();

Expand Down
68 changes: 34 additions & 34 deletions src/offer/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ mod tests {

#[tokio::test]
async fn test_validate_offer() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();
offer.validate_against(&order).unwrap();
}

Expand All @@ -197,23 +197,23 @@ mod tests {
content: maker_obligation_content,
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.maker_obligation(maker_obligation).build().unwrap();
let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();
offer.validate_against(&order).unwrap();
}

#[tokio::test]
async fn test_validate_offer_maker_kind_not_found() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let maker_obligation = Obligation {
kind: ObligationKind::Fiat(Currency::CNY, Some(FiatPaymentMethod::FaceToFace)),
amount: 1000000.0,
bond_amount: Some(4000000.0),
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.maker_obligation(maker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -233,9 +233,9 @@ mod tests {
content: maker_obligation_content,
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.maker_obligation(maker_obligation).build().unwrap();
let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();

let result = offer.validate_against(&order);
assert!(result.is_err());
Expand All @@ -253,10 +253,10 @@ mod tests {
content: maker_obligation_content,
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.maker_obligation(maker_obligation).build().unwrap();

let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();
offer.validate_against(&order).unwrap();
}

Expand All @@ -272,10 +272,10 @@ mod tests {
content: maker_obligation_content,
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.maker_obligation(maker_obligation).build().unwrap();

let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();
offer.validate_against(&order).unwrap();
}

Expand All @@ -291,25 +291,25 @@ mod tests {
content: maker_obligation_content,
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.maker_obligation(maker_obligation).build().unwrap();

let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();
let result = offer.validate_against(&order);
assert!(result.is_err());
}

#[tokio::test]
async fn test_validate_offer_maker_f64_amount_overflow() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let maker_obligation = Obligation {
kind: ObligationKind::Fiat(Currency::CNY, Some(FiatPaymentMethod::WeChatPay)),
amount: f64::MAX,
bond_amount: Some(4000000.0),
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.maker_obligation(maker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -319,15 +319,15 @@ mod tests {

#[tokio::test]
async fn test_validate_offer_maker_bond_mismatch() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let maker_obligation = Obligation {
kind: ObligationKind::Fiat(Currency::CNY, Some(FiatPaymentMethod::WeChatPay)),
amount: 1000000.0,
bond_amount: Some(3000000.0),
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.maker_obligation(maker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -337,15 +337,15 @@ mod tests {

#[tokio::test]
async fn test_validate_offer_maker_bond_not_found() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let maker_obligation = Obligation {
kind: ObligationKind::Fiat(Currency::CNY, Some(FiatPaymentMethod::WeChatPay)),
amount: 1000000.0,
bond_amount: None,
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.maker_obligation(maker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -364,25 +364,25 @@ mod tests {
},
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.trade_details(trade_details).build().unwrap();
let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();

let result = offer.validate_against(&order);
assert!(result.is_err());
}

#[tokio::test]
async fn test_validate_offer_taker_kind_not_found() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let taker_obligation = Obligation {
kind: ObligationKind::Bitcoin(Some(BitcoinSettlementMethod::Onchain)),
amount: 40000000.0,
bond_amount: Some(4000000.0),
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.taker_obligation(taker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -392,7 +392,7 @@ mod tests {

#[tokio::test]
async fn test_validate_offer_taker_amount_not_as_expected() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let maker_obligation = Obligation {
kind: ObligationKind::Fiat(Currency::CNY, Some(FiatPaymentMethod::WeChatPay)),
Expand All @@ -406,7 +406,7 @@ mod tests {
bond_amount: Some(4200000.0),
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.maker_obligation(maker_obligation);
builder.taker_obligation(taker_obligation);
let offer = builder.build().unwrap();
Expand All @@ -417,15 +417,15 @@ mod tests {

#[tokio::test]
async fn test_validate_offer_taker_bond_mismatch() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let taker_obligation = Obligation {
kind: ObligationKind::Bitcoin(Some(BitcoinSettlementMethod::Lightning)),
amount: 40000000.0,
bond_amount: Some(3000000.0),
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.taker_obligation(taker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -435,15 +435,15 @@ mod tests {

#[tokio::test]
async fn test_validate_offer_taker_bond_not_found() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let taker_obligation = Obligation {
kind: ObligationKind::Bitcoin(Some(BitcoinSettlementMethod::Lightning)),
amount: 40000000.0,
bond_amount: None,
};

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.taker_obligation(taker_obligation);
let offer = builder.build().unwrap();

Expand All @@ -462,19 +462,19 @@ mod tests {
},
};

let mut builder = SomeTestOrderParams::default_builder();
let mut builder = SomeTestOrderParams::default_buy_builder();
let order = builder.trade_details(trade_details).build().unwrap();
let offer = SomeTestOfferParams::default_builder().build().unwrap();
let offer = SomeTestOfferParams::default_buy_builder().build().unwrap();

let result = offer.validate_against(&order);
assert!(result.is_err());
}

#[tokio::test]
async fn test_validate_offer_market_oracle_not_yet_supported() {
let order = SomeTestOrderParams::default_builder().build().unwrap();
let order = SomeTestOrderParams::default_buy_builder().build().unwrap();

let mut builder = SomeTestOfferParams::default_builder();
let mut builder = SomeTestOfferParams::default_buy_builder();
builder.market_oracle_used("https://www.bitstamp.com/api/".to_string());
let offer = builder.build().unwrap();

Expand Down
Loading

0 comments on commit 913ad6f

Please sign in to comment.