Skip to content

Commit

Permalink
cmd/devp2p/internal/ethtest: update tests for eth/67 (ethereum#25306)
Browse files Browse the repository at this point in the history
- fixed conflicts: cmd/devp2p/internal/ethtest/helpers.go,
                   cmd/devp2p/internal/ethtest/snapTypes.go,
                   cmd/devp2p/internal/ethtest/suite.go
  • Loading branch information
fjl authored and cp-wjhan committed Oct 11, 2023
1 parent e949d35 commit bef7de8
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 755 deletions.
4 changes: 2 additions & 2 deletions cmd/devp2p/internal/ethtest/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func (c *Chain) Head() *types.Block {
return c.blocks[c.Len()-1]
}

func (c *Chain) GetHeaders(req GetBlockHeaders) (BlockHeaders, error) {
func (c *Chain) GetHeaders(req *GetBlockHeaders) ([]*types.Header, error) {
if req.Amount < 1 {
return nil, fmt.Errorf("no block headers requested")
}

headers := make(BlockHeaders, req.Amount)
headers := make([]*types.Header, req.Amount)
var blockNumber uint64

// range over blocks to check if our chain has the requested header
Expand Down
41 changes: 21 additions & 20 deletions cmd/devp2p/internal/ethtest/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strconv"
"testing"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/p2p"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -140,18 +141,18 @@ func TestChain_GetHeaders(t *testing.T) {

var tests = []struct {
req GetBlockHeaders
expected BlockHeaders
expected []*types.Header
}{
{
req: GetBlockHeaders{
Origin: eth.HashOrNumber{
Number: uint64(2),
GetBlockHeadersPacket: &eth.GetBlockHeadersPacket{
Origin: eth.HashOrNumber{Number: uint64(2)},
Amount: uint64(5),
Skip: 1,
Reverse: false,
},
Amount: uint64(5),
Skip: 1,
Reverse: false,
},
expected: BlockHeaders{
expected: []*types.Header{
chain.blocks[2].Header(),
chain.blocks[4].Header(),
chain.blocks[6].Header(),
Expand All @@ -161,37 +162,37 @@ func TestChain_GetHeaders(t *testing.T) {
},
{
req: GetBlockHeaders{
Origin: eth.HashOrNumber{
Number: uint64(chain.Len() - 1),
GetBlockHeadersPacket: &eth.GetBlockHeadersPacket{
Origin: eth.HashOrNumber{Number: uint64(chain.Len() - 1)},
Amount: uint64(3),
Skip: 0,
Reverse: true,
},
Amount: uint64(3),
Skip: 0,
Reverse: true,
},
expected: BlockHeaders{
expected: []*types.Header{
chain.blocks[chain.Len()-1].Header(),
chain.blocks[chain.Len()-2].Header(),
chain.blocks[chain.Len()-3].Header(),
},
},
{
req: GetBlockHeaders{
Origin: eth.HashOrNumber{
Hash: chain.Head().Hash(),
GetBlockHeadersPacket: &eth.GetBlockHeadersPacket{
Origin: eth.HashOrNumber{Hash: chain.Head().Hash()},
Amount: uint64(1),
Skip: 0,
Reverse: false,
},
Amount: uint64(1),
Skip: 0,
Reverse: false,
},
expected: BlockHeaders{
expected: []*types.Header{
chain.Head().Header(),
},
},
}

for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
headers, err := chain.GetHeaders(tt.req)
headers, err := chain.GetHeaders(&tt.req)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit bef7de8

Please sign in to comment.