Skip to content

Commit

Permalink
Add assertion for now next_entry must be called
Browse files Browse the repository at this point in the history
  • Loading branch information
garious committed Jun 22, 2018
1 parent fe9a1c8 commit fad9d20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction>) -> Entry {
assert!(num_hashes > 0 || transactions.len() == 0);
Entry {
num_hashes,
id: next_hash(start_hash, num_hashes, &transactions),
Expand Down Expand Up @@ -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]);
}
}
4 changes: 2 additions & 2 deletions src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit fad9d20

Please sign in to comment.