Skip to content

Commit

Permalink
eth/catalyst: better equality
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Mar 7, 2023
1 parent 9450dbf commit 87af877
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"math/rand"
"reflect"
"sync"
"testing"
"time"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
)
Expand Down Expand Up @@ -1238,10 +1238,10 @@ func TestNilWithdrawals(t *testing.T) {
}

func setupBodies(t *testing.T) (*node.Node, *eth.Ethereum, []*types.Block) {
genesis, preMergeBlocks := generateMergeChain(10, true)
n, ethservice := startEthService(t, genesis, preMergeBlocks)
genesis, blocks := generateMergeChain(10, true)
n, ethservice := startEthService(t, genesis, blocks)
// enable shanghai on the last block
ethservice.BlockChain().Config().ShanghaiTime = &preMergeBlocks[len(preMergeBlocks)-1].Header().Time
ethservice.BlockChain().Config().ShanghaiTime = &blocks[len(blocks)-1].Header().Time

var (
parent = ethservice.BlockChain().CurrentBlock()
Expand All @@ -1267,12 +1267,12 @@ func setupBodies(t *testing.T) (*node.Node, *eth.Ethereum, []*types.Block) {
}
}

postMergeHeaders := setupBlocks(t, ethservice, 10, parent, callback, withdrawals)
postMergeBlocks := make([]*types.Block, len(postMergeHeaders))
for i, header := range postMergeHeaders {
postMergeBlocks[i] = ethservice.BlockChain().GetBlock(header.Hash(), header.Number.Uint64())
postShanghaiHeaders := setupBlocks(t, ethservice, 10, parent, callback, withdrawals)
postShanghaiBlocks := make([]*types.Block, len(postShanghaiHeaders))
for i, header := range postShanghaiHeaders {
postShanghaiBlocks[i] = ethservice.BlockChain().GetBlock(header.Hash(), header.Number.Uint64())
}
return n, ethservice, append(preMergeBlocks, postMergeBlocks...)
return n, ethservice, append(blocks, postShanghaiBlocks...)
}

func allHashes(blocks []*types.Block) []common.Hash {
Expand Down Expand Up @@ -1478,28 +1478,14 @@ func equalBody(a *types.Body, b *engine.ExecutionPayloadBodyV1) bool {
} else if a == nil || b == nil {
return false
}
var want []hexutil.Bytes
for _, tx := range a.Transactions {
data, _ := tx.MarshalBinary()
want = append(want, hexutil.Bytes(data))
}
aBytes, errA := rlp.EncodeToBytes(want)
bBytes, errB := rlp.EncodeToBytes(b.TransactionData)
if errA != errB {
return false
}
if !bytes.Equal(aBytes, bBytes) {
if len(a.Transactions) != len(b.TransactionData) {
return false
}
if a.Withdrawals == nil && b.Withdrawals == nil {
return true
} else if a.Withdrawals == nil || b.Withdrawals == nil {
return false
}
aBytes, errA = rlp.EncodeToBytes(a.Withdrawals)
bBytes, errB = rlp.EncodeToBytes(b.Withdrawals)
if errA != errB {
return false
for i, tx := range a.Transactions {
data, _ := tx.MarshalBinary()
if !reflect.DeepEqual(hexutil.Bytes(data), b.TransactionData[i]) {
return false
}
}
return bytes.Equal(aBytes, bBytes)
return reflect.DeepEqual(a.Withdrawals, b.Withdrawals)
}

0 comments on commit 87af877

Please sign in to comment.