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

fix: fix unmarshal bug of BaseAccountJSON. #563

Merged
merged 4 commits into from
Jun 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (server/grpc) [\#516](https://github.com/line/lbm-sdk/pull/516) restore build norace flag
* (genesis) [\#517](https://github.com/line/lbm-sdk/pull/517) fix genesis auth account format(cosmos-sdk style -> lbm-sdk style)
* (x/foundation) [\#545](https://github.com/line/lbm-sdk/pull/545) fix genesis and support abstain
* (x/auth) [\#563](https://github.com/line/lbm-sdk/pull/563) fix unmarshal bug of `BaseAccountJSON`

### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ type PubKeyJSON struct {
type BaseAccountJSON struct {
Address string `json:"address"`
PubKey PubKeyJSON `json:"pub_key"`
AccountNumber uint64 `json:"account_number"`
AccountNumber uint64 `json:"account_number,string"`
Sequence string `json:"sequence"`
}

Expand Down
10 changes: 10 additions & 0 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"testing"

"github.com/gogo/protobuf/jsonpb"
Expand Down Expand Up @@ -237,6 +238,15 @@ func TestModuleAccountJSONPB(t *testing.T) {
require.Error(t, err)
}

func TestBaseAccountJSONPB(t *testing.T) {
baseAccountJson := `{"address":"link1rrfywnytlm87ywes0hvxn4rhm4grrn9qquqljc","pub_key":{"type":0,"key":null},"account_number":"10","sequence":"50"}`
ba := new(types.BaseAccount)
jum := jsonpb.Unmarshaler{}
err := jum.Unmarshal(strings.NewReader(baseAccountJson), ba)
require.NoError(t, err)
require.Equal(t, ba.AccountNumber, uint64(10))
}

func TestGenesisAccountsContains(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.BytesToAccAddress(pubkey.Address())
Expand Down