Skip to content

Commit

Permalink
chore: Run clippy in tests (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc authored Jun 27, 2024
1 parent 788dc0a commit df89dca
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rust-doc:
lint:
cd e2e-tests && yarn && yarn lint && yarn fmt && yarn typecheck
cargo fmt --all -- --check
cargo clippy -p era_test_node -Zunstable-options -- -D warnings --allow clippy::unwrap_used
cargo clippy --tests -p era_test_node -Zunstable-options -- -D warnings --allow clippy::unwrap_used

# Fix lint errors for Rust code
lint-fix:
Expand Down
8 changes: 4 additions & 4 deletions src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,14 @@ mod tests {

let mut fork_storage = ForkStorage::new(Some(fork_details), &options);

assert_eq!(fork_storage.is_write_initial(&never_written_key), true);
assert_eq!(fork_storage.is_write_initial(&key_with_some_value), false);
assert!(fork_storage.is_write_initial(&never_written_key));
assert!(!fork_storage.is_write_initial(&key_with_some_value));
// This is the current limitation of the sytem. In theory, this should return false - as the value was written, but we don't have the API to the
// backend to get this information.
assert_eq!(fork_storage.is_write_initial(&key_with_value_0), true);
assert!(fork_storage.is_write_initial(&key_with_value_0));

// But writing any value there in the local storage (even 0) - should make it non-initial write immediately.
fork_storage.set_value(key_with_value_0, H256::zero());
assert_eq!(fork_storage.is_write_initial(&key_with_value_0), false);
assert!(!fork_storage.is_write_initial(&key_with_value_0));
}
}
34 changes: 17 additions & 17 deletions src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,23 @@ impl BlockContext {
}
}

pub fn load_last_l1_batch<S: ReadStorage>(storage: StoragePtr<S>) -> Option<(u64, u64)> {
// Get block number and timestamp
let current_l1_batch_info_key = StorageKey::new(
AccountTreeId::new(SYSTEM_CONTEXT_ADDRESS),
SYSTEM_CONTEXT_BLOCK_INFO_POSITION,
);
let mut storage_ptr = storage.borrow_mut();
let current_l1_batch_info = storage_ptr.read_value(&current_l1_batch_info_key);
let (batch_number, batch_timestamp) = unpack_block_info(h256_to_u256(current_l1_batch_info));
let block_number = batch_number as u32;
if block_number == 0 {
// The block does not exist yet
return None;
}
Some((batch_number, batch_timestamp))
}

#[cfg(test)]
mod tests {
use ethabi::{Token, Uint};
Expand Down Expand Up @@ -2006,20 +2023,3 @@ mod tests {
}
}
}

pub fn load_last_l1_batch<S: ReadStorage>(storage: StoragePtr<S>) -> Option<(u64, u64)> {
// Get block number and timestamp
let current_l1_batch_info_key = StorageKey::new(
AccountTreeId::new(SYSTEM_CONTEXT_ADDRESS),
SYSTEM_CONTEXT_BLOCK_INFO_POSITION,
);
let mut storage_ptr = storage.borrow_mut();
let current_l1_batch_info = storage_ptr.read_value(&current_l1_batch_info_key);
let (batch_number, batch_timestamp) = unpack_block_info(h256_to_u256(current_l1_batch_info));
let block_number = batch_number as u32;
if block_number == 0 {
// The block does not exist yet
return None;
}
Some((batch_number, batch_timestamp))
}
1 change: 0 additions & 1 deletion src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,6 @@ mod test {

let actual_bytecode = storage
.get_bytecode_by_hash(H256::repeat_byte(0x1))
.ok()
.expect("failed getting bytecode")
.expect("missing bytecode");
assert_eq!(input_bytecode, actual_bytecode);
Expand Down
12 changes: 6 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ pub fn internal_error(method_name: &'static str, error: impl fmt::Display) -> We
// Ok(Address::from(address.0))
// }

/// Converts `h256` value as BE into the u64
pub fn h256_to_u64(value: H256) -> u64 {
let be_u64_bytes: [u8; 8] = value[24..].try_into().unwrap();
u64::from_be_bytes(be_u64_bytes)
}

#[cfg(test)]
mod tests {
use zksync_basic_types::{H256, U256};
Expand Down Expand Up @@ -512,9 +518,3 @@ mod tests {
}
}
}

/// Converts `h256` value as BE into the u64
pub fn h256_to_u64(value: H256) -> u64 {
let be_u64_bytes: [u8; 8] = value[24..].try_into().unwrap();
u64::from_be_bytes(be_u64_bytes)
}

0 comments on commit df89dca

Please sign in to comment.