From b0a80872fbc60fe058095ffdddcb4d96d6e9b502 Mon Sep 17 00:00:00 2001
From: Marius van der Wijden <m.vanderwijden@live.de>
Date: Wed, 3 Mar 2021 15:50:07 +0100
Subject: [PATCH] tests: update to latest tests (#22290)

This updates the consensus tests to commit 31d6630 and
adds support for access list transactions in the test runner.

Co-authored-by: Martin Holst Swende <martin@swende.se>
# Conflicts:
#	tests/block_test.go
#	tests/gen_sttransaction.go
#	tests/state_test_util.go
---
 tests/block_test.go        | 14 +++++++-------
 tests/gen_stenv.go         |  2 ++
 tests/gen_sttransaction.go | 36 ++++++++++++++++++++++--------------
 tests/gen_vmexec.go        |  2 ++
 tests/state_test.go        |  8 --------
 tests/state_test_util.go   |  7 ++++++-
 6 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/tests/block_test.go b/tests/block_test.go
index 45cf4dcedd..61a89d27bf 100644
--- a/tests/block_test.go
+++ b/tests/block_test.go
@@ -25,7 +25,11 @@ func TestBlockchain(t *testing.T) {
 
 	bt := new(testMatcher)
 	// General state tests are 'exported' as blockchain tests, but we can run them natively.
-	bt.skipLoad(`^GeneralStateTests/`)
+	// For speedier CI-runs, the line below can be uncommented, so those are skipped.
+	// For now, in hardfork-times (Berlin), we run the tests both as StateTests and
+	// as blockchain tests, since the latter also covers things like receipt root
+	//bt.skipLoad(`^GeneralStateTests/`)
+
 	// Skip random failures due to selfish mining test
 	bt.skipLoad(`.*bcForgedTest/bcForkUncle\.json`)
 
@@ -62,12 +66,8 @@ func TestBlockchain(t *testing.T) {
 
 	bt.fails(`(?m)^TestBlockchain/InvalidBlocks/bcUncleHeaderValidity/incorrectUncleTimestamp5.json`, "Needs to be fixed for TG")
 	bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
-		if test.json.Network == "Berlin" {
-			// Our current berlin-tests were generated using YOLOv2 rules, hence a lot of them
-			// fail when berlin is defined as YOLOv3. We skip those, until they've been
-			// regenerated and re-imported
-			// TODO (@holiman)
-			return
+		if err := bt.checkFailure(t, name+"/trie", test.Run(false)); err != nil {
+			t.Errorf("test without snapshotter failed: %v", err)
 		}
 		if err := bt.checkFailure(t, test.Run(false)); err != nil {
 			t.Error(err)
diff --git a/tests/gen_stenv.go b/tests/gen_stenv.go
index 8db00cbd35..993558d63c 100644
--- a/tests/gen_stenv.go
+++ b/tests/gen_stenv.go
@@ -13,6 +13,7 @@ import (
 
 var _ = (*stEnvMarshaling)(nil)
 
+// MarshalJSON marshals as JSON.
 func (s stEnv) MarshalJSON() ([]byte, error) {
 	type stEnv struct {
 		Coinbase   common.UnprefixedAddress `json:"currentCoinbase"   gencodec:"required"`
@@ -30,6 +31,7 @@ func (s stEnv) MarshalJSON() ([]byte, error) {
 	return json.Marshal(&enc)
 }
 
+// UnmarshalJSON unmarshals from JSON.
 func (s *stEnv) UnmarshalJSON(input []byte) error {
 	type stEnv struct {
 		Coinbase   *common.UnprefixedAddress `json:"currentCoinbase"   gencodec:"required"`
diff --git a/tests/gen_sttransaction.go b/tests/gen_sttransaction.go
index 2419d609a3..908537723e 100644
--- a/tests/gen_sttransaction.go
+++ b/tests/gen_sttransaction.go
@@ -14,21 +14,24 @@ import (
 
 var _ = (*stTransactionMarshaling)(nil)
 
+// MarshalJSON marshals as JSON.
 func (s stTransaction) MarshalJSON() ([]byte, error) {
 	type stTransaction struct {
-		GasPrice   *math.HexOrDecimal256 `json:"gasPrice"`
-		Nonce      math.HexOrDecimal64   `json:"nonce"`
-		To         string                `json:"to"`
-		Data       []string              `json:"data"`
-		GasLimit   []math.HexOrDecimal64 `json:"gasLimit"`
-		Value      []string              `json:"value"`
-		PrivateKey hexutil.Bytes         `json:"secretKey"`
+		GasPrice    *math.HexOrDecimal256 `json:"gasPrice"`
+		Nonce       math.HexOrDecimal64   `json:"nonce"`
+		To          string                `json:"to"`
+		Data        []string              `json:"data"`
+		AccessLists []*types.AccessList   `json:"accessLists,omitempty"`
+		GasLimit    []math.HexOrDecimal64 `json:"gasLimit"`
+		Value       []string              `json:"value"`
+		PrivateKey  hexutil.Bytes         `json:"secretKey"`
 	}
 	var enc stTransaction
 	enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice.ToBig())
 	enc.Nonce = math.HexOrDecimal64(s.Nonce)
 	enc.To = s.To
 	enc.Data = s.Data
+	enc.AccessLists = s.AccessLists
 	if s.GasLimit != nil {
 		enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit))
 		for k, v := range s.GasLimit {
@@ -40,15 +43,17 @@ func (s stTransaction) MarshalJSON() ([]byte, error) {
 	return json.Marshal(&enc)
 }
 
+// UnmarshalJSON unmarshals from JSON.
 func (s *stTransaction) UnmarshalJSON(input []byte) error {
 	type stTransaction struct {
-		GasPrice   *math.HexOrDecimal256 `json:"gasPrice"`
-		Nonce      *math.HexOrDecimal64  `json:"nonce"`
-		To         *string               `json:"to"`
-		Data       []string              `json:"data"`
-		GasLimit   []math.HexOrDecimal64 `json:"gasLimit"`
-		Value      []string              `json:"value"`
-		PrivateKey *hexutil.Bytes        `json:"secretKey"`
+		GasPrice    *math.HexOrDecimal256 `json:"gasPrice"`
+		Nonce       *math.HexOrDecimal64  `json:"nonce"`
+		To          *string               `json:"to"`
+		Data        []string              `json:"data"`
+		AccessLists []*types.AccessList   `json:"accessLists,omitempty"`
+		GasLimit    []math.HexOrDecimal64 `json:"gasLimit"`
+		Value       []string              `json:"value"`
+		PrivateKey  *hexutil.Bytes        `json:"secretKey"`
 	}
 	var dec stTransaction
 	if err := json.Unmarshal(input, &dec); err != nil {
@@ -66,6 +71,9 @@ func (s *stTransaction) UnmarshalJSON(input []byte) error {
 	if dec.Data != nil {
 		s.Data = dec.Data
 	}
+	if dec.AccessLists != nil {
+		s.AccessLists = dec.AccessLists
+	}
 	if dec.GasLimit != nil {
 		s.GasLimit = make([]uint64, len(dec.GasLimit))
 		for k, v := range dec.GasLimit {
diff --git a/tests/gen_vmexec.go b/tests/gen_vmexec.go
index 06e143d42c..a17c8a62b8 100644
--- a/tests/gen_vmexec.go
+++ b/tests/gen_vmexec.go
@@ -14,6 +14,7 @@ import (
 
 var _ = (*vmExecMarshaling)(nil)
 
+// MarshalJSON marshals as JSON.
 func (v vmExec) MarshalJSON() ([]byte, error) {
 	type vmExec struct {
 		Address  common.UnprefixedAddress `json:"address"  gencodec:"required"`
@@ -37,6 +38,7 @@ func (v vmExec) MarshalJSON() ([]byte, error) {
 	return json.Marshal(&enc)
 }
 
+// UnmarshalJSON unmarshals from JSON.
 func (v *vmExec) UnmarshalJSON(input []byte) error {
 	type vmExec struct {
 		Address  *common.UnprefixedAddress `json:"address"  gencodec:"required"`
diff --git a/tests/state_test.go b/tests/state_test.go
index edf40998ec..f06781f3ae 100644
--- a/tests/state_test.go
+++ b/tests/state_test.go
@@ -66,14 +66,6 @@ func TestState(t *testing.T) {
 	} {
 		st.walk(t, dir, func(t *testing.T, name string, test *StateTest) {
 			for _, subtest := range test.Subtests() {
-				if subtest.Fork == "Berlin" {
-					// Our current berlin-tests were generated using YOLOv2 rules, hence a lot of them
-					// fail when berlin is defined as YOLOv3. We skip those, until they've been
-					// regenerated and re-imported
-					// TODO (@holiman)
-					continue
-				}
-
 				subtest := subtest
 				key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
 				t.Run(key, func(t *testing.T) {
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 7ec162b27d..2af54df9aa 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -112,6 +112,7 @@ type stTransaction struct {
 	Nonce      uint64       `json:"nonce"`
 	To         string       `json:"to"`
 	Data       []string     `json:"data"`
+	AccessLists []*types.AccessList `json:"accessLists,omitempty"`
 	GasLimit   []uint64     `json:"gasLimit"`
 	Value      []string     `json:"value"`
 	PrivateKey []byte       `json:"secretKey"`
@@ -342,8 +343,12 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
 	if err != nil {
 		return nil, fmt.Errorf("invalid tx data %q", dataHex)
 	}
+	var accessList types.AccessList
+	if tx.AccessLists != nil && tx.AccessLists[ps.Indexes.Data] != nil {
+		accessList = *tx.AccessLists[ps.Indexes.Data]
+	}
 
-	msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, nil, true)
+	msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, accessList, true)
 	return msg, nil
 }
 
-- 
GitLab