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

Make JSONMarshaler methods require proto.Message #7054

Merged
merged 27 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
97c59de
Make JSONMarshaler require proto.Message
blushi Aug 13, 2020
8f43ba6
Use &msg with MarshalJSON
blushi Aug 13, 2020
b6dd69b
Use *LegacyAmino in queriers instead of JSONMarshaler
blushi Aug 13, 2020
3af5055
Revert ABCIMessageLogs String() and coins tests
blushi Aug 13, 2020
282cc28
Use LegacyAmino in client/debug and fix subspace tests
blushi Aug 13, 2020
f572cd3
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 13, 2020
3f68d9a
Use LegacyAmino in all legacy queriers and adapt simulation
blushi Aug 14, 2020
8ed3b64
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 14, 2020
2d452d4
Make AminoCodec implement Marshaler and some godoc fixes
blushi Aug 14, 2020
fa96cfe
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ma…
aaronc Aug 17, 2020
28db5ea
Test fixes
aaronc Aug 17, 2020
2b65f5a
Remove unrelevant comment
blushi Aug 19, 2020
48103b9
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 19, 2020
b4da972
Use TxConfig.TxJSONEncoder
blushi Aug 19, 2020
ecc133a
Use encoding/json in genutil cli migrate/validate genesis cmds
blushi Aug 19, 2020
7e6d09d
Address simulation related comments
blushi Aug 19, 2020
abfdd22
Use JSONMarshaler in cli tests
blushi Aug 19, 2020
a3e394e
Use proto.Message as respType in cli tests
blushi Aug 20, 2020
e5f88e1
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 20, 2020
7665df4
Use tmjson for tm GenesisDoc
blushi Aug 24, 2020
8ab0066
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 24, 2020
12754cd
Update types/module/simulation.go
blushi Aug 25, 2020
17ea317
Update types/module/module_test.go
blushi Aug 25, 2020
4121810
Add godoc comments
blushi Aug 26, 2020
4aa1d08
Remove unused InsertKeyJSON
blushi Aug 26, 2020
5060ae3
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 26, 2020
0cff5ca
Fix tests
blushi Aug 26, 2020
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
Prev Previous commit
Next Next commit
Use proto.Message as respType in cli tests
  • Loading branch information
blushi committed Aug 20, 2020
commit a3e394e3789bb34c4006c3d306bf4656d0310ed0
12 changes: 4 additions & 8 deletions types/simulation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package simulation

import (
"encoding/json"
"fmt"
"math/rand"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
)

type WeightedProposalContent interface {
Expand Down Expand Up @@ -137,14 +135,12 @@ type AppParams map[string]json.RawMessage
// object. If it exists, it'll be decoded and returned. Otherwise, the provided
// ParamSimulator is used to generate a random value or default value (eg: in the
// case of operation weights where Rand is not used).
func (sp AppParams) GetOrGenerate(cdc codec.JSONMarshaler, key string, ptr interface{}, r *rand.Rand, ps ParamSimulator) {
func (sp AppParams) GetOrGenerate(_ codec.JSONMarshaler, key string, ptr interface{}, r *rand.Rand, ps ParamSimulator) {
if v, ok := sp[key]; ok && v != nil {
msg, ok := ptr.(proto.Message)
if !ok {
panic(fmt.Errorf("can't proto marshal %T", ptr))
err := json.Unmarshal(v, ptr)
if err != nil {
panic(err)
}

cdc.MustUnmarshalJSON(v, msg)
return
}

Expand Down
19 changes: 12 additions & 7 deletions x/bank/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
expected fmt.Stringer
respType proto.Message
expected proto.Message
}{
{"no address provided", []string{}, true, nil, nil},
{
Expand Down Expand Up @@ -86,7 +86,7 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
},
false,
&sdk.Coin{},
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
},
{
"total account balance of a bogus denom",
Expand All @@ -97,7 +97,7 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
},
false,
&sdk.Coin{},
sdk.NewCoin("foobar", sdk.ZeroInt()),
NewCoin("foobar", sdk.ZeroInt()),
},
}

Expand All @@ -112,7 +112,7 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)))
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType))
s.Require().Equal(tc.expected.String(), tc.respType.String())
}
})
Expand Down Expand Up @@ -220,7 +220,7 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
amount sdk.Coins
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -289,7 +289,7 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
} else {
s.Require().NoError(err)

s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), tc.respType.(proto.Message)), bz.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), tc.respType), bz.String())
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
}
Expand All @@ -300,3 +300,8 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

func NewCoin(denom string, amount sdk.Int) *sdk.Coin {
coin := sdk.NewCoin(denom, amount)
return &coin
}
4 changes: 2 additions & 2 deletions x/crisis/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *IntegrationTestSuite) TestNewMsgVerifyInvariantTxCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
Expand Down
20 changes: 10 additions & 10 deletions x/distribution/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawRewardsCmd() {
valAddr fmt.Stringer
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -510,7 +510,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawRewardsCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz, tc.respType.(proto.Message)), string(bz))
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz, tc.respType), string(bz))

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
Expand All @@ -526,7 +526,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -563,7 +563,7 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
Expand All @@ -579,7 +579,7 @@ func (s *IntegrationTestSuite) TestNewSetWithdrawAddrCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -618,7 +618,7 @@ func (s *IntegrationTestSuite) TestNewSetWithdrawAddrCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
Expand All @@ -634,7 +634,7 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -673,7 +673,7 @@ func (s *IntegrationTestSuite) TestNewFundCommunityPoolCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code)
Expand Down Expand Up @@ -719,7 +719,7 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -759,7 +759,7 @@ func (s *IntegrationTestSuite) TestGetCmdSubmitProposal() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
Expand Down
4 changes: 2 additions & 2 deletions x/gov/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *IntegrationTestSuite) TestNewUnjailTxCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand All @@ -175,7 +175,7 @@ func (s *IntegrationTestSuite) TestNewUnjailTxCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
name string
args []string
expectErr bool
respType fmt.Stringer
respType proto.Message
expectedCode uint32
}{
{
Expand Down Expand Up @@ -165,7 +165,7 @@ func (s *IntegrationTestSuite) TestNewCreateValidatorCmd() {
s.Require().Error(err)
} else {
s.Require().NoError(err, out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType.(proto.Message)), out.String())
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), tc.respType), out.String())

txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
Expand Down