From 0832791d9c227fe6a617a0b8e676c2fdcdf84a77 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 1 May 2020 22:25:10 +0300 Subject: [PATCH] extend behaviour penalty test to ensure coverage --- score_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/score_test.go b/score_test.go index 9854e18b..beb63f10 100644 --- a/score_test.go +++ b/score_test.go @@ -749,14 +749,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 {