Browse Source

Remove snapshot tests

These tests don't really add much value anymore.
They were initially added for making sure we don't break the API towards the UI, but we introduced a separate model for that in the meanwhile.
One could still argue that these tests ensure backwards compatibility for the cfd state in the DB, but that is not important at the moment.
Since we have more complex states now it is quite a pain to maintain these tests now - without getting much out.
no-contract-setup-message
Daniel Karzel 3 years ago
parent
commit
b6bb36266d
No known key found for this signature in database GPG Key ID: 30C3FC2E438ADB6E
  1. 111
      daemon/src/model/cfd.rs

111
daemon/src/model/cfd.rs

@ -392,7 +392,6 @@ fn calculate_sell_margin(price: Usd, quantity: Usd) -> Result<Amount> {
mod tests {
use super::*;
use rust_decimal_macros::dec;
use std::time::UNIX_EPOCH;
#[test]
fn given_default_values_then_expected_liquidation_price() {
@ -458,116 +457,6 @@ mod tests {
assert_eq!(sell_margin, Amount::from_btc(2.0).unwrap());
}
#[test]
fn serialize_cfd_state_snapshot() {
// This test is to prevent us from breaking the CfdState API against the database.
// We serialize the state into the database, so changes to the enum result in breaking
// program version changes.
let fixed_timestamp = UNIX_EPOCH;
let cfd_state = CfdState::TakeRequested {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"TakeRequested","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::PendingTakeRequest {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"PendingTakeRequest","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::Accepted {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"Accepted","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::ContractSetup {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"ContractSetup","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::Open {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
settlement_timestamp: fixed_timestamp,
margin: Amount::from_btc(0.5).unwrap(),
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"Open","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}},"settlement_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0},"margin":50000000}}"#
);
let cfd_state = CfdState::CloseRequested {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"CloseRequested","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::PendingClose {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"PendingClose","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::Closed {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"Closed","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
let cfd_state = CfdState::Error {
common: CfdStateCommon {
transition_timestamp: fixed_timestamp,
},
};
let json = serde_json::to_string(&cfd_state).unwrap();
assert_eq!(
json,
r#"{"type":"Error","payload":{"common":{"transition_timestamp":{"secs_since_epoch":0,"nanos_since_epoch":0}}}}"#
);
}
#[test]
fn test_secs_into_blocks() {
let error_margin = f32::EPSILON;

Loading…
Cancel
Save