Skip to content

Commit

Permalink
chore: replace assert!(matches!(...)) with assert_matches!(...) (#…
Browse files Browse the repository at this point in the history
…2723)

## What ❔

Replace `assert!(matches!(...))` with `assert_matches!(...)`.

## Why ❔

To make the code more idiomatic.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
pbeza authored Aug 28, 2024
1 parent bf03274 commit 268e66f
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 65 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ impl VmRevertReasonParsingResult {
mod tests {
use std::convert::TryFrom;

use assert_matches::assert_matches;

use super::VmRevertReason;

#[test]
Expand Down Expand Up @@ -202,7 +204,7 @@ mod tests {
0, 0, 0, 0, 0, 0, 0, 0, 0,
];
let reason = VmRevertReason::try_from(msg.as_slice()).expect("Shouldn't be error");
assert!(matches!(reason, VmRevertReason::Unknown { .. }));
assert_matches!(reason, VmRevertReason::Unknown { .. });
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/vm_1_4_1/tests/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
10 changes: 5 additions & 5 deletions core/lib/multivm/src/versions/vm_1_4_1/tests/simple_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -71,11 +71,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/vm_1_4_2/tests/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
10 changes: 5 additions & 5 deletions core/lib/multivm/src/versions/vm_1_4_2/tests/simple_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -68,11 +68,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -71,11 +71,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
5 changes: 3 additions & 2 deletions core/lib/multivm/src/versions/vm_fast/tests/bootloader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use assert_matches::assert_matches;
use zksync_types::U256;

use crate::{
Expand Down Expand Up @@ -44,10 +45,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
12 changes: 7 additions & 5 deletions core/lib/multivm/src/versions/vm_fast/tests/simple_execution.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use assert_matches::assert_matches;

use crate::{
interface::{ExecutionResult, VmExecutionMode, VmInterface},
vm_fast::tests::tester::{TxType, VmTesterBuilder},
Expand Down Expand Up @@ -25,7 +27,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -68,11 +70,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
5 changes: 3 additions & 2 deletions core/lib/multivm/src/versions/vm_latest/tests/bootloader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use assert_matches::assert_matches;
use zksync_types::U256;

use crate::{
Expand Down Expand Up @@ -47,10 +48,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use assert_matches::assert_matches;

use crate::{
interface::{ExecutionResult, VmExecutionMode, VmInterface},
vm_latest::{
Expand Down Expand Up @@ -28,7 +30,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -71,11 +73,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ impl VmRevertReasonParsingResult {
mod tests {
use std::convert::TryFrom;

use assert_matches::assert_matches;

use super::VmRevertReason;

#[test]
Expand Down Expand Up @@ -182,7 +184,7 @@ mod tests {
0, 0, 0, 0, 0, 0, 0, 0, 0,
];
let reason = VmRevertReason::try_from(msg.as_slice()).expect("Shouldn't be error");
assert!(matches!(reason, VmRevertReason::Unknown { .. }));
assert_matches!(reason, VmRevertReason::Unknown { .. });
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ impl VmRevertReasonParsingResult {
mod tests {
use std::convert::TryFrom;

use assert_matches::assert_matches;

use super::VmRevertReason;

#[test]
Expand Down Expand Up @@ -202,7 +204,7 @@ mod tests {
0, 0, 0, 0, 0, 0, 0, 0, 0,
];
let reason = VmRevertReason::try_from(msg.as_slice()).expect("Shouldn't be error");
assert!(matches!(reason, VmRevertReason::Unknown { .. }));
assert_matches!(reason, VmRevertReason::Unknown { .. });
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -67,11 +67,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ fn test_bootloader_out_of_gas() {

let res = vm.vm.execute(VmExecutionMode::Batch);

assert!(matches!(
assert_matches!(
res.result,
ExecutionResult::Halt {
reason: Halt::BootloaderOutOfGas
}
));
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn estimate_fee() {
vm_tester.vm.push_transaction(tx);

let result = vm_tester.vm.execute(VmExecutionMode::OneTx);
assert!(matches!(result.result, ExecutionResult::Success { .. }));
assert_matches!(result.result, ExecutionResult::Success { .. });
}

#[test]
Expand Down Expand Up @@ -67,11 +67,11 @@ fn simple_execute() {
vm.push_transaction(tx2);
vm.push_transaction(tx3);
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Revert { .. }));
assert_matches!(tx.result, ExecutionResult::Revert { .. });
let tx = vm.execute(VmExecutionMode::OneTx);
assert!(matches!(tx.result, ExecutionResult::Success { .. }));
assert_matches!(tx.result, ExecutionResult::Success { .. });
let block_tip = vm.execute(VmExecutionMode::Batch);
assert!(matches!(block_tip.result, ExecutionResult::Success { .. }));
assert_matches!(block_tip.result, ExecutionResult::Success { .. });
}
1 change: 1 addition & 0 deletions core/lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ blake2.workspace = true

[dev-dependencies]
tokio = { workspace = true, features = ["rt", "macros"] }
assert_matches.workspace = true
bincode.workspace = true

[build-dependencies]
Expand Down
Loading

0 comments on commit 268e66f

Please sign in to comment.