From 9439e10e2bc8c03afb3dd8475ff420557cc23833 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Mon, 9 Dec 2024 07:47:46 +0100 Subject: [PATCH] fix genesis state validation (#328) - fixes genesis validation --- CHANGELOG.md | 14 ++++++++- x/btcstaking/types/genesis.go | 5 ++- x/btcstaking/types/genesis_test.go | 50 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a7a94d9b..7d859ee5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased -### v0.18.0 +### Bug fixes + +- [#324](https://github.com/babylonlabs-io/babylon/pull/324) Fix decrementing +jailed fp counter + +- [#328](https://github.com/babylonlabs-io/babylon/pull/328) Fix btc activation height validation in genesis + +### Improvements + +- [#326](https://github.com/babylonlabs-io/babylon/pull/326) docs: btcstaking: +Update btcstaking module docs to include EOI + +## v0.18.0 ### Improvements diff --git a/x/btcstaking/types/genesis.go b/x/btcstaking/types/genesis.go index 9746fb6b6..fe6f15104 100644 --- a/x/btcstaking/types/genesis.go +++ b/x/btcstaking/types/genesis.go @@ -29,7 +29,10 @@ func (gs GenesisState) Validate() error { return err } - err := heightToVersionMap.AddNewPair(uint64(i), params.BtcActivationHeight) + err := heightToVersionMap.AddNewPair( + uint64(params.BtcActivationHeight), + uint32(i), + ) if err != nil { return err diff --git a/x/btcstaking/types/genesis_test.go b/x/btcstaking/types/genesis_test.go index 3a2ce6cc9..c942153d6 100644 --- a/x/btcstaking/types/genesis_test.go +++ b/x/btcstaking/types/genesis_test.go @@ -84,6 +84,56 @@ func TestGenesisState_Validate(t *testing.T) { }, valid: false, }, + { + desc: "parameters with btc activation height > 0 as initial params are valid", + genState: func() *types.GenesisState { + params1 := types.DefaultParams() + params1.BtcActivationHeight = 100 + + return &types.GenesisState{ + Params: []*types.Params{ + ¶ms1, + }, + } + }, + valid: true, + }, + { + desc: "parameters with btc activation height not in ascending order are invalid", + genState: func() *types.GenesisState { + params1 := types.DefaultParams() + params1.BtcActivationHeight = 100 + + params2 := types.DefaultParams() + params2.BtcActivationHeight = 101 + + return &types.GenesisState{ + Params: []*types.Params{ + ¶ms2, + ¶ms1, + }, + } + }, + valid: false, + }, + { + desc: "parameters with btc activation height in ascending order are valid", + genState: func() *types.GenesisState { + params1 := types.DefaultParams() + params1.BtcActivationHeight = 100 + + params2 := types.DefaultParams() + params2.BtcActivationHeight = 101 + + return &types.GenesisState{ + Params: []*types.Params{ + ¶ms1, + ¶ms2, + }, + } + }, + valid: true, + }, } for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) {