Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Aleksanov <[email protected]>
  • Loading branch information
slumber and popzxc committed Oct 26, 2021
1 parent d0aeea9 commit 624ea74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions core/bin/zksync_core/src/eth_watch/eth_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl ETHState {
new_tokens: Vec<NewTokenEvent>,
register_nft_factory_events: Vec<RegisterNFTFactoryEvent>,
) -> Self {
assert!(
last_ethereum_block_backup <= last_ethereum_block,
"Backup block cannot be greater than last known block"
);
let next_priority_op_id = priority_queue
.keys()
.max()
Expand Down
38 changes: 25 additions & 13 deletions core/bin/zksync_core/src/eth_watch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ async fn test_restore_and_poll() {
])
.await;
watcher.poll_eth_node().await.unwrap();
dbg!(&watcher.eth_state);
assert_eq!(watcher.eth_state.last_ethereum_block(), 5);
let priority_queues = watcher.eth_state.priority_queue();
let unconfirmed_queue = watcher.eth_state.unconfirmed_queue();
Expand Down Expand Up @@ -484,20 +483,32 @@ async fn test_serial_id_gaps() {

// Add a gap.
client
.add_operations(&[PriorityOp {
serial_id: 3, // Then next id is expected to be 2.
data: deposit.clone(),
deadline_block: 0,
eth_hash: [2; 32].into(),
eth_block: 2,
eth_block_index: Some(1),
}])
.add_operations(&[
PriorityOp {
serial_id: 2,
data: deposit.clone(),
deadline_block: 0,
eth_hash: [2; 32].into(),
eth_block: 2,
eth_block_index: Some(1),
},
PriorityOp {
serial_id: 4, // Then next id is expected to be 3.
data: deposit.clone(),
deadline_block: 0,
eth_hash: [3; 32].into(),
eth_block: 2,
eth_block_index: Some(3),
},
])
.await;
client.set_last_block_number(3).await;
// Should detect a gap.
let err = watcher.poll_eth_node().await.unwrap_err();
assert!(is_missing_priority_op_error(&err));

// The partially valid update is still discarded and we're waiting
// for the serial_id = 2 even though it was present.
assert_eq!(watcher.eth_state.next_priority_op_id(), 2);
// The range got reset.
assert_eq!(watcher.eth_state.last_ethereum_block_backup(), 0);
Expand All @@ -506,16 +517,17 @@ async fn test_serial_id_gaps() {
// Add a missing operations to the processed range.
client
.add_operations(&[PriorityOp {
serial_id: 2,
serial_id: 3,
data: deposit.clone(),
deadline_block: 0,
eth_hash: [2; 32].into(),
eth_block: 1,
eth_block_index: Some(1),
eth_block: 2,
eth_block_index: Some(2),
}])
.await;
watcher.poll_eth_node().await.unwrap();
assert_eq!(watcher.eth_state.next_priority_op_id(), 4);
assert_eq!(watcher.eth_state.next_priority_op_id(), 5);
assert_eq!(watcher.eth_state.priority_queue().len(), 5);
assert_eq!(watcher.eth_state.last_ethereum_block_backup(), 0);
assert_eq!(watcher.eth_state.last_ethereum_block(), 3);
}

0 comments on commit 624ea74

Please sign in to comment.