Skip to content

Commit

Permalink
fix validation test
Browse files Browse the repository at this point in the history
It was breaking because validation and execution would have required different VMs.
I fixed that by setting the type of rule violation without actually running a transaction.
  • Loading branch information
joonazan committed Oct 30, 2024
1 parent 9ec83f2 commit 7525074
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
42 changes: 16 additions & 26 deletions core/lib/multivm/src/versions/testonly/account_validation_rules.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use assert_matches::assert_matches;
use ethabi::Token;
use zksync_types::{
fee::Fee, l2::L2Tx, transaction_request::TransactionRequest, Address, Eip712Domain, Execute,
L2ChainId, U256,
fee::Fee, l2::L2Tx, transaction_request::TransactionRequest, AccountTreeId, Address,
Eip712Domain, L2ChainId, StorageKey, U256,
};
use zksync_vm_interface::{tracer::ViolatedValidationRule, InspectExecutionMode, VmInterfaceExt};
use zksync_utils::u256_to_h256;
use zksync_vm_interface::tracer::ViolatedValidationRule;

use super::{
read_validation_test_contract, tester::VmTesterBuilder, ContractToDeploy, TestedVm,
TestedVmForValidation,
get_empty_storage, read_validation_test_contract, tester::VmTesterBuilder, ContractToDeploy,
TestedVm, TestedVmForValidation,
};
use crate::interface::TxExecutionMode;

Expand Down Expand Up @@ -40,35 +40,25 @@ fn test_rule<VM: TestedVm + TestedVmForValidation>(rule: u32) -> Option<Violated
let aa_address = Address::repeat_byte(0x10);
let beneficiary_address = Address::repeat_byte(0x20);

let (bytecode, contract) = read_validation_test_contract();
// Set the type of misbehaviour of the AA contract
let mut storage_with_rule_break_set = get_empty_storage();
storage_with_rule_break_set.set_value(
StorageKey::new(AccountTreeId::new(aa_address), u256_to_h256(0.into())),
u256_to_h256(rule.into()),
);

let bytecode = read_validation_test_contract();
let mut vm = VmTesterBuilder::new()
.with_empty_in_memory_storage()
.with_custom_contracts(vec![
ContractToDeploy::account(bytecode, aa_address).funded()
])
.with_storage(storage_with_rule_break_set)
.with_execution_mode(TxExecutionMode::VerifyExecute)
.with_rich_accounts(1)
.build::<VM>();

let mut private_account = vm.rich_accounts[0].clone();

// Set the type of misbehaviour of the AA contract
let function = contract.function("setTypeOfRuleBreak").unwrap();
let transaction = private_account.get_l2_tx_for_execute(
Execute {
contract_address: Some(aa_address),
calldata: function.encode_input(&[Token::Uint(rule.into())]).unwrap(),
value: U256::zero(),
factory_deps: vec![],
},
None,
);
vm.vm.push_transaction(transaction);
assert!(!vm
.vm
.execute(InspectExecutionMode::OneTx)
.result
.is_failed());
let private_account = vm.rich_accounts[0].clone();

// Use account abstraction
let chain_id: u32 = 270;
Expand Down
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/testonly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ pub(crate) fn read_simple_transfer_contract() -> Vec<u8> {
)
}

pub(crate) fn read_validation_test_contract() -> (Vec<u8>, Contract) {
pub(crate) fn read_validation_test_contract() -> Vec<u8> {
let path = "etc/contracts-test-data/artifacts-zk/contracts/custom-account/validation-rule-breaker.sol/ValidationRuleBreaker.json";
(read_bytecode(path), load_contract(path))
read_bytecode(path)
}

pub(crate) fn get_bootloader(test: &str) -> SystemContractCode {
Expand Down

0 comments on commit 7525074

Please sign in to comment.