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!: remove x/params usage from x/foundation #1234

Open
wants to merge 6 commits into
base: bumpup50
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: bufbuild/buf-setup-action@v1.21.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: bufbuild/buf-lint-action@v1
with:
input: "proto"
Expand All @@ -25,6 +27,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: bufbuild/buf-setup-action@v1.21.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: bufbuild/buf-breaking-action@v1
with:
input: "proto"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ jobs:
cd simapp
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -316,7 +316,7 @@ jobs:
cd x/foundation
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ issues:
- text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out
linters:
- staticcheck
- path: "client/cli" # TODO(@0Tech): remove after foundation exec proposal removed
text: "SA1019: govcli.FlagDescription is deprecated"
- text: "SA1019: govcli.FlagDescription is deprecated" # TODO(@0Tech): remove after foundation exec proposal removed
linters:
- staticcheck
- text: "leading space"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#1198](https://github.com/Finschia/finschia-sdk/pull/1198) update x/foundation to use Finschia/cosmos-sdk
* (all) [\#1205](https://github.com/Finschia/finschia-sdk/pull/1205) delegate native logics to Finschia/cosmos-sdk
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24
* (x/foundation) [\#1234](https://github.com/Finschia/finschia-sdk/pull/1234) remove x/params usage from x/foundation

### Improvements
* (docs) [\#1120](https://github.com/Finschia/finschia-sdk/pull/1120) Update links in x/foundation README.md
Expand Down
5 changes: 5 additions & 0 deletions proto/lbm/foundation/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "lbm/foundation/v1/foundation.proto";

// EventUpdateParams is emitted after updating foundation parameters.
message EventUpdateParams {
Params params = 1 [(gogoproto.nullable) = false];
}

// EventFundTreasury is an event emitted when one funds the treasury.
message EventFundTreasury {
string from = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Expand Down
40 changes: 22 additions & 18 deletions proto/lbm/foundation/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ option (gogoproto.goproto_getters_all) = false;
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines an operation for updating the x/foundation module
// parameters.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);

// FundTreasury defines a method to fund the treasury.
rpc FundTreasury(MsgFundTreasury) returns (MsgFundTreasuryResponse);

Expand Down Expand Up @@ -59,6 +63,24 @@ service Msg {
rpc Revoke(MsgRevoke) returns (MsgRevokeResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
// NOTE: This is not for tx
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "lbm-sdk/MsgUpdateParams";

// authority is the address of the privileged account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// 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.
message MsgUpdateParamsResponse {}

// MsgFundTreasury is the Msg/FundTreasury request type.
message MsgFundTreasury {
option (cosmos.msg.v1.signer) = "from";
Expand Down Expand Up @@ -87,24 +109,6 @@ message MsgWithdrawFromTreasury {
// MsgWithdrawFromTreasuryResponse is the Msg/WithdrawFromTreasury response type.
message MsgWithdrawFromTreasuryResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
// NOTE: This is not for tx
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "lbm-sdk/MsgUpdateParams";

// authority is the address of the privileged account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// 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.
message MsgUpdateParamsResponse {}

// MsgUpdateMembers is the Msg/UpdateMembers request type.
// NOTE: This is not for tx
message MsgUpdateMembers {
Expand Down
4 changes: 2 additions & 2 deletions scripts/go-lint-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else
for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do
echo "linting $f [$(date -Iseconds -u)]" &&
cd $f &&
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" &&
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@"
cd $REPO_ROOT
done
fi
fi
8 changes: 4 additions & 4 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.projectKey=cosmos_cosmos-sdk
sonar.organization=cosmos
sonar.projectKey=Finschia_finschia-sdk
sonar.organization=finschia

sonar.projectName=Cosmos SDK
sonar.projectName=Finschia SDK
sonar.project.monorepo.enabled=true

sonar.sources=.
Expand All @@ -17,4 +17,4 @@ sonar.scm.provider=git
# Exclude C/C++/Objective-C files from analysis
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-
sonar.objc.file.suffixes=-
46 changes: 46 additions & 0 deletions tests/e2e/foundation/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,52 @@ import (
"github.com/Finschia/finschia-sdk/x/foundation/client/cli"
)

func (s *E2ETestSuite) TestNewTxCmdUpdateParams() {
val := s.network.Validators[0]

commonArgs := []string{
fmt.Sprintf("--%s", flags.FlagGenerateOnly),
}

testCases := map[string]struct {
args []string
valid bool
}{
"valid transaction": {
[]string{
s.bytesToString(s.authority),
fmt.Sprintf(`{"foundation_tax": "%s"}`, math.LegacyZeroDec()),
},
true,
},
"wrong number of args": {
[]string{
s.bytesToString(s.authority),
fmt.Sprintf(`{"foundation_tax": "%s"}`, math.LegacyZeroDec()),
"extra",
},
false,
},
}

for name, tc := range testCases {
tc := tc

s.Run(name, func() {
cmd := cli.NewTxCmdUpdateParams()
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
if !tc.valid {
s.Require().Error(err)
return
}
s.Require().NoError(err)

var res txtypes.Tx
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out)
})
}
}

func (s *E2ETestSuite) TestNewTxCmdFundTreasury() {
val := s.network.Validators[0]
commonArgs := []string{
Expand Down
53 changes: 47 additions & 6 deletions x/foundation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ back these foundation-specific functionalities.
## Contents

* [Concepts](#concepts)
* [Parameters](#parameters)
* [State](#state)
* [Msg Service](#msg-service)
* [Msg/UpdateParams](#msgupdateparams)
* [Msg/UpdateDecisionPolicy](#msgupdatedecisionpolicy)
* [Msg/UpdateMembers](#msgupdatemembers)
* [Msg/LeaveFoundation](#msgleavefoundation)
Expand All @@ -30,6 +30,7 @@ back these foundation-specific functionalities.
* [Msg/FundTreasury](#msgfundtreasury)
* [Msg/WithdrawFromTreasury](#msgwithdrawfromtreasury)
* [Events](#events)
* [EventUpdateFoundationParams](#eventupdatefoundationparams)
* [EventUpdateDecisionPolicy](#eventupdatedecisionpolicy)
* [EventUpdateMembers](#eventupdatedmembers)
* [EventLeaveFoundation](#eventleavefoundation)
Expand Down Expand Up @@ -266,15 +267,16 @@ The foundation can withdraw coins from the treasury. The recipient must have
the corresponding authorization (`ReceiveFromTreasuryAuthorization`) prior to
sending the message `Msg/WithdrawFromTreasury`.

# Parameters

## FoundationTax
# State

The value of `FoundationTax` is the foundation tax rate.
## Params

* FoundationTax: `sdk.Dec`
### FoundationTax

# State
* Params: `0x00 -> PropocolBuffer(Params)`.

The value of `FoundationTax` is the foundation tax rate.

## FoundationInfo

Expand Down Expand Up @@ -343,6 +345,17 @@ Authorization) tuple.

# Msg Service

## Msg/UpdateParams

The `MsgUpdateParams` can be used to update the parameters of `foundation`.

+++ https://github.com/Finschia/finschia-sdk/blob/f682f758268c19dd93958abbbaf697f51e6991b3/proto/lbm/foundation/v1/tx.proto#L62-L71

It's expected to fail if:

* the authority is not the module's authority.
* the parameters introduces any new foundation-specific features.

## Msg/UpdateDecisionPolicy

The `MsgUpdateDecisionPolicy` can be used to update the decision policy.
Expand Down Expand Up @@ -508,6 +521,15 @@ The message handling should fail if:

# Events

## EventUpdateFoundationParams

`EventUpdateFoundationParams` is an event emitted when the foundation
parameters have been updated.

| Attribute Key | Attribute Value |
|---------------|-----------------|
| params | {params} |

## EventUpdateDecisionPolicy

`EventUpdateDecisionPolicy` is an event emitted when the decision policy have
Expand Down Expand Up @@ -983,6 +1005,25 @@ simd tx foundation --help
you cannot broadcast the message directly. The use of those commands is to make
it easier to generate the messages by end users.

#### update-params

The `update-params` command allows users to update the foundation's parameters.

```bash
simd tx foundation update-params [authority] [params-json] [flags]
```

Example:

```bash
simd tx foundation update-params link1... \
'{
"foundation_tax": "0.1"
}'
```

**Note:** The signer MUST be the module's authority.

#### update-members

The `update-members` command allows users to update the foundation's members.
Expand Down
48 changes: 48 additions & 0 deletions x/foundation/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func validateGenerateOnly(cmd *cobra.Command) error {
return nil
}

func parseParams(codec codec.Codec, paramsJSON string) (*foundation.Params, error) {
var params foundation.Params
if err := codec.UnmarshalJSON([]byte(paramsJSON), &params); err != nil {
return nil, err
}

return &params, nil
}

func parseMemberRequests(codec codec.Codec, membersJSON string) ([]foundation.MemberRequest, error) {
var cliMembers []json.RawMessage
if err := json.Unmarshal([]byte(membersJSON), &cliMembers); err != nil {
Expand Down Expand Up @@ -158,6 +167,7 @@ func NewTxCmd() *cobra.Command {
}

txCmd.AddCommand(
NewTxCmdUpdateParams(),
NewTxCmdFundTreasury(),
NewTxCmdWithdrawFromTreasury(),
NewTxCmdUpdateMembers(),
Expand All @@ -174,6 +184,44 @@ func NewTxCmd() *cobra.Command {
return txCmd
}

func NewTxCmdUpdateParams() *cobra.Command {
cmd := &cobra.Command{
Use: "update-params [authority] [params-json]",
Args: cobra.ExactArgs(2),
Short: "Update params",
Long: `Update x/foundation parameters.
Example of the content of params-json:
{
"foundation_tax": "0.1"
}
`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateGenerateOnly(cmd); err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

params, err := parseParams(clientCtx.Codec, args[1])
if err != nil {
return err
}

msg := foundation.MsgUpdateParams{
Authority: args[0],
Params: *params,
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

func NewTxCmdFundTreasury() *cobra.Command {
cmd := &cobra.Command{
Use: "fund-treasury [from] [amount]",
Expand Down
Loading
Loading