Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/auth): Add auth sim decoder case for AccountNumberStoreKeyPrefix #13048

Merged
merged 4 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing.
* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store
* [#12953](https://github.com/cosmos/cosmos-sdk/pull/12953) Change the default priority mechanism to be based on gas price.
* [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the x/auth simulation decoder.

### State Machine Breaking

Expand Down
15 changes: 15 additions & 0 deletions x/auth/simulation/decoder.go
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
Expand Up @@ -51,6 +51,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 @@ -63,6 +67,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