From 5215030b9b8e4d51fb63a633cc531c7e4f445224 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Wed, 21 Aug 2024 22:06:15 -0300 Subject: [PATCH] chore: add test for FPs inserted from upgrade --- app/upgrades/signetlaunch/upgrades.go | 4 ++-- app/upgrades/signetlaunch/upgrades_test.go | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/upgrades/signetlaunch/upgrades.go b/app/upgrades/signetlaunch/upgrades.go index bdeb11792..da9fa3c62 100644 --- a/app/upgrades/signetlaunch/upgrades.go +++ b/app/upgrades/signetlaunch/upgrades.go @@ -103,7 +103,7 @@ func LoadBTCHeadersFromData() ([]*btclighttypes.BTCHeaderInfo, error) { // LoadSignedFPsFromData returns the finality providers from the json string. // It also verifies if the msg is correctly signed and is valid to be inserted. -func LoadSignedFPsFromData(cdc codec.Codec, txDecoder sdk.TxDecoder) ([]*btcstktypes.MsgCreateFinalityProvider, error) { +func LoadSignedFPsFromData(cdc codec.Codec, txJSONDecoder sdk.TxDecoder) ([]*btcstktypes.MsgCreateFinalityProvider, error) { buff := bytes.NewBufferString(SignedFPsStr) var d dataSignedFps @@ -119,7 +119,7 @@ func LoadSignedFPsFromData(cdc codec.Codec, txDecoder sdk.TxDecoder) ([]*btcstkt return nil, err } - tx, err := txDecoder(txBytes) + tx, err := txJSONDecoder(txBytes) if err != nil { return nil, err } diff --git a/app/upgrades/signetlaunch/upgrades_test.go b/app/upgrades/signetlaunch/upgrades_test.go index 80b39a351..def169d22 100644 --- a/app/upgrades/signetlaunch/upgrades_test.go +++ b/app/upgrades/signetlaunch/upgrades_test.go @@ -13,6 +13,7 @@ import ( v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" "github.com/babylonlabs-io/babylon/x/btclightclient" btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" + "github.com/babylonlabs-io/babylon/x/btcstaking/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -56,6 +57,7 @@ func TestKeeperTestSuite(t *testing.T) { func (s *UpgradeTestSuite) TestUpgrade() { oldHeadersLen := 0 + oldFPsLen := 0 testCases := []struct { msg string @@ -68,6 +70,10 @@ func (s *UpgradeTestSuite) TestUpgrade() { func() { allBtcHeaders := s.app.BTCLightClientKeeper.GetMainChainFrom(s.ctx, 0) oldHeadersLen = len(allBtcHeaders) + + resp, err := s.app.BTCStakingKeeper.FinalityProviders(s.ctx, &types.QueryFinalityProvidersRequest{}) + s.NoError(err) + oldFPsLen = len(resp.FinalityProviders) }, func() { // inject upgrade plan @@ -105,6 +111,24 @@ func (s *UpgradeTestSuite) TestUpgrade() { s.EqualValues(btcHeaderInserted.Header.MarshalHex(), btcHeaderInState.Header.MarshalHex()) } + + resp, err := s.app.BTCStakingKeeper.FinalityProviders(s.ctx, &types.QueryFinalityProvidersRequest{}) + s.NoError(err) + newFPsLen := len(resp.FinalityProviders) + + fpsInserted, err := v1.LoadSignedFPsFromData(s.app.Codec, s.app.TxConfig().TxJSONDecoder()) + s.NoError(err) + + s.Equal(newFPsLen, oldFPsLen+len(fpsInserted)) + for _, fpInserted := range fpsInserted { + fpFromKeeper, err := s.app.BTCStakingKeeper.GetFinalityProvider(s.ctx, *fpInserted.BtcPk) + s.NoError(err) + + s.EqualValues(fpFromKeeper.Addr, fpInserted.Addr) + s.EqualValues(fpFromKeeper.Description, fpInserted.Description) + s.EqualValues(fpFromKeeper.Commission.String(), fpInserted.Commission.String()) + s.EqualValues(fpFromKeeper.Pop.String(), fpInserted.Pop.String()) + } }, }, }