added inflation rewards test

This commit is contained in:
Matt Johnstone 2024-10-07 12:40:34 +02:00
parent 172d15a309
commit 325848dabf
No known key found for this signature in database
GPG Key ID: BE985FBB9BE7D3BB
2 changed files with 19 additions and 3 deletions

View File

@ -77,7 +77,7 @@ var (
inflationRewards = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "solana_inflation_rewards",
Help: "Inflation reward earned per leader, per epoch",
Help: "Inflation reward earned per validator vote account, per epoch",
},
[]string{"votekey", "epoch"},
)

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/asymmetric-research/solana_exporter/pkg/rpc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
@ -97,13 +98,18 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go watcher.WatchSlots(ctx, collector.slotPace)
// make sure inflation rewards are collected:
err := watcher.fetchAndEmitInflationRewards(ctx, staticEpochInfo.Epoch)
assert.NoError(t, err)
time.Sleep(1 * time.Second)
firstSlot, lastSlot := getEpochBounds(&staticEpochInfo)
tests := []struct {
type testCase struct {
expectedValue float64
metric prometheus.Gauge
}{
}
tests := []testCase{
{expectedValue: float64(staticEpochInfo.AbsoluteSlot), metric: confirmedSlotHeight},
{expectedValue: float64(staticEpochInfo.TransactionCount), metric: totalTransactionsTotal},
{expectedValue: float64(staticEpochInfo.Epoch), metric: currentEpochNumber},
@ -111,6 +117,16 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) {
{expectedValue: float64(lastSlot), metric: epochLastSlot},
}
// add inflation reward tests:
for i, rewardInfo := range staticInflationRewards {
epoch := fmt.Sprintf("%v", staticEpochInfo.Epoch)
test := testCase{
expectedValue: float64(rewardInfo.Amount) / float64(rpc.LamportsInSol),
metric: inflationRewards.WithLabelValues(votekeys[i], epoch),
}
tests = append(tests, test)
}
for _, testCase := range tests {
name := extractName(testCase.metric.Desc())
t.Run(name, func(t *testing.T) {