Skip to content

Commit 4ea656a

Browse files
committed
tests: add EEST transaction type tests
1 parent d118378 commit 4ea656a

File tree

3 files changed

+159
-54
lines changed

3 files changed

+159
-54
lines changed

tests/init_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ import (
3434
)
3535

3636
var (
37-
baseDir = filepath.Join(".", "testdata")
38-
blockTestDir = filepath.Join(baseDir, "BlockchainTests")
39-
stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
40-
legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests")
41-
transactionTestDir = filepath.Join(baseDir, "TransactionTests")
42-
rlpTestDir = filepath.Join(baseDir, "RLPTests")
43-
difficultyTestDir = filepath.Join(baseDir, "BasicTests")
44-
executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests")
45-
executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests")
46-
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks")
37+
baseDir = filepath.Join(".", "testdata")
38+
blockTestDir = filepath.Join(baseDir, "BlockchainTests")
39+
stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
40+
legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests")
41+
transactionTestDir = filepath.Join(baseDir, "TransactionTests")
42+
rlpTestDir = filepath.Join(baseDir, "RLPTests")
43+
difficultyTestDir = filepath.Join(baseDir, "BasicTests")
44+
executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests")
45+
executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests")
46+
executionSpecTransactionTestDir = filepath.Join(".", "spec-tests", "fixtures", "transaction_tests")
47+
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks")
4748
)
4849

4950
func readJSON(reader io.Reader, value interface{}) error {

tests/transaction_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package tests
1919
import (
2020
"testing"
2121

22+
"github.com/ethereum/go-ethereum/common"
2223
"github.com/ethereum/go-ethereum/params"
2324
)
2425

@@ -42,10 +43,36 @@ func TestTransaction(t *testing.T) {
4243
// Geth accepts it, which is not a consensus issue since we use big.Int's
4344
// internally to calculate the cost
4445
txt.skipLoad("^ttValue/TransactionWithHighValueOverflow.json")
46+
47+
// Test requires EVM execution and should be probably done as a state test.
48+
txt.skipLoad("^ttEIP3860/DataTestInitCodeTooBig.json")
49+
50+
// The following tests require the tx precheck to be performed.
51+
txt.skipLoad("^ttEIP1559/maxPriorityFeePerGass32BytesValue.json")
52+
txt.skipLoad("^ttEIP1559/maxPriorityFeePerGasOverflow.json")
53+
txt.skipLoad("^ttEIP1559/maxFeePerGas32BytesValue.json")
54+
txt.skipLoad("^ttEIP1559/maxFeePerGasOverflow.json")
55+
txt.skipLoad("^ttEIP1559/GasLimitPriceProductPlusOneOverflow.json")
56+
txt.skipLoad("^ttEIP1559/GasLimitPriceProductOverflow.json")
57+
4558
txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) {
4659
cfg := params.MainnetChainConfig
4760
if err := txt.checkFailure(t, test.Run(cfg)); err != nil {
4861
t.Error(err)
4962
}
5063
})
5164
}
65+
66+
func TestExecutionSpecTransaction(t *testing.T) {
67+
if !common.FileExist(executionSpecStateTestDir) {
68+
t.Skipf("directory %s does not exist", executionSpecStateTestDir)
69+
}
70+
st := new(testMatcher)
71+
72+
st.walk(t, executionSpecTransactionTestDir, func(t *testing.T, name string, test *TransactionTest) {
73+
cfg := params.MainnetChainConfig
74+
if err := st.checkFailure(t, test.Run(cfg)); err != nil {
75+
t.Error(err)
76+
}
77+
})
78+
}

tests/transaction_test_util.go

Lines changed: 121 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121

2222
"github.com/ethereum/go-ethereum/common"
2323
"github.com/ethereum/go-ethereum/common/hexutil"
24+
"github.com/ethereum/go-ethereum/common/math"
2425
"github.com/ethereum/go-ethereum/core"
2526
"github.com/ethereum/go-ethereum/core/types"
2627
"github.com/ethereum/go-ethereum/params"
27-
"github.com/ethereum/go-ethereum/rlp"
2828
)
2929

3030
// TransactionTest checks RLP decoding and sender derivation of transactions.
@@ -34,80 +34,157 @@ type TransactionTest struct {
3434
}
3535

