@@ -23,10 +23,13 @@ use starknet_api::core::{
2323 Nonce ,
2424} ;
2525use starknet_api:: executable_transaction:: {
26+ AccountTransaction ,
2627 DeclareTransaction ,
2728 DeployAccountTransaction ,
2829 InvokeTransaction ,
2930 L1HandlerTransaction as ExecutableL1HandlerTransaction ,
31+ Transaction ,
32+ TransactionType ,
3033} ;
3134use starknet_api:: execution_resources:: GasAmount ;
3235use starknet_api:: test_utils:: declare:: declare_tx;
@@ -1612,3 +1615,154 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu
16121615 test_output. assert_account_balance_change ( * FUNDED_ACCOUNT_ADDRESS ) ;
16131616 test_output. assert_account_balance_change ( contract_address ! ( TEST_SEQUENCER_ADDRESS ) ) ;
16141617}
1618+
1619+ #[ rstest]
1620+ #[ tokio:: test]
1621+ async fn test_deprecated_tx_info ( ) {
1622+ let tx_info_writer = FeatureContract :: TxInfoWriter ;
1623+ let class_hash = get_class_hash_of_feature_contract ( tx_info_writer) ;
1624+ // Initialize the test manager with the tx info writer already declared.
1625+ // We can ignore the address of the dpeloyed instance.
1626+ let ( mut test_manager, _) = TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ (
1627+ tx_info_writer,
1628+ calldata ! [ ] ,
1629+ ) ] )
1630+ . await ;
1631+
1632+ // Prepare to deploy: precompute the address.
1633+ let salt = Felt :: ZERO ;
1634+ let tx_info_account_address = calculate_contract_address (
1635+ ContractAddressSalt ( salt) ,
1636+ class_hash,
1637+ & calldata ! [ ] ,
1638+ ContractAddress :: default ( ) ,
1639+ )
1640+ . unwrap ( ) ;
1641+
1642+ // Fund the address.
1643+ test_manager. add_fund_address_tx_with_default_amount ( tx_info_account_address) ;
1644+
1645+ // Deploy the account.
1646+ let deploy_tx_args = deploy_account_tx_args ! {
1647+ class_hash,
1648+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1649+ contract_address_salt: ContractAddressSalt ( salt) ,
1650+ } ;
1651+ let deploy_account_tx = DeployAccountTransaction :: create (
1652+ deploy_account_tx ( deploy_tx_args, test_manager. next_nonce ( tx_info_account_address) ) ,
1653+ & CHAIN_ID_FOR_TESTS ,
1654+ )
1655+ . unwrap ( ) ;
1656+ test_manager. add_deploy_account_tx ( deploy_account_tx. clone ( ) ) ;
1657+
1658+ // Invoke (call write).
1659+ let invoke_args = invoke_tx_args ! {
1660+ sender_address: tx_info_account_address,
1661+ nonce: test_manager. next_nonce( tx_info_account_address) ,
1662+ calldata: calldata![ Felt :: ZERO ] ,
1663+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1664+ } ;
1665+ let invoke_tx = InvokeTransaction :: create ( invoke_tx ( invoke_args) , & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1666+ test_manager. add_invoke_tx ( invoke_tx. clone ( ) , None ) ;
1667+
1668+ // Declare.
1669+ let empty_contract = FeatureContract :: Empty ( CairoVersion :: Cairo1 ( RunnableCairo1 :: Casm ) ) ;
1670+ let empty_contract_sierra = empty_contract. get_sierra ( ) ;
1671+ let empty_contract_class_hash = empty_contract_sierra. calculate_class_hash ( ) ;
1672+ let empty_contract_compiled_class_hash =
1673+ empty_contract. get_compiled_class_hash ( & HashVersion :: V2 ) ;
1674+ let declare_tx_args = declare_tx_args ! {
1675+ sender_address: tx_info_account_address,
1676+ class_hash: empty_contract_class_hash,
1677+ compiled_class_hash: empty_contract_compiled_class_hash,
1678+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
1679+ nonce: test_manager. next_nonce( tx_info_account_address) ,
1680+ } ;
1681+ let account_declare_tx = declare_tx ( declare_tx_args) ;
1682+ let class_info = get_class_info_of_feature_contract ( empty_contract) ;
1683+ let declare_tx =
1684+ DeclareTransaction :: create ( account_declare_tx, class_info, & CHAIN_ID_FOR_TESTS ) . unwrap ( ) ;
1685+ test_manager. add_cairo1_declare_tx ( declare_tx. clone ( ) , & empty_contract_sierra) ;
1686+
1687+ // L1 handler (call `l1_write`).
1688+ let from_address = Felt :: from ( 85 ) ;
1689+ let selector = selector_from_name ( "l1_write" ) ;
1690+ let l1_handler_tx = ExecutableL1HandlerTransaction :: create (
1691+ L1HandlerTransaction {
1692+ version : L1HandlerTransaction :: VERSION ,
1693+ nonce : Nonce :: default ( ) ,
1694+ contract_address : tx_info_account_address,
1695+ entry_point_selector : selector,
1696+ // from_address (L1 address), key, value.
1697+ calldata : calldata ! [ from_address] ,
1698+ } ,
1699+ & CHAIN_ID_FOR_TESTS ,
1700+ Fee ( 1_000_000 ) ,
1701+ )
1702+ . unwrap ( ) ;
1703+ test_manager. add_l1_handler_tx ( l1_handler_tx. clone ( ) , None ) ;
1704+
1705+ // Run the test.
1706+ let messages_to_l2 = vec ! [ MessageToL2 {
1707+ from_address: from_address. try_into( ) . unwrap( ) ,
1708+ to_address: tx_info_account_address,
1709+ selector,
1710+ payload: L1ToL2Payload :: default ( ) ,
1711+ nonce: Nonce :: default ( ) ,
1712+ } ] ;
1713+ let test_output = test_manager
1714+ . execute_test_with_default_block_contexts ( & TestParameters {
1715+ messages_to_l2,
1716+ ..Default :: default ( )
1717+ } )
1718+ . await ;
1719+
1720+ // Perform general validations and storage update validations.
1721+ let mut contract_storage_updates = HashMap :: new ( ) ;
1722+ for tx in [
1723+ Transaction :: Account ( AccountTransaction :: DeployAccount ( deploy_account_tx) ) ,
1724+ Transaction :: Account ( AccountTransaction :: Invoke ( invoke_tx) ) ,
1725+ Transaction :: Account ( AccountTransaction :: Declare ( declare_tx) ) ,
1726+ Transaction :: L1Handler ( l1_handler_tx) ,
1727+ ] {
1728+ let tx_type = & [ tx. tx_type ( ) . tx_type_as_felt ( ) ] ;
1729+ contract_storage_updates
1730+ . insert ( get_storage_var_address ( "transaction_hash" , tx_type) , tx. tx_hash ( ) . 0 ) ;
1731+ contract_storage_updates. insert ( get_storage_var_address ( "max_fee" , tx_type) , Felt :: ZERO ) ;
1732+ contract_storage_updates. insert ( get_storage_var_address ( "nonce" , tx_type) , tx. nonce ( ) . 0 ) ;
1733+ contract_storage_updates. insert (
1734+ get_storage_var_address ( "account_contract_address" , tx_type) ,
1735+ * * tx_info_account_address,
1736+ ) ;
1737+ contract_storage_updates
1738+ . insert ( get_storage_var_address ( "signature_len" , tx_type) , Felt :: ZERO ) ;
1739+ contract_storage_updates. insert (
1740+ get_storage_var_address ( "chain_id" , tx_type) ,
1741+ Felt :: try_from ( & * CHAIN_ID_FOR_TESTS ) . unwrap ( ) ,
1742+ ) ;
1743+ if !matches ! ( tx. tx_type( ) , TransactionType :: L1Handler ) {
1744+ contract_storage_updates
1745+ . insert ( get_storage_var_address ( "version" , tx_type) , tx. version ( ) . 0 ) ;
1746+ } else {
1747+ contract_storage_updates
1748+ . insert ( get_storage_var_address ( "version" , tx_type) , Felt :: ZERO ) ;
1749+ }
1750+ }
1751+ // Add the offset to all storage update values and convert types.
1752+ let offset = Felt :: from_hex_unchecked ( "0x1234" ) ;
1753+ let contract_storage_updates = contract_storage_updates
1754+ . into_iter ( )
1755+ . map ( |( key, value) | ( StarknetStorageKey ( key) , StarknetStorageValue ( value + offset) ) )
1756+ . collect ( ) ;
1757+
1758+ let expected_storage_updates =
1759+ HashMap :: from ( [ ( tx_info_account_address, contract_storage_updates) ] ) ;
1760+
1761+ let perform_global_validations = true ;
1762+ test_output. perform_validations (
1763+ perform_global_validations,
1764+ Some ( & StateDiff { storage_updates : expected_storage_updates, ..Default :: default ( ) } ) ,
1765+ ) ;
1766+ test_output. assert_account_balance_change ( tx_info_account_address) ;
1767+ test_output. assert_account_balance_change ( contract_address ! ( TEST_SEQUENCER_ADDRESS ) ) ;
1768+ }
0 commit comments