Skip to content

Commit 87af877

Browse files
eth/catalyst: better equality
1 parent 9450dbf commit 87af877

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

eth/catalyst/api_test.go

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"math/big"
2424
"math/rand"
25+
"reflect"
2526
"sync"
2627
"testing"
2728
"time"
@@ -42,7 +43,6 @@ import (
4243
"github.com/ethereum/go-ethereum/node"
4344
"github.com/ethereum/go-ethereum/p2p"
4445
"github.com/ethereum/go-ethereum/params"
45-
"github.com/ethereum/go-ethereum/rlp"
4646
"github.com/ethereum/go-ethereum/rpc"
4747
"github.com/ethereum/go-ethereum/trie"
4848
)
@@ -1238,10 +1238,10 @@ func TestNilWithdrawals(t *testing.T) {
12381238
}
12391239

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

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

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

12781278
func allHashes(blocks []*types.Block) []common.Hash {
@@ -1478,28 +1478,14 @@ func equalBody(a *types.Body, b *engine.ExecutionPayloadBodyV1) bool {
14781478
} else if a == nil || b == nil {
14791479
return false
14801480
}
1481-
var want []hexutil.Bytes
1482-
for _, tx := range a.Transactions {
1483-
data, _ := tx.MarshalBinary()
1484-
want = append(want, hexutil.Bytes(data))
1485-
}
1486-
aBytes, errA := rlp.EncodeToBytes(want)
1487-
bBytes, errB := rlp.EncodeToBytes(b.TransactionData)
1488-
if errA != errB {
1489-
return false
1490-
}
1491-
if !bytes.Equal(aBytes, bBytes) {
1481+
if len(a.Transactions) != len(b.TransactionData) {
14921482
return false
14931483
}
1494-
if a.Withdrawals == nil && b.Withdrawals == nil {
1495-
return true
1496-
} else if a.Withdrawals == nil || b.Withdrawals == nil {
1497-
return false
1498-
}
1499-
aBytes, errA = rlp.EncodeToBytes(a.Withdrawals)
1500-
bBytes, errB = rlp.EncodeToBytes(b.Withdrawals)
1501-
if errA != errB {
1502-
return false
1484+
for i, tx := range a.Transactions {
1485+
data, _ := tx.MarshalBinary()
1486+
if !reflect.DeepEqual(hexutil.Bytes(data), b.TransactionData[i]) {
1487+
return false
1488+
}
15031489
}
1504-
return bytes.Equal(aBytes, bBytes)
1490+
return reflect.DeepEqual(a.Withdrawals, b.Withdrawals)
15051491
}

0 commit comments

Comments
 (0)