Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
539b7504
Commit
539b7504
authored
Mar 22, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove band scorer mock
⚙
parent
4b0f4739
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
96 deletions
+28
-96
BandScorer.go
op-node/p2p/mocks/BandScorer.go
+0
-58
peer_scorer.go
op-node/p2p/peer_scorer.go
+1
-2
peer_scorer_test.go
op-node/p2p/peer_scorer_test.go
+19
-26
peer_scores_test.go
op-node/p2p/peer_scores_test.go
+8
-10
No files found.
op-node/p2p/mocks/BandScorer.go
deleted
100644 → 0
View file @
4b0f4739
// Code generated by mockery v2.22.1. DO NOT EDIT.
package
mocks
import
mock
"github.com/stretchr/testify/mock"
// BandScorer is an autogenerated mock type for the BandScorer type
type
BandScorer
struct
{
mock
.
Mock
}
// Bucket provides a mock function with given fields: score
func
(
_m
*
BandScorer
)
Bucket
(
score
float64
)
string
{
ret
:=
_m
.
Called
(
score
)
var
r0
string
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
float64
)
string
);
ok
{
r0
=
rf
(
score
)
}
else
{
r0
=
ret
.
Get
(
0
)
.
(
string
)
}
return
r0
}
// Parse provides a mock function with given fields: str
func
(
_m
*
BandScorer
)
Parse
(
str
string
)
error
{
ret
:=
_m
.
Called
(
str
)
var
r0
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
)
error
);
ok
{
r0
=
rf
(
str
)
}
else
{
r0
=
ret
.
Error
(
0
)
}
return
r0
}
// Reset provides a mock function with given fields:
func
(
_m
*
BandScorer
)
Reset
()
{
_m
.
Called
()
}
type
mockConstructorTestingTNewBandScorer
interface
{
mock
.
TestingT
Cleanup
(
func
())
}
// NewBandScorer creates a new instance of BandScorer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func
NewBandScorer
(
t
mockConstructorTestingTNewBandScorer
)
*
BandScorer
{
mock
:=
&
BandScorer
{}
mock
.
Mock
.
Test
(
t
)
t
.
Cleanup
(
func
()
{
mock
.
AssertExpectations
(
t
)
})
return
mock
}
op-node/p2p/peer_scorer.go
View file @
539b7504
...
@@ -19,6 +19,7 @@ type scorer struct {
...
@@ -19,6 +19,7 @@ type scorer struct {
bandScoreThresholds
BandScorer
bandScoreThresholds
BandScorer
}
}
// scorePair holds a band and its corresponding threshold.
type
scorePair
struct
{
type
scorePair
struct
{
band
string
band
string
threshold
float64
threshold
float64
...
@@ -36,8 +37,6 @@ type BandScoreThresholds struct {
...
@@ -36,8 +37,6 @@ type BandScoreThresholds struct {
// Implementations are expected to construct internals using the
// Implementations are expected to construct internals using the
// [Parse] function and then expose the [Bucket] function for
// [Parse] function and then expose the [Bucket] function for
// downstream [BandScorer] consumers.
// downstream [BandScorer] consumers.
//
//go:generate mockery --name BandScorer --output mocks/
type
BandScorer
interface
{
type
BandScorer
interface
{
Parse
(
str
string
)
error
Parse
(
str
string
)
error
Bucket
(
score
float64
)
string
Bucket
(
score
float64
)
string
...
...
op-node/p2p/peer_scorer_test.go
View file @
539b7504
...
@@ -17,11 +17,11 @@ type PeerScorerTestSuite struct {
...
@@ -17,11 +17,11 @@ type PeerScorerTestSuite struct {
suite
.
Suite
suite
.
Suite
// mockConnGater *p2pMocks.ConnectionGater
// mockConnGater *p2pMocks.ConnectionGater
mockGater
*
p2pMocks
.
PeerGater
mockGater
*
p2pMocks
.
PeerGater
mockStore
*
p2pMocks
.
Peerstore
mockStore
*
p2pMocks
.
Peerstore
mockMetricer
*
p2pMocks
.
GossipMetricer
mockMetricer
*
p2pMocks
.
GossipMetricer
mockBandScorer
*
p2pMocks
.
BandScorer
bandScorer
p2p
.
BandScorer
logger
log
.
Logger
logger
log
.
Logger
}
}
// SetupTest sets up the test suite.
// SetupTest sets up the test suite.
...
@@ -29,7 +29,8 @@ func (testSuite *PeerScorerTestSuite) SetupTest() {
...
@@ -29,7 +29,8 @@ func (testSuite *PeerScorerTestSuite) SetupTest() {
testSuite
.
mockGater
=
&
p2pMocks
.
PeerGater
{}
testSuite
.
mockGater
=
&
p2pMocks
.
PeerGater
{}
testSuite
.
mockStore
=
&
p2pMocks
.
Peerstore
{}
testSuite
.
mockStore
=
&
p2pMocks
.
Peerstore
{}
testSuite
.
mockMetricer
=
&
p2pMocks
.
GossipMetricer
{}
testSuite
.
mockMetricer
=
&
p2pMocks
.
GossipMetricer
{}
testSuite
.
mockBandScorer
=
&
p2pMocks
.
BandScorer
{}
testSuite
.
bandScorer
=
&
p2p
.
BandScoreThresholds
{}
testSuite
.
NoError
(
testSuite
.
bandScorer
.
Parse
(
"0:graylist;"
))
testSuite
.
logger
=
testlog
.
Logger
(
testSuite
.
T
(),
log
.
LvlError
)
testSuite
.
logger
=
testlog
.
Logger
(
testSuite
.
T
(),
log
.
LvlError
)
}
}
...
@@ -38,45 +39,41 @@ func TestPeerScorer(t *testing.T) {
...
@@ -38,45 +39,41 @@ func TestPeerScorer(t *testing.T) {
suite
.
Run
(
t
,
new
(
PeerScorerTestSuite
))
suite
.
Run
(
t
,
new
(
PeerScorerTestSuite
))
}
}
// Test
PeerScorer
OnConnect ensures we can call the OnConnect method on the peer scorer.
// Test
Scorer_
OnConnect ensures we can call the OnConnect method on the peer scorer.
func
(
testSuite
*
PeerScorerTestSuite
)
Test
PeerScorer
OnConnect
()
{
func
(
testSuite
*
PeerScorerTestSuite
)
Test
Scorer_
OnConnect
()
{
scorer
:=
p2p
.
NewScorer
(
scorer
:=
p2p
.
NewScorer
(
testSuite
.
mockGater
,
testSuite
.
mockGater
,
testSuite
.
mockStore
,
testSuite
.
mockStore
,
testSuite
.
mockMetricer
,
testSuite
.
mockMetricer
,
testSuite
.
mockB
andScorer
,
testSuite
.
b
andScorer
,
testSuite
.
logger
,
testSuite
.
logger
,
)
)
scorer
.
OnConnect
()
scorer
.
OnConnect
()
}
}
// Test
PeerScorer
OnDisconnect ensures we can call the OnDisconnect method on the peer scorer.
// Test
Scorer_
OnDisconnect ensures we can call the OnDisconnect method on the peer scorer.
func
(
testSuite
*
PeerScorerTestSuite
)
Test
PeerScorer
OnDisconnect
()
{
func
(
testSuite
*
PeerScorerTestSuite
)
Test
Scorer_
OnDisconnect
()
{
scorer
:=
p2p
.
NewScorer
(
scorer
:=
p2p
.
NewScorer
(
testSuite
.
mockGater
,
testSuite
.
mockGater
,
testSuite
.
mockStore
,
testSuite
.
mockStore
,
testSuite
.
mockMetricer
,
testSuite
.
mockMetricer
,
testSuite
.
mockB
andScorer
,
testSuite
.
b
andScorer
,
testSuite
.
logger
,
testSuite
.
logger
,
)
)
scorer
.
OnDisconnect
()
scorer
.
OnDisconnect
()
}
}
// TestSnapshotHook tests running the snapshot hook on the peer scorer.
// TestS
corer_S
napshotHook tests running the snapshot hook on the peer scorer.
func
(
testSuite
*
PeerScorerTestSuite
)
TestSnapshotHook
()
{
func
(
testSuite
*
PeerScorerTestSuite
)
TestS
corer_S
napshotHook
()
{
scorer
:=
p2p
.
NewScorer
(
scorer
:=
p2p
.
NewScorer
(
testSuite
.
mockGater
,
testSuite
.
mockGater
,
testSuite
.
mockStore
,
testSuite
.
mockStore
,
testSuite
.
mockMetricer
,
testSuite
.
mockMetricer
,
testSuite
.
mockB
andScorer
,
testSuite
.
b
andScorer
,
testSuite
.
logger
,
testSuite
.
logger
,
)
)
inspectFn
:=
scorer
.
SnapshotHook
()
inspectFn
:=
scorer
.
SnapshotHook
()
// Mock the band scorer calls
testSuite
.
mockBandScorer
.
On
(
"Reset"
)
.
Return
(
nil
)
testSuite
.
mockBandScorer
.
On
(
"Bucket"
,
float64
(
-
100
))
.
Return
(
"graylist"
)
// Mock the peer gater call
// Mock the peer gater call
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
100
))
.
Return
(
nil
)
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
100
))
.
Return
(
nil
)
...
@@ -94,22 +91,18 @@ func (testSuite *PeerScorerTestSuite) TestSnapshotHook() {
...
@@ -94,22 +91,18 @@ func (testSuite *PeerScorerTestSuite) TestSnapshotHook() {
inspectFn
(
snapshotMap
)
inspectFn
(
snapshotMap
)
}
}
// TestS
napshotHookBlock
Peer tests running the snapshot hook on the peer scorer with a peer score below the threshold.
// TestS
corer_SnapshotHookBlocks
Peer tests running the snapshot hook on the peer scorer with a peer score below the threshold.
// This implies that the peer should be blocked.
// This implies that the peer should be blocked.
func
(
testSuite
*
PeerScorerTestSuite
)
TestS
napshotHookBlock
Peer
()
{
func
(
testSuite
*
PeerScorerTestSuite
)
TestS
corer_SnapshotHookBlocks
Peer
()
{
scorer
:=
p2p
.
NewScorer
(
scorer
:=
p2p
.
NewScorer
(
testSuite
.
mockGater
,
testSuite
.
mockGater
,
testSuite
.
mockStore
,
testSuite
.
mockStore
,
testSuite
.
mockMetricer
,
testSuite
.
mockMetricer
,
testSuite
.
mockB
andScorer
,
testSuite
.
b
andScorer
,
testSuite
.
logger
,
testSuite
.
logger
,
)
)
inspectFn
:=
scorer
.
SnapshotHook
()
inspectFn
:=
scorer
.
SnapshotHook
()
// Mock the band scorer calls
testSuite
.
mockBandScorer
.
On
(
"Reset"
)
.
Return
(
nil
)
testSuite
.
mockBandScorer
.
On
(
"Bucket"
,
float64
(
-
101
))
.
Return
(
"graylist"
)
// Mock the peer gater call
// Mock the peer gater call
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
101
))
.
Return
(
nil
)
testSuite
.
mockGater
.
On
(
"Update"
,
peer
.
ID
(
"peer1"
),
float64
(
-
101
))
.
Return
(
nil
)
...
...
op-node/p2p/peer_scores_test.go
View file @
539b7504
...
@@ -27,11 +27,11 @@ import (
...
@@ -27,11 +27,11 @@ import (
type
PeerScoresTestSuite
struct
{
type
PeerScoresTestSuite
struct
{
suite
.
Suite
suite
.
Suite
mockGater
*
p2pMocks
.
ConnectionGater
mockGater
*
p2pMocks
.
ConnectionGater
mockStore
*
p2pMocks
.
Peerstore
mockStore
*
p2pMocks
.
Peerstore
mockMetricer
*
p2pMocks
.
GossipMetricer
mockMetricer
*
p2pMocks
.
GossipMetricer
mockBandScorer
*
p2pMocks
.
BandScorer
bandScorer
p2p
.
BandScorer
logger
log
.
Logger
logger
log
.
Logger
}
}
// SetupTest sets up the test suite.
// SetupTest sets up the test suite.
...
@@ -39,7 +39,8 @@ func (testSuite *PeerScoresTestSuite) SetupTest() {
...
@@ -39,7 +39,8 @@ func (testSuite *PeerScoresTestSuite) SetupTest() {
testSuite
.
mockGater
=
&
p2pMocks
.
ConnectionGater
{}
testSuite
.
mockGater
=
&
p2pMocks
.
ConnectionGater
{}
testSuite
.
mockStore
=
&
p2pMocks
.
Peerstore
{}
testSuite
.
mockStore
=
&
p2pMocks
.
Peerstore
{}
testSuite
.
mockMetricer
=
&
p2pMocks
.
GossipMetricer
{}
testSuite
.
mockMetricer
=
&
p2pMocks
.
GossipMetricer
{}
testSuite
.
mockBandScorer
=
&
p2pMocks
.
BandScorer
{}
testSuite
.
bandScorer
=
&
p2p
.
BandScoreThresholds
{}
testSuite
.
NoError
(
testSuite
.
bandScorer
.
Parse
(
"0:graylist;"
))
testSuite
.
logger
=
testlog
.
Logger
(
testSuite
.
T
(),
log
.
LvlError
)
testSuite
.
logger
=
testlog
.
Logger
(
testSuite
.
T
(),
log
.
LvlError
)
}
}
...
@@ -70,7 +71,7 @@ func newGossipSubs(testSuite *PeerScoresTestSuite, ctx context.Context, hosts []
...
@@ -70,7 +71,7 @@ func newGossipSubs(testSuite *PeerScoresTestSuite, ctx context.Context, hosts []
rt
:=
pubsub
.
DefaultGossipSubRouter
(
h
)
rt
:=
pubsub
.
DefaultGossipSubRouter
(
h
)
opts
:=
[]
pubsub
.
Option
{}
opts
:=
[]
pubsub
.
Option
{}
opts
=
append
(
opts
,
p2p
.
ConfigurePeerScoring
(
h
,
testSuite
.
mockGater
,
&
p2p
.
Config
{
opts
=
append
(
opts
,
p2p
.
ConfigurePeerScoring
(
h
,
testSuite
.
mockGater
,
&
p2p
.
Config
{
BandScoreThresholds
:
testSuite
.
mockB
andScorer
,
BandScoreThresholds
:
testSuite
.
b
andScorer
,
PeerScoring
:
pubsub
.
PeerScoreParams
{
PeerScoring
:
pubsub
.
PeerScoreParams
{
AppSpecificScore
:
func
(
p
peer
.
ID
)
float64
{
AppSpecificScore
:
func
(
p
peer
.
ID
)
float64
{
if
p
==
hosts
[
0
]
.
ID
()
{
if
p
==
hosts
[
0
]
.
ID
()
{
...
@@ -121,9 +122,6 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() {
...
@@ -121,9 +122,6 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
testSuite
.
mockBandScorer
.
On
(
"Reset"
)
.
Return
(
nil
)
testSuite
.
mockBandScorer
.
On
(
"Bucket"
,
float64
(
0
))
.
Return
(
"nopx"
)
testSuite
.
mockBandScorer
.
On
(
"Bucket"
,
float64
(
-
1000
))
.
Return
(
"graylist"
)
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
mock
.
Anything
)
.
Return
(
nil
)
testSuite
.
mockMetricer
.
On
(
"SetPeerScores"
,
mock
.
Anything
)
.
Return
(
nil
)
testSuite
.
mockGater
.
On
(
"ListBlockedPeers"
)
.
Return
([]
peer
.
ID
{})
testSuite
.
mockGater
.
On
(
"ListBlockedPeers"
)
.
Return
([]
peer
.
ID
{})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment