diff --git a/src/entry.rs b/src/entry.rs index 3555834e971f0f..19e4d13d8c2a72 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -109,6 +109,7 @@ fn next_hash(start_hash: &Hash, num_hashes: u64, transactions: &[Transaction]) - /// Creates the next Tick or Transaction Entry `num_hashes` after `start_hash`. pub fn next_entry(start_hash: &Hash, num_hashes: u64, transactions: Vec) -> Entry { + assert!(num_hashes > 0 || transactions.len() == 0); Entry { num_hashes, id: next_hash(start_hash, num_hashes, &transactions), @@ -180,4 +181,13 @@ mod tests { assert_eq!(tick.num_hashes, 0); assert_eq!(tick.id, zero); } + + #[test] + #[should_panic] + fn test_next_entry_panic() { + let zero = Hash::default(); + let keypair = KeyPair::new(); + let tx = Transaction::new(&keypair, keypair.pubkey(), 0, zero); + next_entry(&zero, 0, vec![tx]); + } } diff --git a/src/ledger.rs b/src/ledger.rs index 3e792d35e1b959..6eaf3b1f26932c 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -179,13 +179,13 @@ mod tests { let tx0 = Transaction::new(&keypair, keypair.pubkey(), 1, next_id); let transactions = vec![tx0; 5]; let transaction_batches = vec![transactions.clone(); 5]; - let entries0 = next_entries(&id, 0, transaction_batches); + let entries0 = next_entries(&id, 1, transaction_batches); assert_eq!(entries0.len(), 5); let mut entries1 = vec![]; for _ in 0..5 { - let entry = next_entry(&id, 0, transactions.clone()); + let entry = next_entry(&id, 1, transactions.clone()); id = entry.id; entries1.push(entry); }