Skip to content

Commit

Permalink
Add UpdateParams rpc and Params query to ibchooks module (#2006)
Browse files Browse the repository at this point in the history
* add update and query protos for ibchooks params

* add authority and updateparams endpoint

* add query server

* add typed event

* add msg validate basic, add tests

* revert mistake

* add query server test

* add commands and start test

* register query server, register msg

* query test works

* add validate basic in cli, finish test for cli tx

* add change log

* fix receiver name

* fix lint

* fix addresses

* fix params query url

* remove gen keyrings and accounts

* fix error msg

* use tesutil
  • Loading branch information
nullpointer0x00 authored May 29, 2024
1 parent c257c1b commit 5d3ed55
Show file tree
Hide file tree
Showing 24 changed files with 2,032 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Fix unit tests for ibchooks [#1980](https://github.com/provenance-io/provenance/pull/1980).
* Replace deprecated wasm features [#1988](https://github.com/provenance-io/provenance/pull/1988).
* Add `UpdateParams` and `Params` query rpc endpoints to modules.
* `ibchooks` add `UpdateParams` endpoint and `Params` query endpoint [#2006](https://github.com/provenance-io/provenance/pull/2006).
* `ibcratelimit` add `UpdateParams` endpoint and deprecate `GovUpdateParams` [#1984](https://github.com/provenance-io/provenance/pull/1984).
* `attribute` add `UpdateParams` endpoint and cli [#1987](https://github.com/provenance-io/provenance/pull/1987).
* `marker` add `UpdateParams` endpoint and cli [#1991](https://github.com/provenance-io/provenance/pull/1991).
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105863,6 +105863,19 @@ definitions:
ibc_ack:
type: string
title: MsgEmitIBCAckResponse is the IBC Acknowledgement response
provenance.ibchooks.v1.MsgUpdateParamsResponse:
type: object
description: >-
MsgUpdateParamsResponse is a response message for the UpdateParams
endpoint.
provenance.ibchooks.v1.Params:
type: object
properties:
allowed_async_ack_contracts:
type: array
items:
type: string
title: Params defines the allowed async ack contracts
provenance.ibcratelimit.v1.Params:
type: object
properties:
Expand Down
12 changes: 12 additions & 0 deletions proto/provenance/ibchooks/v1/event.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package provenance.ibchooks.v1;

option go_package = "github.com/provenance-io/provenance/x/ibchooks/types";

option java_package = "io.provenance.ibchooks.v1";
option java_multiple_files = true;

// EventIBCHooksParamsUpdated defines the event emitted after updating ibchooks parameters.
message EventIBCHooksParamsUpdated {
repeated string allowed_async_ack_contracts = 1;
}
28 changes: 28 additions & 0 deletions proto/provenance/ibchooks/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package provenance.ibchooks.v1;

option go_package = "github.com/provenance-io/provenance/x/ibchooks/types";

option java_package = "io.provenance.ibchooks.v1";
option java_multiple_files = true;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "provenance/ibchooks/v1/params.proto";

// Query defines the gRPC querier service for attribute module.
service Query {
// Params queries params of the ihchooks module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/provenance/ibchooks/v1/params";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
24 changes: 22 additions & 2 deletions proto/provenance/ibchooks/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
syntax = "proto3";
package provenance.ibchooks.v1;

import "cosmos/msg/v1/msg.proto";

option go_package = "github.com/provenance-io/provenance/x/ibchooks/types";

option java_package = "io.provenance.ibchooks.v1";
option java_multiple_files = true;

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "provenance/ibchooks/v1/params.proto";

// Msg defines the Msg service.
service Msg {
// EmitIBCAck checks the sender can emit the ack and writes the IBC
// acknowledgement
rpc EmitIBCAck(MsgEmitIBCAck) returns (MsgEmitIBCAckResponse);

// UpdateParams is a governance proposal endpoint for updating the ibchooks module's params.
rpc UpdateParams(MsgUpdateParamsRequest) returns (MsgUpdateParamsResponse);
}

// MsgEmitIBCAck is the IBC Acknowledgement
Expand All @@ -29,3 +35,17 @@ message MsgEmitIBCAckResponse {
string contract_result = 1;
string ibc_ack = 2;
}

// MsgUpdateParamsRequest is a request message for the UpdateParams endpoint.
message MsgUpdateParamsRequest {
option (cosmos.msg.v1.signer) = "authority";

// authority should be the governance module account address.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params are the new param values to set.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse is a response message for the UpdateParams endpoint.
message MsgUpdateParamsResponse {}
128 changes: 128 additions & 0 deletions x/ibchooks/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package cli_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/suite"

cmtcli "github.com/cometbft/cometbft/libs/cli"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/provenance-io/provenance/internal/antewrapper"
"github.com/provenance-io/provenance/internal/pioconfig"
"github.com/provenance-io/provenance/testutil"
testcli "github.com/provenance-io/provenance/testutil/cli"
ibchookscli "github.com/provenance-io/provenance/x/ibchooks/client/cli"
"github.com/provenance-io/provenance/x/ibchooks/types"
)

type IntegrationTestSuite struct {
suite.Suite

cfg network.Config
testnet *network.Network
accountAddr sdk.AccAddress
accountKey *secp256k1.PrivKey
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
pioconfig.SetProvenanceConfig("", 0)
govv1.DefaultMinDepositRatio = sdkmath.LegacyZeroDec()
s.accountKey = secp256k1.GenPrivKeyFromSecret([]byte("acc2"))
addr, err := sdk.AccAddressFromHexUnsafe(s.accountKey.PubKey().Address().String())
s.Require().NoError(err)
s.accountAddr = addr

s.cfg = testutil.DefaultTestNetworkConfig()
genesisState := s.cfg.GenesisState

s.cfg.NumValidators = 1

testutil.MutateGenesisState(s.T(), &s.cfg, types.ModuleName, &types.GenesisState{}, func(ibchooks *types.GenesisState) *types.GenesisState {
ibchooksParams := types.DefaultParams()
ibchooksGenesis := &types.GenesisState{Params: ibchooksParams}
return ibchooksGenesis
})

s.cfg.GenesisState = genesisState

s.cfg.ChainID = antewrapper.SimAppChainID

s.testnet, err = network.New(s.T(), s.T().TempDir(), s.cfg)
s.Require().NoError(err, "network.New")

_, err = testutil.WaitForHeight(s.testnet, 6)
s.Require().NoError(err, "WaitForHeight")
}

func (s *IntegrationTestSuite) TearDownSuite() {
testutil.Cleanup(s.testnet, s.T())
}

func (s *IntegrationTestSuite) TestQueryParams() {
clientCtx := s.testnet.Validators[0].ClientCtx
cmd := ibchookscli.GetCmdQueryParams()

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{fmt.Sprintf("--%s=json", cmtcli.OutputFlag)})
s.Require().NoError(err)

var response types.QueryParamsResponse
s.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response))
expectedParams := types.DefaultParams()
s.Equal(expectedParams, response.Params, "should have the default params")
}

func (s *IntegrationTestSuite) TestUpdateParamsCmd() {
testCases := []struct {
name string
args []string
expectErrMsg string
expectedCode uint32
}{
{
name: "success - update allowed async ack contracts",
args: []string{fmt.Sprintf("%v,%v", s.accountAddr.String(), sdk.AccAddress("input111111111111111").String())},
expectedCode: 0,
},
{
name: "failure - invalid args",
args: []string{"contract1"},
expectErrMsg: `invalid contract address: "contract1": decoding bech32 failed: invalid separator index 8`,
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
cmd := ibchookscli.NewUpdateParamsCmd()
tc.args = append(tc.args,
"--title", fmt.Sprintf("title: %v", tc.name),
"--summary", fmt.Sprintf("summary: %v", tc.name),
"--deposit=1000000stake",
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.testnet.Validators[0].Address.String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 10)).String()),
fmt.Sprintf("--%s=json", cmtcli.OutputFlag),
)

testcli.NewTxExecutor(cmd, tc.args).
WithExpErrMsg(tc.expectErrMsg).
WithExpCode(tc.expectedCode).
Execute(s.T(), s.testnet)
})
}
}
26 changes: 26 additions & 0 deletions x/ibchooks/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cli

import (
"context"
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -39,6 +41,7 @@ func GetQueryCmd() *cobra.Command {

cmd.AddCommand(
GetCmdWasmSender(),
GetCmdQueryParams(),
)
return cmd
}
Expand Down Expand Up @@ -75,3 +78,26 @@ $ %s query ibchooks wasm-hooks-sender channel-7 pb12smx2wdlyttvyzvzg54y2vnqwq2qj

return cmd
}

// GetCmdQueryParams returns a command to query the ibchooks module parameters.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current ibchooks module parameters",
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
65 changes: 65 additions & 0 deletions x/ibchooks/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cli

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"

"github.com/provenance-io/provenance/internal/provcli"
"github.com/provenance-io/provenance/x/ibchooks/types"
)

// NewTxCmd is the top-level command for attribute CLI transactions.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Aliases: []string{"ih"},
Short: "Transaction commands for the ibchooks module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(
NewUpdateParamsCmd(),
)
return txCmd
}

// NewUpdateParamsCmd creates a command to update the ibchooks module's params via governance proposal.
func NewUpdateParamsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update-params <allowed-async-ack-contracts>",
Short: "Update the ibchooks module's params via governance proposal",
Long: "Submit an update params via governance proposal along with an initial deposit.",
Args: cobra.ExactArgs(1),
Example: fmt.Sprintf(`%[1]s tx ibchooks update-params contract1,contract2 --deposit 50000nhash`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

flagSet := cmd.Flags()
authority := provcli.GetAuthority(flagSet)
allowedAsyncAckContracts := strings.Split(args[0], ",")

msg := types.NewMsgUpdateParamsRequest(allowedAsyncAckContracts, authority)
if err := msg.ValidateBasic(); err != nil {
return err
}
return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg)
},
}

govcli.AddGovPropFlagsToCmd(cmd)
provcli.AddAuthorityFlagToCmd(cmd)
flags.AddTxFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit 5d3ed55

Please sign in to comment.