Skip to content

Commit 8faf048

Browse files
starknet_os_flow_tests: migrate test_declare_and_deploy_in_separate_blocks
1 parent 0fc55c9 commit 8faf048

File tree

1 file changed

+71
-0
lines changed
  • crates/starknet_os_flow_tests/src

1 file changed

+71
-0
lines changed

crates/starknet_os_flow_tests/src/tests.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,3 +2639,74 @@ async fn test_meta_tx() {
26392639
test_output.assert_storage_diff_eq(meta_tx_contract_address, expected_meta_tx_contract_diffs);
26402640
test_output.assert_storage_diff_eq(tx_info_contract_address, expected_tx_info_writer_diffs);
26412641
}
2642+
2643+
#[rstest]
2644+
#[tokio::test]
2645+
/// Verifies that a contract can be declared in one block and deployed in a later block:
2646+
/// 1. Class declarations persist across block boundaries.
2647+
/// 2. The deployed contract's storage is properly initialized.
2648+
/// 3. The class hash to compiled class hash mapping appears in the state diff.
2649+
async fn test_declare_and_deploy_in_separate_blocks() {
2650+
let (mut test_manager, _) =
2651+
TestManager::<DictStateReader>::new_with_default_initial_state([]).await;
2652+
2653+
// Declare a test contract.
2654+
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
2655+
let test_contract_sierra = test_contract.get_sierra();
2656+
let class_hash = test_contract_sierra.calculate_class_hash();
2657+
let compiled_class_hash = test_contract.get_compiled_class_hash(&HashVersion::V2);
2658+
let declare_tx_args = declare_tx_args! {
2659+
sender_address: *FUNDED_ACCOUNT_ADDRESS,
2660+
class_hash,
2661+
compiled_class_hash,
2662+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
2663+
nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
2664+
};
2665+
let account_declare_tx = declare_tx(declare_tx_args);
2666+
let class_info = get_class_info_of_feature_contract(test_contract);
2667+
let tx =
2668+
DeclareTransaction::create(account_declare_tx, class_info, &CHAIN_ID_FOR_TESTS).unwrap();
2669+
test_manager.add_cairo1_declare_tx(tx, &test_contract_sierra);
2670+
2671+
// Move on to the next block, with an empty block in between.
2672+
test_manager.move_to_next_block();
2673+
test_manager.move_to_next_block();
2674+
2675+
// Deploy the test contract using the deploy contract syscall.
2676+
let (constructor_arg1, constructor_arg2) = (Felt::from(7), Felt::from(90));
2677+
let salt = ContractAddressSalt(Felt::ZERO);
2678+
let (deploy_tx, address) = get_deploy_contract_tx_and_address_with_salt(
2679+
class_hash,
2680+
calldata![constructor_arg1, constructor_arg2],
2681+
test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS),
2682+
*NON_TRIVIAL_RESOURCE_BOUNDS,
2683+
salt,
2684+
);
2685+
test_manager.add_invoke_tx(deploy_tx, None);
2686+
2687+
// Run the test and verify the storage changes.
2688+
let test_output = test_manager
2689+
.execute_test_with_default_block_contexts(&TestParameters {
2690+
use_kzg_da: true,
2691+
..Default::default()
2692+
})
2693+
.await;
2694+
test_output.perform_default_validations();
2695+
// The test contract constructor writes the sum of the two input arguments to storage.
2696+
test_output.assert_storage_diff_eq(
2697+
address,
2698+
HashMap::from([(
2699+
**get_storage_var_address("my_storage_var", &[]),
2700+
constructor_arg1 + constructor_arg2,
2701+
)]),
2702+
);
2703+
assert_eq!(
2704+
test_output
2705+
.decompressed_state_diff
2706+
.class_hash_to_compiled_class_hash
2707+
.get(&class_hash)
2708+
.unwrap()
2709+
.0,
2710+
compiled_class_hash.0
2711+
);
2712+
}

0 commit comments

Comments
 (0)