|
1 | 1 | use std::collections::{HashMap, HashSet}; |
2 | 2 | use std::sync::{Arc, LazyLock}; |
3 | 3 |
|
| 4 | +use assert_matches::assert_matches; |
4 | 5 | use blockifier::abi::constants::STORED_BLOCK_HASH_BUFFER; |
5 | 6 | use blockifier::blockifier_versioned_constants::VersionedConstants; |
6 | 7 | use blockifier::test_utils::contracts::FeatureContractTrait; |
@@ -90,6 +91,8 @@ use crate::initial_state::{ |
90 | 91 | get_deploy_contract_tx_and_address_with_salt, |
91 | 92 | }; |
92 | 93 | use crate::special_contracts::{ |
| 94 | + DATA_GAS_ACCOUNT_CONTRACT_CASM, |
| 95 | + DATA_GAS_ACCOUNT_CONTRACT_SIERRA, |
93 | 96 | V1_BOUND_CAIRO0_CONTRACT, |
94 | 97 | V1_BOUND_CAIRO1_CONTRACT_CASM, |
95 | 98 | V1_BOUND_CAIRO1_CONTRACT_SIERRA, |
@@ -2325,3 +2328,66 @@ async fn test_resources_type() { |
2325 | 2328 | test_output.assert_storage_diff_eq(cairo_steps_contract_address, HashMap::default()); |
2326 | 2329 | test_output.assert_storage_diff_eq(sierra_gas_contract_address, expected_storage_updates); |
2327 | 2330 | } |
| 2331 | + |
| 2332 | +/// Runs the OS test for data gas Cairo1 accounts. |
| 2333 | +#[rstest] |
| 2334 | +#[tokio::test] |
| 2335 | +async fn test_data_gas_accounts() { |
| 2336 | + let test_contract_sierra = &DATA_GAS_ACCOUNT_CONTRACT_SIERRA; |
| 2337 | + let test_contract_casm = &DATA_GAS_ACCOUNT_CONTRACT_CASM; |
| 2338 | + let class_hash = test_contract_sierra.calculate_class_hash(); |
| 2339 | + let compiled_class_hash = test_contract_casm.hash(&HashVersion::V2); |
| 2340 | + assert!( |
| 2341 | + VersionedConstants::latest_constants().os_constants.data_gas_accounts.contains(&class_hash) |
| 2342 | + ); |
| 2343 | + let (mut test_manager, _) = |
| 2344 | + TestManager::<DictStateReader>::new_with_default_initial_state([]).await; |
| 2345 | + |
| 2346 | + // Declare the data gas account. |
| 2347 | + let declare_args = declare_tx_args! { |
| 2348 | + sender_address: *FUNDED_ACCOUNT_ADDRESS, |
| 2349 | + nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), |
| 2350 | + class_hash, |
| 2351 | + compiled_class_hash, |
| 2352 | + resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, |
| 2353 | + }; |
| 2354 | + let account_declare_tx = declare_tx(declare_args); |
| 2355 | + let sierra_version = test_contract_sierra.get_sierra_version().unwrap(); |
| 2356 | + let class_info = ClassInfo { |
| 2357 | + contract_class: ContractClass::V1(((**test_contract_casm).clone(), sierra_version.clone())), |
| 2358 | + sierra_program_length: test_contract_sierra.sierra_program.len(), |
| 2359 | + abi_length: test_contract_sierra.abi.len(), |
| 2360 | + sierra_version, |
| 2361 | + }; |
| 2362 | + let tx = |
| 2363 | + DeclareTransaction::create(account_declare_tx, class_info, &CHAIN_ID_FOR_TESTS).unwrap(); |
| 2364 | + test_manager.add_cairo1_declare_tx(tx, test_contract_sierra); |
| 2365 | + |
| 2366 | + // Deploy it (from funded account). |
| 2367 | + let salt = ContractAddressSalt(Felt::ZERO); |
| 2368 | + let (deploy_tx, data_gas_account_address) = get_deploy_contract_tx_and_address_with_salt( |
| 2369 | + class_hash, |
| 2370 | + calldata![], |
| 2371 | + test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), |
| 2372 | + *NON_TRIVIAL_RESOURCE_BOUNDS, |
| 2373 | + salt, |
| 2374 | + ); |
| 2375 | + test_manager.add_invoke_tx(deploy_tx, None); |
| 2376 | + |
| 2377 | + // Create and run an invoke tx. |
| 2378 | + let invoke_args = invoke_tx_args! { |
| 2379 | + sender_address: *FUNDED_ACCOUNT_ADDRESS, |
| 2380 | + nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), |
| 2381 | + calldata: create_calldata(data_gas_account_address, "test_resource_bounds", &[]), |
| 2382 | + resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, |
| 2383 | + }; |
| 2384 | + let tx = InvokeTransaction::create(invoke_tx(invoke_args), &CHAIN_ID_FOR_TESTS).unwrap(); |
| 2385 | + assert_eq!(tx.version(), TransactionVersion::THREE); |
| 2386 | + assert_matches!(tx.resource_bounds(), ValidResourceBounds::AllResources(_)); |
| 2387 | + test_manager.add_invoke_tx(tx, None); |
| 2388 | + |
| 2389 | + // Run test. |
| 2390 | + let test_output = |
| 2391 | + test_manager.execute_test_with_default_block_contexts(&TestParameters::default()).await; |
| 2392 | + test_output.perform_default_validations(); |
| 2393 | +} |
0 commit comments