tests: update for London (#22976)
This updates the tests submodule to the London fork tests, and also updates the test runner to support the new EIP-1559 fields in test JSON.
This commit is contained in:
committed by
GitHub
parent
08379b5533
commit
0e9c7d564d
@ -82,6 +82,7 @@ type stEnv struct {
|
||||
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
|
||||
Number uint64 `json:"currentNumber" gencodec:"required"`
|
||||
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
|
||||
BaseFee *big.Int `json:"currentBaseFee" gencodec:"optional"`
|
||||
}
|
||||
|
||||
type stEnvMarshaling struct {
|
||||
@ -90,26 +91,31 @@ type stEnvMarshaling struct {
|
||||
GasLimit math.HexOrDecimal64
|
||||
Number math.HexOrDecimal64
|
||||
Timestamp math.HexOrDecimal64
|
||||
BaseFee *math.HexOrDecimal256
|
||||
}
|
||||
|
||||
//go:generate gencodec -type stTransaction -field-override stTransactionMarshaling -out gen_sttransaction.go
|
||||
|
||||
type stTransaction struct {
|
||||
GasPrice *big.Int `json:"gasPrice"`
|
||||
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"`
|
||||
GasPrice *big.Int `json:"gasPrice"`
|
||||
MaxFeePerGas *big.Int `json:"maxFeePerGas"`
|
||||
MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type stTransactionMarshaling struct {
|
||||
GasPrice *math.HexOrDecimal256
|
||||
Nonce math.HexOrDecimal64
|
||||
GasLimit []math.HexOrDecimal64
|
||||
PrivateKey hexutil.Bytes
|
||||
GasPrice *math.HexOrDecimal256
|
||||
MaxFeePerGas *math.HexOrDecimal256
|
||||
MaxPriorityFeePerGas *math.HexOrDecimal256
|
||||
Nonce math.HexOrDecimal64
|
||||
GasLimit []math.HexOrDecimal64
|
||||
PrivateKey hexutil.Bytes
|
||||
}
|
||||
|
||||
// GetChainConfig takes a fork definition and returns a chain config.
|
||||
@ -177,8 +183,17 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
||||
block := t.genesis(config).ToBlock(nil)
|
||||
snaps, statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, snapshotter)
|
||||
|
||||
var baseFee *big.Int
|
||||
if config.IsLondon(new(big.Int)) {
|
||||
baseFee = t.json.Env.BaseFee
|
||||
if baseFee == nil {
|
||||
// Retesteth uses `0x10` for genesis baseFee. Therefore, it defaults to
|
||||
// parent - 2 : 0xa as the basefee for 'this' context.
|
||||
baseFee = big.NewInt(0x0a)
|
||||
}
|
||||
}
|
||||
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||
msg, err := t.json.Tx.toMessage(post)
|
||||
msg, err := t.json.Tx.toMessage(post, baseFee)
|
||||
if err != nil {
|
||||
return nil, nil, common.Hash{}, err
|
||||
}
|
||||
@ -187,6 +202,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
||||
txContext := core.NewEVMTxContext(msg)
|
||||
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
|
||||
context.GetHash = vmTestBlockHash
|
||||
context.BaseFee = baseFee
|
||||
evm := vm.NewEVM(context, txContext, statedb, config, vmconfig)
|
||||
|
||||
// Execute the message.
|
||||
@ -248,7 +264,7 @@ func (t *StateTest) genesis(config *params.ChainConfig) *core.Genesis {
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
|
||||
func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (core.Message, error) {
|
||||
// Derive sender from private key if present.
|
||||
var from common.Address
|
||||
if len(tx.PrivateKey) > 0 {
|
||||
@ -297,7 +313,24 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
|
||||
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, nil, nil, data, accessList, true)
|
||||
// If baseFee provided, set gasPrice to effectiveGasPrice.
|
||||
gasPrice := tx.GasPrice
|
||||
if baseFee != nil {
|
||||
if tx.MaxFeePerGas == nil {
|
||||
tx.MaxFeePerGas = gasPrice
|
||||
}
|
||||
if tx.MaxFeePerGas == nil {
|
||||
tx.MaxFeePerGas = new(big.Int)
|
||||
}
|
||||
if tx.MaxPriorityFeePerGas == nil {
|
||||
tx.MaxPriorityFeePerGas = tx.MaxFeePerGas
|
||||
}
|
||||
gasPrice = math.BigMin(new(big.Int).Add(tx.MaxPriorityFeePerGas, baseFee),
|
||||
tx.MaxFeePerGas)
|
||||
}
|
||||
|
||||
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, gasPrice,
|
||||
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, true)
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user