Skip to content

Commit

Permalink
Benchmark tests support
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Mar 4, 2024
1 parent 72e932f commit 7113249
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
57 changes: 57 additions & 0 deletions tests/evm_benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package tests

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/require"
)

const (
benchmarksDir = "tests/evm-benchmarks/benchmarks"
)

func BenchmarkEVM(b *testing.B) {
folders, err := listFolders([]string{benchmarksDir})
require.NoError(b, err)

for _, folder := range folders {
files, err := listFiles(folder, ".json")
require.NoError(b, err)

for _, file := range files {
name := getTestName(file)

b.Run(name, func(b *testing.B) {
data, err := os.ReadFile(file)
require.NoError(b, err)

var testCases map[string]testCase
if err = json.Unmarshal(data, &testCases); err != nil {
b.Fatalf("failed to unmarshal %s: %v", file, err)
}

for _, tc := range testCases {
for fork, postState := range tc.Post {
forks, exists := Forks[fork]
if !exists {
b.Logf("%s fork is not supported, skipping test case.", fork)
continue
}

fc := &forkConfig{name: fork, forks: forks}

for idx, postStateEntry := range postState {
runBenchmarkTest(b, file, tc, fc, idx, postStateEntry)
}
}
}
})
}
}
}

func runBenchmarkTest(b *testing.B, file string, c testCase, fc *forkConfig, index int, p postEntry) {

}
10 changes: 1 addition & 9 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"math/big"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -116,8 +114,7 @@ func TestState(t *testing.T) {
func runSpecificTestCase(t *testing.T, file string, c testCase, fc *forkConfig, index int, p postEntry) error {
t.Helper()

testName := filepath.Base(file)
testName = strings.TrimSuffix(testName, ".json")
testName := getTestName(file)

env := c.Env.ToEnv(t)
forks := fc.forks
Expand Down Expand Up @@ -231,8 +228,3 @@ func runSpecificTestCase(t *testing.T, file string, c testCase, fc *forkConfig,

return nil
}

type forkConfig struct {
name string
forks *chain.Forks
}
12 changes: 12 additions & 0 deletions tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,15 @@ func rlpHashLogs(logs []*types.Log) (res types.Hash) {
func vmTestBlockHash(n uint64) types.Hash {
return types.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
}

// getTestName extracts test name from the test file path
func getTestName(testFile string) string {
testName := filepath.Base(testFile)

return strings.TrimSuffix(testName, ".json")
}

type forkConfig struct {
name string
forks *chain.Forks
}

0 comments on commit 7113249

Please sign in to comment.