Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve sew test #150

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#150](https://github.com/babylonlabs-io/vigilante/pull/150) additional asserts for sew unit test

## v0.19.0

### Bug Fixes
Expand Down
21 changes: 19 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,20 @@ 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 +109,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)
}
Loading