tests: add EEST transaction type tests

pull/31088/head
Sina Mahmoodi 1 week ago
parent d1183788fc
commit 4ea656a521
  1. 21
      tests/init_test.go
  2. 27
      tests/transaction_test.go
  3. 165
      tests/transaction_test_util.go

@ -34,16 +34,17 @@ import (
) )
var ( var (
baseDir = filepath.Join(".", "testdata") baseDir = filepath.Join(".", "testdata")
blockTestDir = filepath.Join(baseDir, "BlockchainTests") blockTestDir = filepath.Join(baseDir, "BlockchainTests")
stateTestDir = filepath.Join(baseDir, "GeneralStateTests") stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests") legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests") rlpTestDir = filepath.Join(baseDir, "RLPTests")
difficultyTestDir = filepath.Join(baseDir, "BasicTests") difficultyTestDir = filepath.Join(baseDir, "BasicTests")
executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests") executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests")
executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests") executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests")
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") executionSpecTransactionTestDir = filepath.Join(".", "spec-tests", "fixtures", "transaction_tests")
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks")
) )
func readJSON(reader io.Reader, value interface{}) error { func readJSON(reader io.Reader, value interface{}) error {

@ -19,6 +19,7 @@ package tests
import ( import (
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
@ -42,6 +43,18 @@ func TestTransaction(t *testing.T) {
// Geth accepts it, which is not a consensus issue since we use big.Int's // Geth accepts it, which is not a consensus issue since we use big.Int's
// internally to calculate the cost // internally to calculate the cost
txt.skipLoad("^ttValue/TransactionWithHighValueOverflow.json") txt.skipLoad("^ttValue/TransactionWithHighValueOverflow.json")
// Test requires EVM execution and should be probably done as a state test.
txt.skipLoad("^ttEIP3860/DataTestInitCodeTooBig.json")
// The following tests require the tx precheck to be performed.
txt.skipLoad("^ttEIP1559/maxPriorityFeePerGass32BytesValue.json")
txt.skipLoad("^ttEIP1559/maxPriorityFeePerGasOverflow.json")
txt.skipLoad("^ttEIP1559/maxFeePerGas32BytesValue.json")
txt.skipLoad("^ttEIP1559/maxFeePerGasOverflow.json")
txt.skipLoad("^ttEIP1559/GasLimitPriceProductPlusOneOverflow.json")
txt.skipLoad("^ttEIP1559/GasLimitPriceProductOverflow.json")
txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) { txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) {
cfg := params.MainnetChainConfig cfg := params.MainnetChainConfig
if err := txt.checkFailure(t, test.Run(cfg)); err != nil { if err := txt.checkFailure(t, test.Run(cfg)); err != nil {
@ -49,3 +62,17 @@ func TestTransaction(t *testing.T) {
} }
}) })
} }
func TestExecutionSpecTransaction(t *testing.T) {
if !common.FileExist(executionSpecStateTestDir) {
t.Skipf("directory %s does not exist", executionSpecStateTestDir)
}
st := new(testMatcher)
st.walk(t, executionSpecTransactionTestDir, func(t *testing.T, name string, test *TransactionTest) {
cfg := params.MainnetChainConfig
if err := st.checkFailure(t, test.Run(cfg)); err != nil {
t.Error(err)
}
})
}

