11use blockifier:: execution:: contract_class:: {
22 ContractClass as BlockifierContractClass , ContractClassV0 , ContractClassV0Inner ,
3- ContractClassV1 , ContractClassV1Inner ,
43} ;
5- use blockifier:: execution:: entry_point:: CallInfo ;
6- use cairo_lang_starknet:: abi:: Contract ;
74use cairo_lang_starknet:: casm_contract_class:: CasmContractClass ;
85use cairo_lang_starknet:: contract_class:: {
96 ContractClass as SierraContractClass , ContractEntryPoints ,
107} ;
11- use cairo_vm:: felt:: { felt_str, Felt252 } ;
128use cairo_vm:: types:: program:: Program ;
139use cairo_vm:: vm:: runners:: cairo_runner:: ExecutionResources as VmExecutionResources ;
1410use core:: fmt;
1511use dotenv:: dotenv;
1612use serde:: { Deserialize , Deserializer } ;
1713use serde_json:: json;
1814use serde_with:: { serde_as, DeserializeAs } ;
19- use starknet:: core:: types:: { ContractClass as SNContractClass , FieldElement } ;
15+ use starknet:: core:: types:: ContractClass as SNContractClass ;
2016use starknet_api:: block:: { BlockNumber , BlockTimestamp } ;
2117use starknet_api:: core:: { ChainId , ClassHash , EntryPointSelector } ;
22- use starknet_api:: deprecated_contract_class:: { self , EntryPointOffset } ;
18+ use starknet_api:: deprecated_contract_class:: EntryPointOffset ;
2319use starknet_api:: hash:: StarkFelt ;
24- use starknet_api:: serde_utils:: { NonPrefixedBytesAsHex , PrefixedBytesAsHex } ;
20+ use starknet_api:: serde_utils:: PrefixedBytesAsHex ;
2521use starknet_api:: transaction:: { InvokeTransaction , Transaction , TransactionHash } ;
2622use starknet_api:: { core:: ContractAddress , hash:: StarkHash , state:: StorageKey } ;
2723use std:: collections:: HashMap ;
@@ -263,7 +259,6 @@ impl<'de> Deserialize<'de> for TransactionTrace {
263259 }
264260}
265261
266- #[ cfg( test) ]
267262impl RpcState {
268263 /// Requests the transaction trace to the Feeder Gateway API.
269264 /// It's useful for testing the transaction outputs like:
@@ -308,7 +303,7 @@ impl RpcState {
308303 }
309304 }
310305
311- fn get_chain_name ( & self ) -> ChainId {
306+ pub fn get_chain_name ( & self ) -> ChainId {
312307 ChainId ( match self . chain {
313308 RpcChain :: MainNet => "alpha-mainnet" . to_string ( ) ,
314309 RpcChain :: TestNet => "alpha4" . to_string ( ) ,
@@ -419,31 +414,51 @@ impl RpcState {
419414 }
420415
421416 fn get_storage_at ( & self , contract_address : & ContractAddress , key : & StorageKey ) -> StarkFelt {
422- let contract_address = Felt252 :: from_bytes_be ( contract_address. 0 . key ( ) . bytes ( ) ) ;
423- let key = Felt252 :: from_bytes_be ( key. 0 . key ( ) . bytes ( ) ) ;
417+ let contract_address = contract_address. 0 . key ( ) ;
418+ let key = key. 0 . key ( ) ;
424419 let params = ureq:: json!( {
425420 "jsonrpc" : "2.0" ,
426421 "method" : "starknet_getStorageAt" ,
427- "params" : [ format!( "0x{}" , contract_address. to_str_radix( 16 ) ) , format!(
428- "0x{}" ,
429- key. to_str_radix( 16 )
430- ) , self . block. to_value( ) ] ,
422+ "params" : [ contract_address. to_string( ) ,
423+ key. to_string( ) , self . block. to_value( ) ] ,
431424 "id" : 1
432425 } ) ;
433426
434427 let resp: RpcResponseFelt = self . rpc_call ( & params) . unwrap ( ) ;
435428
436429 resp. result
437430 }
431+
432+ /// Requests the given transaction to the Feeder Gateway API.
433+ pub fn get_transaction_receipt ( & self , hash : & TransactionHash ) -> Transaction {
434+ let params = ureq:: json!( {
435+ "jsonrpc" : "2.0" ,
436+ "method" : "starknet_getTransactionReceipt" ,
437+ "params" : [ hash. to_string( ) ] ,
438+ "id" : 1
439+ } ) ;
440+ let result = self . rpc_call :: < serde_json:: Value > ( & params) . unwrap ( ) [ "result" ] . clone ( ) ;
441+
442+ match result[ "type" ] . as_str ( ) . unwrap ( ) {
443+ "INVOKE" => match result[ "version" ] . as_str ( ) . unwrap ( ) {
444+ "0x0" => Transaction :: Invoke ( InvokeTransaction :: V0 (
445+ serde_json:: from_value ( result) . unwrap ( ) ,
446+ ) ) ,
447+ "0x1" => Transaction :: Invoke ( InvokeTransaction :: V1 (
448+ serde_json:: from_value ( result) . unwrap ( ) ,
449+ ) ) ,
450+ _ => unreachable ! ( ) ,
451+ } ,
452+ _ => unreachable ! ( ) ,
453+ }
454+ }
438455}
439456
440457mod utils {
441458 use std:: io:: { self , Read } ;
442459
443460 use cairo_lang_utils:: bigint:: BigUintAsHex ;
444- use starknet:: core:: types:: {
445- EntryPointsByType , LegacyContractEntryPoint , LegacyEntryPointsByType , SierraEntryPoint ,
446- } ;
461+ use starknet:: core:: types:: { LegacyContractEntryPoint , LegacyEntryPointsByType } ;
447462 use starknet_api:: deprecated_contract_class:: { EntryPoint , EntryPointType } ;
448463
449464 use super :: * ;
@@ -759,7 +774,6 @@ mod tests {
759774 }
760775}
761776
762- #[ cfg( test) ]
763777mod blockifier_transaction_tests {
764778 use blockifier:: {
765779 block_context:: BlockContext ,
@@ -783,7 +797,7 @@ mod blockifier_transaction_tests {
783797
784798 use super :: * ;
785799
786- struct RpcStateReader ( RpcState ) ;
800+ pub struct RpcStateReader ( RpcState ) ;
787801
788802 impl StateReader for RpcStateReader {
789803 fn get_storage_at (
@@ -826,7 +840,8 @@ mod blockifier_transaction_tests {
826840 }
827841 }
828842
829- fn test_tx (
843+ #[ allow( unused) ]
844+ pub fn execute_tx (
830845 tx_hash : & str ,
831846 network : RpcChain ,
832847 block_number : u64 ,
@@ -906,134 +921,41 @@ mod blockifier_transaction_tests {
906921 )
907922 }
908923
909- #[ test]
910- fn test_recent_tx ( ) {
911- let ( tx_info, trace) = test_tx (
912- "0x05d200ef175ba15d676a68b36f7a7b72c17c17604eda4c1efc2ed5e4973e2c91" ,
913- RpcChain :: MainNet ,
914- 169928 ,
915- 2280457869 ,
916- ) ;
917-
918- let TransactionExecutionInfo {
919- execute_call_info,
920- actual_fee,
921- actual_resources,
922- ..
923- } = tx_info;
924-
925- let CallInfo {
926- vm_resources,
927- inner_calls,
928- ..
929- } = execute_call_info. unwrap ( ) ;
930-
931- assert ! ( false ) ;
932- //dbg!(actual_fee); // test=83714806176032, explorer=67749104314311, diff=15965701861721 (23%)
933- //dbg!(execute_call_info.unwrap().vm_resources); // Ok with explorer
934- //dbg!(execute_call_info.unwrap().inner_calls.len()); // Ok with explorer
935- //dbg!(trace.function_invocation.execution_resources);
936- //dbg!(trace.function_invocation.internal_calls.len());
937- //dbg!(execute_call_info);
938-
939- assert_eq ! ( vm_resources, trace. function_invocation. execution_resources) ;
940- assert_eq ! (
941- inner_calls. len( ) ,
942- trace. function_invocation. internal_calls. len( )
943- ) ;
944-
945- assert_eq ! ( actual_fee. 0 , 5728510166928 ) ;
946- }
947-
948- /// - Transaction Hash: `0x014640564509873cf9d24a311e1207040c8b60efd38d96caef79855f0b0075d5`
949- /// - Network: `mainnet`
950- /// - Type: `Invoke`
951- /// - Contract: StarkGate `0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7`
952- /// - Entrypoint: `transfer(recipient, amount)`
953- /// - Fee discrepancy: test=83714806176032, explorer=67749104314311, diff=15965701861721 (23%)
954- /// - Link to Explorer: https://starkscan.co/tx/0x014640564509873cf9d24a311e1207040c8b60efd38d96caef79855f0b0075d5
955- #[ test]
956- fn test_invoke_0x014640564509873cf9d24a311e1207040c8b60efd38d96caef79855f0b0075d5 ( ) {
957- let ( tx_info, trace) = test_tx (
958- "0x014640564509873cf9d24a311e1207040c8b60efd38d96caef79855f0b0075d5" ,
959- RpcChain :: MainNet ,
960- 90_006 ,
961- 13563643256 ,
962- ) ;
963-
964- let TransactionExecutionInfo {
965- execute_call_info,
966- actual_fee,
967- actual_resources,
968- ..
969- } = tx_info;
970-
971- let CallInfo {
972- vm_resources,
973- inner_calls,
974- ..
975- } = execute_call_info. unwrap ( ) ;
976-
977- dbg ! ( actual_resources) ;
978- //dbg!(actual_fee); // test=83714806176032, explorer=67749104314311, diff=15965701861721 (23%)
979- //dbg!(execute_call_info.unwrap().vm_resources); // Ok with explorer
980- //dbg!(execute_call_info.unwrap().inner_calls.len()); // Ok with explorer
981- //dbg!(trace.function_invocation.execution_resources);
982- //dbg!(trace.function_invocation.internal_calls.len());
983- //dbg!(execute_call_info);
984-
985- assert_eq ! ( vm_resources, trace. function_invocation. execution_resources) ;
986- assert_eq ! (
987- inner_calls. len( ) ,
988- trace. function_invocation. internal_calls. len( )
989- ) ;
990-
991- assert_eq ! ( actual_fee. 0 , 67749104314311 ) ;
992- }
993-
994- /// - Transaction Hash: `0x074dab0828ec1b6cfde5188c41d41af1c198192a7d118217f95a802aa923dacf`
995- /// - Network: `testnet`
996- /// - Type: `Invoke`
997- /// - Contract: Fibonacci `0x012d37c39a385cf56801b57626e039147abce1183ce55e419e4296398b81d9e2`
998- /// - Entrypoint: `fib(first_element, second_element, n)`
999- /// - Fee discrepancy: test=7252831227950, explorer=7207614784695, diff=45216443255 (0.06%)
1000- /// - Link to Explorer: https://testnet.starkscan.co/tx/0x074dab0828ec1b6cfde5188c41d41af1c198192a7d118217f95a802aa923dacf
1001- #[ test]
1002- fn test_invoke_0x074dab0828ec1b6cfde5188c41d41af1c198192a7d118217f95a802aa923dacf ( ) {
1003- let ( tx_info, trace) = test_tx (
1004- "0x074dab0828ec1b6cfde5188c41d41af1c198192a7d118217f95a802aa923dacf" ,
1005- RpcChain :: TestNet ,
1006- 838683 ,
1007- 2917470325 ,
1008- ) ;
1009-
1010- let TransactionExecutionInfo {
1011- execute_call_info,
1012- actual_fee,
1013- actual_resources,
1014- ..
1015- } = tx_info;
1016-
1017- let CallInfo {
1018- vm_resources,
1019- inner_calls,
1020- ..
1021- } = execute_call_info. unwrap ( ) ;
1022-
1023- assert_eq ! ( vm_resources, trace. function_invocation. execution_resources) ;
1024- assert_eq ! (
1025- inner_calls. len( ) ,
1026- trace. function_invocation. internal_calls. len( )
1027- ) ;
1028-
1029- assert_eq ! ( actual_fee. 0 , 7207614784695 ) ;
1030-
1031- dbg ! ( actual_resources) ;
1032- //dbg!(actual_fee); // test=83714806176032, explorer=67749104314311, diff=15965701861721 (23%)
1033- //dbg!(execute_call_info.unwrap().vm_resources); // Ok with explorer
1034- //dbg!(execute_call_info.unwrap().inner_calls.len()); // Ok with explorer
1035- //dbg!(trace.function_invocation.execution_resources);
1036- //dbg!(trace.function_invocation.internal_calls.len());
1037- //dbg!(execute_call_info);
924+ #[ cfg( test) ]
925+ mod test {
926+ use blockifier:: execution:: entry_point:: CallInfo ;
927+
928+ use super :: * ;
929+
930+ #[ test]
931+ #[ ignore = "working on fixes" ]
932+ fn test_recent_tx ( ) {
933+ let ( tx_info, trace) = execute_tx (
934+ "0x05d200ef175ba15d676a68b36f7a7b72c17c17604eda4c1efc2ed5e4973e2c91" ,
935+ RpcChain :: MainNet ,
936+ 169928 ,
937+ 17110275391107 ,
938+ ) ;
939+
940+ let TransactionExecutionInfo {
941+ execute_call_info,
942+ actual_fee,
943+ ..
944+ } = tx_info;
945+
946+ let CallInfo {
947+ vm_resources,
948+ inner_calls,
949+ ..
950+ } = execute_call_info. unwrap ( ) ;
951+
952+ assert_eq ! ( vm_resources, trace. function_invocation. execution_resources) ;
953+ assert_eq ! (
954+ inner_calls. len( ) ,
955+ trace. function_invocation. internal_calls. len( )
956+ ) ;
957+
958+ assert_eq ! ( actual_fee. 0 , 5728510166928 ) ;
959+ }
1038960 }
1039961}
0 commit comments