Skip to content

Commit

Permalink
backport-fix genesis state validation (#328) (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec authored Dec 9, 2024
1 parent bd4906f commit 8d280df
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion x/btcstaking/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions x/btcstaking/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
&params1,
},
}
},
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{
&params2,
&params1,
},
}
},
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{
&params1,
&params2,
},
}
},
valid: true,
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
Expand Down

0 comments on commit 8d280df

Please sign in to comment.