Skip to content

Commit

Permalink
chore: add declare_tx fixture to compilation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Aug 1, 2024
1 parent ac83ee0 commit 56c45e8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions crates/gateway/src/compilation_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use assert_matches::assert_matches;
use blockifier::execution::contract_class::ContractClass;
use cairo_lang_starknet_classes::allowed_libfuncs::AllowedLibfuncsError;
use mempool_test_utils::starknet_api_test_utils::declare_tx;
use mempool_test_utils::starknet_api_test_utils::declare_tx as rpc_declare_tx;
use rstest::{fixture, rstest};
use starknet_api::core::CompiledClassHash;
use starknet_api::rpc_transaction::{RpcDeclareTransaction, RpcTransaction};
Expand All @@ -15,13 +15,21 @@ fn gateway_compiler() -> GatewayCompiler {
GatewayCompiler { config: Default::default() }
}

#[fixture]
fn declare_tx() -> RpcDeclareTransaction {
assert_matches!(
rpc_declare_tx(),
RpcTransaction::Declare(declare_tx) => declare_tx
)
}

// TODO(Arni): Redesign this test once the compiler is passed with dependancy injection.
#[rstest]
fn test_compile_contract_class_compiled_class_hash_mismatch(gateway_compiler: GatewayCompiler) {
let mut tx = assert_matches!(
declare_tx(),
RpcTransaction::Declare(RpcDeclareTransaction::V3(tx)) => tx
);
fn test_compile_contract_class_compiled_class_hash_mismatch(
gateway_compiler: GatewayCompiler,
declare_tx: RpcDeclareTransaction,
) {
let RpcDeclareTransaction::V3(mut tx) = declare_tx;
let expected_hash = tx.compiled_class_hash;
let wrong_supplied_hash = CompiledClassHash::default();
tx.compiled_class_hash = wrong_supplied_hash;
Expand All @@ -36,11 +44,11 @@ fn test_compile_contract_class_compiled_class_hash_mismatch(gateway_compiler: Ga
}

#[rstest]
fn test_compile_contract_class_bad_sierra(gateway_compiler: GatewayCompiler) {
let mut tx = assert_matches!(
declare_tx(),
RpcTransaction::Declare(RpcDeclareTransaction::V3(tx)) => tx
);
fn test_compile_contract_class_bad_sierra(
gateway_compiler: GatewayCompiler,
declare_tx: RpcDeclareTransaction,
) {
let RpcDeclareTransaction::V3(mut tx) = declare_tx;
// Truncate the sierra program to trigger an error.
tx.contract_class.sierra_program = tx.contract_class.sierra_program[..100].to_vec();
let declare_tx = RpcDeclareTransaction::V3(tx);
Expand All @@ -55,11 +63,10 @@ fn test_compile_contract_class_bad_sierra(gateway_compiler: GatewayCompiler) {
}

#[rstest]
fn test_process_declare_tx_success(gateway_compiler: GatewayCompiler) {
let declare_tx = assert_matches!(
declare_tx(),
RpcTransaction::Declare(declare_tx) => declare_tx
);
fn test_process_declare_tx_success(
gateway_compiler: GatewayCompiler,
declare_tx: RpcDeclareTransaction,
) {
let RpcDeclareTransaction::V3(declare_tx_v3) = &declare_tx;
let contract_class = &declare_tx_v3.contract_class;

Expand Down

0 comments on commit 56c45e8

Please sign in to comment.