Skip to content

Commit

Permalink
add fuzz test
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Aug 19, 2024
1 parent 0205016 commit c742a8e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions x/btcstaking/keeper/voting_power_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) {
btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl)
btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl)
finalityKeeper := types.NewMockFinalityKeeper(ctrl)
finalityKeeper.EXPECT().HasTimestampedPubRand(gomock.Any(), gomock.Any(), gomock.Any()).Return(true).AnyTimes()
h := NewHelper(t, btclcKeeper, btccKeeper, finalityKeeper)

// set all parameters
Expand All @@ -176,6 +175,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) {
// generate a random batch of finality providers, each with a BTC delegation with random power
fpsWithMeta := []*types.FinalityProviderDistInfo{}
numFps := datagen.RandomInt(r, 300) + 1
noTimestampedFps := map[string]bool{}
for i := uint64(0); i < numFps; i++ {
// generate finality provider
_, _, fp := h.CreateFinalityProvider(r)
Expand All @@ -191,11 +191,20 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) {
)
h.CreateCovenantSigs(r, covenantSKs, delMsg, del)

// 30 percent not have timestamped randomness, which causes
// zero voting power in the table
fpDistInfo := &types.FinalityProviderDistInfo{BtcPk: fp.BtcPk}
if r.Intn(10) <= 2 {
finalityKeeper.EXPECT().HasTimestampedPubRand(gomock.Any(), fp.BtcPk, gomock.Any()).Return(false).AnyTimes()
noTimestampedFps[fp.BtcPk.MarshalHex()] = true
fpDistInfo.TotalVotingPower = 0
} else {
finalityKeeper.EXPECT().HasTimestampedPubRand(gomock.Any(), fp.BtcPk, gomock.Any()).Return(true).AnyTimes()
fpDistInfo.TotalVotingPower = stakingValue
}

// record voting power
fpsWithMeta = append(fpsWithMeta, &types.FinalityProviderDistInfo{
BtcPk: fp.BtcPk,
TotalVotingPower: stakingValue,
})
fpsWithMeta = append(fpsWithMeta, fpDistInfo)
}

maxActiveFpsParam := h.BTCStakingKeeper.GetParams(h.Ctx).MaxActiveFinalityProviders
Expand Down

0 comments on commit c742a8e

Please sign in to comment.