@ -21,10 +21,10 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
) )
// TransactionTest checks RLP decoding and sender derivation of transactions. // TransactionTest checks RLP decoding and sender derivation of transactions.
@ -34,80 +34,157 @@ type TransactionTest struct {
} }
type ttResult struct { type ttResult struct {
Byzantium ttFork Prague *ttFork
Constantinople ttFork Cancun *ttFork
Istanbul ttFork Shanghai *ttFork
EIP150 ttFork Paris *ttFork
EIP158 ttFork London *ttFork
Frontier ttFork Berlin *ttFork
Homestead ttFork Byzantium *ttFork
Constantinople *ttFork
Istanbul *ttFork
EIP150 *ttFork
EIP158 *ttFork
Frontier *ttFork
Homestead *ttFork
} }
type ttFork struct { type ttFork struct {
Sender common.UnprefixedAddress `json:"sender"` Sender *common.UnprefixedAddress `json:"sender"`
Hash common.UnprefixedHash `json:"hash"` Hash *common.UnprefixedHash `json:"hash"`
Exception *string `json:"exception"`
IntrinsicGas math.HexOrDecimal64 `json:"intrinsicGas"`
}
func (tt *TransactionTest) validate() error {
if tt.Txbytes == nil {
return fmt.Errorf("missing txbytes")
}
if err := tt.validateFork(tt.Result.Prague); err != nil {
return fmt.Errorf("invalid Prague: %v", err)
}
if err := tt.validateFork(tt.Result.Cancun); err != nil {
return fmt.Errorf("invalid Cancun: %v", err)
}
if err := tt.validateFork(tt.Result.Shanghai); err != nil {
return fmt.Errorf("invalid Shanghai: %v", err)
}
if err := tt.validateFork(tt.Result.Paris); err != nil {
return fmt.Errorf("invalid Paris: %v", err)
}
if err := tt.validateFork(tt.Result.London); err != nil {
return fmt.Errorf("invalid London: %v", err)
}
if err := tt.validateFork(tt.Result.Berlin); err != nil {
return fmt.Errorf("invalid Berlin: %v", err)
}
if err := tt.validateFork(tt.Result.Byzantium); err != nil {
return fmt.Errorf("invalid Byzantium: %v", err)
}
if err := tt.validateFork(tt.Result.Constantinople); err != nil {
return fmt.Errorf("invalid Constantinople: %v", err)
}
if err := tt.validateFork(tt.Result.Istanbul); err != nil {
return fmt.Errorf("invalid Istanbul: %v", err)
}
if err := tt.validateFork(tt.Result.EIP150); err != nil {
return fmt.Errorf("invalid EIP150: %v", err)
}
if err := tt.validateFork(tt.Result.EIP158); err != nil {
return fmt.Errorf("invalid EIP158: %v", err)
}
if err := tt.validateFork(tt.Result.Frontier); err != nil {
return fmt.Errorf("invalid Frontier: %v", err)
}
if err := tt.validateFork(tt.Result.Homestead); err != nil {
return fmt.Errorf("invalid Homestead: %v", err)
}
return nil
}
func (tt *TransactionTest) validateFork(fork *ttFork) error {
if fork == nil {
return nil
}
if fork.Hash == nil && fork.Exception == nil {
return fmt.Errorf("missing hash and exception")
}
if fork.Hash != nil && fork.Sender == nil {
return fmt.Errorf("missing sender")
}
return nil
} }
func (tt *TransactionTest) Run(config *params.ChainConfig) error { func (tt *TransactionTest) Run(config *params.ChainConfig) error {
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead bool, isIstanbul bool) (*common.Address, *common.Hash, error) { if err := tt.validate(); err != nil {
return err
}
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead, isIstanbul, isShanghai bool) (sender common.Address, hash common.Hash, requiredGas uint64, err error) {
tx := new(types.Transaction) tx := new(types.Transaction)
if err := rlp.DecodeBytes(rlpData, tx); err != nil { if err = tx.UnmarshalBinary(rlpData); err != nil {
return nil, nil, err return
} }
sender, err := types.Sender(signer, tx) sender, err = types.Sender(signer, tx)
if err != nil { if err != nil {
return nil, nil, err return
} }
// Intrinsic gas // Intrinsic gas
requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, false) requiredGas, err = core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, isShanghai)
if err != nil { if err != nil {
return nil, nil, err return
} }
if requiredGas > tx.Gas() { if requiredGas > tx.Gas() {
return nil, nil, fmt.Errorf("insufficient gas ( %d < %d )", tx.Gas(), requiredGas) return sender, hash, 0, fmt.Errorf("insufficient gas ( %d < %d )", tx.Gas(), requiredGas)
} }
h := tx.Hash() hash = tx.Hash()
return &sender, &h, nil return sender, hash, requiredGas, nil
} }
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
signer types.Signer signer types.Signer
fork ttFork fork *ttFork
isHomestead bool isHomestead bool
isIstanbul bool isIstanbul bool
isShanghai bool
}{ }{
{"Frontier", types.FrontierSigner{}, tt.Result.Frontier, false, false}, {"Frontier", types.FrontierSigner{}, tt.Result.Frontier, false, false, false},
{"Homestead", types.HomesteadSigner{}, tt.Result.Homestead, true, false}, {"Homestead", types.HomesteadSigner{}, tt.Result.Homestead, true, false, false},
{"EIP150", types.HomesteadSigner{}, tt.Result.EIP150, true, false}, {"EIP150", types.HomesteadSigner{}, tt.Result.EIP150, true, false, false},
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result.EIP158, true, false}, {"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result.EIP158, true, false, false},
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result.Byzantium, true, false}, {"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result.Byzantium, true, false, false},
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result.Constantinople, true, false}, {"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result.Constantinople, true, false, false},
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result.Istanbul, true, true}, {"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result.Istanbul, true, true, false},
{"Berlin", types.NewEIP2930Signer(config.ChainID), tt.Result.Berlin, true, true, false},
{"London", types.NewLondonSigner(config.ChainID), tt.Result.London, true, true, false},
{"Paris", types.NewLondonSigner(config.ChainID), tt.Result.Paris, true, true, false},
{"Shanghai", types.NewLondonSigner(config.ChainID), tt.Result.Shanghai, true, true, true},
{"Cancun", types.NewCancunSigner(config.ChainID), tt.Result.Cancun, true, true, true},
{"Prague", types.NewPragueSigner(config.ChainID), tt.Result.Prague, true, true, true},
} { } {
sender, txhash, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul) if testcase.fork == nil {
if testcase.fork.Sender == (common.UnprefixedAddress{}) {
if err == nil {
return fmt.Errorf("expected error, got none (address %v)[%v]", sender.String(), testcase.name)
}
continue continue
} }
// Should resolve the right address sender, hash, gas, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul, testcase.isShanghai)
if err != nil { if err != nil {
return fmt.Errorf("got error, expected none: %v", err) if testcase.fork.Hash != nil {
return fmt.Errorf("unexpected error: %v", err)
}
continue
}
if testcase.fork.Exception != nil {
return fmt.Errorf("expected error %v, got none (%v)", *testcase.fork.Exception, err)
} }
if sender == nil { if common.Hash(*testcase.fork.Hash) != hash {
return fmt.Errorf("sender was nil, should be %x", common.Address(testcase.fork.Sender)) return fmt.Errorf("hash mismatch: got %x, want %x", hash, common.Hash(*testcase.fork.Hash))
} }
if *sender != common.Address(testcase.fork.Sender) { if common.Address(*testcase.fork.Sender) != sender {
return fmt.Errorf("sender mismatch: got %x, want %x", sender, testcase.fork.Sender) return fmt.Errorf("sender mismatch: got %x, want %x", sender, testcase.fork.Sender)
} }
if txhash == nil { if hash != common.Hash(*testcase.fork.Hash) {
return fmt.Errorf("txhash was nil, should be %x", common.Hash(testcase.fork.Hash)) return fmt.Errorf("hash mismatch: got %x, want %x", hash, testcase.fork.Hash)
} }
if *txhash != common.Hash(testcase.fork.Hash) { if uint64(testcase.fork.IntrinsicGas) != gas {
return fmt.Errorf("hash mismatch: got %x, want %x", *txhash, testcase.fork.Hash) return fmt.Errorf("intrinsic gas mismatch: got %d, want %d", gas, uint64(testcase.fork.IntrinsicGas))
} }
} }
return nil return nil

Loading…
Cancel
Save