3636
type ttResult struct {
37-
Byzantium ttFork
38-
Constantinople ttFork
39-
Istanbul ttFork
40-
EIP150 ttFork
41-
EIP158 ttFork
42-
Frontier ttFork
43-
Homestead ttFork
37+
Prague *ttFork
38+
Cancun *ttFork
39+
Shanghai *ttFork
40+
Paris *ttFork
41+
London *ttFork
42+
Berlin *ttFork
43+
Byzantium *ttFork
44+
Constantinople *ttFork
45+
Istanbul *ttFork
46+
EIP150 *ttFork
47+
EIP158 *ttFork
48+
Frontier *ttFork
49+
Homestead *ttFork
4450
}
4551

4652
type ttFork struct {
47-
Sender common.UnprefixedAddress `json:"sender"`
48-
Hash common.UnprefixedHash `json:"hash"`
53+
Sender *common.UnprefixedAddress `json:"sender"`
54+
Hash *common.UnprefixedHash `json:"hash"`
55+
Exception *string `json:"exception"`
56+
IntrinsicGas math.HexOrDecimal64 `json:"intrinsicGas"`
57+
}
58+
59+
func (tt *TransactionTest) validate() error {
60+
if tt.Txbytes == nil {
61+
return fmt.Errorf("missing txbytes")
62+
}
63+
if err := tt.validateFork(tt.Result.Prague); err != nil {
64+
return fmt.Errorf("invalid Prague: %v", err)
65+
}
66+
if err := tt.validateFork(tt.Result.Cancun); err != nil {
67+
return fmt.Errorf("invalid Cancun: %v", err)
68+
}
69+
if err := tt.validateFork(tt.Result.Shanghai); err != nil {
70+
return fmt.Errorf("invalid Shanghai: %v", err)
71+
}
72+
if err := tt.validateFork(tt.Result.Paris); err != nil {
73+
return fmt.Errorf("invalid Paris: %v", err)
74+
}
75+
if err := tt.validateFork(tt.Result.London); err != nil {
76+
return fmt.Errorf("invalid London: %v", err)
77+
}
78+
if err := tt.validateFork(tt.Result.Berlin); err != nil {
79+
return fmt.Errorf("invalid Berlin: %v", err)
80+
}
81+
if err := tt.validateFork(tt.Result.Byzantium); err != nil {
82+
return fmt.Errorf("invalid Byzantium: %v", err)
83+
}
84+
if err := tt.validateFork(tt.Result.Constantinople); err != nil {
85+
return fmt.Errorf("invalid Constantinople: %v", err)
86+
}
87+
if err := tt.validateFork(tt.Result.Istanbul); err != nil {
88+
return fmt.Errorf("invalid Istanbul: %v", err)
89+
}
90+
if err := tt.validateFork(tt.Result.EIP150); err != nil {
91+
return fmt.Errorf("invalid EIP150: %v", err)
92+
}
93+
if err := tt.validateFork(tt.Result.EIP158); err != nil {
94+
return fmt.Errorf("invalid EIP158: %v", err)
95+
}
96+
if err := tt.validateFork(tt.Result.Frontier); err != nil {
97+
return fmt.Errorf("invalid Frontier: %v", err)
98+
}
99+
if err := tt.validateFork(tt.Result.Homestead); err != nil {
100+
return fmt.Errorf("invalid Homestead: %v", err)
101+
}
102+
return nil
103+
}
104+
105+
func (tt *TransactionTest) validateFork(fork *ttFork) error {
106+
if fork == nil {
107+
return nil
108+
}
109+
if fork.Hash == nil && fork.Exception == nil {
110+
return fmt.Errorf("missing hash and exception")
111+
}
112+
if fork.Hash != nil && fork.Sender == nil {
113+
return fmt.Errorf("missing sender")
114+
}
115+
return nil
49116
}
50117

