Skip to content

Commit

Permalink
more assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Dec 23, 2024
1 parent 1a49a14 commit b4989dc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"time"
)

// TestHandlingDelegations - Validates the following:
// - All expected delegations are activated, as indicated by the metrics.
// - The `pendingTracker` is empty after processing, confirming all delegations are handled.
func TestHandlingDelegations(t *testing.T) {
t.Parallel()
r := rand.New(rand.NewSource(time.Now().Unix()))
Expand Down Expand Up @@ -49,7 +52,7 @@ func TestHandlingDelegations(t *testing.T) {

defer close(sew.quit)

expectedActivated := 1000
expectedActivated := 5000
delegations := make([]Delegation, 0, expectedActivated)
for i := 0; i < expectedActivated; i++ {
stk := datagen.GenRandomTx(r)
Expand All @@ -61,10 +64,18 @@ func TestHandlingDelegations(t *testing.T) {
HasProof: false,
})
}
callCounter := 0
maxCalls := 10

mockBabylonNodeAdapter.EXPECT().
DelegationsByStatus(gomock.Any(), gomock.Any(), gomock.Any()).
Return(delegations, nil).AnyTimes()
DoAndReturn(func(_, _, _ interface{}) ([]Delegation, error) {
if callCounter < maxCalls {
callCounter++
return delegations, nil
}
return nil, nil
}).AnyTimes()

mockBabylonNodeAdapter.EXPECT().
ActivateDelegation(gomock.Any(), gomock.Any(), gomock.Any()).
Expand Down Expand Up @@ -96,4 +107,8 @@ func TestHandlingDelegations(t *testing.T) {
require.Eventually(t, func() bool {
return promtestutil.ToFloat64(sew.metrics.ReportedActivateDelegationsCounter) >= float64(expectedActivated)
}, 60*time.Second, 100*time.Millisecond)

require.Eventually(t, func() bool {
return sew.pendingTracker.Count() == 0
}, 60*time.Second, 100*time.Millisecond)
}

0 comments on commit b4989dc

Please sign in to comment.