Skip to content

Commit e24cf8a

Browse files
committed
les: add tests
1 parent 3d921ed commit e24cf8a

17 files changed

+693
-255
lines changed

les/client_handler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package les
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"math/big"
2223
"sync"
2324
"sync/atomic"
@@ -108,10 +109,10 @@ func (h *clientHandler) handle(p *serverPeer) error {
108109
}
109110
p.Log().Debug("Light Ethereum peer connected", "name", p.Name())
110111

111-
// Execute the LES handshake
112+
// Execute the LES handshakeWithClient
112113
forkid := forkid.NewID(h.backend.blockchain.Config(), h.backend.genesis, h.backend.blockchain.CurrentHeader().Number.Uint64())
113114
if err := p.Handshake(h.backend.blockchain.Genesis().Hash(), forkid, h.forkFilter); err != nil {
114-
p.Log().Debug("Light Ethereum handshake failed", "err", err)
115+
p.Log().Debug("Light Ethereum handshakeWithClient failed", "err", err)
115116
return err
116117
}
117118
// Register the peer locally
@@ -309,6 +310,7 @@ func (h *clientHandler) handleMsg(p *serverPeer) error {
309310
}
310311
case msg.Code == TxStatusMsg:
311312
p.Log().Trace("Received tx status response")
313+
fmt.Println("Received tx status response")
312314
var resp struct {
313315
ReqID, BV uint64
314316
Status []light.TxStatus

les/clientpool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (f *clientPool) stop() {
195195
f.bt.Stop()
196196
}
197197

198-
// connect should be called after a successful handshake. If the connection was
198+
// connect should be called after a successful handshakeWithClient. If the connection was
199199
// rejected, there is no need to call disconnect.
200200
func (f *clientPool) connect(peer clientPoolPeer) (uint64, error) {
201201
f.lock.Lock()

les/fetcher_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ func TestSequentialAnnouncementsLes2(t *testing.T) { testSequentialAnnouncements
6666
func TestSequentialAnnouncementsLes3(t *testing.T) { testSequentialAnnouncements(t, 3) }
6767

6868
func testSequentialAnnouncements(t *testing.T, protocol int) {
69-
s, c, teardown := newClientServerEnv(t, 4, protocol, nil, nil, 0, false, false, true)
69+
netconfig := testnetConfig{
70+
blocks: 4,
71+
protocol: protocol,
72+
nopruning: true,
73+
}
74+
s, c, teardown := newClientServerEnv(t, netconfig)
7075
defer teardown()
7176

7277
// Create connected peer pair.
@@ -101,7 +106,12 @@ func TestGappedAnnouncementsLes2(t *testing.T) { testGappedAnnouncements(t, 2) }
101106
func TestGappedAnnouncementsLes3(t *testing.T) { testGappedAnnouncements(t, 3) }
102107

103108
func testGappedAnnouncements(t *testing.T, protocol int) {
104-
s, c, teardown := newClientServerEnv(t, 4, protocol, nil, nil, 0, false, false, true)
109+
netconfig := testnetConfig{
110+
blocks: 4,
111+
protocol: protocol,
112+
nopruning: true,
113+
}
114+
s, c, teardown := newClientServerEnv(t, netconfig)
105115
defer teardown()
106116

107117
// Create connected peer pair.
@@ -183,7 +193,13 @@ func testTrustedAnnouncement(t *testing.T, protocol int) {
183193
ids = append(ids, n.String())
184194
}
185195
}
186-
_, c, teardown := newClientServerEnv(t, 0, protocol, nil, ids, 60, false, false, true)
196+
netconfig := testnetConfig{
197+
protocol: protocol,
198+
nopruning: true,
199+
ulcServers: ids,
200+
ulcFraction: 60,
201+
}
202+
_, c, teardown := newClientServerEnv(t, netconfig)
187203
defer teardown()
188204
defer func() {
189205
for i := 0; i < len(teardowns); i++ {
@@ -233,8 +249,17 @@ func testTrustedAnnouncement(t *testing.T, protocol int) {
233249
check([]uint64{10}, 10, func() { <-newHead }) // Sync the whole chain.
234250
}
235251

236-
func TestInvalidAnnounces(t *testing.T) {
237-
s, c, teardown := newClientServerEnv(t, 4, lpv3, nil, nil, 0, false, false, true)
252+
func TestInvalidAnnouncesLES2(t *testing.T) { testInvalidAnnounces(t, lpv2) }
253+
func TestInvalidAnnouncesLES3(t *testing.T) { testInvalidAnnounces(t, lpv3) }
254+
func TestInvalidAnnouncesLES4(t *testing.T) { testInvalidAnnounces(t, lpv4) }
255+
256+
func testInvalidAnnounces(t *testing.T, protocol int) {
257+
netconfig := testnetConfig{
258+
blocks: 4,
259+
protocol: protocol,
260+
nopruning: true,
261+
}
262+
s, c, teardown := newClientServerEnv(t, netconfig)
238263
defer teardown()
239264

240265
// Create connected peer pair.

0 commit comments

Comments
 (0)