@@ -8,7 +8,7 @@ use katana_rpc_api::katana::KatanaApiClient;
88use katana_rpc_types:: broadcasted:: {
99 BroadcastedDeclareTx , BroadcastedDeployAccountTx , BroadcastedInvokeTx ,
1010} ;
11- use katana_rpc_types:: receipt:: { RpcDeployAccountTxReceipt , RpcTxReceipt } ;
11+ use katana_rpc_types:: receipt:: { ReceiptBlockInfo , RpcDeployAccountTxReceipt , RpcTxReceipt } ;
1212use katana_utils:: node:: test_config;
1313use katana_utils:: TestNode ;
1414use starknet:: accounts:: {
@@ -41,7 +41,7 @@ async fn katana_add_transactions_return_receipts() {
4141 let account = sequencer. account ( ) ;
4242
4343 // -----------------------------------------------------------------------
44- // katana_addInvokeTransaction
44+ // katana_addInvokeTransactionSync
4545
4646 let erc20 = Erc20Contract :: new ( DEFAULT_STRK_FEE_TOKEN_ADDRESS . into ( ) , & account) ;
4747 let recipient = Felt :: ONE ;
@@ -66,12 +66,15 @@ async fn katana_add_transactions_return_receipts() {
6666 let invoke_tx: BroadcastedInvokeTx =
6767 convert_broadcasted_tx ( prepared_invoke. get_invoke_request ( false , false ) . await . unwrap ( ) ) ;
6868
69- let invoke_receipt =
70- KatanaApiClient :: add_invoke_transaction ( & rpc_client, invoke_tx) . await . unwrap ( ) ;
69+ let invoke_receipt = rpc_client. add_invoke_transaction_sync ( invoke_tx) . await . unwrap ( ) ;
7170 assert_matches ! ( invoke_receipt. receipt, RpcTxReceipt :: Invoke ( _) ) ;
7271
72+ let invoke_receipt_from_provider =
73+ provider. get_transaction_receipt ( invoke_receipt. transaction_hash ) . await . unwrap ( ) ;
74+ assert_eq ! ( invoke_receipt, invoke_receipt_from_provider) ;
75+
7376 // -----------------------------------------------------------------------
74- // katana_addDeclareTransaction
77+ // katana_addDeclareTransactionSync
7578
7679 let path: PathBuf = PathBuf :: from ( "tests/test_data/cairo1_contract.json" ) ;
7780 let ( contract, compiled_class_hash) =
@@ -100,12 +103,15 @@ async fn katana_add_transactions_return_receipts() {
100103 let declare_tx: BroadcastedDeclareTx =
101104 convert_broadcasted_tx ( prepared_declare. get_declare_request ( false , false ) . await . unwrap ( ) ) ;
102105
103- let declare_receipt =
104- KatanaApiClient :: add_declare_transaction ( & rpc_client, declare_tx) . await . unwrap ( ) ;
106+ let declare_receipt = rpc_client. add_declare_transaction_sync ( declare_tx) . await . unwrap ( ) ;
105107 assert_matches ! ( declare_receipt. receipt, RpcTxReceipt :: Declare ( _) ) ;
106108
109+ let declare_receipt_from_provider =
110+ provider. get_transaction_receipt ( declare_receipt. transaction_hash ) . await . unwrap ( ) ;
111+ assert_eq ! ( declare_receipt, declare_receipt_from_provider) ;
112+
107113 // -----------------------------------------------------------------------
108- // katana_addDeployAccountTransaction
114+ // katana_addDeployAccountTransactionSync
109115
110116 let chain_id = provider. chain_id ( ) . await . unwrap ( ) ;
111117 let signer = LocalWallet :: from ( SigningKey :: from_random ( ) ) ;
@@ -140,12 +146,147 @@ async fn katana_add_transactions_return_receipts() {
140146 let deploy_tx: BroadcastedDeployAccountTx =
141147 convert_broadcasted_tx ( prepared_deploy. get_deploy_request ( false , false ) . await . unwrap ( ) ) ;
142148
143- let deploy_receipt =
144- KatanaApiClient :: add_deploy_account_transaction ( & rpc_client, deploy_tx) . await . unwrap ( ) ;
149+ let deploy_receipt = rpc_client. add_deploy_account_transaction_sync ( deploy_tx) . await . unwrap ( ) ;
145150
146151 assert_matches ! (
147152 deploy_receipt. receipt,
148153 RpcTxReceipt :: DeployAccount ( RpcDeployAccountTxReceipt { contract_address, .. } )
149154 => assert_eq!( contract_address, deployed_address)
150155 ) ;
156+
157+ let deploy_receipt_from_provider =
158+ provider. get_transaction_receipt ( deploy_receipt. transaction_hash ) . await . unwrap ( ) ;
159+ assert_eq ! ( deploy_receipt, deploy_receipt_from_provider) ;
160+ }
161+
162+ #[ tokio:: test]
163+ async fn katana_add_transactions_return_preconfirmed_receipts ( ) {
164+ let mut config = test_config ( ) ;
165+ config. sequencing . no_mining = true ;
166+
167+ let sequencer = TestNode :: new_with_config ( config) . await ;
168+ let rpc_client = sequencer. rpc_http_client ( ) ;
169+ let provider = sequencer. starknet_rpc_client ( ) ;
170+ let account = sequencer. account ( ) ;
171+
172+ // -----------------------------------------------------------------------
173+ // katana_addInvokeTransactionSync
174+
175+ let erc20 = Erc20Contract :: new ( DEFAULT_STRK_FEE_TOKEN_ADDRESS . into ( ) , & account) ;
176+ let recipient = Felt :: ONE ;
177+ let amount = Uint256 { low : Felt :: ONE , high : Felt :: ZERO } ;
178+
179+ let fee = erc20. transfer ( & recipient, & amount) . estimate_fee ( ) . await . unwrap ( ) ;
180+ let nonce = account. get_nonce ( ) . await . unwrap ( ) ;
181+
182+ let prepared_invoke = erc20
183+ . transfer ( & recipient, & amount)
184+ . nonce ( nonce)
185+ . l1_gas ( fee. l1_gas_consumed )
186+ . l1_gas_price ( fee. l1_gas_price )
187+ . l2_gas ( fee. l2_gas_consumed )
188+ . l2_gas_price ( fee. l2_gas_price )
189+ . l1_data_gas ( fee. l1_data_gas_consumed )
190+ . l1_data_gas_price ( fee. l1_data_gas_price )
191+ . tip ( 0 )
192+ . prepared ( )
193+ . unwrap ( ) ;
194+
195+ let invoke_tx: BroadcastedInvokeTx =
196+ convert_broadcasted_tx ( prepared_invoke. get_invoke_request ( false , false ) . await . unwrap ( ) ) ;
197+
198+ let invoke_receipt = rpc_client. add_invoke_transaction_sync ( invoke_tx) . await . unwrap ( ) ;
199+ assert_matches ! ( invoke_receipt. receipt, RpcTxReceipt :: Invoke ( _) ) ;
200+ assert_matches ! ( invoke_receipt. block, ReceiptBlockInfo :: PreConfirmed { .. } ) ;
201+
202+ let invoke_receipt_from_provider =
203+ provider. get_transaction_receipt ( invoke_receipt. transaction_hash ) . await . unwrap ( ) ;
204+ assert_eq ! ( invoke_receipt, invoke_receipt_from_provider) ;
205+
206+ // -----------------------------------------------------------------------
207+ // katana_addDeclareTransactionSync
208+
209+ let path: PathBuf = PathBuf :: from ( "tests/test_data/cairo1_contract.json" ) ;
210+ let ( contract, compiled_class_hash) =
211+ common:: prepare_contract_declaration_params ( & path) . unwrap ( ) ;
212+
213+ let fee = account
214+ . declare_v3 ( contract. clone ( ) . into ( ) , compiled_class_hash)
215+ . estimate_fee ( )
216+ . await
217+ . unwrap ( ) ;
218+ let nonce = account. get_nonce ( ) . await . unwrap ( ) ;
219+
220+ let prepared_declare = account
221+ . declare_v3 ( contract. into ( ) , compiled_class_hash)
222+ . nonce ( nonce)
223+ . l1_gas ( fee. l1_gas_consumed )
224+ . l1_gas_price ( fee. l1_gas_price )
225+ . l2_gas ( fee. l2_gas_consumed )
226+ . l2_gas_price ( fee. l2_gas_price )
227+ . l1_data_gas ( fee. l1_data_gas_consumed )
228+ . l1_data_gas_price ( fee. l1_data_gas_price )
229+ . tip ( 0 )
230+ . prepared ( )
231+ . unwrap ( ) ;
232+
233+ let declare_tx: BroadcastedDeclareTx =
234+ convert_broadcasted_tx ( prepared_declare. get_declare_request ( false , false ) . await . unwrap ( ) ) ;
235+
236+ let declare_receipt = rpc_client. add_declare_transaction_sync ( declare_tx) . await . unwrap ( ) ;
237+ assert_matches ! ( declare_receipt. receipt, RpcTxReceipt :: Declare ( _) ) ;
238+ assert_matches ! ( declare_receipt. block, ReceiptBlockInfo :: PreConfirmed { .. } ) ;
239+
240+ let declare_receipt_from_provider =
241+ provider. get_transaction_receipt ( declare_receipt. transaction_hash ) . await . unwrap ( ) ;
242+ assert_eq ! ( declare_receipt, declare_receipt_from_provider) ;
243+
244+ // -----------------------------------------------------------------------
245+ // katana_addDeployAccountTransactionSync
246+
247+ let chain_id = provider. chain_id ( ) . await . unwrap ( ) ;
248+ let signer = LocalWallet :: from ( SigningKey :: from_random ( ) ) ;
249+ let class_hash = provider
250+ . get_class_hash_at ( BlockIdOrTag :: PreConfirmed , account. address ( ) . into ( ) )
251+ . await
252+ . unwrap ( ) ;
253+ let salt = felt ! ( "0x123" ) ;
254+
255+ let factory =
256+ OZAccountFactory :: new ( class_hash, chain_id, & signer, account. provider ( ) ) . await . unwrap ( ) ;
257+
258+ let deploy_account_tx = factory. deploy_v3 ( salt) ;
259+ let deployed_address = deploy_account_tx. address ( ) ;
260+
261+ let fee = deploy_account_tx. estimate_fee ( ) . await . unwrap ( ) ;
262+ let nonce = deploy_account_tx. fetch_nonce ( ) . await . unwrap ( ) ;
263+
264+ let prepared_deploy = factory
265+ . deploy_v3 ( salt)
266+ . nonce ( nonce)
267+ . l1_gas ( fee. l1_gas_consumed )
268+ . l1_gas_price ( fee. l1_gas_price )
269+ . l2_gas ( fee. l2_gas_consumed )
270+ . l2_gas_price ( fee. l2_gas_price )
271+ . l1_data_gas ( fee. l1_data_gas_consumed )
272+ . l1_data_gas_price ( fee. l1_data_gas_price )
273+ . tip ( 0 )
274+ . prepared ( )
275+ . unwrap ( ) ;
276+
277+ let deploy_tx: BroadcastedDeployAccountTx =
278+ convert_broadcasted_tx ( prepared_deploy. get_deploy_request ( false , false ) . await . unwrap ( ) ) ;
279+
280+ let deploy_receipt = rpc_client. add_deploy_account_transaction_sync ( deploy_tx) . await . unwrap ( ) ;
281+
282+ assert_matches ! (
283+ deploy_receipt. receipt,
284+ RpcTxReceipt :: DeployAccount ( RpcDeployAccountTxReceipt { contract_address, .. } )
285+ => assert_eq!( contract_address, deployed_address)
286+ ) ;
287+ assert_matches ! ( deploy_receipt. block, ReceiptBlockInfo :: PreConfirmed { .. } ) ;
288+
289+ let deploy_receipt_from_provider =
290+ provider. get_transaction_receipt ( deploy_receipt. transaction_hash ) . await . unwrap ( ) ;
291+ assert_eq ! ( deploy_receipt, deploy_receipt_from_provider) ;
151292}
0 commit comments