|
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; |
@@ -92,6 +93,8 @@ use crate::initial_state::{ |
92 | 93 | get_deploy_contract_tx_and_address_with_salt, |
93 | 94 | }; |
94 | 95 | use crate::special_contracts::{ |
| 96 | + DATA_GAS_ACCOUNT_CONTRACT_CASM, |
| 97 | + DATA_GAS_ACCOUNT_CONTRACT_SIERRA, |
95 | 98 | V1_BOUND_CAIRO0_CONTRACT, |
96 | 99 | V1_BOUND_CAIRO1_CONTRACT_CASM, |
97 | 100 | V1_BOUND_CAIRO1_CONTRACT_SIERRA, |
@@ -2266,3 +2269,66 @@ async fn test_resources_type() { |
2266 | 2269 | test_output.assert_storage_diff_eq(cairo_steps_contract_address, HashMap::default()); |
2267 | 2270 | test_output.assert_storage_diff_eq(sierra_gas_contract_address, expected_storage_updates); |
2268 | 2271 | } |
| 2272 | + |
| 2273 | +/// Runs the OS test for data gas Cairo1 accounts. |
| 2274 | +#[rstest] |
| 2275 | +#[tokio::test] |
| 2276 | +async fn test_data_gas_accounts() { |
| 2277 | + let test_contract_sierra = &DATA_GAS_ACCOUNT_CONTRACT_SIERRA; |
| 2278 | + let test_contract_casm = &DATA_GAS_ACCOUNT_CONTRACT_CASM; |
| 2279 | + let class_hash = test_contract_sierra.calculate_class_hash(); |
| 2280 | + let compiled_class_hash = test_contract_casm.hash(&HashVersion::V2); |
| 2281 | + assert!( |
| 2282 | + VersionedConstants::latest_constants().os_constants.data_gas_accounts.contains(&class_hash) |
| 2283 | + ); |
| 2284 | + let (mut test_manager, _) = |
| 2285 | + TestManager::<DictStateReader>::new_with_default_initial_state([]).await; |
| 2286 | + |
| 2287 | + // Declare the data gas account. |
| 2288 | + let declare_args = declare_tx_args! { |
| 2289 | + sender_address: *FUNDED_ACCOUNT_ADDRESS, |
| 2290 | + nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), |
| 2291 | + class_hash, |
| 2292 | + compiled_class_hash, |
| 2293 | + resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, |
| 2294 | + }; |
| 2295 | + let account_declare_tx = declare_tx(declare_args); |
| 2296 | + let sierra_version = test_contract_sierra.get_sierra_version().unwrap(); |
| 2297 | + let class_info = ClassInfo { |
| 2298 | + contract_class: ContractClass::V1(((**test_contract_casm).clone(), sierra_version.clone())), |
| 2299 | + sierra_program_length: test_contract_sierra.sierra_program.len(), |
| 2300 | + abi_length: test_contract_sierra.abi.len(), |
| 2301 | + sierra_version, |
| 2302 | + }; |
| 2303 | + let tx = |
| 2304 | + DeclareTransaction::create(account_declare_tx, class_info, &CHAIN_ID_FOR_TESTS).unwrap(); |
| 2305 | + test_manager.add_cairo1_declare_tx(tx, test_contract_sierra); |
| 2306 | + |
| 2307 | + // Deploy it (from funded account). |
| 2308 | + let salt = ContractAddressSalt(Felt::ZERO); |
| 2309 | + let (deploy_tx, data_gas_account_address) = get_deploy_contract_tx_and_address_with_salt( |
| 2310 | + class_hash, |
| 2311 | + calldata![], |
| 2312 | + test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), |
| 2313 | + *NON_TRIVIAL_RESOURCE_BOUNDS, |
| 2314 | + salt, |
| 2315 | + ); |
| 2316 | + test_manager.add_invoke_tx(deploy_tx, None); |
| 2317 | + |
| 2318 | + // Create and run an invoke tx. |
| 2319 | + let invoke_args = invoke_tx_args! { |
| 2320 | + sender_address: *FUNDED_ACCOUNT_ADDRESS, |
| 2321 | + nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), |
| 2322 | + calldata: create_calldata(data_gas_account_address, "test_resource_bounds", &[]), |
| 2323 | + resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, |
| 2324 | + }; |
| 2325 | + let tx = InvokeTransaction::create(invoke_tx(invoke_args), &CHAIN_ID_FOR_TESTS).unwrap(); |
| 2326 | + assert_eq!(tx.version(), TransactionVersion::THREE); |
| 2327 | + assert_matches!(tx.resource_bounds(), ValidResourceBounds::AllResources(_)); |
| 2328 | + test_manager.add_invoke_tx(tx, None); |
| 2329 | + |
| 2330 | + // Run test. |
| 2331 | + let test_output = |
| 2332 | + test_manager.execute_test_with_default_block_contexts(&TestParameters::default()).await; |
| 2333 | + test_output.perform_default_validations(); |
| 2334 | +} |
0 commit comments