Skip to content

Commit

Permalink
extend behaviour penalty test to ensure coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed May 1, 2020
1 parent 970e739 commit 98d2fd9
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions score_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,34 @@ func TestScoreBehaviourPenalty(t *testing.T) {
}

peerA := peer.ID("A")
ps := newPeerScore(params)
ps.AddPeer(peerA, "myproto")

var ps *peerScore

// first check AddPenalty on a nil peerScore
ps.AddPenalty(peerA, 1)
aScore := ps.Score(peerA)
if aScore != 0 {
t.Errorf("expected peer score to be 0, got %f", aScore)
}

// instantiate the peerScore
ps = newPeerScore(params)

// next AddPenalty on a non-existent peer
ps.AddPenalty(peerA, 1)
aScore = ps.Score(peerA)
if aScore != 0 {
t.Errorf("expected peer score to be 0, got %f", aScore)
}

// add the peer and test penalties
ps.AddPeer(peerA, "myproto")

aScore = ps.Score(peerA)
if aScore != 0 {
t.Errorf("expected peer score to be 0, got %f", aScore)
}

ps.AddPenalty(peerA, 1)
aScore = ps.Score(peerA)
if aScore != -1 {
Expand Down

0 comments on commit 98d2fd9

Please sign in to comment.