Skip to content

Commit

Permalink
Simplify assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Dec 23, 2024
1 parent c5e52c7 commit 7d5aa94
Showing 1 changed file with 6 additions and 35 deletions.
41 changes: 6 additions & 35 deletions malfeasance2/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,7 @@ func TestHandler_HandleSync(t *testing.T) {
# TYPE spacemesh_malfeasance2_num_invalid_proofs counter
spacemesh_malfeasance2_num_invalid_proofs{domain="ATX",type="invalidPost"} 1
`
err = testutil.CollectAndCompare(
malfeasance2.NumInvalidProofs().WithLabelValues("ATX", "invalidPost"),
strings.NewReader(expected),
"spacemesh_malfeasance2_num_invalid_proofs",
)
require.NoError(t, err)
require.NoError(t, testutil.CollectAndCompare(malfeasance2.NumInvalidProofs(), strings.NewReader(expected)))
})

t.Run("valid proof", func(t *testing.T) {
Expand All @@ -201,12 +196,7 @@ spacemesh_malfeasance2_num_invalid_proofs{domain="ATX",type="invalidPost"} 1
# TYPE spacemesh_malfeasance2_num_proofs counter
spacemesh_malfeasance2_num_proofs{domain="ATX",type="invalidPost"} 1
`
err = testutil.CollectAndCompare(
malfeasance2.NumValidProofs().WithLabelValues("ATX", "invalidPost"),
strings.NewReader(expected),
"spacemesh_malfeasance2_num_proofs",
)
require.NoError(t, err)
require.NoError(t, testutil.CollectAndCompare(malfeasance2.NumValidProofs(), strings.NewReader(expected)))

malicious, err := malfeasance.IsMalicious(h.db, nodeID)
require.NoError(t, err)
Expand Down Expand Up @@ -245,12 +235,7 @@ spacemesh_malfeasance2_num_proofs{domain="ATX",type="invalidPost"} 1
# TYPE spacemesh_malfeasance2_num_invalid_proofs counter
spacemesh_malfeasance2_num_invalid_proofs{domain="ATX",type="invalidPost"} 1
`
err = testutil.CollectAndCompare(
malfeasance2.NumInvalidProofs().WithLabelValues("ATX", "invalidPost"),
strings.NewReader(expected),
"spacemesh_malfeasance2_num_invalid_proofs",
)
require.NoError(t, err)
require.NoError(t, testutil.CollectAndCompare(malfeasance2.NumInvalidProofs(), strings.NewReader(expected)))
})
}

Expand Down Expand Up @@ -320,12 +305,7 @@ func TestHandler_HandleGossip(t *testing.T) {
# TYPE spacemesh_malfeasance2_num_invalid_proofs counter
spacemesh_malfeasance2_num_invalid_proofs{domain="ATX",type="invalidPost"} 1
`
err = testutil.CollectAndCompare(
malfeasance2.NumInvalidProofs().WithLabelValues("ATX", "invalidPost"),
strings.NewReader(expected),
"spacemesh_malfeasance2_num_invalid_proofs",
)
require.NoError(t, err)
require.NoError(t, testutil.CollectAndCompare(malfeasance2.NumInvalidProofs(), strings.NewReader(expected)))
})

t.Run("valid proof", func(t *testing.T) {
Expand All @@ -352,11 +332,7 @@ spacemesh_malfeasance2_num_invalid_proofs{domain="ATX",type="invalidPost"} 1
# TYPE spacemesh_malfeasance2_num_proofs counter
spacemesh_malfeasance2_num_proofs{domain="ATX",type="invalidPost"} 1
`
err = testutil.CollectAndCompare(
malfeasance2.NumValidProofs().WithLabelValues("ATX", "invalidPost"),
strings.NewReader(expected),
"spacemesh_malfeasance2_num_proofs",
)
require.NoError(t, testutil.CollectAndCompare(malfeasance2.NumValidProofs(), strings.NewReader(expected)))
require.NoError(t, err)
})

Expand Down Expand Up @@ -388,12 +364,7 @@ spacemesh_malfeasance2_num_proofs{domain="ATX",type="invalidPost"} 1
# TYPE spacemesh_malfeasance2_num_proofs counter
spacemesh_malfeasance2_num_proofs{domain="ATX",type="invalidPost"} 1
`
err = testutil.CollectAndCompare(
malfeasance2.NumValidProofs().WithLabelValues("ATX", "invalidPost"),
strings.NewReader(expected),
"spacemesh_malfeasance2_num_proofs",
)
require.NoError(t, err)
require.NoError(t, testutil.CollectAndCompare(malfeasance2.NumValidProofs(), strings.NewReader(expected)))
})
}

Expand Down

0 comments on commit 7d5aa94

Please sign in to comment.