Skip to content

Commit

Permalink
refactor(gateway): return the Blockifier error in StatefulTransaction…
Browse files Browse the repository at this point in the history
…ValidatorTrait
  • Loading branch information
yair-starkware committed Jul 24, 2024
1 parent fc5813a commit 6f8b965
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 14 additions & 6 deletions crates/gateway/src/stateful_transaction_validator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use blockifier::blockifier::block::BlockInfo;
use blockifier::blockifier::stateful_validator::{StatefulValidator, StatefulValidatorResult};
use blockifier::blockifier::stateful_validator::{
StatefulValidator, StatefulValidatorResult as BlockifierStatefulValidatorResult,
};
use blockifier::bouncer::BouncerConfig;
use blockifier::context::BlockContext;
use blockifier::execution::contract_class::ClassInfo;
Expand Down Expand Up @@ -35,21 +37,27 @@ pub trait StatefulTransactionValidatorTrait {
&mut self,
account_tx: AccountTransaction,
skip_validate: bool,
) -> StatefulTransactionValidatorResult<()>;
) -> BlockifierStatefulValidatorResult<()>;

fn get_nonce(&mut self, account_address: ContractAddress) -> StatefulValidatorResult<Nonce>;
fn get_nonce(
&mut self,
account_address: ContractAddress,
) -> BlockifierStatefulValidatorResult<Nonce>;
}

impl StatefulTransactionValidatorTrait for BlockifierStatefulValidator {
fn validate(
&mut self,
account_tx: AccountTransaction,
skip_validate: bool,
) -> StatefulTransactionValidatorResult<()> {
Ok(self.perform_validations(account_tx, skip_validate)?)
) -> BlockifierStatefulValidatorResult<()> {
self.perform_validations(account_tx, skip_validate)
}

fn get_nonce(&mut self, account_address: ContractAddress) -> StatefulValidatorResult<Nonce> {
fn get_nonce(
&mut self,
account_address: ContractAddress,
) -> BlockifierStatefulValidatorResult<Nonce> {
self.get_nonce(account_address)
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/gateway/src/stateful_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ fn test_stateful_tx_validator(
let expected_result_msg = format!("{:?}", expected_result);

let mut mock_validator = MockStatefulTransactionValidatorTrait::new();
mock_validator.expect_validate().return_once(|_, _| expected_result.map(|_| ()));
mock_validator.expect_validate().return_once(|_, _| match expected_result {
Ok(_) => Ok(()),
Err(StatefulTransactionValidatorError::StatefulValidatorError(err)) => Err(err),
_ => panic!("Expecting StatefulTransactionValidatorError::StatefulValidatorError"),
});
mock_validator.expect_get_nonce().returning(|_| Ok(Nonce(Felt::ZERO)));

let result = stateful_validator.run_validate(&external_tx, optional_class_info, mock_validator);
Expand Down

0 comments on commit 6f8b965

Please sign in to comment.