-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
c257c1b
commit 5d3ed55
Showing
24 changed files
with
2,032 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.