tests: improve cancun support

This commit is contained in:
Felix Lange 2023-08-26 05:31:28 +02:00
parent 26722ef214
commit cc2fea08e0
3 changed files with 119 additions and 66 deletions

View file

@ -91,6 +91,9 @@ type btHeader struct {
Timestamp uint64
BaseFeePerGas *big.Int
WithdrawalsRoot *common.Hash
BlobGasUsed *uint64
ExcessBlobGas *uint64
ParentBeaconBlockRoot *common.Hash
}
type btHeaderMarshaling struct {
@ -101,6 +104,8 @@ type btHeaderMarshaling struct {
GasUsed math.HexOrDecimal64
Timestamp math.HexOrDecimal64
BaseFeePerGas *math.HexOrDecimal256
BlobGasUsed *math.HexOrDecimal64
ExcessBlobGas *math.HexOrDecimal64
}
func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger) error {
@ -187,6 +192,8 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
Coinbase: t.json.Genesis.Coinbase,
Alloc: t.json.Pre,
BaseFee: t.json.Genesis.BaseFeePerGas,
BlobGasUsed: t.json.Genesis.BlobGasUsed,
ExcessBlobGas: t.json.Genesis.ExcessBlobGas,
}
}
@ -295,6 +302,15 @@ func validateHeader(h *btHeader, h2 *types.Header) error {
if !reflect.DeepEqual(h.WithdrawalsRoot, h2.WithdrawalsHash) {
return fmt.Errorf("withdrawalsRoot: want: %v have: %v", h.WithdrawalsRoot, h2.WithdrawalsHash)
}
if !reflect.DeepEqual(h.BlobGasUsed, h2.BlobGasUsed) {
return fmt.Errorf("blobGasUsed: want: %v have: %v", h.BlobGasUsed, h2.BlobGasUsed)
}
if !reflect.DeepEqual(h.ExcessBlobGas, h2.ExcessBlobGas) {
return fmt.Errorf("excessBlobGas: want: %v have: %v", h.ExcessBlobGas, h2.ExcessBlobGas)
}
if !reflect.DeepEqual(h.ParentBeaconBlockRoot, h2.ParentBeaconRoot) {
return fmt.Errorf("parentBeaconBlockRoot: want: %v have: %v", h.ParentBeaconBlockRoot, h2.ParentBeaconRoot)
}
return nil
}

View file

@ -35,6 +35,9 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
Timestamp math.HexOrDecimal64
BaseFeePerGas *math.HexOrDecimal256
WithdrawalsRoot *common.Hash
BlobGasUsed *math.HexOrDecimal64
ExcessBlobGas *math.HexOrDecimal64
ParentBeaconBlockRoot *common.Hash
}
var enc btHeader
enc.Bloom = b.Bloom
@ -55,6 +58,9 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
enc.Timestamp = math.HexOrDecimal64(b.Timestamp)
enc.BaseFeePerGas = (*math.HexOrDecimal256)(b.BaseFeePerGas)
enc.WithdrawalsRoot = b.WithdrawalsRoot
enc.BlobGasUsed = (*math.HexOrDecimal64)(b.BlobGasUsed)
enc.ExcessBlobGas = (*math.HexOrDecimal64)(b.ExcessBlobGas)
enc.ParentBeaconBlockRoot = b.ParentBeaconBlockRoot
return json.Marshal(&enc)
}
@ -79,6 +85,9 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
Timestamp *math.HexOrDecimal64
BaseFeePerGas *math.HexOrDecimal256
WithdrawalsRoot *common.Hash
BlobGasUsed *math.HexOrDecimal64
ExcessBlobGas *math.HexOrDecimal64
ParentBeaconBlockRoot *common.Hash
}
var dec btHeader
if err := json.Unmarshal(input, &dec); err != nil {
@ -138,5 +147,14 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
if dec.WithdrawalsRoot != nil {
b.WithdrawalsRoot = dec.WithdrawalsRoot
}
if dec.BlobGasUsed != nil {
b.BlobGasUsed = (*uint64)(dec.BlobGasUsed)
}
if dec.ExcessBlobGas != nil {
b.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
}
if dec.ParentBeaconBlockRoot != nil {
b.ParentBeaconBlockRoot = dec.ParentBeaconBlockRoot
}
return nil
}

View file

@ -318,6 +318,25 @@ var Forks = map[string]*params.ChainConfig{
ShanghaiTime: u64(0),
CancunTime: u64(0),
},
"ShanghaiToCancunAtTime15k": {
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
ShanghaiTime: u64(0),
CancunTime: u64(15_000),
},
}
// AvailableForks returns the set of defined fork names