Skip to content

Commit b8f10ef

Browse files
committed
protocols: fix failing dBFT test
Should be a part of #298. Signed-off-by: Anna Shaleva <[email protected]>
1 parent 7344fb6 commit b8f10ef

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

eth/protocols/dbft/handler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func TestHandling(t *testing.T) {
2929
key, _ = crypto.GenerateKey()
3030
addr = crypto.PubkeyToAddress(key.PublicKey)
3131
bc = &testBC{height: 10}
32-
s1 = New(bc, nil, func(u uint64, address common.Address) bool { return true })
33-
s2 = New(bc, nil, func(u uint64, address common.Address) bool { return true })
34-
s3 = New(bc, nil, func(u uint64, address common.Address) bool { return true })
32+
s1 = New(bc, nil, func(u uint64, address common.Address) error { return nil })
33+
s2 = New(bc, nil, func(u uint64, address common.Address) error { return nil })
34+
s3 = New(bc, nil, func(u uint64, address common.Address) error { return nil })
3535
p1 = p2p.NewPeer(enode.ID{1}, "peer1", nil)
3636
p2 = p2p.NewPeer(enode.ID{2}, "peer2", nil)
3737
p3 = p2p.NewPeer(enode.ID{3}, "peer3", nil)

eth/protocols/dbft/pool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package dbft
66
import (
77
"container/list"
88
"errors"
9+
"fmt"
910
"sync"
1011

1112
"github.com/ethereum/go-ethereum/common"
@@ -96,7 +97,7 @@ func (p *Pool) verify(m *Message) (bool, error) {
9697
if errors.Is(err, ErrSyncing) {
9798
return false, nil
9899
}
99-
return false, err
100+
return false, fmt.Errorf("%w: %w", errDisallowedSender, err)
100101
}
101102
return true, nil
102103
}

eth/protocols/dbft/pool_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ func TestAddGet(t *testing.T) {
2222
m := someMessage(t, 100, bc.goodAddrs[0], bc.badKey)
2323
p.testAdd(t, false, invalidSig, m)
2424
})
25+
t.Run("syncing", func(t *testing.T) {
26+
bc.syncing = true
27+
m := bc.badMessage(t, 100)
28+
p.testAdd(t, false, nil, m)
29+
bc.syncing = false
30+
})
2531
t.Run("disallowed sender", func(t *testing.T) {
2632
m := bc.badMessage(t, 100)
2733
p.testAdd(t, false, errDisallowedSender, m)
@@ -106,6 +112,7 @@ type testChain struct {
106112
badKey *ecdsa.PrivateKey
107113
goodAddrs []common.Address
108114
badAddr common.Address
115+
syncing bool
109116
}
110117

111118
var errVerification = errors.New("verification failed")
@@ -120,13 +127,16 @@ func newTestChain() *testChain {
120127
badAddr: crypto.PubkeyToAddress(bk.PublicKey),
121128
}
122129
}
123-
func (c *testChain) IsAddressAllowed(u common.Address) bool {
130+
func (c *testChain) IsAddressAllowed(u common.Address) error {
131+
if c.syncing {
132+
return ErrSyncing
133+
}
124134
for i := range c.goodAddrs {
125135
if u == c.goodAddrs[i] {
126-
return true
136+
return nil
127137
}
128138
}
129-
return false
139+
return errors.New("address not allowed")
130140
}
131141
func (c *testChain) BlockHeight() uint64 { return c.height }
132142

0 commit comments

Comments
 (0)