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

Support additional CLI query commands for the ratelimit module #241

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ bin/*
# Dependency directories (remove the comment below to include it)
# vendor/


.DS_Store
.terraform
*.pem
Expand All @@ -43,4 +42,7 @@ bin/*
.vendor
vendor
go.work
go.work.sum
go.work.sum

# Testing
coverage.txt
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ifeq (,$(VERSION))
endif
endif

PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
DOCKER := $(shell which docker)
Expand Down Expand Up @@ -82,6 +83,9 @@ ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

###############################################################################
### Build ###
###############################################################################

all: install

Expand All @@ -100,6 +104,24 @@ lint:
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -name '*.gw.go' | xargs go run golang.org/x/tools/cmd/goimports -w -local github.com/notional-labs/centauri
.PHONY: lint

###############################################################################
### Tests & Simulation ###
###############################################################################

test: test-unit
test-all: test-unit test-race test-cover

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='norace' $(PACKAGES_NOSIMULATION)

test-race:
@go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./...

test-cover:
@go test -mod=readonly -timeout 30m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock' ./...

.PHONY: test test-all test-unit test-race test-cover

###############################################################################
### Proto ###
###############################################################################
Expand Down Expand Up @@ -128,6 +150,8 @@ proto-check-breaking:
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=main

.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking

###############################################################################
### Interchain test ###
###############################################################################

Expand Down
7 changes: 7 additions & 0 deletions app/ibctesting/path.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ibctesting

import (
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)

Expand All @@ -26,6 +27,12 @@ func NewPath(chainA, chainB *TestChain) *Path {
}
}

// SetChannelOrdered sets the channel order for both endpoints to ORDERED.
func (path *Path) SetChannelOrdered() {
path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
}

// NewDefaultEndpoint constructs a new endpoint using default values.
// CONTRACT: the counterparty endpoitn must be set by the caller.
func NewDefaultEndpoint(chain *TestChain) *Endpoint {
Expand Down
141 changes: 140 additions & 1 deletion x/ratelimit/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/notional-labs/centauri/v5/x/ratelimit/types"
)
Expand All @@ -24,6 +25,10 @@ func GetQueryCmd() *cobra.Command {

cmd.AddCommand(
GetCmdQueryAllRateLimits(),
GetCmdQueryRateLimit(),
GetRateLimitsByChainID(),
GetRateLimitsByChannelID(),
GetAllWhitelistedAddresses(),
)
return cmd
}
Expand All @@ -35,7 +40,11 @@ func GetCmdQueryAllRateLimits() *cobra.Command {
Short: "Query all rate limits",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryAllRateLimitsRequest{}
Expand All @@ -52,3 +61,133 @@ func GetCmdQueryAllRateLimits() *cobra.Command {

return cmd
}

// GetCmdQueryRateLimit return a rate limit by denom and channel id.
func GetCmdQueryRateLimit() *cobra.Command {
cmd := &cobra.Command{
Use: "rate-limit [denom] [channel-id]",
Short: "Query a rate limit by denom and channel id",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

denom := args[0]
channelID := args[1]

if err := sdk.ValidateDenom(denom); err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryRateLimitRequest{
Denom: denom,
ChannelID: channelID,
}
res, err := queryClient.RateLimit(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetRateLimitsByChainID return all rate limits by chain id.
func GetRateLimitsByChainID() *cobra.Command {
cmd := &cobra.Command{
Use: "list-rate-limits [chain-id]",
Short: "Query all rate limits by chain id",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryRateLimitsByChainIDRequest{
ChainId: args[0],
}
res, err := queryClient.RateLimitsByChainID(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetRateLimitsByChannelID return all rate limits by channel id.
func GetRateLimitsByChannelID() *cobra.Command {
cmd := &cobra.Command{
Use: "list-rate-limits [channel-id]",
Short: "Query a rate limit by denom and channel id",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryRateLimitsByChannelIDRequest{
ChannelID: args[0],
}
res, err := queryClient.RateLimitsByChannelID(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetAllWhitelistedAddresses return all whitelisted addresses.
func GetAllWhitelistedAddresses() *cobra.Command {
cmd := &cobra.Command{
Use: "list-whitelisted-addresses",
Short: "Query all whitelisted addresses",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryAllWhitelistedAddressesRequest{}
res, err := queryClient.AllWhitelistedAddresses(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
23 changes: 0 additions & 23 deletions x/ratelimit/client/cli/tx.go

This file was deleted.

Loading
Loading