@@ -341,98 +341,6 @@ func lineIterator(path string) func() (string, error) {
341341 }
342342}
343343
344- // TestT8nTracing is a test that checks the tracing-output from t8n.
345- func TestT8nTracing (t * testing.T ) {
346- t .Parallel ()
347- tt := new (testT8n )
348- tt .TestCmd = cmdtest .NewTestCmd (t , tt )
349- for i , tc := range []struct {
350- base string
351- input t8nInput
352- expExitCode int
353- extraArgs []string
354- expectedTraces []string
355- }{
356- {
357- base : "./testdata/31" ,
358- input : t8nInput {
359- "alloc.json" , "txs.json" , "env.json" , "Cancun" , "" ,
360- },
361- extraArgs : []string {"--trace" },
362- expectedTraces : []string {"trace-0-0x88f5fbd1524731a81e49f637aa847543268a5aaf2a6b32a69d2c6d978c45dcfb.jsonl" },
363- },
364- {
365- base : "./testdata/31" ,
366- input : t8nInput {
367- "alloc.json" , "txs.json" , "env.json" , "Cancun" , "" ,
368- },
369- extraArgs : []string {"--trace.tracer" , `
370- {
371- result: function(){
372- return "hello world"
373- },
374- fault: function(){}
375- }` },
376- expectedTraces : []string {"trace-0-0x88f5fbd1524731a81e49f637aa847543268a5aaf2a6b32a69d2c6d978c45dcfb.json" },
377- },
378- {
379- base : "./testdata/32" ,
380- input : t8nInput {
381- "alloc.json" , "txs.json" , "env.json" , "Paris" , "" ,
382- },
383- extraArgs : []string {"--trace" , "--trace.callframes" },
384- expectedTraces : []string {"trace-0-0x47806361c0fa084be3caa18afe8c48156747c01dbdfc1ee11b5aecdbe4fcf23e.jsonl" },
385- },
386- } {
387- args := []string {"t8n" }
388- args = append (args , tc .input .get (tc .base )... )
389- // Place the output somewhere we can find it
390- outdir := t .TempDir ()
391- args = append (args , "--output.basedir" , outdir )
392- args = append (args , tc .extraArgs ... )
393-
394- var qArgs []string // quoted args for debugging purposes
395- for _ , arg := range args {
396- if len (arg ) == 0 {
397- qArgs = append (qArgs , `""` )
398- } else {
399- qArgs = append (qArgs , arg )
400- }
401- }
402- tt .Logf ("args: %v\n " , strings .Join (qArgs , " " ))
403- tt .Run ("evm-test" , args ... )
404- t .Log (string (tt .Output ()))
405-
406- // Compare the expected traces
407- for _ , traceFile := range tc .expectedTraces {
408- haveFn := lineIterator (filepath .Join (outdir , traceFile ))
409- wantFn := lineIterator (filepath .Join (tc .base , traceFile ))
410-
411- for line := 0 ; ; line ++ {
412- want , wErr := wantFn ()
413- have , hErr := haveFn ()
414- if want != have {
415- t .Fatalf ("test %d, trace %v, line %d\n want: %v\n have: %v\n " ,
416- i , traceFile , line , want , have )
417- }
418- if wErr != nil && hErr != nil {
419- break
420- }
421- if wErr != nil {
422- t .Fatal (wErr )
423- }
424- if hErr != nil {
425- t .Fatal (hErr )
426- }
427- t .Logf ("%v\n " , want )
428- }
429- }
430- if have , want := tt .ExitStatus (), tc .expExitCode ; have != want {
431- t .Fatalf ("test %d: wrong exit code, have %d, want %d" , i , have , want )
432- }
433- }
434- }
435-
436344type t9nInput struct {
437345 inTxs string
438346 stFork string
@@ -672,6 +580,88 @@ func TestB11r(t *testing.T) {
672580 }
673581}
674582
583+ func TestEvmRun (t * testing.T ) {
584+ t .Parallel ()
585+ tt := cmdtest .NewTestCmd (t , nil )
586+ for i , tc := range []struct {
587+ input []string
588+ wantStdout string
589+ wantStderr string
590+ }{
591+ { // json tracing
592+ input : []string {"run" , "--trace" , "--trace.format=json" , "6040" },
593+ wantStdout : "./testdata/evmrun/1.out.1.txt" ,
594+ wantStderr : "./testdata/evmrun/1.out.2.txt" ,
595+ },
596+ { // Same as above, using the deprecated --json
597+ input : []string {"run" , "--json" , "6040" },
598+ wantStdout : "./testdata/evmrun/1.out.1.txt" ,
599+ wantStderr : "./testdata/evmrun/1.out.2.txt" ,
600+ },
601+ { // default tracing (struct)
602+ input : []string {"run" , "--trace" , "0x6040" },
603+ wantStdout : "./testdata/evmrun/2.out.1.txt" ,
604+ wantStderr : "./testdata/evmrun/2.out.2.txt" ,
605+ },
606+ { // default tracing (struct), plus alloc-dump
607+ input : []string {"run" , "--trace" , "--dump" , "0x6040" },
608+ wantStdout : "./testdata/evmrun/3.out.1.txt" ,
609+ //wantStderr: "./testdata/evmrun/3.out.2.txt",
610+ },
611+ { // json-tracing, plus alloc-dump
612+ input : []string {"run" , "--trace" , "--trace.format=json" , "--dump" , "0x6040" },
613+ wantStdout : "./testdata/evmrun/4.out.1.txt" ,
614+ //wantStderr: "./testdata/evmrun/4.out.2.txt",
615+ },
616+ { // md-tracing
617+ input : []string {"run" , "--trace" , "--trace.format=md" , "0x6040" },
618+ wantStdout : "./testdata/evmrun/5.out.1.txt" ,
619+ wantStderr : "./testdata/evmrun/5.out.2.txt" ,
620+ },
621+ { // statetest subcommand
622+ input : []string {"statetest" , "./testdata/statetest.json" },
623+ wantStdout : "./testdata/evmrun/6.out.1.txt" ,
624+ wantStderr : "./testdata/evmrun/6.out.2.txt" ,
625+ },
626+ { // statetest subcommand with output
627+ input : []string {"statetest" , "--trace" , "--trace.format=md" , "./testdata/statetest.json" },
628+ wantStdout : "./testdata/evmrun/7.out.1.txt" ,
629+ wantStderr : "./testdata/evmrun/7.out.2.txt" ,
630+ },
631+ { // statetest subcommand with output
632+ input : []string {"statetest" , "--trace" , "--trace.format=json" , "./testdata/statetest.json" },
633+ wantStdout : "./testdata/evmrun/8.out.1.txt" ,
634+ wantStderr : "./testdata/evmrun/8.out.2.txt" ,
635+ },
636+ } {
637+ tt .Logf ("args: go run ./cmd/evm %v\n " , strings .Join (tc .input , " " ))
638+ tt .Run ("evm-test" , tc .input ... )
639+
640+ haveStdOut := tt .Output ()
641+ tt .WaitExit ()
642+ haveStdErr := tt .StderrText ()
643+
644+ if have , wantFile := haveStdOut , tc .wantStdout ; wantFile != "" {
645+ want , err := os .ReadFile (wantFile )
646+ if err != nil {
647+ t .Fatalf ("test %d: could not read expected output: %v" , i , err )
648+ }
649+ if string (haveStdOut ) != string (want ) {
650+ t .Fatalf ("test %d, output wrong, have \n %v\n want\n %v\n " , i , string (have ), string (want ))
651+ }
652+ }
653+ if have , wantFile := haveStdErr , tc .wantStderr ; wantFile != "" {
654+ want , err := os .ReadFile (wantFile )
655+ if err != nil {
656+ t .Fatalf ("test %d: could not read expected output: %v" , i , err )
657+ }
658+ if have != string (want ) {
659+ t .Fatalf ("test %d, output wrong\n have %q\n want %q\n " , i , have , string (want ))
660+ }
661+ }
662+ }
663+ }
664+
675665// cmpJson compares the JSON in two byte slices.
676666func cmpJson (a , b []byte ) (bool , error ) {
677667 var j , j2 interface {}
@@ -683,3 +673,93 @@ func cmpJson(a, b []byte) (bool, error) {
683673 }
684674 return reflect .DeepEqual (j2 , j ), nil
685675}
676+
677+ // TestEVMTracing is a test that checks the tracing-output from evm.
678+ func TestEVMTracing (t * testing.T ) {
679+ t .Parallel ()
680+ tt := cmdtest .NewTestCmd (t , nil )
681+ for i , tc := range []struct {
682+ base string
683+ input []string
684+ expectedTraces []string
685+ }{
686+ {
687+ base : "./testdata/31" ,
688+ input : []string {"t8n" ,
689+ "--input.alloc=./testdata/31/alloc.json" , "--input.txs=./testdata/31/txs.json" ,
690+ "--input.env=./testdata/31/env.json" , "--state.fork=Cancun" ,
691+ "--trace" ,
692+ },
693+ expectedTraces : []string {"trace-0-0x88f5fbd1524731a81e49f637aa847543268a5aaf2a6b32a69d2c6d978c45dcfb.jsonl" },
694+ },
695+ {
696+ base : "./testdata/31" ,
697+ input : []string {"t8n" ,
698+ "--input.alloc=./testdata/31/alloc.json" , "--input.txs=./testdata/31/txs.json" ,
699+ "--input.env=./testdata/31/env.json" , "--state.fork=Cancun" ,
700+ "--trace.tracer" , `
701+ {
702+ result: function(){
703+ return "hello world"
704+ },
705+ fault: function(){}
706+ }` ,
707+ },
708+ expectedTraces : []string {"trace-0-0x88f5fbd1524731a81e49f637aa847543268a5aaf2a6b32a69d2c6d978c45dcfb.json" },
709+ },
710+ {
711+ base : "./testdata/32" ,
712+ input : []string {"t8n" ,
713+ "--input.alloc=./testdata/32/alloc.json" , "--input.txs=./testdata/32/txs.json" ,
714+ "--input.env=./testdata/32/env.json" , "--state.fork=Paris" ,
715+ "--trace" , "--trace.callframes" ,
716+ },
717+ expectedTraces : []string {"trace-0-0x47806361c0fa084be3caa18afe8c48156747c01dbdfc1ee11b5aecdbe4fcf23e.jsonl" },
718+ },
719+ // TODO, make it possible to run tracers on statetests, e.g:
720+ //{
721+ // base: "./testdata/31",
722+ // input: []string{"statetest", "--trace", "--trace.tracer", `{
723+ // result: function(){
724+ // return "hello world"
725+ // },
726+ // fault: function(){}
727+ //}`, "./testdata/statetest.json"},
728+ // expectedTraces: []string{"trace-0-0x88f5fbd1524731a81e49f637aa847543268a5aaf2a6b32a69d2c6d978c45dcfb.json"},
729+ // },
730+ } {
731+ // Place the output somewhere we can find it
732+ outdir := t .TempDir ()
733+ args := append (tc .input , "--output.basedir" , outdir )
734+
735+ tt .Run ("evm-test" , args ... )
736+ tt .Logf ("args: go run ./cmd/evm %v\n " , args )
737+ tt .WaitExit ()
738+ //t.Log(string(tt.Output()))
739+
740+ // Compare the expected traces
741+ for _ , traceFile := range tc .expectedTraces {
742+ haveFn := lineIterator (filepath .Join (outdir , traceFile ))
743+ wantFn := lineIterator (filepath .Join (tc .base , traceFile ))
744+
745+ for line := 0 ; ; line ++ {
746+ want , wErr := wantFn ()
747+ have , hErr := haveFn ()
748+ if want != have {
749+ t .Fatalf ("test %d, trace %v, line %d\n want: %v\n have: %v\n " ,
750+ i , traceFile , line , want , have )
751+ }
752+ if wErr != nil && hErr != nil {
753+ break
754+ }
755+ if wErr != nil {
756+ t .Fatal (wErr )
757+ }
758+ if hErr != nil {
759+ t .Fatal (hErr )
760+ }
761+ //t.Logf("%v\n", want)
762+ }
763+ }
764+ }
765+ }
0 commit comments