Skip to content

Commit

Permalink
feat(x/auth): Add auth sim decoder case for AccountNumberStoreKeyPref…
Browse files Browse the repository at this point in the history
…ix (backport #13048) (#13054)
  • Loading branch information
mergify[bot] committed Aug 27, 2022
1 parent e2fe96a commit 1af5c72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (x/authz) [#13047](https://github.com/cosmos/cosmos-sdk/pull/13047) Add a GetAuthorization function to the keeper.

### Improvements

* (x/auth) [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the simulation decoder.

### Bug Fixes

* (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression.
Expand Down
15 changes: 15 additions & 0 deletions x/auth/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
gogotypes "github.com/gogo/protobuf/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand Down Expand Up @@ -41,6 +42,20 @@ func NewDecodeStore(ak AuthUnmarshaler) func(kvA, kvB kv.Pair) string {

return fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumberA, globalAccNumberB)

case bytes.HasPrefix(kvA.Key, types.AccountNumberStoreKeyPrefix):
var accNumA, accNumB sdk.AccAddress
err := accNumA.Unmarshal(kvA.Value)
if err != nil {
panic(err)
}

err = accNumB.Unmarshal(kvB.Value)
if err != nil {
panic(err)
}

return fmt.Sprintf("AccNumA: %s\nAccNumB: %s", accNumA, accNumB)

default:
panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
}
Expand Down
5 changes: 5 additions & 0 deletions x/auth/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestDecodeStore(t *testing.T) {
Key: types.GlobalAccountNumberKey,
Value: cdc.MustMarshal(&globalAccNumber),
},
{
Key: types.AccountNumberStoreKey(5),
Value: acc.GetAddress().Bytes(),
},
{
Key: []byte{0x99},
Value: []byte{0x99},
Expand All @@ -53,6 +57,7 @@ func TestDecodeStore(t *testing.T) {
}{
{"Account", fmt.Sprintf("%v\n%v", acc, acc)},
{"GlobalAccNumber", fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumber, globalAccNumber)},
{"AccNum", fmt.Sprintf("AccNumA: %s\nAccNumB: %s", acc.GetAddress(), acc.GetAddress())},
{"other", ""},
}

Expand Down

0 comments on commit 1af5c72

Please sign in to comment.