diff --git a/massa-db-worker/src/massa_db.rs b/massa-db-worker/src/massa_db.rs index 6a4e2e018f..ef592800d7 100644 --- a/massa-db-worker/src/massa_db.rs +++ b/massa-db-worker/src/massa_db.rs @@ -349,8 +349,8 @@ where change_id: Option, reset_history: bool, ) -> Result<(), MassaDBError> { - if let Some(change_id) = change_id.clone() { - if change_id < self.get_change_id().expect(CHANGE_ID_DESER_ERROR) { + if let Some(change_id) = change_id.as_ref() { + if *change_id < self.get_change_id().expect(CHANGE_ID_DESER_ERROR) { return Err(MassaDBError::InvalidChangeID(String::from( "change_id should monotonically increase after every write", ))); diff --git a/massa-execution-worker/src/active_history.rs b/massa-execution-worker/src/active_history.rs index db6079080b..fa9beca03a 100644 --- a/massa-execution-worker/src/active_history.rs +++ b/massa-execution-worker/src/active_history.rs @@ -254,11 +254,11 @@ impl ActiveHistory { return SlotIndexPosition::Past; // too old } let index: usize = match slot.slots_since(first_slot, thread_count) { - Err(_) => return SlotIndexPosition::Past, // overflow + Err(_) => return SlotIndexPosition::Past, // first_slot > slot - see slots_since docstring Ok(d) => { match d.try_into() { Ok(d) => d, - Err(_) => return SlotIndexPosition::Future, // usize overflow + Err(_) => return SlotIndexPosition::Future, // conversion from u64 to usize fail } } }; diff --git a/massa-ledger-worker/src/ledger_db.rs b/massa-ledger-worker/src/ledger_db.rs index a2e517d6f0..f428a5584e 100644 --- a/massa-ledger-worker/src/ledger_db.rs +++ b/massa-ledger-worker/src/ledger_db.rs @@ -697,4 +697,28 @@ mod tests { assert_eq!(end_prefix(&[5, 6, 7]), Some(vec![5, 6, 8])); assert_eq!(end_prefix(&[5, 6, 255]), Some(vec![5, 7])); } + + #[test] + fn test_ledger_delete() { + let keypair = KeyPair::generate(0).unwrap(); + let addr = Address::from_public_key(&keypair.get_public_key()); + let (ledger_db, _data) = init_test_ledger(addr); + + let datastore = ledger_db.get_entire_datastore(&addr); + // println!("datastore: {:?}", datastore); + assert!(!datastore.is_empty()); + + let mut batch = DBBatch::new(); + let guard = ledger_db.db.read(); + delete_datastore_entries(&addr, &guard, &mut batch); + drop(guard); + + let mut guard = ledger_db.db.write(); + guard.write_batch(batch, Default::default(), None); + drop(guard); + + let datastore = ledger_db.get_entire_datastore(&addr); + // println!("datastore: {:?}", datastore); + assert!(datastore.is_empty()); + } }