Skip to content

Commit

Permalink
Use ..Default::default in TU
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Nov 29, 2024
1 parent 1774d4b commit 025630f
Showing 1 changed file with 8 additions and 42 deletions.
50 changes: 8 additions & 42 deletions massa-event-cache/src/event_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl DbKeyBuilder {
is_prefix: bool,
is_counter: bool,
) -> Option<Vec<u8>> {
// High level key builder function
// Db format:
// * Regular keys:
// * Event key: [Event Indent][Slot][Index] -> Event value: Event serialized
Expand Down Expand Up @@ -171,7 +170,6 @@ impl DbKeyBuilder {
let item =
KeyBuilderType::Event(&event.context.slot, event.context.index_in_slot);
if !is_prefix && !is_counter {
// key.extend(self.key_from_item(indent, item, false, false));
key.extend(self.key(&KeyIndent::Event, item, false, false));
}
Some(key)
Expand All @@ -196,13 +194,11 @@ impl DbKeyBuilder {

/// Prefix key to iterate over all events / emitter_address / ...
fn prefix_key_from_indent(&self, indent: &KeyIndent) -> Vec<u8> {
// High level key builder function
self.key(indent, KeyBuilderType::None, false, false)
}

/// Prefix key to iterate over specific emitter_address / operation_id / ...
fn prefix_key_from_filter_item(&self, filter_item: &FilterItem, indent: &KeyIndent) -> Vec<u8> {
// High level key builder function
match (indent, filter_item) {
(KeyIndent::Event, FilterItem::SlotStartEnd(_start, _end)) => {
unimplemented!()
Expand Down Expand Up @@ -944,8 +940,8 @@ mod tests {
use tempfile::TempDir;
// internal
use massa_models::config::{
MAX_EVENTS_PER_QUERY, MAX_EVENT_DATA_SIZE, MAX_OPERATIONS_PER_BLOCK,
MAX_RECURSIVE_CALLS_DEPTH, THREAD_COUNT,
MAX_EVENTS_PER_QUERY, MAX_EVENT_DATA_SIZE, MAX_EVENT_PER_OPERATION,
MAX_OPERATIONS_PER_BLOCK, MAX_RECURSIVE_CALLS_DEPTH, THREAD_COUNT,
};
use massa_models::operation::OperationId;
use massa_models::output_event::EventExecutionContext;
Expand All @@ -960,9 +956,7 @@ mod tests {
THREAD_COUNT,
MAX_RECURSIVE_CALLS_DEPTH,
MAX_EVENT_DATA_SIZE as u64,
// TODO: rebase
// MAX_EVENT_PER_OPERATION as u64,
25u64,
MAX_EVENT_PER_OPERATION as u64,
MAX_OPERATIONS_PER_BLOCK as u64,
MAX_EVENTS_PER_QUERY,
)
Expand Down Expand Up @@ -1222,21 +1216,14 @@ mod tests {

let filter_1 = EventFilter {
start: Some(Slot::new(2, 0)),
end: None,
emitter_address: None,
original_caller_address: None,
original_operation_id: None,
is_final: None,
is_error: None,
..Default::default()
};

let (_, filtered_events_1) = cache.get_filtered_sc_output_events(&filter_1);

assert_eq!(filtered_events_1.len(), 2);
// println!("filtered_events_1[0]: {:?}", filtered_events_1[0]);
assert_eq!(filtered_events_1[0].context.slot, slot_2);
assert_eq!(filtered_events_1[0].context.index_in_slot, index_2_1);
// println!("filtered_events_1[1]: {:?}", filtered_events_1[1]);
assert_eq!(filtered_events_1[1].context.slot, slot_2);
assert_eq!(filtered_events_1[1].context.index_in_slot, index_2_2);
}
Expand Down Expand Up @@ -1304,13 +1291,8 @@ mod tests {
cache.insert_multi_it(events.into_iter());

let mut filter_1 = EventFilter {
start: None,
end: None,
emitter_address: None,
original_caller_address: None,
original_operation_id: Some(op_id_1),
is_final: None,
is_error: None,
..Default::default()
};

let (_, filtered_events_1) = cache.get_filtered_sc_output_events(&filter_1);
Expand Down Expand Up @@ -1416,13 +1398,8 @@ mod tests {
cache.insert_multi_it(events.into_iter());

let mut filter_1 = EventFilter {
start: None,
end: None,
emitter_address: Some(emit_addr_1),
original_caller_address: None,
original_operation_id: None,
is_final: None,
is_error: None,
..Default::default()
};

let (_, filtered_events_1) = cache.get_filtered_sc_output_events(&filter_1);
Expand Down Expand Up @@ -1529,13 +1506,8 @@ mod tests {
cache.insert_multi_it(events.into_iter());

let mut filter_1 = EventFilter {
start: None,
end: None,
emitter_address: None,
original_caller_address: Some(caller_addr_1),
original_operation_id: None,
is_final: None,
is_error: None,
..Default::default()
};

let (_, filtered_events_1) = cache.get_filtered_sc_output_events(&filter_1);
Expand Down Expand Up @@ -1638,17 +1610,11 @@ mod tests {
cache.insert_multi_it(events.into_iter());

let filter_1 = EventFilter {
start: None, // Some(Slot::new(2, 0)),
end: None,
emitter_address: None,
original_caller_address: None,
original_operation_id: None,
is_final: None,
is_error: Some(true),
..Default::default()
};

let (_, filtered_events_1) = cache.get_filtered_sc_output_events(&filter_1);

assert_eq!(filtered_events_1.len(), 1);
assert!(filtered_events_1[0].context.is_error);
assert_eq!(filtered_events_1[0].context.slot, slot_2);
Expand Down

0 comments on commit 025630f

Please sign in to comment.