Skip to content

Commit

Permalink
feat(x/foundation): rollback codec for MsgUpdateParams (#1108)
Browse files Browse the repository at this point in the history
* feat(x/foundation): rollback codec for MsgUpdateParams

* feat(x/foundation): rollback testcase

* feat(x/foundation): fix deprecated comment

* chore: fix conflict

* chore: dummy test for coverage of deprecated message

* feat: block removed MsgUpdateParams as proposal

* chore: update comment for MsgUpdateParams/Response

* chore: update comment for MsgUpdateParams/Response
  • Loading branch information
jaeseung-bae authored Sep 5, 2023
1 parent 4f7b891 commit 022614f
Show file tree
Hide file tree
Showing 8 changed files with 570 additions and 96 deletions.
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/
* (x/foundation) [\#1053](https://github.com/Finschia/finschia-sdk/pull/1053) Make x/foundation MsgExec propagate events
* (baseapp) [\#1091](https://github.com/finschia/finschia-sdk/pull/1091) Add `events.GetAttributes` and `event.GetAttribute` methods to simplify the retrieval of an attribute from event(s) (backport #1075)
* (baseapp) [\#1092](https://github.com/finschia/finschia-sdk/pull/1092) Do not add `module` attribute in case of ibc messages (backport #1079)
* (x/foundation) [\#1108](https://github.com/Finschia/finschia-sdk/pull/1108) Rollback MsgUpdateParams parts from #999

### Removed

Expand Down
7 changes: 3 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@
- [MsgUpdateDecisionPolicyResponse](#lbm.foundation.v1.MsgUpdateDecisionPolicyResponse)
- [MsgUpdateMembers](#lbm.foundation.v1.MsgUpdateMembers)
- [MsgUpdateMembersResponse](#lbm.foundation.v1.MsgUpdateMembersResponse)
- [MsgUpdateParams](#lbm.foundation.v1.MsgUpdateParams)
- [MsgUpdateParamsResponse](#lbm.foundation.v1.MsgUpdateParamsResponse)
- [MsgVote](#lbm.foundation.v1.MsgVote)
- [MsgVoteResponse](#lbm.foundation.v1.MsgVoteResponse)
- [MsgWithdrawFromTreasury](#lbm.foundation.v1.MsgWithdrawFromTreasury)
Expand Down Expand Up @@ -12890,6 +12892,36 @@ MsgUpdateMembersResponse is the Msg/UpdateMembers response type.



<a name="lbm.foundation.v1.MsgUpdateParams"></a>

### MsgUpdateParams
MsgUpdateParams is the Msg/UpdateParams request type.
NOTE: This is not for tx


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the privileged account. |
| `params` | [Params](#lbm.foundation.v1.Params) | | params defines the x/foundation parameters to update.

NOTE: All parameters must be supplied. |






<a name="lbm.foundation.v1.MsgUpdateParamsResponse"></a>

### MsgUpdateParamsResponse
MsgUpdateParamsResponse is the Msg/UpdateParams response type.
NOTE: This is not for tx






<a name="lbm.foundation.v1.MsgVote"></a>

### MsgVote
Expand Down
16 changes: 16 additions & 0 deletions proto/lbm/foundation/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ message MsgWithdrawFromTreasury {
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coins"];
}

// MsgUpdateParams is the Msg/UpdateParams request type.
// NOTE: This is not for tx
message MsgUpdateParams {
// authority is the address of the privileged account.
string authority = 1;

// params defines the x/foundation parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse is the Msg/UpdateParams response type.
// NOTE: This is not for tx
message MsgUpdateParamsResponse {}

// MsgWithdrawFromTreasuryResponse is the Msg/WithdrawFromTreasury response type.
message MsgWithdrawFromTreasuryResponse {}

Expand Down
2 changes: 2 additions & 0 deletions x/foundation/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgWithdrawProposal{}, "lbm-sdk/MsgWithdrawProposal")

// proposal from foundation operator
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "lbm-sdk/MsgUpdateParams")
legacy.RegisterAminoMsg(cdc, &MsgWithdrawFromTreasury{}, "lbm-sdk/MsgWithdrawFromTreasury")
legacy.RegisterAminoMsg(cdc, &MsgUpdateMembers{}, "lbm-sdk/MsgUpdateMembers")
legacy.RegisterAminoMsg(cdc, &MsgUpdateDecisionPolicy{}, "lbm-sdk/MsgUpdateDecisionPolicy")
Expand All @@ -40,6 +41,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateParams{},
&MsgFundTreasury{},
&MsgWithdrawFromTreasury{},
&MsgUpdateMembers{},
Expand Down
28 changes: 28 additions & 0 deletions x/foundation/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ import (
"github.com/Finschia/finschia-sdk/x/foundation/codec"
)

var _ sdk.Msg = (*MsgUpdateParams)(nil)

// ValidateBasic implements Msg.
func (m MsgUpdateParams) ValidateBasic() error {
return sdkerrors.ErrUnknownRequest.Wrapf("unrecognized message route: %s", m.Route())
}

// GetSigners implements Msg.
func (m MsgUpdateParams) GetSigners() []sdk.AccAddress {
signer := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{signer}
}

// Type implements the LegacyMsg.Type method.
func (m MsgUpdateParams) Type() string {
return sdk.MsgTypeURL(&m)
}

// Route implements the LegacyMsg.Route method.
func (m MsgUpdateParams) Route() string {
return sdk.MsgTypeURL(&m)
}

// GetSignBytes implements the LegacyMsg.GetSignBytes method.
func (m MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m))
}

var _ sdk.Msg = (*MsgFundTreasury)(nil)

// ValidateBasic implements Msg.
Expand Down
58 changes: 58 additions & 0 deletions x/foundation/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package foundation_test

import (
"fmt"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
"testing"
"time"

Expand All @@ -14,6 +15,56 @@ import (
"github.com/Finschia/finschia-sdk/x/foundation"
)

func TestMsgUpdateParams(t *testing.T) {
addrs := make([]sdk.AccAddress, 1)
for i := range addrs {
addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
}

testCases := map[string]struct {
authority sdk.AccAddress
params foundation.Params
valid bool
}{
"handler for MsgUpdateParams removed, ValidateBasic should throw error always": {
authority: addrs[0],
params: foundation.Params{
FoundationTax: sdk.ZeroDec(),
},
valid: false,
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
msg := foundation.MsgUpdateParams{
Authority: tc.authority.String(),
Params: tc.params,
}

err := msg.ValidateBasic()
require.Error(t, err)
require.ErrorIs(t, err, sdkerrors.ErrUnknownRequest)
})
msg := foundation.MsgUpdateParams{
addrs[0].String(),
foundation.Params{},
}
// Note: Dummy test for coverage of deprecated message
_ = msg.GetSigners()
_ = msg.String()
_, _ = msg.Descriptor()
_ = msg.GetSignBytes()
_, _ = msg.Marshal()
msg.ProtoMessage()
msg.Reset()
_ = msg.Route()
_ = msg.Size()
_ = msg.Type()
_ = msg.XXX_Size()
}
}

func TestMsgFundTreasury(t *testing.T) {
addrs := make([]sdk.AccAddress, 1)
for i := range addrs {
Expand Down Expand Up @@ -681,6 +732,13 @@ func TestMsgSubmitProposalAminoJSON(t *testing.T) {
msg sdk.Msg
expected string
}{
"MsgUpdateParams": {
&foundation.MsgUpdateParams{
Authority: addrs[0].String(),
Params: foundation.Params{FoundationTax: sdk.ZeroDec()},
},
fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgSubmitProposal\",\"value\":{\"exec\":1,\"messages\":[{\"type\":\"lbm-sdk/MsgUpdateParams\",\"value\":{\"authority\":\"%s\",\"params\":{\"foundation_tax\":\"0.000000000000000000\"}}}],\"metadata\":\"MsgUpdateParams\",\"proposers\":[\"%s\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String(), proposer.String()),
},
"MsgWithdrawFromTreasury": {
&foundation.MsgWithdrawFromTreasury{
Authority: addrs[0].String(),
Expand Down
Loading

0 comments on commit 022614f

Please sign in to comment.