added inflation rewards test
This commit is contained in:
parent
172d15a309
commit
325848dabf
|
@ -77,7 +77,7 @@ var (
|
||||||
inflationRewards = prometheus.NewGaugeVec(
|
inflationRewards = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "solana_inflation_rewards",
|
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"},
|
[]string{"votekey", "epoch"},
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/asymmetric-research/solana_exporter/pkg/rpc"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -97,13 +98,18 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
go watcher.WatchSlots(ctx, collector.slotPace)
|
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)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
firstSlot, lastSlot := getEpochBounds(&staticEpochInfo)
|
firstSlot, lastSlot := getEpochBounds(&staticEpochInfo)
|
||||||
tests := []struct {
|
type testCase struct {
|
||||||
expectedValue float64
|
expectedValue float64
|
||||||
metric prometheus.Gauge
|
metric prometheus.Gauge
|
||||||
}{
|
}
|
||||||
|
tests := []testCase{
|
||||||
{expectedValue: float64(staticEpochInfo.AbsoluteSlot), metric: confirmedSlotHeight},
|
{expectedValue: float64(staticEpochInfo.AbsoluteSlot), metric: confirmedSlotHeight},
|
||||||
{expectedValue: float64(staticEpochInfo.TransactionCount), metric: totalTransactionsTotal},
|
{expectedValue: float64(staticEpochInfo.TransactionCount), metric: totalTransactionsTotal},
|
||||||
{expectedValue: float64(staticEpochInfo.Epoch), metric: currentEpochNumber},
|
{expectedValue: float64(staticEpochInfo.Epoch), metric: currentEpochNumber},
|
||||||
|
@ -111,6 +117,16 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) {
|
||||||
{expectedValue: float64(lastSlot), metric: epochLastSlot},
|
{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 {
|
for _, testCase := range tests {
|
||||||
name := extractName(testCase.metric.Desc())
|
name := extractName(testCase.metric.Desc())
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue