-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add table testing for ShouldSyncStatusFromVotingPower and Shou…
…ldStart
- Loading branch information
1 parent
56ffa3b
commit 95d20c7
Showing
1 changed file
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package store_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/babylonlabs-io/finality-provider/finality-provider/proto" | ||
"github.com/babylonlabs-io/finality-provider/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestShouldStart(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
currFpStatus proto.FinalityProviderStatus | ||
expShouldStart bool | ||
}{ | ||
{ | ||
"Created: Should NOT start", | ||
proto.FinalityProviderStatus_CREATED, | ||
false, | ||
}, | ||
{ | ||
"Slashed: Should NOT start", | ||
proto.FinalityProviderStatus_SLASHED, | ||
false, | ||
}, | ||
{ | ||
"Inactive: Should start", | ||
proto.FinalityProviderStatus_INACTIVE, | ||
true, | ||
}, | ||
{ | ||
"Registered: Should start", | ||
proto.FinalityProviderStatus_REGISTERED, | ||
true, | ||
}, | ||
{ | ||
"Active: Should start", | ||
proto.FinalityProviderStatus_ACTIVE, | ||
true, | ||
}, | ||
} | ||
|
||
r := rand.New(rand.NewSource(10)) | ||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
fp := testutil.GenRandomFinalityProvider(r, t) | ||
fp.Status = tc.currFpStatus | ||
|
||
shouldStart := fp.ShouldStart() | ||
require.Equal(t, tc.expShouldStart, shouldStart) | ||
}) | ||
} | ||
} | ||
|
||
func TestShouldSyncStatusFromVotingPower(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
votingPowerOnChain uint64 | ||
currFpStatus proto.FinalityProviderStatus | ||
expShouldSyncStatus bool | ||
}{ | ||
{ | ||
"zero vp and Registered: Should NOT sync", | ||
0, | ||
proto.FinalityProviderStatus_REGISTERED, | ||
false, | ||
}, | ||
{ | ||
"zero vp and Inactive: Should NOT sync", | ||
0, | ||
proto.FinalityProviderStatus_INACTIVE, | ||
false, | ||
}, | ||
{ | ||
"zero vp and Slashed: Should NOT sync", | ||
0, | ||
proto.FinalityProviderStatus_SLASHED, | ||
false, | ||
}, | ||
{ | ||
"zero vp and Created: Should sync", | ||
0, | ||
proto.FinalityProviderStatus_CREATED, | ||
true, | ||
}, | ||
{ | ||
"zero vp and Active: Should sync", | ||
0, | ||
proto.FinalityProviderStatus_ACTIVE, | ||
true, | ||
}, | ||
{ | ||
"some vp: Should sync", | ||
1, | ||
proto.FinalityProviderStatus_SLASHED, | ||
true, | ||
}, | ||
{ | ||
"some vp: Should sync from even inactive", | ||
1, | ||
proto.FinalityProviderStatus_INACTIVE, | ||
true, | ||
}, | ||
{ | ||
"some vp: Should sync even if it is already active", | ||
10, | ||
proto.FinalityProviderStatus_ACTIVE, | ||
true, | ||
}, | ||
} | ||
|
||
r := rand.New(rand.NewSource(10)) | ||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
fp := testutil.GenRandomFinalityProvider(r, t) | ||
fp.Status = tc.currFpStatus | ||
|
||
shouldSync := fp.ShouldSyncStatusFromVotingPower(tc.votingPowerOnChain) | ||
require.Equal(t, tc.expShouldSyncStatus, shouldSync) | ||
}) | ||
} | ||
} |