mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
test: add eip1559_scroll_test.go (#784)
This commit is contained in:
parent
e5171495e1
commit
f3c8cc1cb7
1 changed files with 126 additions and 0 deletions
126
consensus/misc/eip1559/eip1559_scroll_test.go
Normal file
126
consensus/misc/eip1559/eip1559_scroll_test.go
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
// Copyright 2021 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package eip1559
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
// copyConfig does a _shallow_ copy of a given config. Safe to set new values, but
|
||||
// do not use e.g. SetInt() on the numbers. For testing only
|
||||
func copyConfig(original *params.ChainConfig) *params.ChainConfig {
|
||||
return ¶ms.ChainConfig{
|
||||
ChainID: original.ChainID,
|
||||
HomesteadBlock: original.HomesteadBlock,
|
||||
DAOForkBlock: original.DAOForkBlock,
|
||||
DAOForkSupport: original.DAOForkSupport,
|
||||
EIP150Block: original.EIP150Block,
|
||||
EIP155Block: original.EIP155Block,
|
||||
EIP158Block: original.EIP158Block,
|
||||
ByzantiumBlock: original.ByzantiumBlock,
|
||||
ConstantinopleBlock: original.ConstantinopleBlock,
|
||||
PetersburgBlock: original.PetersburgBlock,
|
||||
IstanbulBlock: original.IstanbulBlock,
|
||||
MuirGlacierBlock: original.MuirGlacierBlock,
|
||||
BerlinBlock: original.BerlinBlock,
|
||||
LondonBlock: original.LondonBlock,
|
||||
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
|
||||
Ethash: original.Ethash,
|
||||
Clique: original.Clique,
|
||||
}
|
||||
}
|
||||
|
||||
func config() *params.ChainConfig {
|
||||
config := copyConfig(params.TestChainConfig)
|
||||
config.BernoulliBlock = big.NewInt(3)
|
||||
config.CurieBlock = big.NewInt(5)
|
||||
return config
|
||||
}
|
||||
|
||||
// TestBlockGasLimits tests the gasLimit checks for blocks both across
|
||||
// the EIP-1559 boundary and post-1559 blocks
|
||||
func TestBlockGasLimits(t *testing.T) {
|
||||
initial := new(big.Int).SetUint64(params.InitialBaseFee)
|
||||
|
||||
for i, tc := range []struct {
|
||||
pGasLimit uint64
|
||||
pNum int64
|
||||
gasLimit uint64
|
||||
ok bool
|
||||
}{
|
||||
// Transitions from non-curie to curie
|
||||
{10000000, 4, 10000000, true}, // No change
|
||||
{10000000, 4, 10009764, true}, // Upper limit
|
||||
{10000000, 4, 10009765, false}, // Upper +1
|
||||
{10000000, 4, 9990236, true}, // Lower limit
|
||||
{10000000, 4, 9990235, false}, // Lower limit -1
|
||||
// Curie to Curie
|
||||
{20000000, 5, 20000000, true},
|
||||
{20000000, 5, 20019530, true}, // Upper limit
|
||||
{20000000, 5, 20019531, false}, // Upper limit +1
|
||||
{20000000, 5, 19980470, true}, // Lower limit
|
||||
{20000000, 5, 19980469, false}, // Lower limit -1
|
||||
{40000000, 5, 40039061, true}, // Upper limit
|
||||
{40000000, 5, 40039062, false}, // Upper limit +1
|
||||
{40000000, 5, 39960939, true}, // lower limit
|
||||
{40000000, 5, 39960938, false}, // Lower limit -1
|
||||
} {
|
||||
parent := &types.Header{
|
||||
GasUsed: tc.pGasLimit / 2,
|
||||
GasLimit: tc.pGasLimit,
|
||||
BaseFee: initial,
|
||||
Number: big.NewInt(tc.pNum),
|
||||
}
|
||||
header := &types.Header{
|
||||
GasUsed: tc.gasLimit / 2,
|
||||
GasLimit: tc.gasLimit,
|
||||
BaseFee: initial,
|
||||
Number: big.NewInt(tc.pNum + 1),
|
||||
}
|
||||
err := VerifyEIP1559Header(config(), parent, header)
|
||||
if tc.ok && err != nil {
|
||||
t.Errorf("test %d: Expected valid header: %s", i, err)
|
||||
}
|
||||
if !tc.ok && err == nil {
|
||||
t.Errorf("test %d: Expected invalid header", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestCalcBaseFee assumes all blocks are 1559-blocks
|
||||
func TestCalcBaseFee(t *testing.T) {
|
||||
tests := []struct {
|
||||
parentL1BaseFee int64
|
||||
expectedL2BaseFee int64
|
||||
}{
|
||||
{0, 150000000},
|
||||
{1000000000, 164000000},
|
||||
{2000000000, 178000000},
|
||||
{100000000000, 1550000000},
|
||||
{111111111111, 1705555555},
|
||||
{1000000000000, 10000000000}, // cap at max L2 base fee
|
||||
}
|
||||
for i, test := range tests {
|
||||
if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {
|
||||
t.Errorf("test %d: have %d want %d, ", i, have, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue