Skip to content

Commit

Permalink
Update Ethereum tests spec to v10.4 (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed May 22, 2023
1 parent d7a35c3 commit 97e07b2
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 346 deletions.
2 changes: 1 addition & 1 deletion state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func (t *Transition) applyCreate(c *runtime.Contract, host runtime.Host) *runtim
// Increment the nonce of the caller
t.state.IncrNonce(c.Caller)

// Check if there if there is a collision and the address already exists
// Check if there is a collision and the address already exists
if t.hasCodeOrNonce(c.Address) {
return &runtime.ExecutionResult{
GasLeft: 0,
Expand Down
193 changes: 0 additions & 193 deletions tests/evm_test.go

This file was deleted.

62 changes: 41 additions & 21 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,58 @@ import (
"github.com/hashicorp/go-hclog"
)

var (
stateTests = "GeneralStateTests"
legacyStateTests = "LegacyTests/Constantinople/GeneralStateTests"
)
// Currently used test cases suite version is v10.4.
// It does not include Merge hardfork test cases.

type stateCase struct {
Info *info `json:"_info"`
Env *env `json:"env"`
Pre map[types.Address]*chain.GenesisAccount `json:"pre"`
Post map[string]postState `json:"post"`
Transaction *stTransaction `json:"transaction"`
}
const (
stateTests = "tests/GeneralStateTests"
legacyStateTests = "tests/LegacyTests/Constantinople/GeneralStateTests"
testGenesisBaseFee = 0x0a
)

var ripemd = types.StringToAddress("0000000000000000000000000000000000000003")
var (
ripemd = types.StringToAddress("0000000000000000000000000000000000000003")
)

func RunSpecificTest(t *testing.T, file string, c stateCase, name, fork string, index int, p postEntry) {
func RunSpecificTest(t *testing.T, file string, c testCase, name, fork string, index int, p postEntry) {
t.Helper()

config, ok := Forks[fork]
if !ok {
t.Fatalf("config %s not found", fork)
t.Skipf("%s fork is not supported", fork)

return
}

env := c.Env.ToEnv(t)

msg, err := c.Transaction.At(p.Indexes)
var baseFee *big.Int

if config.IsLondon(0) {
if c.Env.BaseFee != "" {
baseFee = stringToBigIntT(t, c.Env.BaseFee)
} else {
// Retesteth uses `10` for genesis baseFee. Therefore, it defaults to
// parent - 2 : 0xa as the basefee for 'this' context.
baseFee = big.NewInt(testGenesisBaseFee)
}
}

msg, err := c.Transaction.At(p.Indexes, baseFee)
if err != nil {
t.Fatal(err)
t.Fatalf("failed to create transaction: %v", err)
}

s, snapshot, pastRoot := buildState(c.Pre)
forks := config.At(uint64(env.Number))

xxx := state.NewExecutor(&chain.Params{Forks: config, ChainID: 1}, s, hclog.NewNullLogger())
xxx := state.NewExecutor(&chain.Params{
Forks: config,
ChainID: 1,
BurnContract: map[uint64]string{
0: types.ZeroAddress.String(),
},
}, s, hclog.NewNullLogger())

xxx.PostHook = func(t *state.Transition) {
if name == "failed_tx_xcf416c53" {
Expand All @@ -73,6 +91,7 @@ func RunSpecificTest(t *testing.T, file string, c stateCase, name, fork string,
objs := txn.Commit(forks.EIP155)
_, root := snapshot.Commit(objs)

// Check block root
if !bytes.Equal(root, p.Root.Bytes()) {
t.Fatalf(
"root mismatch (%s %s %s %d): expected %s but found %s",
Expand All @@ -85,6 +104,7 @@ func RunSpecificTest(t *testing.T, file string, c stateCase, name, fork string,
)
}

// Check transaction logs
if logs := rlpHashLogs(txn.Logs()); logs != p.Logs {
t.Fatalf(
"logs mismatch (%s, %s %d): expected %s but found %s",
Expand Down Expand Up @@ -151,12 +171,12 @@ func TestState(t *testing.T) {
t.Fatal(err)
}

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

for name, i := range c {
for name, i := range testCases {
for fork, f := range i.Post {
for indx, e := range f {
RunSpecificTest(t, file, i, name, fork, indx, e)
Expand Down
Loading

0 comments on commit 97e07b2

Please sign in to comment.