Skip to content

Commit

Permalink
fix compile and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jan 13, 2025
1 parent 92ed24c commit e2651ab
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 371 deletions.
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[finalitytypes.StoreKey]),
ak.BTCStakingKeeper,
ak.IncentiveKeeper,
ak.CheckpointingKeeper,
&checkpointingKeeper,
appparams.AccGov.String(),
)

Expand Down
9 changes: 7 additions & 2 deletions proto/buf.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cometbft
repository: cometbft
commit: c0d3497e35d649538679874acdd86660
digest: shake256:05d2fb9e6b6bf82385ac26b250afbba281a2ca79f51729291373d24ca676d743183bf70a921daae6feafd5f9917120e2548a7c477d9743f668bca27cc1e12fdf
- remote: buf.build
owner: cosmos
repository: cosmos-proto
Expand All @@ -19,8 +24,8 @@ deps:
- remote: buf.build
owner: cosmos
repository: ibc
commit: 41fbc441e4d645119d275150719c5441
digest: shake256:a61d3e152909abddc91dcc1aec8ac997007bebd48a7921bc243681c708e6c9068f6484aa7ed4e6ff60101d3422c98744a4a5294bbda6aacdba07f1dfa4291020
commit: f3cb7e9a10ab4cd5a402b9913f65e38d
digest: shake256:aaa8a2a46a3ab5cb4c54f9f14920bc472e5e5f93453fa250de49f15c76dce7f82faa5615afd341967797ead8052306db6b1e6327cb1d8d94345bf07a22f8aebd
- remote: buf.build
owner: cosmos
repository: ics23
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/btc_staking_pre_approval_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func (s *BTCStakingPreApprovalTestSuite) Test1CreateFinalityProviderAndDelegatio
// submit the message for creating BTC delegation
delBtcPK := bbn.NewBIP340PubKeyFromBTCPK(s.delBTCSK.PubKey())
nonValidatorNode.CreateBTCDelegation(
*delBtcPK,
delBtcPK,
pop,
stakingTx,
// We are passing `nil` as inclusion proof will be provided in separate tx
nil,
[]*bbn.BIP340PubKey{s.cacheFP.BtcPk},
[]bbn.BIP340PubKey{*s.cacheFP.BtcPk},
stakingTimeBlocks,
btcutil.Amount(s.stakingValue),
testStakingInfo.SlashingTx,
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/configurer/chain/commands_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (n *NodeConfig) CreateFinalityProvider(walletAddrOrName string, btcPK *bbn.
}

func (n *NodeConfig) CreateBTCDelegation(
btcPK bbn.BIP340PubKey,
btcPK *bbn.BIP340PubKey,
pop *bstypes.ProofOfPossessionBTC,
stakingTx []byte,
inclusionProof *bstypes.InclusionProof,
fpPKs []*bbn.BIP340PubKey,
fpPKs []bbn.BIP340PubKey,
stakingTimeBlocks uint16,
stakingValue btcutil.Amount,
slashingTx *bstypes.BTCSlashingTx,
Expand Down Expand Up @@ -428,7 +428,7 @@ func (n *NodeConfig) CreateBTCDelegationAndCheck(
popDel1,
stakingTx,
inclusionProof,
fp.BtcPk,
bbn.NewBIP340PKsFromBTCPKs([]*btcec.PublicKey{fp.BtcPk.MustToBTCPK()}),
stakingTimeBlocks,
btcutil.Amount(stakingSatAmt),
testStakingInfo.SlashingTx,
Expand Down
3 changes: 1 addition & 2 deletions test/replay/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ func (d *BabylonAppDriver) WaitTillAllFpsJailed(t *testing.T) {
}
}

// SendTxWithMsgsFromDriverAccount sends tx with msgs from driver account and asserts that
// SendTxWithMsgsFromDriverAccount sends tx with msgs from driver account and asserts that
// execution was successful. It assumes that there will only be one tx in the block.
func (d *BabylonAppDriver) SendTxWithMsgsFromDriverAccount(
Expand All @@ -741,7 +740,7 @@ func (d *BabylonAppDriver) SendTxWithMsgsFromDriverAccount(
}

// all executions should be successful
require.Equal(t, rs.Code, uint32(0))
require.Equal(t, rs.Code, uint32(0), rs.Log)
}

d.DriverAccountSeqNr++
Expand Down
2 changes: 1 addition & 1 deletion testutil/btcstaking-helper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func (h *Helper) CreateCovenantSigs(
covenantMsgs := h.GenerateCovenantSignaturesMessages(r, covenantSKs, msgCreateBTCDel, del)
for _, m := range covenantMsgs {
msgCopy := m
h.BTCLightClientKeeper.EXPECT().GetTipInfo(gomock.Any()).Return(&btclctypes.BTCHeaderInfo{Height: lightClientTipHeight})
h.BTCLightClientKeeper.EXPECT().GetTipInfo(gomock.Any()).Return(&btclctypes.BTCHeaderInfo{Height: lightClientTipHeight}).MaxTimes(1)
_, err := h.MsgServer.AddCovenantSigs(h.Ctx, msgCopy)
h.NoError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion testutil/incentives-helper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (h *IncentiveHelper) CreateBtcDelegation(
stakingTxHash, msgCreateBTCDel, _, _, _, unbondingInfo, err = h.CreateDelegationWithBtcBlockHeight(
r,
delSK,
fpPK,
[]*btcec.PublicKey{fpPK},
stakingValue,
stakingTime,
0,
Expand Down
2 changes: 2 additions & 0 deletions testutil/keeper/btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/require"

appparams "github.com/babylonlabs-io/babylon/app/params"
Expand Down
1 change: 0 additions & 1 deletion x/btcstaking/keeper/btc_consumer_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (k Keeper) GetBTCConsumerDelegatorDelegationsResponses(
for i, btcDel := range curBTCDels.Dels {
status := btcDel.GetStatus(
btcHeight,
wValue,
covenantQuorum,
)
btcDelsResp[i] = bstypes.NewBTCDelegationResponse(btcDel, status)
Expand Down
4 changes: 2 additions & 2 deletions x/btcstaking/keeper/btc_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (k Keeper) addCovenantSigsToBTCDelegation(
unbondingTxSig *bbn.BIP340Signature,
parsedUnbondingSlashingAdaptorSignatures []asig.AdaptorSignature,
params *types.Params,
btcTipHeight uint32,
) {
hadQuorum := btcDel.HasCovenantQuorums(params.CovenantQuorum)

Expand Down Expand Up @@ -138,8 +139,7 @@ func (k Keeper) addCovenantSigsToBTCDelegation(
NewState: types.BTCDelegationStatus_ACTIVE,
},
)
btcTip := k.btclcKeeper.GetTipInfo(ctx)
k.addPowerDistUpdateEvent(ctx, btcTip.Height, activeEvent)
k.addPowerDistUpdateEvent(ctx, btcTipHeight, activeEvent)

// notify consumer chains about the active BTC delegation
k.notifyConsumersOnActiveBTCDel(ctx, btcDel)
Expand Down
33 changes: 19 additions & 14 deletions x/btcstaking/keeper/btc_staking_consumer_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

testutil "github.com/babylonlabs-io/babylon/testutil/btcstaking-helper"
"github.com/babylonlabs-io/babylon/testutil/datagen"
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
"github.com/babylonlabs-io/babylon/x/btcstaking/types"
bsctypes "github.com/babylonlabs-io/babylon/x/btcstkconsumer/types"
"github.com/btcsuite/btcd/btcec/v2"
Expand Down Expand Up @@ -85,8 +86,6 @@ func FuzzSetBTCStakingEventStore_ActiveDel(f *testing.F) {

// set all parameters
covenantSKs, _ := h.GenAndApplyParams(r)
changeAddress, err := datagen.GenRandomBTCAddress(r, h.Net)
require.NoError(t, err)

// register a random consumer on Babylon
randomConsumer := registerAndVerifyConsumer(t, r, h)
Expand All @@ -100,20 +99,23 @@ func FuzzSetBTCStakingEventStore_ActiveDel(f *testing.F) {
stakingValue := int64(2 * 10e8)
delSK, _, err := datagen.GenRandomBTCKeyPair(r)
h.NoError(err)
stakingTxHash, msgCreateBTCDel, _, _, _, _, err := h.CreateDelegation(
stakingTxHash, msgCreateBTCDel, _, _, _, _, err := h.CreateDelegationWithBtcBlockHeight(
r,
delSK,
[]*btcec.PublicKey{consumerFpPK, babylonFpPK},
changeAddress.EncodeAddress(),
stakingValue,
1000,
0,
0,
false,
false,
10,
30,
)
h.NoError(err)

h.BTCLightClientKeeper.EXPECT().GetTipInfo(gomock.Eq(h.Ctx)).Return(&btclctypes.BTCHeaderInfo{Height: 30}).AnyTimes()

// delegation related assertions
actualDel, err := h.BTCStakingKeeper.GetBTCDelegation(h.Ctx, stakingTxHash)
h.NoError(err)
Expand All @@ -133,7 +135,10 @@ func FuzzSetBTCStakingEventStore_ActiveDel(f *testing.F) {
h.NoError(err)
require.True(t, actualDel.HasCovenantQuorums(h.BTCStakingKeeper.GetParams(h.Ctx).CovenantQuorum))
require.True(t, actualDel.BtcUndelegation.HasCovenantQuorums(h.BTCStakingKeeper.GetParams(h.Ctx).CovenantQuorum))
votingPower := actualDel.VotingPower(h.BTCLightClientKeeper.GetTipInfo(h.Ctx).Height, h.BTCCheckpointKeeper.GetParams(h.Ctx).CheckpointFinalizationTimeout, h.BTCStakingKeeper.GetParams(h.Ctx).CovenantQuorum)
votingPower := actualDel.VotingPower(
h.BTCLightClientKeeper.GetTipInfo(h.Ctx).Height,
h.BTCStakingKeeper.GetParams(h.Ctx).CovenantQuorum,
)
require.Equal(t, uint64(stakingValue), votingPower)

// event store related assertions
Expand Down Expand Up @@ -177,9 +182,6 @@ func FuzzSetBTCStakingEventStore_UnbondedDel(f *testing.F) {
covenantSKs, _ := h.GenAndApplyParams(r)

bsParams := h.BTCStakingKeeper.GetParams(h.Ctx)
wValue := h.BTCCheckpointKeeper.GetParams(h.Ctx).CheckpointFinalizationTimeout
changeAddress, err := datagen.GenRandomBTCAddress(r, h.Net)
require.NoError(t, err)

// register a random consumer on Babylon
randomConsumer := registerAndVerifyConsumer(t, r, h)
Expand All @@ -193,28 +195,29 @@ func FuzzSetBTCStakingEventStore_UnbondedDel(f *testing.F) {
stakingValue := int64(2 * 10e8)
delSK, _, err := datagen.GenRandomBTCKeyPair(r)
h.NoError(err)
stakingTxHash, msgCreateBTCDel, actualDel, _, _, unbondingInfo, err := h.CreateDelegation(
stakingTxHash, msgCreateBTCDel, actualDel, _, _, unbondingInfo, err := h.CreateDelegationWithBtcBlockHeight(
r,
delSK,
[]*btcec.PublicKey{consumerFpPK, babylonFpPK},
changeAddress.EncodeAddress(),
stakingValue,
1000,
0,
0,
false,
false,
10,
30,
)
h.NoError(err)

// add covenant signatures to this BTC delegation
h.CreateCovenantSigs(r, covenantSKs, msgCreateBTCDel, actualDel)
h.CreateCovenantSigs(r, covenantSKs, msgCreateBTCDel, actualDel, 10)

// ensure the BTC delegation is bonded right now
actualDel, err = h.BTCStakingKeeper.GetBTCDelegation(h.Ctx, stakingTxHash)
h.NoError(err)
btcTip := h.BTCLightClientKeeper.GetTipInfo(h.Ctx).Height
status := actualDel.GetStatus(btcTip, wValue, bsParams.CovenantQuorum)
btcTip := uint32(30)
status := actualDel.GetStatus(btcTip, bsParams.CovenantQuorum)
require.Equal(t, types.BTCDelegationStatus_ACTIVE, status)

// construct unbonding msg
Expand All @@ -232,14 +235,16 @@ func FuzzSetBTCStakingEventStore_UnbondedDel(f *testing.F) {
_, err = h.MsgServer.BTCUndelegate(h.Ctx, &bogusMsg)
h.Error(err)

h.BTCLightClientKeeper.EXPECT().GetTipInfo(gomock.Eq(h.Ctx)).Return(&btclctypes.BTCHeaderInfo{Height: 30}).AnyTimes()

// unbond
_, err = h.MsgServer.BTCUndelegate(h.Ctx, msg)
h.NoError(err)

// ensure the BTC delegation is unbonded
actualDel, err = h.BTCStakingKeeper.GetBTCDelegation(h.Ctx, stakingTxHash)
h.NoError(err)
status = actualDel.GetStatus(btcTip, wValue, bsParams.CovenantQuorum)
status = actualDel.GetStatus(btcTip, bsParams.CovenantQuorum)
require.Equal(t, types.BTCDelegationStatus_UNBONDED, status)

// event store related assertions
Expand Down
1 change: 1 addition & 0 deletions x/btcstaking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ func (ms msgServer) AddCovenantSigs(goCtx context.Context, req *types.MsgAddCove
req.UnbondingTxSig,
parsedUnbondingSlashingAdaptorSignatures,
params,
btcTipHeight,
)

// at this point, the covenant signatures are verified and are not duplicated.
Expand Down
Loading

0 comments on commit e2651ab

Please sign in to comment.