Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Sep 10, 2024
1 parent 0a90a5e commit 890fab3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions x/finality/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func (ms msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdatePara
func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinalitySig) (*types.MsgAddFinalitySigResponse, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricsKeyAddFinalitySig)

if req.FpBtcPk == nil {
return nil, types.ErrInvalidFinalitySig.Wrap("empty finality provider BTC PK")
}
fpPK := req.FpBtcPk

ctx := sdk.UnwrapSDKContext(goCtx)

// ensure the finality provider exists
Expand All @@ -74,14 +79,14 @@ func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinal
// corrupt a new finality provider and equivocate a historical block over and over again, making a previous block
// unfinalisable forever
if fp.IsSlashed() {
return nil, bstypes.ErrFpAlreadySlashed
return nil, bstypes.ErrFpAlreadySlashed.Wrapf(fmt.Sprintf("finality provider public key: %s", fpPK.MarshalHex()))
}

// ensure the finality provider has voting power at this height
if req.FpBtcPk == nil {
return nil, types.ErrInvalidFinalitySig.Wrap("empty finality provider BTC PK")
if fp.IsJailed() {
return nil, bstypes.ErrFpAlreadyJailed.Wrapf(fmt.Sprintf("finality provider public key: %s", fpPK.MarshalHex()))
}
fpPK := req.FpBtcPk

// ensure the finality provider has voting power at this height
if ms.BTCStakingKeeper.GetVotingPower(ctx, fpPK.MustMarshal(), req.BlockHeight) == 0 {
return nil, types.ErrInvalidFinalitySig.Wrapf("the finality provider %s does not have voting power at height %d", fpPK.MarshalHex(), req.BlockHeight)
}
Expand Down
2 changes: 1 addition & 1 deletion x/finality/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func FuzzAddFinalitySig(f *testing.F) {
fp.SlashedBabylonHeight = blockHeight
bsKeeper.EXPECT().GetFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(fp, nil).Times(1)
_, err = ms.AddFinalitySig(ctx, msg)
require.Equal(t, bstypes.ErrFpAlreadySlashed, err)
require.ErrorIs(t, err, bstypes.ErrFpAlreadySlashed)
})
}

Expand Down

0 comments on commit 890fab3

Please sign in to comment.