Skip to content

Commit

Permalink
assert on snapshot as well
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed May 9, 2024
1 parent 456926d commit 406fca6
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions crates/katana/storage/provider/src/providers/fork/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ impl StateProvider for ForkedSnapshot {
.inner
.contract_state
.get(&address)
.map(|info| info.nonce)
.filter(|n| n != &Nonce::ZERO)
.filter(|c| c.nonce != Nonce::default() || c.class_hash != ClassHash::default())
.map(|c| c.nonce)
{
return Ok(nonce);
}
Expand Down Expand Up @@ -235,12 +235,16 @@ mod tests {

// Case: contract doesn't exist at all
{
let forked_state = SharedStateProvider::new_with_backend(backend.clone());
let state = ForkedStateDb::new(forked_state.clone());
let remote = SharedStateProvider::new_with_backend(backend.clone());
let local = ForkedStateDb::new(remote.clone());

// asserts that its error for now
assert!(state.nonce(address).is_err());
assert!(forked_state.nonce(address).is_err());
assert!(local.nonce(address).is_err());
assert!(remote.nonce(address).is_err());

// make sure the snapshot maintains the same behavior
let snapshot = local.create_snapshot();
assert!(snapshot.nonce(address).is_err());
}

// Case: contract exist remotely
Expand All @@ -257,6 +261,10 @@ mod tests {

assert_eq!(local.nonce(address).unwrap(), Some(remote_nonce));
assert_eq!(remote.nonce(address).unwrap(), Some(remote_nonce));

// make sure the snapshot maintains the same behavior
let snapshot = local.create_snapshot();
assert_eq!(snapshot.nonce(address).unwrap(), Some(remote_nonce));
}

// Case: contract exist remotely but nonce was updated locally
Expand Down Expand Up @@ -285,6 +293,10 @@ mod tests {

assert_eq!(local.nonce(address).unwrap(), Some(local_nonce));
assert_eq!(remote.nonce(address).unwrap(), Some(remote_nonce));

// make sure the snapshot maintains the same behavior
let snapshot = local.create_snapshot();
assert_eq!(snapshot.nonce(address).unwrap(), Some(local_nonce));
}

// Case: contract was deployed locally only and has non-zero nonce
Expand All @@ -306,6 +318,10 @@ mod tests {

assert_eq!(local.nonce(address).unwrap(), Some(local_nonce));
assert!(remote.nonce(address).is_err());

// make sure the snapshot maintains the same behavior
let snapshot = local.create_snapshot();
assert_eq!(snapshot.nonce(address).unwrap(), Some(local_nonce));
}

// Case: contract was deployed locally only and has zero nonce
Expand All @@ -322,6 +338,10 @@ mod tests {

assert_eq!(local.nonce(address).unwrap(), Some(Default::default()));
assert!(remote.nonce(address).is_err());

// make sure the snapshot maintains the same behavior
let snapshot = local.create_snapshot();
assert_eq!(snapshot.nonce(address).unwrap(), Some(Default::default()));
}
}
}

0 comments on commit 406fca6

Please sign in to comment.