Skip to content

Commit fdc06d5

Browse files
starknet_os_flow_tests: migrate test_declare_and_deploy_in_separate_blocks
1 parent 90a9881 commit fdc06d5

File tree

1 file changed

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

1 file changed

+63
-0
lines changed

crates/starknet_os_flow_tests/src/tests.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,3 +2805,66 @@ async fn test_meta_tx() {
28052805
test_output.assert_storage_diff_eq(meta_tx_contract_address, expected_meta_tx_contract_diffs);
28062806
test_output.assert_storage_diff_eq(tx_info_contract_address, expected_tx_info_writer_diffs);
28072807
}
2808+
2809+
#[rstest]
2810+
#[tokio::test]
2811+
async fn test_declare_and_deploy_in_separate_blocks() {
2812+
let (mut test_manager, mut nonce_manager, _) =
2813+
TestManager::<DictStateReader>::new_with_default_initial_state([]).await;
2814+
2815+
// Declare a test contract.
2816+
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
2817+
let test_contract_sierra = test_contract.get_sierra();
2818+
let class_hash = test_contract_sierra.calculate_class_hash();
2819+
let compiled_class_hash = test_contract.get_compiled_class_hash(&HashVersion::V2);
2820+
let declare_tx_args = declare_tx_args! {
2821+
sender_address: *FUNDED_ACCOUNT_ADDRESS,
2822+
class_hash,
2823+
compiled_class_hash,
2824+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
2825+
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
2826+
};
2827+
let account_declare_tx = declare_tx(declare_tx_args);
2828+
let class_info = get_class_info_of_feature_contract(test_contract);
2829+
let tx =
2830+
DeclareTransaction::create(account_declare_tx, class_info, &CHAIN_ID_FOR_TESTS).unwrap();
2831+
test_manager.add_cairo1_declare_tx(tx, &test_contract_sierra);
2832+
2833+
// Move on to the next block, with an empty block in between.
2834+
test_manager.move_to_next_block();
2835+
test_manager.move_to_next_block();
2836+
2837+
// Deploy the test contract using the deploy contract syscall.
2838+
let (arg1, arg2) = (Felt::from(7), Felt::from(90));
2839+
let salt = Felt::ZERO;
2840+
let (deploy_tx, address) = get_deploy_contract_tx_and_address_with_salt(
2841+
class_hash,
2842+
calldata![arg1, arg2],
2843+
nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
2844+
*NON_TRIVIAL_RESOURCE_BOUNDS,
2845+
salt,
2846+
);
2847+
test_manager.add_invoke_tx(deploy_tx, None);
2848+
2849+
// Run the test and verify the storage changes.
2850+
let test_output = test_manager
2851+
.execute_test_with_default_block_contexts(&TestParameters {
2852+
use_kzg_da: true,
2853+
..Default::default()
2854+
})
2855+
.await;
2856+
test_output.perform_default_validations();
2857+
test_output.assert_storage_diff_eq(
2858+
address,
2859+
HashMap::from([(**get_storage_var_address("my_storage_var", &[]), arg1 + arg2)]),
2860+
);
2861+
assert_eq!(
2862+
test_output
2863+
.decompressed_state_diff
2864+
.class_hash_to_compiled_class_hash
2865+
.get(&class_hash)
2866+
.unwrap()
2867+
.0,
2868+
compiled_class_hash.0
2869+
);
2870+
}

0 commit comments

Comments
 (0)