@@ -25,10 +25,13 @@ use starknet_api::core::{
2525 PatriciaKey ,
2626} ;
2727use starknet_api:: executable_transaction:: {
28+ AccountTransaction ,
2829 DeclareTransaction ,
2930 DeployAccountTransaction ,
3031 InvokeTransaction ,
3132 L1HandlerTransaction as ExecutableL1HandlerTransaction ,
33+ Transaction ,
34+ TransactionType ,
3235} ;
3336use starknet_api:: execution_resources:: GasAmount ;
3437use starknet_api:: state:: StorageKey ;
@@ -1504,3 +1507,154 @@ async fn test_new_class_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_multi
15041507 . assert_debug_eq ( poseidons) ;
15051508 }
15061509}
1510+
1511+ #[ rstest]
1512+ #[ tokio:: test]
1513+ async fn test_deprecated_tx_info ( ) {
1514+ let tx_info_writer = FeatureContract :: TxInfoWriter ;
1515+ let class_hash = get_class_hash_of_feature_contract ( tx_info_writer) ;
1516+ // Initialize the test manager with the tx info writer already declared.
1517+ // We can ignore the address of the dpeloyed instance.
1518+ let ( mut test_manager, _) = TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ (
1519+ tx_info_writer,
1520+ calldata ! [ ] ,
1521+ ) ] )
1522+ . await ;
1523+
1524+ // Prepare to deploy: precompute the address.
1525+ let salt = Felt :: ZERO ;
1526+ let tx_info_account_address = calculate_contract_address (
1527+ ContractAddressSalt ( salt) ,
1528+ class_hash,
1529+ & calldata ! [ ] ,
1530+ ContractAddress :: default ( ) ,
1531+ )
1532+ . unwrap ( ) ;
1533+
1534+ // Fund the address.
1535+ test_manager. add_fund_address_tx_with_default_amount ( tx_info_account_address) ;
1536+
1537+ // Deploy the account.
1538+ let deploy_tx_args = deploy_account_tx_args ! {
1539+ class_hash,
1540+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1541+ contract_address_salt: ContractAddressSalt ( salt) ,
1542+ } ;
1543+ let deploy_account_tx = DeployAccountTransaction :: create (
1544+ deploy_account_tx ( deploy_tx_args, test_manager. next_nonce ( tx_info_account_address) ) ,
1545+ & CHAIN_ID_FOR_TESTS ,
1546+ )
1547+ . unwrap ( ) ;
1548+ test_manager. add_deploy_account_tx ( deploy_account_tx. clone ( ) ) ;
1549+
1550+ // Invoke (call write).
1551+ let invoke_args = invoke_tx_args ! {
1552+ sender_address: tx_info_account_address,
1553+ nonce: test_manager. next_nonce( tx_info_account_address) ,
1554+ calldata: calldata![ Felt :: ZERO ] ,
1555+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1556+ } ;
1557+ let invoke_tx = InvokeTransaction :: create ( invoke_tx ( invoke_args) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1558+ test_manager. add_invoke_tx ( invoke_tx. clone ( ) , None ) ;
1559+
1560+ // Declare.
1561+ let empty_contract = FeatureContract :: Empty ( CairoVersion :: Cairo1 ( RunnableCairo1 :: Casm ) ) ;
1562+ let empty_contract_sierra = empty_contract. get_sierra ( ) ;
1563+ let empty_contract_class_hash = empty_contract_sierra. calculate_class_hash ( ) ;
1564+ let empty_contract_compiled_class_hash =
1565+ empty_contract. get_compiled_class_hash ( & HashVersion :: V2 ) ;
1566+ let declare_tx_args = declare_tx_args ! {
1567+ sender_address: tx_info_account_address,
1568+ class_hash: empty_contract_class_hash,
1569+ compiled_class_hash: empty_contract_compiled_class_hash,
1570+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1571+ nonce: test_manager. next_nonce( tx_info_account_address) ,
1572+ } ;
1573+ let account_declare_tx = declare_tx ( declare_tx_args) ;
1574+ let class_info = get_class_info_of_feature_contract ( empty_contract) ;
1575+ let declare_tx =
1576+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1577+ test_manager. add_cairo1_declare_tx ( declare_tx. clone ( ) , & empty_contract_sierra) ;
1578+
1579+ // L1 handler (call `l1_write`).
1580+ let from_address = Felt :: from ( 85 ) ;
1581+ let selector = selector_from_name ( "l1_write" ) ;
1582+ let l1_handler_tx = ExecutableL1HandlerTransaction :: create (
1583+ L1HandlerTransaction {
1584+ version : L1HandlerTransaction :: VERSION ,
1585+ nonce : Nonce :: default ( ) ,
1586+ contract_address : tx_info_account_address,
1587+ entry_point_selector : selector,
1588+ // from_address (L1 address), key, value.
1589+ calldata : calldata ! [ from_address] ,
1590+ } ,
1591+ & CHAIN_ID_FOR_TESTS ,
1592+ Fee ( 1_000_000 ) ,
1593+ )
1594+ . unwrap ( ) ;
1595+ test_manager. add_l1_handler_tx ( l1_handler_tx. clone ( ) , None ) ;
1596+
1597+ // Run the test.
1598+ let messages_to_l2 = vec ! [ MessageToL2 {
1599+ from_address: from_address. try_into( ) . unwrap( ) ,
1600+ to_address: tx_info_account_address,
1601+ selector,
1602+ payload: L1ToL2Payload :: default ( ) ,
1603+ nonce: Nonce :: default ( ) ,
1604+ } ] ;
1605+ let test_output = test_manager
1606+ . execute_test_with_default_block_contexts ( & TestParameters {
1607+ messages_to_l2,
1608+ ..Default :: default ( )
1609+ } )
1610+ . await ;
1611+
1612+ // Perform general validations and storage update validations.
1613+ let mut contract_storage_updates = HashMap :: new ( ) ;
1614+ for tx in [
1615+ Transaction :: Account ( AccountTransaction :: DeployAccount ( deploy_account_tx) ) ,
1616+ Transaction :: Account ( AccountTransaction :: Invoke ( invoke_tx) ) ,
1617+ Transaction :: Account ( AccountTransaction :: Declare ( declare_tx) ) ,
1618+ Transaction :: L1Handler ( l1_handler_tx) ,
1619+ ] {
1620+ let tx_type = & [ tx. tx_type ( ) . tx_type_as_felt ( ) ] ;
1621+ contract_storage_updates
1622+ . insert ( get_storage_var_address ( "transaction_hash" , tx_type) , tx. tx_hash ( ) . 0 ) ;
1623+ contract_storage_updates. insert ( get_storage_var_address ( "max_fee" , tx_type) , Felt :: ZERO ) ;
1624+ contract_storage_updates. insert ( get_storage_var_address ( "nonce" , tx_type) , tx. nonce ( ) . 0 ) ;
1625+ contract_storage_updates. insert (
1626+ get_storage_var_address ( "account_contract_address" , tx_type) ,
1627+ * * tx_info_account_address,
1628+ ) ;
1629+ contract_storage_updates
1630+ . insert ( get_storage_var_address ( "signature_len" , tx_type) , Felt :: ZERO ) ;
1631+ contract_storage_updates. insert (
1632+ get_storage_var_address ( "chain_id" , tx_type) ,
1633+ Felt :: try_from ( & * CHAIN_ID_FOR_TESTS ) . unwrap ( ) ,
1634+ ) ;
1635+ if !matches ! ( tx. tx_type( ) , TransactionType :: L1Handler ) {
1636+ contract_storage_updates
1637+ . insert ( get_storage_var_address ( "version" , tx_type) , tx. version ( ) . 0 ) ;
1638+ } else {
1639+ contract_storage_updates
1640+ . insert ( get_storage_var_address ( "version" , tx_type) , Felt :: ZERO ) ;
1641+ }
1642+ }
1643+ // Add the offset to all storage update values and convert types.
1644+ let offset = Felt :: from_hex_unchecked ( "0x1234" ) ;
1645+ let contract_storage_updates = contract_storage_updates
1646+ . into_iter ( )
1647+ . map ( |( key, value) | ( StarknetStorageKey ( key) , StarknetStorageValue ( value + offset) ) )
1648+ . collect ( ) ;
1649+
1650+ let expected_storage_updates =
1651+ HashMap :: from ( [ ( tx_info_account_address, contract_storage_updates) ] ) ;
1652+
1653+ let perform_global_validations = true ;
1654+ test_output. perform_validations (
1655+ perform_global_validations,
1656+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ,
1657+ ) ;
1658+ test_output. assert_account_balance_change ( tx_info_account_address) ;
1659+ test_output. assert_account_balance_change ( contract_address ! ( TEST_SEQUENCER_ADDRESS ) ) ;
1660+ }
0 commit comments