From 34e22fbcb8859b18381a6c9e6704227c7ac5d5d3 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Wed, 11 Mar 2020 17:45:02 +0100 Subject: [PATCH 01/10] refactor parsing to use unified version --- x/gov/client/cli/parse.go | 3 ++- x/params/client/cli/tx.go | 7 +++++- x/params/client/cli/tx_test.go | 45 ++++++++++++++++++++++++++++++++++ x/params/client/utils/utils.go | 2 +- 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 x/params/client/cli/tx_test.go diff --git a/x/gov/client/cli/parse.go b/x/gov/client/cli/parse.go index dd9415f18d..e29840db74 100644 --- a/x/gov/client/cli/parse.go +++ b/x/gov/client/cli/parse.go @@ -24,7 +24,8 @@ func parseSubmitProposalFlags() (*proposal, error) { for _, flag := range ProposalFlags { if viper.GetString(flag) != "" { - return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag) + return nil, fmt.Errorf( + "--%s flag provided alongside --proposal, which is a noop", flag) } } diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 67a890a51e..6f56240835 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -77,7 +77,12 @@ Where proposal.json contains: from := cliCtx.GetFromAddress() content := paramproposal.NewParameterChangeProposal(proposal.Title, proposal.Description, proposal.Changes.ToParamChanges()) - msg := govtypes.NewMsgSubmitProposal(content, proposal.Deposit, from) + deposit, err := sdk.ParseCoins(proposal.Deposit) + if err != nil { + return err + } + + msg := govtypes.NewMsgSubmitProposal(content, deposit, from) if err := msg.ValidateBasic(); err != nil { return err } diff --git a/x/params/client/cli/tx_test.go b/x/params/client/cli/tx_test.go new file mode 100644 index 0000000000..0f3cb5c499 --- /dev/null +++ b/x/params/client/cli/tx_test.go @@ -0,0 +1,45 @@ +package cli + +import ( + "io/ioutil" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/params/client/utils" +) + +func TestParseProposal(t *testing.T) { + cdc := codec.New() + okJSON, err := ioutil.TempFile("", "proposal") + require.Nil(t, err, "unexpected error") + okJSON.WriteString(` +{ + "title": "Staking Param Change", + "description": "Update max validators", + "changes": [ + { + "subspace": "staking", + "key": "MaxValidators", + "value": 1 + } + ], + "deposit": "1000stake" +} +`) + + proposal, err := utils.ParseParamChangeProposalJSON(cdc, okJSON.Name()) + require.NoError(t, err) + + require.Equal(t, "Staking Param Change", proposal.Title) + require.Equal(t, "Update max validators", proposal.Description) + require.Equal(t, "1000stake", proposal.Deposit) + require.Equal(t, utils.ParamChangesJSON{ + { + Subspace: "staking", + Key: "MaxValidators", + Value: []byte{0x31}, + }, + }, proposal.Changes) +} diff --git a/x/params/client/utils/utils.go b/x/params/client/utils/utils.go index 231c5e2b06..2cac0b21a8 100644 --- a/x/params/client/utils/utils.go +++ b/x/params/client/utils/utils.go @@ -29,7 +29,7 @@ type ( Title string `json:"title" yaml:"title"` Description string `json:"description" yaml:"description"` Changes ParamChangesJSON `json:"changes" yaml:"changes"` - Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + Deposit string `json:"deposit" yaml:"deposit"` } // ParamChangeProposalReq defines a parameter change proposal request body. From 36554e73e22206dbee0c7f5f031b6319c4a669df Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Wed, 11 Mar 2020 18:03:47 +0100 Subject: [PATCH 02/10] refactor cli tx for distribution param change request --- x/distribution/client/cli/tx.go | 13 ++++++++++-- x/distribution/client/cli/tx_test.go | 30 ++++++++++++++++++++++++++++ x/distribution/client/cli/utils.go | 4 ++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index a033fd28dc..12baebcf07 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -248,9 +248,18 @@ Where proposal.json contains: } from := cliCtx.GetFromAddress() - content := types.NewCommunityPoolSpendProposal(proposal.Title, proposal.Description, proposal.Recipient, proposal.Amount) - msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from) + amount, err := sdk.ParseCoins(proposal.Amount) + if err != nil { + return err + } + content := types.NewCommunityPoolSpendProposal(proposal.Title, proposal.Description, proposal.Recipient, amount) + + deposit, err := sdk.ParseCoins(proposal.Deposit) + if err != nil { + return err + } + msg := gov.NewMsgSubmitProposal(content, deposit, from) if err := msg.ValidateBasic(); err != nil { return err } diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go index 860b31fa63..d8f8b3921c 100644 --- a/x/distribution/client/cli/tx_test.go +++ b/x/distribution/client/cli/tx_test.go @@ -1,8 +1,11 @@ package cli import ( + "io/ioutil" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/crypto/secp256k1" @@ -77,3 +80,30 @@ func Test_splitAndCall_Splitting(t *testing.T) { assert.NoError(t, err, "") assert.Equal(t, 3, callCount) } + +func TestParseProposal(t *testing.T) { + cdc := codec.New() + okJSON, err := ioutil.TempFile("", "proposal") + require.Nil(t, err, "unexpected error") + okJSON.WriteString(` +{ + "title": "Community Pool Spend", + "description": "Pay me some Atoms!", + "recipient": "cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq", + "amount": "1000stake", + "deposit": "1000stake" +} +`) + + proposal, err := ParseCommunityPoolSpendProposalJSON(cdc, okJSON.Name()) + require.NoError(t, err) + + addr, err := sdk.AccAddressFromBech32("cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq") + require.NoError(t, err) + + require.Equal(t, "Community Pool Spend", proposal.Title) + require.Equal(t, "Pay me some Atoms!", proposal.Description) + require.Equal(t, addr, proposal.Recipient) + require.Equal(t, "1000stake", proposal.Deposit) + require.Equal(t, "1000stake", proposal.Amount) +} diff --git a/x/distribution/client/cli/utils.go b/x/distribution/client/cli/utils.go index 2860162502..4d4169a7fa 100644 --- a/x/distribution/client/cli/utils.go +++ b/x/distribution/client/cli/utils.go @@ -13,8 +13,8 @@ type ( Title string `json:"title" yaml:"title"` Description string `json:"description" yaml:"description"` Recipient sdk.AccAddress `json:"recipient" yaml:"recipient"` - Amount sdk.Coins `json:"amount" yaml:"amount"` - Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + Amount string `json:"amount" yaml:"amount"` + Deposit string `json:"deposit" yaml:"deposit"` } ) From 382e5021b24c2dd3faeefef30959d8db7b087e8a Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Wed, 11 Mar 2020 18:06:39 +0100 Subject: [PATCH 03/10] update cli documentation distribution --- x/distribution/client/cli/tx.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 12baebcf07..35d12391d0 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -220,18 +220,8 @@ Where proposal.json contains: "title": "Community Pool Spend", "description": "Pay me some Atoms!", "recipient": "cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq", - "amount": [ - { - "denom": "stake", - "amount": "10000" - } - ], - "deposit": [ - { - "denom": "stake", - "amount": "10000" - } - ] + "amount": "1000stake", + "deposit": "1000stake" } `, version.ClientName, From 1c7ec9e3391b0f02e1984a9628e76d25f7238446 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Wed, 11 Mar 2020 18:07:49 +0100 Subject: [PATCH 04/10] update params cli msg --- x/params/client/cli/tx.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 6f56240835..969d9052ea 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -53,12 +53,7 @@ Where proposal.json contains: "value": 105 } ], - "deposit": [ - { - "denom": "stake", - "amount": "10000" - } - ] + "deposit": "1000stake" } `, version.ClientName, From 520b397dc2157bd5dd29d97357d1c4ffb1c383eb Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Wed, 11 Mar 2020 18:12:10 +0100 Subject: [PATCH 05/10] update cli --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2a9a1025..c00a127ee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ balances or a single balance by denom when the `denom` query parameter is presen * (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´. * (x/auth) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5702) The `x/auth` querier route has changed from `"acc"` to `"auth"`. * (store/types) [\#5730](https://github.com/cosmos/cosmos-sdk/pull/5730) store.types.Cp() is removed in favour of types.CopyBytes(). +* (client) [\#5640](https://github.com/cosmos/cosmos-sdk/issues/5783) Unify all coins representations on json client requests. ### API Breaking Changes From f8897308d64b268a8543e748e90651f8ae7a498a Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Mar 2020 01:29:38 +0100 Subject: [PATCH 06/10] fix error's raw log messages ugly encoding Closes: #5785 --- CHANGELOG.md | 3 +++ x/bank/keeper/keeper.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5054c8883..22a94af272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,9 @@ balances or a single balance by denom when the `denom` query parameter is presen * (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´. * (x/auth) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5702) The `x/auth` querier route has changed from `"acc"` to `"auth"`. * (store/types) [\#5730](https://github.com/cosmos/cosmos-sdk/pull/5730) store.types.Cp() is removed in favour of types.CopyBytes(). +* [\#5785](https://github.com/cosmos/cosmos-sdk/issues/5785) JSON strings coerced to valid UTF-8 bytes at JSON marshalling time +are now replaced by human-readable expressions. This change can potentially break compatibility with all those client side tools +that parse log messages. ### API Breaking Changes diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index b1b2bdfa7a..330ab201f5 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -67,7 +67,7 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr balance := k.GetBalance(ctx, delegatorAddr, coin.Denom) if balance.IsLT(coin) { return sdkerrors.Wrapf( - sdkerrors.ErrInsufficientFunds, "failed to delegate; %s < %s", balance, amt, + sdkerrors.ErrInsufficientFunds, "failed to delegate; %s is smaller than %s", balance, amt, ) } @@ -265,7 +265,7 @@ func (k BaseSendKeeper) SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt _, hasNeg := sdk.Coins{spendable}.SafeSub(sdk.Coins{coin}) if hasNeg { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s < %s", spendable, coin) + return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin) } newBalance := balance.Sub(coin) From 810a37802c66f15ba28be0ddfb8a99ce3d55cccc Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 14:17:16 +0100 Subject: [PATCH 07/10] Update CHANGELOG.md Co-Authored-By: Alexander Bezobchuk --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e659229a2..c5c2d3ff6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ balances or a single balance by denom when the `denom` query parameter is presen * (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´. * (x/auth) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5702) The `x/auth` querier route has changed from `"acc"` to `"auth"`. * (store/types) [\#5730](https://github.com/cosmos/cosmos-sdk/pull/5730) store.types.Cp() is removed in favour of types.CopyBytes(). -* (client) [\#5640](https://github.com/cosmos/cosmos-sdk/issues/5783) Unify all coins representations on json client requests. +* (client) [\#5640](https://github.com/cosmos/cosmos-sdk/issues/5783) Unify all coins representations on JSON client requests for governance proposals. ### API Breaking Changes From ee0e0aeaff8b47edfaad8b4ad7df61f202ffe802 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 12 Mar 2020 14:27:19 +0100 Subject: [PATCH 08/10] undo change --- x/gov/client/cli/parse.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/gov/client/cli/parse.go b/x/gov/client/cli/parse.go index e29840db74..dd9415f18d 100644 --- a/x/gov/client/cli/parse.go +++ b/x/gov/client/cli/parse.go @@ -24,8 +24,7 @@ func parseSubmitProposalFlags() (*proposal, error) { for _, flag := range ProposalFlags { if viper.GetString(flag) != "" { - return nil, fmt.Errorf( - "--%s flag provided alongside --proposal, which is a noop", flag) + return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag) } } From 39f416faa3fa1c4cb3cc5a1ade14a3430f6bca80 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 12 Mar 2020 15:46:55 +0100 Subject: [PATCH 09/10] Simplify flaky test case and disable parallelism (#5793) * Simplify flaky test casea and disable parallelism * Fix failing test Co-authored-by: Alexander Bezobchuk Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- types/module/module_test.go | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/types/module/module_test.go b/types/module/module_test.go index db23346962..65df4e8ea2 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -24,29 +24,19 @@ func TestBasicManager(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) cdc := codec.New() - wantDefaultGenesis := map[string]json.RawMessage{ - "mockAppModuleBasic1": json.RawMessage(``), - "mockAppModuleBasic2": json.RawMessage(`{"key":"value"}`), - } + wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)} mockAppModuleBasic1 := mocks.NewMockAppModuleBasic(mockCtrl) - mockAppModuleBasic2 := mocks.NewMockAppModuleBasic(mockCtrl) mockAppModuleBasic1.EXPECT().Name().AnyTimes().Return("mockAppModuleBasic1") - mockAppModuleBasic2.EXPECT().Name().AnyTimes().Return("mockAppModuleBasic2") mockAppModuleBasic1.EXPECT().DefaultGenesis(gomock.Eq(cdc)).Times(1).Return(json.RawMessage(``)) - mockAppModuleBasic2.EXPECT().DefaultGenesis(gomock.Eq(cdc)).Times(1).Return(json.RawMessage(`{"key":"value"}`)) mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(wantDefaultGenesis["mockAppModuleBasic1"])).Times(1).Return(errFoo) mockAppModuleBasic1.EXPECT().RegisterRESTRoutes(gomock.Eq(context.CLIContext{}), gomock.Eq(&mux.Router{})).Times(1) - mockAppModuleBasic2.EXPECT().RegisterRESTRoutes(gomock.Eq(context.CLIContext{}), gomock.Eq(&mux.Router{})).Times(1) mockAppModuleBasic1.EXPECT().RegisterCodec(gomock.Eq(cdc)).Times(1) - mockAppModuleBasic2.EXPECT().RegisterCodec(gomock.Eq(cdc)).Times(1) mockAppModuleBasic1.EXPECT().GetTxCmd(cdc).Times(1).Return(nil) - mockAppModuleBasic2.EXPECT().GetTxCmd(cdc).Times(1).Return(&cobra.Command{}) mockAppModuleBasic1.EXPECT().GetQueryCmd(cdc).Times(1).Return(nil) - mockAppModuleBasic2.EXPECT().GetQueryCmd(cdc).Times(1).Return(&cobra.Command{}) - mm := module.NewBasicManager(mockAppModuleBasic1, mockAppModuleBasic2) + mm := module.NewBasicManager(mockAppModuleBasic1) require.Equal(t, mm["mockAppModuleBasic1"], mockAppModuleBasic1) mm.RegisterCodec(cdc) @@ -54,8 +44,7 @@ func TestBasicManager(t *testing.T) { require.Equal(t, wantDefaultGenesis, mm.DefaultGenesis(cdc)) var data map[string]string - require.NoError(t, json.Unmarshal(wantDefaultGenesis["mockAppModuleBasic2"], &data)) - require.Equal(t, map[string]string{"key": "value"}, data) + require.Equal(t, map[string]string(nil), data) require.True(t, errors.Is(errFoo, mm.ValidateGenesis(cdc, wantDefaultGenesis))) @@ -71,7 +60,6 @@ func TestBasicManager(t *testing.T) { } func TestGenesisOnlyAppModule(t *testing.T) { - t.Parallel() mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) @@ -91,7 +79,6 @@ func TestGenesisOnlyAppModule(t *testing.T) { } func TestManagerOrderSetters(t *testing.T) { - t.Parallel() mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) mockAppModule1 := mocks.NewMockAppModule(mockCtrl) @@ -121,7 +108,6 @@ func TestManagerOrderSetters(t *testing.T) { } func TestManager_RegisterInvariants(t *testing.T) { - t.Parallel() mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) @@ -141,7 +127,6 @@ func TestManager_RegisterInvariants(t *testing.T) { } func TestManager_RegisterRoutes(t *testing.T) { - t.Parallel() mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) @@ -173,7 +158,6 @@ func TestManager_RegisterRoutes(t *testing.T) { } func TestManager_InitGenesis(t *testing.T) { - t.Parallel() mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) From fe999c4201cca5d5eab0187fb42ec0d0497e2666 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2020 06:24:56 +0000 Subject: [PATCH 10/10] Bump github.com/golang/protobuf from 1.3.4 to 1.3.5 Bumps [github.com/golang/protobuf](https://github.com/golang/protobuf) from 1.3.4 to 1.3.5. - [Release notes](https://github.com/golang/protobuf/releases) - [Commits](https://github.com/golang/protobuf/compare/v1.3.4...v1.3.5) Signed-off-by: dependabot-preview[bot] --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 446acc15d8..c29e55729b 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/cosmos/ledger-cosmos-go v0.11.1 github.com/gogo/protobuf v1.3.1 github.com/golang/mock v1.4.1 - github.com/golang/protobuf v1.3.4 + github.com/golang/protobuf v1.3.5 github.com/gorilla/handlers v1.4.2 github.com/gorilla/mux v1.7.4 github.com/hashicorp/golang-lru v0.5.4 diff --git a/go.sum b/go.sum index a1723495d7..e651867532 100644 --- a/go.sum +++ b/go.sum @@ -139,6 +139,8 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=