@@ -992,11 +992,11 @@ fault: function(log) {}
992
992
" Result: 1" ,
993
993
"772: SLOAD 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:1" ,
994
994
" Result: 1" ,
995
- "835: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:4.4498830125527143e+76 <- 1" ,
996
- "919: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:0 <- 8.008442285988055e+76 " ,
995
+ "835: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:44498830125527143464827115118378702402016761369235290884359940707316142178310 <- 1" ,
996
+ "919: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:0 <- 80084422859880547211683076133703299733277748156566366325829078699459944778998 " ,
997
997
"712: SLOAD 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:0" ,
998
998
" Result: 0" ,
999
- "765: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:5.465844868464591e+47 <- 0" ,
999
+ "765: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:546584486846459126461364135121053344201067465379 <- 0" ,
1000
1000
] ;
1001
1001
1002
1002
let actual: Vec < String > = result
@@ -1008,3 +1008,97 @@ fault: function(log) {}
1008
1008
1009
1009
assert_eq ! ( actual, expected) ;
1010
1010
}
1011
+
1012
+ #[ cfg( feature = "js-tracer" ) ]
1013
+ #[ tokio:: test( flavor = "multi_thread" ) ]
1014
+ async fn test_debug_trace_transaction_js_tracer ( ) {
1015
+ let node_config = NodeConfig :: test ( ) . with_hardfork ( Some ( EthereumHardfork :: Prague . into ( ) ) ) ;
1016
+ let ( api, handle) = spawn ( node_config) . await ;
1017
+ let provider = crate :: utils:: http_provider ( & handle. http_endpoint ( ) ) ;
1018
+
1019
+ let wallets = handle. dev_wallets ( ) . collect :: < Vec < _ > > ( ) ;
1020
+ let from = wallets[ 0 ] . address ( ) ;
1021
+ api. anvil_add_balance ( from, U256 :: MAX ) . await . unwrap ( ) ;
1022
+ api. anvil_add_balance ( wallets[ 1 ] . address ( ) , U256 :: MAX ) . await . unwrap ( ) ;
1023
+
1024
+ let multicall_contract = Multicall :: deploy ( & provider) . await . unwrap ( ) ;
1025
+ let simple_storage_contract =
1026
+ SimpleStorage :: deploy ( & provider, "init value" . to_string ( ) ) . await . unwrap ( ) ;
1027
+
1028
+ let set_value = simple_storage_contract. setValue ( "bar" . to_string ( ) ) ;
1029
+ let set_value_calldata = set_value. calldata ( ) ;
1030
+
1031
+ let internal_call_tx_builder = multicall_contract. aggregate ( vec ! [ Multicall :: Call {
1032
+ target: * simple_storage_contract. address( ) ,
1033
+ callData: set_value_calldata. to_owned( ) ,
1034
+ } ] ) ;
1035
+
1036
+ let internal_call_tx_calldata = internal_call_tx_builder. calldata ( ) . to_owned ( ) ;
1037
+
1038
+ let internal_call_tx = TransactionRequest :: default ( )
1039
+ . from ( wallets[ 1 ] . address ( ) )
1040
+ . to ( * multicall_contract. address ( ) )
1041
+ . with_input ( internal_call_tx_calldata)
1042
+ . with_gas_limit ( 1_000_000 )
1043
+ . with_max_fee_per_gas ( 100_000_000_000 )
1044
+ . with_max_priority_fee_per_gas ( 100_000_000_000 ) ;
1045
+
1046
+ let receipt = provider
1047
+ . send_transaction ( internal_call_tx. into ( ) )
1048
+ . await
1049
+ . unwrap ( )
1050
+ . get_receipt ( )
1051
+ . await
1052
+ . unwrap ( ) ;
1053
+ let js_tracer_code = r#"
1054
+ {
1055
+ data: [],
1056
+ step: function(log) {
1057
+ var op = log.op.toString();
1058
+ var pc = log.getPC();
1059
+ var addr = log.contract.getAddress();
1060
+
1061
+ if (op === "SLOAD") {
1062
+ this.data.push(pc + ": SLOAD " + addr + ":" + log.stack.peek(0));
1063
+ this.data.push(" Result: " + log.stack.peek(0));
1064
+ } else if (op === "SSTORE") {
1065
+ this.data.push(pc + ": SSTORE " + addr + ":" + log.stack.peek(1) + " <- " + log.stack.peek(0));
1066
+ }
1067
+ },
1068
+ result: function() {
1069
+ return this.data;
1070
+ },
1071
+ fault: function(log) {}
1072
+ }
1073
+ "# ;
1074
+
1075
+ let expected = vec ! [
1076
+ "547: SLOAD 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:0" ,
1077
+ " Result: 0" ,
1078
+ "1907: SLOAD 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:1" ,
1079
+ " Result: 1" ,
1080
+ "772: SLOAD 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:1" ,
1081
+ " Result: 1" ,
1082
+ "835: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:44498830125527143464827115118378702402016761369235290884359940707316142178310 <- 1" ,
1083
+ "919: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:0 <- 80084422859880547211683076133703299733277748156566366325829078699459944778998" ,
1084
+ "712: SLOAD 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:0" ,
1085
+ " Result: 0" ,
1086
+ "765: SSTORE 231,241,114,94,119,52,206,40,143,131,103,225,187,20,62,144,187,63,5,18:546584486846459126461364135121053344201067465379 <- 0" ,
1087
+ ] ;
1088
+ let result = api
1089
+ . debug_trace_transaction (
1090
+ receipt. transaction_hash ,
1091
+ GethDebugTracingOptions :: js_tracer ( js_tracer_code) ,
1092
+ )
1093
+ . await
1094
+ . unwrap ( ) ;
1095
+
1096
+ let actual: Vec < String > = result
1097
+ . try_into_json_value ( )
1098
+ . ok ( )
1099
+ . and_then ( |val| val. as_array ( ) . cloned ( ) )
1100
+ . map ( |arr| arr. into_iter ( ) . filter_map ( |v| v. as_str ( ) . map ( |s| s. to_string ( ) ) ) . collect ( ) )
1101
+ . unwrap_or_default ( ) ;
1102
+
1103
+ assert_eq ! ( actual, expected) ;
1104
+ }
0 commit comments