51118
func (tt *TransactionTest) Run(config *params.ChainConfig) error {
52-
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead bool, isIstanbul bool) (*common.Address, *common.Hash, error) {
119+
if err := tt.validate(); err != nil {
120+
return err
121+
}
122+
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead, isIstanbul, isShanghai bool) (sender common.Address, hash common.Hash, requiredGas uint64, err error) {
53123
tx := new(types.Transaction)
54-
if err := rlp.DecodeBytes(rlpData, tx); err != nil {
55-
return nil, nil, err
124+
if err = tx.UnmarshalBinary(rlpData); err != nil {
125+
return
56126
}
57-
sender, err := types.Sender(signer, tx)
127+
sender, err = types.Sender(signer, tx)
58128
if err != nil {
59-
return nil, nil, err
129+
return
60130
}
61131
// Intrinsic gas
62-
requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, false)
132+
requiredGas, err = core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, isShanghai)
63133
if err != nil {
64-
return nil, nil, err
134+
return
65135
}
66136
if requiredGas > tx.Gas() {
67-
return nil, nil, fmt.Errorf("insufficient gas ( %d < %d )", tx.Gas(), requiredGas)
137+
return sender, hash, 0, fmt.Errorf("insufficient gas ( %d < %d )", tx.Gas(), requiredGas)
68138
}
69-
h := tx.Hash()
70-
return &sender, &h, nil
139+
hash = tx.Hash()
140+
return sender, hash, requiredGas, nil
71141
}
72-
73142
for _, testcase := range []struct {
74143
name string
75144
signer types.Signer
76-
fork ttFork
145+
fork *ttFork
77146
isHomestead bool
78147
isIstanbul bool
148+
isShanghai bool
79149
}{
80-
{"Frontier", types.FrontierSigner{}, tt.Result.Frontier, false, false},
81-
{"Homestead", types.HomesteadSigner{}, tt.Result.Homestead, true, false},
82-
{"EIP150", types.HomesteadSigner{}, tt.Result.EIP150, true, false},
83-
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result.EIP158, true, false},
84-
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result.Byzantium, true, false},
85-
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result.Constantinople, true, false},
86-
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result.Istanbul, true, true},
150+
{"Frontier", types.FrontierSigner{}, tt.Result.Frontier, false, false, false},
151+
{"Homestead", types.HomesteadSigner{}, tt.Result.Homestead, true, false, false},
152+
{"EIP150", types.HomesteadSigner{}, tt.Result.EIP150, true, false, false},
153+
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result.EIP158, true, false, false},
154+
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result.Byzantium, true, false, false},
155+
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result.Constantinople, true, false, false},
156+
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result.Istanbul, true, true, false},
157+
{"Berlin", types.NewEIP2930Signer(config.ChainID), tt.Result.Berlin, true, true, false},
158+
{"London", types.NewLondonSigner(config.ChainID), tt.Result.London, true, true, false},
159+
{"Paris", types.NewLondonSigner(config.ChainID), tt.Result.Paris, true, true, false},
160+
{"Shanghai", types.NewLondonSigner(config.ChainID), tt.Result.Shanghai, true, true, true},
161+
{"Cancun", types.NewCancunSigner(config.ChainID), tt.Result.Cancun, true, true, true},
162+
{"Prague", types.NewPragueSigner(config.ChainID), tt.Result.Prague, true, true, true},
87163
} {
88-
sender, txhash, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul)
89-
90-
if testcase.fork.Sender == (common.UnprefixedAddress{}) {
91-
if err == nil {
92-
return fmt.Errorf("expected error, got none (address %v)[%v]", sender.String(), testcase.name)
93-
}
164+
if testcase.fork == nil {
94165
continue
95166
}
96-
// Should resolve the right address
167+
sender, hash, gas, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul, testcase.isShanghai)
97168
if err != nil {
98-
return fmt.Errorf("got error, expected none: %v", err)
169+
if testcase.fork.Hash != nil {
170+
return fmt.Errorf("unexpected error: %v", err)
171+
}
172+
continue
173+
}
174+
if testcase.fork.Exception != nil {
175+
return fmt.Errorf("expected error %v, got none (%v)", *testcase.fork.Exception, err)
99176
}
100-
if sender == nil {
101-
return fmt.Errorf("sender was nil, should be %x", common.Address(testcase.fork.Sender))
177+
if common.Hash(*testcase.fork.Hash) != hash {
178+
return fmt.Errorf("hash mismatch: got %x, want %x", hash, common.Hash(*testcase.fork.Hash))
102179
}
103-
if *sender != common.Address(testcase.fork.Sender) {
180+
if common.Address(*testcase.fork.Sender) != sender {
104181
return fmt.Errorf("sender mismatch: got %x, want %x", sender, testcase.fork.Sender)
105182
}
106-
if txhash == nil {
107-
return fmt.Errorf("txhash was nil, should be %x", common.Hash(testcase.fork.Hash))
183+
if hash != common.Hash(*testcase.fork.Hash) {
184+
return fmt.Errorf("hash mismatch: got %x, want %x", hash, testcase.fork.Hash)
108185
}
109-
if *txhash != common.Hash(testcase.fork.Hash) {
110-
return fmt.Errorf("hash mismatch: got %x, want %x", *txhash, testcase.fork.Hash)
186+
if uint64(testcase.fork.IntrinsicGas) != gas {
187+
return fmt.Errorf("intrinsic gas mismatch: got %d, want %d", gas, uint64(testcase.fork.IntrinsicGas))
111188
}
112189
}
113190
return nil

0 commit comments

Comments
 (0)