Skip to content

Commit

Permalink
chore: add test for FPs inserted from upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Aug 22, 2024
1 parent b51ca17 commit 5215030
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/upgrades/signetlaunch/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions app/upgrades/signetlaunch/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -56,6 +57,7 @@ func TestKeeperTestSuite(t *testing.T) {

func (s *UpgradeTestSuite) TestUpgrade() {
oldHeadersLen := 0
oldFPsLen := 0

testCases := []struct {
msg string
Expand All @@ -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
Expand Down Expand Up @@ -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())
}
},
},
}
Expand Down

0 comments on commit 5215030

Please sign in to comment.