@ -82,6 +82,7 @@ func TestCallTracerNative(t *testing.T) {
}
func testCallTracer ( tracerName string , dirPath string , t * testing . T ) {
isLegacy := strings . HasSuffix ( dirPath , "_legacy" )
files , err := os . ReadDir ( filepath . Join ( "testdata" , dirPath ) )
if err != nil {
t . Fatalf ( "failed to retrieve tracer test suite: %v" , err )
@ -136,8 +137,8 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
if err != nil {
t . Fatalf ( "failed to prepare transaction for tracing: %v" , err )
}
st := core . NewStateTransition ( evm , msg , new ( core . GasPool ) . AddGas ( tx . Gas ( ) ) )
if _ , err = st . TransitionDb ( ) ; err != nil {
vmRet , err := core . ApplyMessage ( evm , msg , new ( core . GasPool ) . AddGas ( tx . Gas ( ) ) )
if err != nil {
t . Fatalf ( "failed to execute transaction: %v" , err )
}
// Retrieve the trace result and compare against the expected.
@ -147,7 +148,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
}
// The legacy javascript calltracer marshals json in js, which
// is not deterministic (as opposed to the golang json encoder).
if strings . HasSuffix ( dirPath , "_legacy" ) {
if isLegacy {
// This is a tweak to make it deterministic. Can be removed when
// we remove the legacy tracer.
var x callTrace
@ -161,6 +162,17 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
if string ( want ) != string ( res ) {
t . Fatalf ( "trace mismatch\n have: %v\n want: %v\n" , string ( res ) , string ( want ) )
}
// Sanity check: compare top call's gas used against vm result
type simpleResult struct {
GasUsed hexutil . Uint64
}
var topCall simpleResult
if err := json . Unmarshal ( res , & topCall ) ; err != nil {
t . Fatalf ( "failed to unmarshal top calls gasUsed: %v" , err )
}
if uint64 ( topCall . GasUsed ) != vmRet . UsedGas {
t . Fatalf ( "top call has invalid gasUsed. have: %d want: %d" , topCall . GasUsed , vmRet . UsedGas )
}
} )
}
}
@ -303,7 +315,7 @@ func TestZeroValueToNotExitCall(t *testing.T) {
if err != nil {
t . Fatalf ( "failed to retrieve trace result: %v" , err )
}
wantStr := ` { "from":"0x682a80a6f560eec50d54e63cbeda1c324c5f8d1b","gas":"0x7148","gasUsed":"0x2d0 ","to":"0x00000000000000000000000000000000deadbeef","input":"0x","calls":[ { "from":"0x00000000000000000000000000000000deadbeef","gas":"0x6cbf","gasUsed":"0x0","to":"0x00000000000000000000000000000000000000ff","input":"0x","value":"0x0","type":"CALL"}],"value":"0x0","type":"CALL"} `
wantStr := ` { "from":"0x682a80a6f560eec50d54e63cbeda1c324c5f8d1b","gas":"0x7148","gasUsed":"0x54d8 ","to":"0x00000000000000000000000000000000deadbeef","input":"0x","calls":[ { "from":"0x00000000000000000000000000000000deadbeef","gas":"0x6cbf","gasUsed":"0x0","to":"0x00000000000000000000000000000000000000ff","input":"0x","value":"0x0","type":"CALL"}],"value":"0x0","type":"CALL"} `
if string ( res ) != wantStr {
t . Fatalf ( "trace mismatch\n have: %v\n want: %v\n" , string ( res ) , wantStr )
}