chore: backport add MustValAddressFromBech32 function (#23919)
Co-authored-by: Luke <luchenqun@qq.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
047379caaf
commit
9d04acb366
@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Features
|
||||
|
||||
* (types) [#23919](https://github.com/cosmos/cosmos-sdk/pull/23919) Add MustValAddressFromBech32 function.
|
||||
* (all) [23708](https://github.com/cosmos/cosmos-sdk/pull/23708) Add unordered transaction support.
|
||||
* Adds a `--timeout-timestamp` flag that allows users to specify a block time at which the unordered transactions should expire from the mempool.
|
||||
* (x/epochs) [#23815](https://github.com/cosmos/cosmos-sdk/pull/23815) Upstream `x/epochs` from Osmosis
|
||||
|
||||
@ -363,6 +363,16 @@ func ValAddressFromBech32(address string) (addr ValAddress, err error) {
|
||||
return ValAddress(bz), nil
|
||||
}
|
||||
|
||||
// MustValAddressFromBech32 calls ValAddressFromBech32 and panics on error.
|
||||
func MustValAddressFromBech32(address string) ValAddress {
|
||||
addr, err := ValAddressFromBech32(address)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return addr
|
||||
}
|
||||
|
||||
// Returns boolean for whether two ValAddresses are Equal
|
||||
func (va ValAddress) Equals(va2 Address) bool {
|
||||
if va.Empty() && va2.Empty() {
|
||||
|
||||
@ -558,3 +558,16 @@ func (s *addressTestSuite) TestGetFromBech32() {
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal("invalid Bech32 prefix; expected x, got cosmos", err.Error())
|
||||
}
|
||||
|
||||
func (s *addressTestSuite) TestMustAccAddressFromBech32() {
|
||||
bech32PrefixValAddr := types.GetConfig().GetBech32ValidatorAddrPrefix()
|
||||
addr20byte := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
|
||||
address := types.MustBech32ifyAddressBytes(bech32PrefixValAddr, addr20byte)
|
||||
|
||||
valAddress1, err := types.ValAddressFromBech32(address)
|
||||
s.Require().Nil(err)
|
||||
|
||||
valAddress2 := types.MustValAddressFromBech32(address)
|
||||
|
||||
s.Require().Equal(valAddress1, valAddress2)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user