diff --git a/Cargo.toml b/Cargo.toml index be90d6bf..9c88672b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ features = ["client-api", "federation-api", "appservice-api", "unstable-pre-spec [features] default = ["unstable-pre-spec"] -gen-eventid = [] unstable-pre-spec = ["ruma/unstable-pre-spec"] [dev-dependencies] diff --git a/benches/state_res_bench.rs b/benches/state_res_bench.rs index dc8696c6..71732fde 100644 --- a/benches/state_res_bench.rs +++ b/benches/state_res_bench.rs @@ -561,21 +561,6 @@ pub mod event { event_id: EventId, } - /// This feature is turned on in conduit but off when the tests run because - /// we rely on the EventId to check the state-res. - #[cfg(feature = "gen-eventid")] - fn event_id(json: &RawJsonValue) -> Result { - use std::convert::TryFrom; - EventId::try_from(format!( - "${}", - reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6) - .map_err(de::Error::custom)?, - )) - .map_err(de::Error::custom) - } - - /// Only turned on for testing where we need to keep the ID. - #[cfg(not(feature = "gen-eventid"))] fn event_id(json: &RawJsonValue) -> Result { use std::convert::TryFrom; Ok(match from_raw_json_value::(&json) { diff --git a/rustfmt.toml b/rustfmt.toml index 7d2cf549..d3db3454 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -merge_imports = true +imports_granularity="Crate" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index f41a0de7..a5c94d9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,9 @@ impl StateResolution { current_state: &StateMap, event_map: &EventMap>, ) -> Result { - let state_key = incoming_event.state_key().ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?; + let state_key = incoming_event + .state_key() + .ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?; log::info!("Applying a single event, state resolution starting"); let ev = incoming_event; @@ -60,9 +62,12 @@ impl StateResolution { }; let mut auth_events = StateMap::new(); - for key in - event_auth::auth_types_for_event(&ev.kind(), &ev.sender(), Some(state_key), ev.content()) - { + for key in event_auth::auth_types_for_event( + &ev.kind(), + &ev.sender(), + Some(state_key), + ev.content(), + ) { if let Some(ev_id) = current_state.get(&key) { if let Ok(event) = StateResolution::get_or_load_event(room_id, ev_id, event_map) { // TODO synapse checks `rejected_reason` is None here @@ -500,7 +505,9 @@ impl StateResolution { for (idx, event_id) in events_to_check.iter().enumerate() { let event = StateResolution::get_or_load_event(room_id, event_id, event_map)?; - let state_key = event.state_key().ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?; + let state_key = event + .state_key() + .ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?; let mut auth_events = BTreeMap::new(); for aid in &event.auth_events() { diff --git a/tests/utils.rs b/tests/utils.rs index 3d365092..7c2f32cf 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -222,7 +222,14 @@ pub fn do_check( .get(&event_id("$END:foo")) .unwrap() .iter() - .filter(|(k, v)| expected_state.contains_key(k) || start_state.get(k) != Some(*v)) + .filter(|(k, v)| { + expected_state.contains_key(k) + || start_state.get(k) != Some(*v) + // Filter out the dummy messages events. + // These act as points in time where there should be a known state to + // test against. + && k != &&(EventType::RoomMessage, "dummy".to_string()) + }) .map(|(k, v)| (k.clone(), v.clone())) .collect::>(); @@ -482,7 +489,7 @@ pub fn INITIAL_EVENTS() -> BTreeMap> { "START", charlie(), EventType::RoomMessage, - None, + Some("dummy"), json!({}), &[], &[], @@ -491,7 +498,7 @@ pub fn INITIAL_EVENTS() -> BTreeMap> { "END", charlie(), EventType::RoomMessage, - None, + Some("dummy"), json!({}), &[], &[], @@ -585,21 +592,6 @@ pub mod event { event_id: EventId, } - /// This feature is turned on in conduit but off when the tests run because - /// we rely on the EventId to check the state-res. - #[cfg(feature = "gen-eventid")] - fn event_id(json: &RawJsonValue) -> Result { - use std::convert::TryFrom; - EventId::try_from(format!( - "${}", - reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6) - .map_err(de::Error::custom)?, - )) - .map_err(de::Error::custom) - } - - /// Only turned on for testing where we need to keep the ID. - #[cfg(not(feature = "gen-eventid"))] fn event_id(json: &RawJsonValue) -> Result { use std::convert::TryFrom; Ok(match from_raw_json_value::(&json) {