Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Ethereum tests version #119

Merged
merged 11 commits into from
Feb 16, 2024
1 change: 1 addition & 0 deletions crypto/txsigner_london_berlin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestLondonSignerSender(t *testing.T) {
require.NoError(t, err, "unable to generate private key")

var txn *types.Transaction

switch tc.txType {
case types.AccessListTx:
txn = types.NewTx(&types.AccessListTxn{
Expand Down
4 changes: 4 additions & 0 deletions state/runtime/evm/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1624,8 +1624,10 @@
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

s, closeFn := getState(tt.config)
defer closeFn()

s.msg = tt.contract
s.gas = tt.initState.gas
s.sp = tt.initState.sp
Expand All @@ -1634,7 +1636,8 @@
s.config = tt.config
s.host = tt.mockHost
tt.contract.AccessList = tt.initState.accessList
opSload(s)

Check failure on line 1639 in state/runtime/evm/instructions_test.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

only cuddled expressions if assigning variable or using from line above (wsl)

assert.Equal(t, tt.resultState.gas, s.gas, "gas in state after execution is not correct")
assert.Equal(t, tt.resultState.sp, s.sp, "sp in state after execution is not correct")
assert.Equal(t, tt.resultState.stack, s.stack, "stack in state after execution is not correct")
Expand Down Expand Up @@ -2383,6 +2386,7 @@
test := tt
t.Run(test.name, func(t *testing.T) {
t.Parallel()

state, closeFn := getState(&test.config)
defer closeFn()

Expand Down
22 changes: 12 additions & 10 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/0xPolygon/polygon-edge/chain"
"github.com/0xPolygon/polygon-edge/crypto"
Expand Down Expand Up @@ -163,34 +164,31 @@ func TestState(t *testing.T) {

skip := []string{
"RevertPrecompiledTouch",
"RevertPrecompiledTouch_storage",
"loopMul",
"CALLBlake2f_MaxRounds",
}

// There are two folders in spec tests, one for the current tests for the Istanbul fork
// and one for the legacy tests for the other forks
folders, err := listFolders(stateTests)
folders, err := listFolders([]string{stateTests})
if err != nil {
t.Fatal(err)
}

for _, folder := range folders {
files, err := listFiles(folder)
files, err := listFiles(folder, ".json")
if err != nil {
t.Fatal(err)
}

for _, file := range files {
if !strings.HasSuffix(file, ".json") {
continue
}

if contains(long, file) && testing.Short() {
t.Skipf("Long tests are skipped in short mode")
t.Logf("Long test '%s' is skipped in short mode\n", file)

continue
}

if contains(skip, file) {
t.Skip()
t.Logf("Test '%s' is skipped\n", file)

continue
}
Expand Down Expand Up @@ -220,7 +218,11 @@ func TestState(t *testing.T) {
fc := &forkConfig{name: fork, forks: forks}

for idx, postStateEntry := range postState {
start := time.Now()
err := RunSpecificTest(t, file, tc, fc, idx, postStateEntry)

t.Logf("'%s' executed. Fork: %s. Case: %d, Duration=%v\n", file, fork, idx, time.Since(start))

require.NoError(t, tc.checkError(fork, idx, err))
}
}
Expand Down
60 changes: 40 additions & 20 deletions tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -483,16 +484,17 @@ var Forks = map[string]*chain.Forks{
chain.Constantinople: chain.NewFork(0),
},
"ConstantinopleFix": {
chain.EIP3607: chain.NewFork(0),
chain.Homestead: chain.NewFork(0),
chain.EIP150: chain.NewFork(0),
chain.EIP155: chain.NewFork(0),
chain.EIP158: chain.NewFork(0),
chain.Byzantium: chain.NewFork(0),
chain.Constantinople: chain.NewFork(0),
chain.Petersburg: chain.NewFork(0),
chain.EIP3607: chain.NewFork(0),
},
"Istanbul": {
chain.EIP3607: chain.NewFork(0),
chain.Homestead: chain.NewFork(0),
chain.EIP150: chain.NewFork(0),
chain.EIP155: chain.NewFork(0),
Expand All @@ -501,7 +503,6 @@ var Forks = map[string]*chain.Forks{
chain.Constantinople: chain.NewFork(0),
chain.Petersburg: chain.NewFork(0),
chain.Istanbul: chain.NewFork(0),
chain.EIP3607: chain.NewFork(0),
},
"FrontierToHomesteadAt5": {
chain.EIP3607: chain.NewFork(0),
Expand Down Expand Up @@ -551,6 +552,7 @@ var Forks = map[string]*chain.Forks{
chain.Istanbul: chain.NewFork(5),
},
"Berlin": {
chain.EIP3607: chain.NewFork(0),
chain.Homestead: chain.NewFork(0),
chain.EIP150: chain.NewFork(0),
chain.EIP155: chain.NewFork(0),
Expand All @@ -562,6 +564,7 @@ var Forks = map[string]*chain.Forks{
chain.Berlin: chain.NewFork(0),
},
"BerlinToLondonAt5": {
chain.EIP3607: chain.NewFork(0),
chain.Homestead: chain.NewFork(0),
chain.EIP150: chain.NewFork(0),
chain.EIP155: chain.NewFork(0),
Expand All @@ -574,6 +577,7 @@ var Forks = map[string]*chain.Forks{
chain.London: chain.NewFork(5),
},
// "London": {
// chain.EIP3607: chain.NewFork(0),
// chain.Homestead: chain.NewFork(0),
// chain.EIP150: chain.NewFork(0),
// chain.EIP155: chain.NewFork(0),
Expand All @@ -596,41 +600,57 @@ func contains(l []string, name string) bool {
return false
}

func listFolders(tests ...string) ([]string, error) {
func listFolders(paths []string) ([]string, error) {
var folders []string

for _, t := range tests {
dir, err := os.Open(t)
if err != nil {
return nil, err
}
defer dir.Close()
for _, rootPath := range paths {
err := filepath.WalkDir(rootPath, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

fileInfos, err := dir.Readdir(-1)
if err != nil {
return nil, err
}
if d.IsDir() {
files, err := os.ReadDir(path)
if err != nil {
return err
}

for _, fileInfo := range fileInfos {
if fileInfo.IsDir() && t != "path" {
folders = append(folders, filepath.Join(t, fileInfo.Name()))
if len(files) > 0 {
folders = append(folders, path)
}
}

return nil
})

if err != nil {
return nil, err
}
}

return folders, nil
}

func listFiles(folder string) ([]string, error) {
func listFiles(folder string, extensions ...string) ([]string, error) {
var files []string

err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
err := filepath.WalkDir(folder, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

if !info.IsDir() {
files = append(files, path)
if !d.IsDir() {
if len(extensions) > 0 {
// filter files by extensions
for _, ext := range extensions {
if strings.HasSuffix(path, ext) {
files = append(files, path)
}
}
} else {
// if no extensions filter is provided, add all files
files = append(files, path)
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion tests/tests
Submodule tests updated from 428f21 to 853b1e
Loading