@@ -39,6 +39,7 @@ import (
3939 "github.com/ethereum/go-ethereum/consensus/ethash"
4040 "github.com/ethereum/go-ethereum/core"
4141 "github.com/ethereum/go-ethereum/core/types"
42+ "github.com/ethereum/go-ethereum/core/types/bal"
4243 "github.com/ethereum/go-ethereum/crypto"
4344 "github.com/ethereum/go-ethereum/crypto/kzg4844"
4445 "github.com/ethereum/go-ethereum/eth"
@@ -1366,7 +1367,7 @@ func TestGetBlockBodiesByHash(t *testing.T) {
13661367 for k , test := range tests {
13671368 result := api .GetPayloadBodiesByHashV2 (test .hashes )
13681369 for i , r := range result {
1369- if err := checkEqualBody (test .results [i ], r ); err != nil {
1370+ if err := checkEqualBodyV2 (test .results [i ], r ); err != nil {
13701371 t .Fatalf ("test %v: invalid response: %v\n expected %+v\n got %+v" , k , err , test .results [i ], r )
13711372 }
13721373 }
@@ -1444,7 +1445,7 @@ func TestGetBlockBodiesByRange(t *testing.T) {
14441445 }
14451446 if len (result ) == len (test .results ) {
14461447 for i , r := range result {
1447- if err := checkEqualBody (test .results [i ], r ); err != nil {
1448+ if err := checkEqualBodyV2 (test .results [i ], r ); err != nil {
14481449 t .Fatalf ("test %d: invalid response: %v\n expected %+v\n got %+v" , k , err , test .results [i ], r )
14491450 }
14501451 }
@@ -1520,6 +1521,75 @@ func checkEqualBody(a *types.Body, b *engine.ExecutionPayloadBody) error {
15201521 return nil
15211522}
15221523
1524+ func checkEqualBodyV2 (a * types.Body , b * engine.ExecutionPayloadBodyV2 ) error {
1525+ if b == nil {
1526+ return checkEqualBody (a , nil )
1527+ }
1528+ return checkEqualBody (a , & b .ExecutionPayloadBody )
1529+ }
1530+
1531+ func TestGetPayloadBodyV2BlockAccessList (t * testing.T ) {
1532+ empty := bal.BlockAccessList {}
1533+ emptyHash := empty .Hash ()
1534+ tests := []struct {
1535+ name string
1536+ header * types.Header
1537+ accessList * bal.BlockAccessList
1538+ want string
1539+ }{
1540+ {
1541+ name : "retained empty BAL" ,
1542+ header : & types.Header {BlockAccessListHash : & emptyHash },
1543+ accessList : & empty ,
1544+ want : "[]" ,
1545+ },
1546+ {
1547+ name : "pruned BAL" ,
1548+ header : & types.Header {BlockAccessListHash : & emptyHash },
1549+ want : "null" ,
1550+ },
1551+ {
1552+ name : "pre-Amsterdam block" ,
1553+ header : new (types.Header ),
1554+ want : "null" ,
1555+ },
1556+ }
1557+ for _ , test := range tests {
1558+ t .Run (test .name , func (t * testing.T ) {
1559+ block := types .NewBlockWithHeader (test .header ).WithAccessListUnsafe (test .accessList )
1560+ body := getBodyV2 (block )
1561+ encoded , err := json .Marshal (body )
1562+ if err != nil {
1563+ t .Fatal (err )
1564+ }
1565+ var fields map [string ]json.RawMessage
1566+ if err := json .Unmarshal (encoded , & fields ); err != nil {
1567+ t .Fatal (err )
1568+ }
1569+ if got := string (fields ["blockAccessList" ]); got != test .want {
1570+ t .Fatalf ("unexpected blockAccessList: got %s, want %s" , got , test .want )
1571+ }
1572+ })
1573+ }
1574+ }
1575+
1576+ func TestGetPayloadBodyV1OmitsBlockAccessList (t * testing.T ) {
1577+ empty := bal.BlockAccessList {}
1578+ emptyHash := empty .Hash ()
1579+ block := types .NewBlockWithHeader (& types.Header {BlockAccessListHash : & emptyHash }).WithAccessListUnsafe (& empty )
1580+ encoded , err := json .Marshal (getBody (block ))
1581+ if err != nil {
1582+ t .Fatal (err )
1583+ }
1584+ var fields map [string ]json.RawMessage
1585+ if err := json .Unmarshal (encoded , & fields ); err != nil {
1586+ t .Fatal (err )
1587+ }
1588+ if _ , ok := fields ["blockAccessList" ]; ok {
1589+ t .Fatal ("V1 payload body contains blockAccessList" )
1590+ }
1591+ }
1592+
15231593func TestBlockToPayloadWithBlobs (t * testing.T ) {
15241594 header := types.Header {}
15251595 var txs []* types.Transaction
0 commit comments