diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2a4ca6a4b..484f13d22 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,7 +15,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: - version: v1.54 + version: v1.61.0 only-new-issues: true args: --timeout=10m diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 912c2a7fe..89e6cf272 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -20,8 +20,7 @@ import ( "github.com/avast/retry-go/v4" tmjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/p2p" - rpcclient "github.com/cometbft/cometbft/rpc/client" - rpchttp "github.com/cometbft/cometbft/rpc/client/http" + coretypes "github.com/cometbft/cometbft/rpc/core/types" libclient "github.com/cometbft/cometbft/rpc/jsonrpc/client" "github.com/cosmos/cosmos-sdk/client" @@ -44,6 +43,8 @@ import ( icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client" "github.com/strangelove-ventures/interchaintest/v8/blockdb" + cli "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/cli" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/consensus" "github.com/strangelove-ventures/interchaintest/v8/dockerutil" "github.com/strangelove-ventures/interchaintest/v8/ibc" "github.com/strangelove-ventures/interchaintest/v8/testutil" @@ -51,17 +52,18 @@ import ( // ChainNode represents a node in the test network that is being created type ChainNode struct { - VolumeName string - Index int - Chain ibc.Chain - Validator bool - NetworkID string - DockerClient *dockerclient.Client - Client rpcclient.Client - GrpcConn *grpc.ClientConn - TestName string - Image ibc.DockerImage - preStartNode func(*ChainNode) + VolumeName string + Index int + Chain ibc.Chain + Validator bool + NetworkID string + DockerClient *dockerclient.Client + ConsensusClient consensus.Client + TestName string + Image ibc.DockerImage + GRPCClient *grpc.ClientConn + preStartNode func(*ChainNode) + consensus consensus.ClientType // Additional processes that need to be run on a per-validator basis. Sidecars SidecarProcesses @@ -71,6 +73,8 @@ type ChainNode struct { containerLifecycle *dockerutil.ContainerLifecycle + Cache map[string]interface{} + // Ports set during StartContainer. hostRPCPort string hostAPIPort string @@ -82,7 +86,7 @@ type ChainNode struct { func NewChainNode(log *zap.Logger, validator bool, chain *CosmosChain, dockerClient *dockerclient.Client, networkID string, testName string, image ibc.DockerImage, index int) *ChainNode { tn := &ChainNode{ log: log.With( - zap.Bool("validator", validator), + zap.Bool("is_val", validator), zap.Int("i", index), ), @@ -94,6 +98,7 @@ func NewChainNode(log *zap.Logger, validator bool, chain *CosmosChain, dockerCli TestName: testName, Image: image, Index: index, + Cache: make(map[string]interface{}), } tn.containerLifecycle = dockerutil.NewContainerLifecycle(log, dockerClient, tn.Name()) @@ -138,22 +143,17 @@ func (tn *ChainNode) NewClient(addr string) error { if err != nil { return err } - httpClient.Timeout = 10 * time.Second - rpcClient, err := rpchttp.NewWithClient(addr, "/websocket", httpClient) - if err != nil { - return err - } - - tn.Client = rpcClient - grpcConn, err := grpc.NewClient( + tn.GRPCClient, err = grpc.NewClient( tn.hostGRPCPort, grpc.WithTransportCredentials(insecure.NewCredentials()), ) if err != nil { return fmt.Errorf("grpc dial: %w", err) } - tn.GrpcConn = grpcConn + + tn.ConsensusClient = consensus.NewClientFactory(tn.consensus, addr, httpClient) + tn.log.Info("created new consensus client", zap.String("name", string(tn.ConsensusClient.ClientType())), zap.String("addr", addr)) return nil } @@ -204,9 +204,10 @@ func (tn *ChainNode) NewSidecarProcess( // CliContext creates a new Cosmos SDK client context func (tn *ChainNode) CliContext() client.Context { cfg := tn.Chain.Config() - return client.Context{ - Client: tn.Client, - GRPCClient: tn.GrpcConn, + + cliCtx := client.Context{ + // Client: tn.Client, + GRPCClient: tn.GRPCClient, ChainID: cfg.ChainID, InterfaceRegistry: cfg.EncodingConfig.InterfaceRegistry, Input: os.Stdin, @@ -215,6 +216,14 @@ func (tn *ChainNode) CliContext() client.Context { LegacyAmino: cfg.EncodingConfig.Amino, TxConfig: cfg.EncodingConfig.TxConfig, } + + if tn.ConsensusClient.ClientType() == consensus.CometBFT { + // resolves 'no RPC client is defined in offline mode' for direct broadcast + // using `cosmos.NewBroadcaster` + cliCtx.Client = tn.ConsensusClient.(*consensus.CometBFTClient).Client + } + + return cliCtx } // Name of the test node container @@ -419,12 +428,7 @@ func (tn *ChainNode) SetPeers(ctx context.Context, peers string) error { } func (tn *ChainNode) Height(ctx context.Context) (int64, error) { - res, err := tn.Client.Status(ctx) - if err != nil { - return 0, fmt.Errorf("tendermint rpc client status: %w", err) - } - height := res.SyncInfo.LatestBlockHeight - return height, nil + return tn.ConsensusClient.Height(ctx) } // FindTxs implements blockdb.BlockSaver. @@ -434,11 +438,11 @@ func (tn *ChainNode) FindTxs(ctx context.Context, height int64) ([]blockdb.Tx, e var blockRes *coretypes.ResultBlockResults var block *coretypes.ResultBlock eg.Go(func() (err error) { - blockRes, err = tn.Client.BlockResults(ctx, &h) + blockRes, err = tn.ConsensusClient.BlockResults(ctx, &h) return err }) eg.Go(func() (err error) { - block, err = tn.Client.Block(ctx, &h) + block, err = tn.ConsensusClient.Block(ctx, &h) return err }) if err := eg.Wait(); err != nil { @@ -747,7 +751,14 @@ func (tn *ChainNode) IsAboveSDK47(ctx context.Context) bool { // In SDK v47, a new genesis core command was added. This spec has many state breaking features // so we use this to switch between new and legacy SDK logic. // https://github.com/cosmos/cosmos-sdk/pull/14149 - return tn.HasCommand(ctx, "genesis") + key := "IsAboveSDK47" + if tn.Cache[key] != nil { + return tn.Cache[key].(bool) + } + + hasGenesisSubCmd := tn.HasCommand(ctx, "genesis") + tn.Cache[key] = hasGenesisSubCmd + return hasGenesisSubCmd } // ICSVersion returns the version of interchain-security the binary was built with. @@ -927,16 +938,7 @@ func (tn *ChainNode) HasCommand(ctx context.Context, command ...string) bool { return true } - if strings.Contains(string(err.Error()), "Error: unknown command") { - return false - } - - // cmd just needed more arguments, but it is a valid command (ex: appd tx bank send) - if strings.Contains(string(err.Error()), "Error: accepts") { - return true - } - - return false + return cli.HasCommand(err) } // GetBuildInformation returns the build information and dependencies for the chain binary. @@ -1103,15 +1105,22 @@ func (tn *ChainNode) UnsafeResetAll(ctx context.Context) error { func (tn *ChainNode) CreateNodeContainer(ctx context.Context) error { chainCfg := tn.Chain.Config() + // A new tmp image is created to verify the subcommands to grab the consensus state. + // We can not query endpoints yet as the node is not running, so we must depend on a new BlankClient to get startup flags. + img := dockerutil.NewImage(tn.logger(), tn.DockerClient, tn.NetworkID, tn.TestName, tn.Image.Repository, tn.Image.Version) + blankCC := consensus.NewBlankClient(ctx, tn.log, img, chainCfg.Bin) + + tn.consensus = blankCC.ClientType() + var cmd []string if chainCfg.NoHostMount { - startCmd := fmt.Sprintf("cp -r %s %s_nomnt && %s start --home %s_nomnt --x-crisis-skip-assert-invariants", tn.HomeDir(), tn.HomeDir(), chainCfg.Bin, tn.HomeDir()) + startCmd := fmt.Sprintf("cp -r %s %s_nomnt && %s start --home %s_nomnt %s", tn.HomeDir(), tn.HomeDir(), chainCfg.Bin, tn.HomeDir(), blankCC.StartFlags(ctx)) if len(chainCfg.AdditionalStartArgs) > 0 { startCmd = fmt.Sprintf("%s %s", startCmd, chainCfg.AdditionalStartArgs) } cmd = []string{"sh", "-c", startCmd} } else { - cmd = []string{chainCfg.Bin, "start", "--home", tn.HomeDir(), "--x-crisis-skip-assert-invariants"} + cmd = []string{chainCfg.Bin, "start", "--home", tn.HomeDir(), blankCC.StartFlags(ctx)} if len(chainCfg.AdditionalStartArgs) > 0 { cmd = append(cmd, chainCfg.AdditionalStartArgs...) } @@ -1239,17 +1248,8 @@ func (tn *ChainNode) StartContainer(ctx context.Context) error { time.Sleep(5 * time.Second) return retry.Do(func() error { - stat, err := tn.Client.Status(ctx) - if err != nil { - return err - } - // TODO: re-enable this check, having trouble with it for some reason - if stat != nil && stat.SyncInfo.CatchingUp { - return fmt.Errorf("still catching up: height(%d) catching-up(%t)", - stat.SyncInfo.LatestBlockHeight, stat.SyncInfo.CatchingUp) - } - return nil - }, retry.Context(ctx), retry.Attempts(40), retry.Delay(3*time.Second), retry.DelayType(retry.FixedDelay)) + return tn.ConsensusClient.IsSynced(ctx) + }, retry.Context(ctx), retry.Attempts(40), retry.Delay(2*time.Second), retry.DelayType(retry.FixedDelay)) } func (tn *ChainNode) PauseContainer(ctx context.Context) error { diff --git a/chain/cosmos/cli/has_command.go b/chain/cosmos/cli/has_command.go new file mode 100644 index 000000000..5530b5788 --- /dev/null +++ b/chain/cosmos/cli/has_command.go @@ -0,0 +1,20 @@ +package cli + +import "strings" + +func HasCommand(err error) bool { + if err == nil { + return true + } + + if strings.Contains(string(err.Error()), "Error: unknown command") { + return false + } + + // cmd just needed more arguments, but it is a valid command (ex: appd tx bank send) + if strings.Contains(string(err.Error()), "Error: accepts") { + return true + } + + return false +} diff --git a/chain/cosmos/consensus/cometbft.go b/chain/cosmos/consensus/cometbft.go new file mode 100644 index 000000000..531bbf9a6 --- /dev/null +++ b/chain/cosmos/consensus/cometbft.go @@ -0,0 +1,90 @@ +package consensus + +import ( + "context" + "fmt" + "net/http" + + rpcclient "github.com/cometbft/cometbft/rpc/client" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + ctypes "github.com/cometbft/cometbft/rpc/core/types" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/cli" + "github.com/strangelove-ventures/interchaintest/v8/dockerutil" +) + +var _ Client = (*CometBFTClient)(nil) + +type CometBFTClient struct { + Client rpcclient.Client +} + +// NewCometBFTClient creates a new CometBFTClient. +func NewCometBFTClient(remote string, client *http.Client) (*CometBFTClient, error) { + rpcClient, err := rpchttp.NewWithClient(remote, "/websocket", client) + if err != nil { + return nil, fmt.Errorf("failed to create CometBFT client: %w", err) + } + + if rpcClient == nil { + return nil, fmt.Errorf("failed to create CometBFT client: rpc client is nil") + } + + return &CometBFTClient{ + Client: rpcClient, + }, nil +} + +// ClientType implements Client. +func (c *CometBFTClient) ClientType() ClientType { + return CometBFT +} + +// IsClient implements Client. +func (c *CometBFTClient) IsClient(ctx context.Context, img *dockerutil.Image, bin string) bool { + res := img.Run(ctx, []string{bin, "cometbft"}, dockerutil.ContainerOptions{}) + return cli.HasCommand(res.Err) +} + +// IsSynced implements Client. +func (c *CometBFTClient) IsSynced(ctx context.Context) error { + stat, err := c.Client.Status(ctx) + if err != nil { + return fmt.Errorf("failed to get status: %w", err) + } + + if stat != nil && stat.SyncInfo.CatchingUp { + return fmt.Errorf("still catching up: height(%d) catching-up(%t)", stat.SyncInfo.LatestBlockHeight, stat.SyncInfo.CatchingUp) + } + + return nil +} + +// StartupFlags implements Client. +func (c *CometBFTClient) StartFlags(context.Context) string { + return "--x-crisis-skip-assert-invariants" +} + +// Height implements Client. +func (c *CometBFTClient) Height(ctx context.Context) (int64, error) { + s, err := c.Client.Status(ctx) + if err != nil { + return 0, fmt.Errorf("tendermint rpc client status: %w", err) + } + + return s.SyncInfo.LatestBlockHeight, nil +} + +// Block implements Client. +func (c *CometBFTClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) { + return c.Client.Block(ctx, height) +} + +// BlockResults implements Client. +func (c *CometBFTClient) BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error) { + return c.Client.BlockResults(ctx, height) +} + +// Status implements Client. +func (c *CometBFTClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { + return c.Client.Status(ctx) +} diff --git a/chain/cosmos/consensus/consensus.go b/chain/cosmos/consensus/consensus.go new file mode 100644 index 000000000..bcb0fd9f6 --- /dev/null +++ b/chain/cosmos/consensus/consensus.go @@ -0,0 +1,75 @@ +package consensus + +import ( + "context" + "net/http" + + ctypes "github.com/cometbft/cometbft/rpc/core/types" + "github.com/strangelove-ventures/interchaintest/v8/dockerutil" + "go.uber.org/zap" +) + +// create an enum for the different client types (gordian and cometbft) +type ClientType string + +const ( + Gordian ClientType = "gordian" + CometBFT ClientType = "cometbft" +) + +type Client interface { + ClientType() ClientType + StartFlags(context.Context) string + IsSynced(ctx context.Context) error + IsClient(ctx context.Context, img *dockerutil.Image, bin string) bool + + Status(ctx context.Context) (*ctypes.ResultStatus, error) + BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error) + Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) + Height(ctx context.Context) (int64, error) +} + +// GetBlankClientByName returns a blank client so non state logic (like startup params) can be used. +func NewBlankClient(ctx context.Context, logger *zap.Logger, img *dockerutil.Image, bin string) Client { + clients := []Client{ + &CometBFTClient{}, + &GordianClient{}, + } + + for _, client := range clients { + if client.IsClient(ctx, img, bin) { + logger.Info("NewBlankClient: Found client", zap.String("client", string(client.ClientType()))) + return client + } + } + + logger.Info("NewBlankClient: No client found. Defaulting to CometBFT") + return &CometBFTClient{} +} + +// consensus is gathered from `NewBlankClient` on startup of the node. +func NewClientFactory(consensus ClientType, remote string, client *http.Client) Client { + switch consensus { + case CometBFT: + cbft, err := NewCometBFTClient(remote, client) + if err != nil { + panic(err) + } + + if cbft != nil { + return cbft + } + + panic("NewClientFactory: No client available for " + CometBFT) + case Gordian: + gordian := NewGordianClient(remote, client) + if gordian != nil { + return gordian + } + + panic("NewClientFactory: No client available for " + Gordian) + + default: + panic("NewClientFactory: No client available") + } +} diff --git a/chain/cosmos/consensus/gordian.go b/chain/cosmos/consensus/gordian.go new file mode 100644 index 000000000..f2bdbda0f --- /dev/null +++ b/chain/cosmos/consensus/gordian.go @@ -0,0 +1,113 @@ +package consensus + +import ( + "context" + "encoding/json" + "fmt" + "log" + "net/http" + "os" + "strings" + + coretypes "github.com/cometbft/cometbft/rpc/core/types" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/cli" + "github.com/strangelove-ventures/interchaintest/v8/dockerutil" +) + +var _ Client = (*GordianClient)(nil) + +type GordianClient struct { + addr string + client *http.Client +} + +func NewGordianClient(addr string, client *http.Client) *GordianClient { + addr = strings.Replace(addr, "tcp://", "http://", 1) + + return &GordianClient{ + addr: addr, + client: client, + } +} + +// ClientType implements Client. +func (g *GordianClient) ClientType() ClientType { + return Gordian +} + +// Block implements Client. +func (g *GordianClient) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) { + return &coretypes.ResultBlock{}, nil +} + +// BlockResults implements Client. +func (g *GordianClient) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) { + return &coretypes.ResultBlockResults{}, nil +} + +// Height implements Client. +func (g *GordianClient) Height(ctx context.Context) (int64, error) { + type GordianCurrentBlockResponse struct { + VotingHeight *uint64 `protobuf:"varint,1,opt,name=voting_height,json=votingHeight,proto3,oneof" json:"voting_height,omitempty"` + } + + // TODO: get hostname query to work + endpoint := fmt.Sprintf("%s/blocks/watermark", g.addr) + req, err := http.NewRequest("GET", endpoint, nil) + if err != nil { + log.Print(err) + os.Exit(1) + } + q := req.URL.Query() + + // make request as JSON + req.Header.Set("Content-Type", "application/json") + req.URL.RawQuery = q.Encode() + + // client := &http.Client{} + resp, err := g.client.Do(req) + if err != nil { + log.Print(err) + os.Exit(1) + } + defer resp.Body.Close() + + var watermark GordianCurrentBlockResponse + if err := json.NewDecoder(resp.Body).Decode(&watermark); err != nil { + log.Print(err) + os.Exit(1) + } + + return int64(*watermark.VotingHeight), nil +} + +// IsClient implements Client. +func (g *GordianClient) IsClient(ctx context.Context, img *dockerutil.Image, bin string) bool { + res := img.Run(ctx, []string{bin, "gordian"}, dockerutil.ContainerOptions{}) + return cli.HasCommand(res.Err) +} + +// IsSynced implements Client. +func (g *GordianClient) IsSynced(ctx context.Context) error { + // TODO: + h, err := g.Height(ctx) + if err != nil { + return fmt.Errorf("failed to get height: %w", err) + } + + if h > 0 { + return nil + } + + return fmt.Errorf("height is 0") +} + +// StartFlags implements Client. +func (g *GordianClient) StartFlags(context.Context) string { + return "" +} + +// Status implements Client. +func (g *GordianClient) Status(ctx context.Context) (*coretypes.ResultStatus, error) { + return &coretypes.ResultStatus{}, nil +} diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index c493806ce..32a8237de 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -38,6 +38,7 @@ import ( "github.com/strangelove-ventures/interchaintest/v8/testutil" "go.uber.org/zap" "golang.org/x/sync/errgroup" + grpc "google.golang.org/grpc" ) // CosmosChain is a local docker testnet for a Cosmos SDK chain. @@ -216,6 +217,10 @@ func (c *CosmosChain) GetNode() *ChainNode { return c.Validators[0] } +func (c *CosmosChain) GetNodeGRPC() *grpc.ClientConn { + return c.GetNode().GRPCClient +} + // Exec implements ibc.Chain. func (c *CosmosChain) Exec(ctx context.Context, cmd []string, env []string) (stdout, stderr []byte, err error) { return c.getFullNode().Exec(ctx, cmd, env) @@ -1077,7 +1082,7 @@ func (c *CosmosChain) Height(ctx context.Context) (int64, error) { // Acknowledgements implements ibc.Chain, returning all acknowledgments in block at height func (c *CosmosChain) Acknowledgements(ctx context.Context, height int64) ([]ibc.PacketAcknowledgement, error) { var acks []*chanTypes.MsgAcknowledgement - err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool { + err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().ConsensusClient, height, func(msg types.Msg) bool { found, ok := msg.(*chanTypes.MsgAcknowledgement) if ok { acks = append(acks, found) @@ -1110,7 +1115,7 @@ func (c *CosmosChain) Acknowledgements(ctx context.Context, height int64) ([]ibc // Timeouts implements ibc.Chain, returning all timeouts in block at height func (c *CosmosChain) Timeouts(ctx context.Context, height int64) ([]ibc.PacketTimeout, error) { var timeouts []*chanTypes.MsgTimeout - err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool { + err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().ConsensusClient, height, func(msg types.Msg) bool { found, ok := msg.(*chanTypes.MsgTimeout) if ok { timeouts = append(timeouts, found) diff --git a/chain/cosmos/module_auth.go b/chain/cosmos/module_auth.go index c847025eb..0715a944c 100644 --- a/chain/cosmos/module_auth.go +++ b/chain/cosmos/module_auth.go @@ -12,7 +12,7 @@ import ( // AuthQueryAccount performs a query to get the account details of the specified address func (c *CosmosChain) AuthQueryAccount(ctx context.Context, addr string) (*cdctypes.Any, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).Account(ctx, &authtypes.QueryAccountRequest{ + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).Account(ctx, &authtypes.QueryAccountRequest{ Address: addr, }) return res.Account, err @@ -20,13 +20,13 @@ func (c *CosmosChain) AuthQueryAccount(ctx context.Context, addr string) (*cdcty // AuthQueryParams performs a query to get the auth module parameters func (c *CosmosChain) AuthQueryParams(ctx context.Context) (*authtypes.Params, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).Params(ctx, &authtypes.QueryParamsRequest{}) + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).Params(ctx, &authtypes.QueryParamsRequest{}) return &res.Params, err } // AuthQueryModuleAccounts performs a query to get the account details of all the chain modules func (c *CosmosChain) AuthQueryModuleAccounts(ctx context.Context) ([]authtypes.ModuleAccount, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).ModuleAccounts(ctx, &authtypes.QueryModuleAccountsRequest{}) + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).ModuleAccounts(ctx, &authtypes.QueryModuleAccountsRequest{}) maccs := make([]authtypes.ModuleAccount, len(res.Accounts)) @@ -44,7 +44,7 @@ func (c *CosmosChain) AuthQueryModuleAccounts(ctx context.Context) ([]authtypes. // AuthGetModuleAccount performs a query to get the account details of the specified chain module func (c *CosmosChain) AuthQueryModuleAccount(ctx context.Context, moduleName string) (authtypes.ModuleAccount, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).ModuleAccountByName(ctx, &authtypes.QueryModuleAccountByNameRequest{ + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).ModuleAccountByName(ctx, &authtypes.QueryModuleAccountByNameRequest{ Name: moduleName, }) if err != nil { @@ -78,13 +78,13 @@ func (c *CosmosChain) GetGovernanceAddress(ctx context.Context) (string, error) } func (c *CosmosChain) AuthQueryBech32Prefix(ctx context.Context) (string, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).Bech32Prefix(ctx, &authtypes.Bech32PrefixRequest{}) + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).Bech32Prefix(ctx, &authtypes.Bech32PrefixRequest{}) return res.Bech32Prefix, err } // AddressBytesToString converts a byte array address to a string func (c *CosmosChain) AuthAddressBytesToString(ctx context.Context, addrBz []byte) (string, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).AddressBytesToString(ctx, &authtypes.AddressBytesToStringRequest{ + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).AddressBytesToString(ctx, &authtypes.AddressBytesToStringRequest{ AddressBytes: addrBz, }) return res.AddressString, err @@ -92,7 +92,7 @@ func (c *CosmosChain) AuthAddressBytesToString(ctx context.Context, addrBz []byt // AddressStringToBytes converts a string address to a byte array func (c *CosmosChain) AuthAddressStringToBytes(ctx context.Context, addr string) ([]byte, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).AddressStringToBytes(ctx, &authtypes.AddressStringToBytesRequest{ + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).AddressStringToBytes(ctx, &authtypes.AddressStringToBytesRequest{ AddressString: addr, }) return res.AddressBytes, err @@ -100,7 +100,7 @@ func (c *CosmosChain) AuthAddressStringToBytes(ctx context.Context, addr string) // AccountInfo queries the account information of the given address func (c *CosmosChain) AuthQueryAccountInfo(ctx context.Context, addr string) (*authtypes.BaseAccount, error) { - res, err := authtypes.NewQueryClient(c.GetNode().GrpcConn).AccountInfo(ctx, &authtypes.QueryAccountInfoRequest{ + res, err := authtypes.NewQueryClient(c.GetNodeGRPC()).AccountInfo(ctx, &authtypes.QueryAccountInfoRequest{ Address: addr, }) return res.Info, err diff --git a/chain/cosmos/module_authz.go b/chain/cosmos/module_authz.go index ad5ac5e76..9f67dee69 100644 --- a/chain/cosmos/module_authz.go +++ b/chain/cosmos/module_authz.go @@ -83,7 +83,7 @@ func (tn *ChainNode) AuthzRevoke(ctx context.Context, granter ibc.Wallet, grante // AuthzQueryGrants queries all grants for a given granter and grantee. func (c *CosmosChain) AuthzQueryGrants(ctx context.Context, granter string, grantee string, msgType string, extraFlags ...string) ([]*authz.Grant, error) { - res, err := authz.NewQueryClient(c.GetNode().GrpcConn).Grants(ctx, &authz.QueryGrantsRequest{ + res, err := authz.NewQueryClient(c.GetNodeGRPC()).Grants(ctx, &authz.QueryGrantsRequest{ Granter: granter, Grantee: grantee, MsgTypeUrl: msgType, @@ -93,7 +93,7 @@ func (c *CosmosChain) AuthzQueryGrants(ctx context.Context, granter string, gran // AuthzQueryGrantsByGrantee queries all grants for a given grantee. func (c *CosmosChain) AuthzQueryGrantsByGrantee(ctx context.Context, grantee string, extraFlags ...string) ([]*authz.GrantAuthorization, error) { - res, err := authz.NewQueryClient(c.GetNode().GrpcConn).GranteeGrants(ctx, &authz.QueryGranteeGrantsRequest{ + res, err := authz.NewQueryClient(c.GetNodeGRPC()).GranteeGrants(ctx, &authz.QueryGranteeGrantsRequest{ Grantee: grantee, }) return res.Grants, err @@ -101,7 +101,7 @@ func (c *CosmosChain) AuthzQueryGrantsByGrantee(ctx context.Context, grantee str // AuthzQueryGrantsByGranter returns all grants for a granter. func (c *CosmosChain) AuthzQueryGrantsByGranter(ctx context.Context, granter string, extraFlags ...string) ([]*authz.GrantAuthorization, error) { - res, err := authz.NewQueryClient(c.GetNode().GrpcConn).GranterGrants(ctx, &authz.QueryGranterGrantsRequest{ + res, err := authz.NewQueryClient(c.GetNodeGRPC()).GranterGrants(ctx, &authz.QueryGranterGrantsRequest{ Granter: granter, }) return res.Grants, err diff --git a/chain/cosmos/module_bank.go b/chain/cosmos/module_bank.go index 5f54071ce..0903e57a8 100644 --- a/chain/cosmos/module_bank.go +++ b/chain/cosmos/module_bank.go @@ -49,51 +49,51 @@ func (c *CosmosChain) GetBalance(ctx context.Context, address string, denom stri // BankGetBalance is an alias for GetBalance func (c *CosmosChain) BankQueryBalance(ctx context.Context, address string, denom string) (sdkmath.Int, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).Balance(ctx, &banktypes.QueryBalanceRequest{Address: address, Denom: denom}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).Balance(ctx, &banktypes.QueryBalanceRequest{Address: address, Denom: denom}) return res.Balance.Amount, err } // AllBalances fetches an account address's balance for all denoms it holds func (c *CosmosChain) BankQueryAllBalances(ctx context.Context, address string) (types.Coins, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).AllBalances(ctx, &banktypes.QueryAllBalancesRequest{Address: address}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).AllBalances(ctx, &banktypes.QueryAllBalancesRequest{Address: address}) return res.GetBalances(), err } // BankDenomMetadata fetches the metadata of a specific coin denomination func (c *CosmosChain) BankQueryDenomMetadata(ctx context.Context, denom string) (*banktypes.Metadata, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).DenomMetadata(ctx, &banktypes.QueryDenomMetadataRequest{Denom: denom}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).DenomMetadata(ctx, &banktypes.QueryDenomMetadataRequest{Denom: denom}) return &res.Metadata, err } func (c *CosmosChain) BankQueryDenomMetadataByQueryString(ctx context.Context, denom string) (*banktypes.Metadata, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).DenomMetadataByQueryString(ctx, &banktypes.QueryDenomMetadataByQueryStringRequest{Denom: denom}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).DenomMetadataByQueryString(ctx, &banktypes.QueryDenomMetadataByQueryStringRequest{Denom: denom}) return &res.Metadata, err } func (c *CosmosChain) BankQueryDenomOwners(ctx context.Context, denom string) ([]*banktypes.DenomOwner, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).DenomOwners(ctx, &banktypes.QueryDenomOwnersRequest{Denom: denom}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).DenomOwners(ctx, &banktypes.QueryDenomOwnersRequest{Denom: denom}) return res.DenomOwners, err } func (c *CosmosChain) BankQueryDenomsMetadata(ctx context.Context) ([]banktypes.Metadata, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).DenomsMetadata(ctx, &banktypes.QueryDenomsMetadataRequest{}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).DenomsMetadata(ctx, &banktypes.QueryDenomsMetadataRequest{}) return res.Metadatas, err } func (c *CosmosChain) BankQueryParams(ctx context.Context) (*banktypes.Params, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).Params(ctx, &banktypes.QueryParamsRequest{}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).Params(ctx, &banktypes.QueryParamsRequest{}) return &res.Params, err } func (c *CosmosChain) BankQuerySendEnabled(ctx context.Context, denoms []string) ([]*banktypes.SendEnabled, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).SendEnabled(ctx, &banktypes.QuerySendEnabledRequest{ + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).SendEnabled(ctx, &banktypes.QuerySendEnabledRequest{ Denoms: denoms, }) return res.SendEnabled, err } func (c *CosmosChain) BankQuerySpendableBalance(ctx context.Context, address, denom string) (*types.Coin, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).SpendableBalanceByDenom(ctx, &banktypes.QuerySpendableBalanceByDenomRequest{ + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).SpendableBalanceByDenom(ctx, &banktypes.QuerySpendableBalanceByDenomRequest{ Address: address, Denom: denom, }) @@ -101,17 +101,17 @@ func (c *CosmosChain) BankQuerySpendableBalance(ctx context.Context, address, de } func (c *CosmosChain) BankQuerySpendableBalances(ctx context.Context, address string) (*types.Coins, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).SpendableBalances(ctx, &banktypes.QuerySpendableBalancesRequest{Address: address}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).SpendableBalances(ctx, &banktypes.QuerySpendableBalancesRequest{Address: address}) return &res.Balances, err } func (c *CosmosChain) BankQueryTotalSupply(ctx context.Context) (*types.Coins, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).TotalSupply(ctx, &banktypes.QueryTotalSupplyRequest{}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).TotalSupply(ctx, &banktypes.QueryTotalSupplyRequest{}) return &res.Supply, err } func (c *CosmosChain) BankQueryTotalSupplyOf(ctx context.Context, address string) (*types.Coin, error) { - res, err := banktypes.NewQueryClient(c.GetNode().GrpcConn).SupplyOf(ctx, &banktypes.QuerySupplyOfRequest{Denom: address}) + res, err := banktypes.NewQueryClient(c.GetNodeGRPC()).SupplyOf(ctx, &banktypes.QuerySupplyOfRequest{Denom: address}) return &res.Amount, err } diff --git a/chain/cosmos/module_distribution.go b/chain/cosmos/module_distribution.go index 29acc0de2..7d69fde2f 100644 --- a/chain/cosmos/module_distribution.go +++ b/chain/cosmos/module_distribution.go @@ -55,7 +55,7 @@ func (tn *ChainNode) DistributionWithdrawValidatorRewards(ctx context.Context, k // DistributionCommission returns the validator's commission func (c *CosmosChain) DistributionQueryCommission(ctx context.Context, valAddr string) (*distrtypes.ValidatorAccumulatedCommission, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). ValidatorCommission(ctx, &distrtypes.QueryValidatorCommissionRequest{ ValidatorAddress: valAddr, }) @@ -64,42 +64,42 @@ func (c *CosmosChain) DistributionQueryCommission(ctx context.Context, valAddr s // DistributionCommunityPool returns the community pool func (c *CosmosChain) DistributionQueryCommunityPool(ctx context.Context) (*sdk.DecCoins, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). CommunityPool(ctx, &distrtypes.QueryCommunityPoolRequest{}) return &res.Pool, err } // DistributionDelegationTotalRewards returns the delegator's total rewards func (c *CosmosChain) DistributionQueryDelegationTotalRewards(ctx context.Context, delegatorAddr string) (*distrtypes.QueryDelegationTotalRewardsResponse, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). DelegationTotalRewards(ctx, &distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: delegatorAddr}) return res, err } // DistributionDelegatorValidators returns the delegator's validators func (c *CosmosChain) DistributionQueryDelegatorValidators(ctx context.Context, delegatorAddr string) (*distrtypes.QueryDelegatorValidatorsResponse, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). DelegatorValidators(ctx, &distrtypes.QueryDelegatorValidatorsRequest{DelegatorAddress: delegatorAddr}) return res, err } // DistributionDelegatorWithdrawAddress returns the delegator's withdraw address func (c *CosmosChain) DistributionQueryDelegatorWithdrawAddress(ctx context.Context, delegatorAddr string) (string, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). DelegatorWithdrawAddress(ctx, &distrtypes.QueryDelegatorWithdrawAddressRequest{DelegatorAddress: delegatorAddr}) return res.WithdrawAddress, err } // DistributionParams returns the distribution params func (c *CosmosChain) DistributionQueryParams(ctx context.Context) (*distrtypes.Params, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). Params(ctx, &distrtypes.QueryParamsRequest{}) return &res.Params, err } // DistributionRewards returns the delegator's rewards func (c *CosmosChain) DistributionQueryRewards(ctx context.Context, delegatorAddr, valAddr string) (sdk.DecCoins, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). DelegationRewards(ctx, &distrtypes.QueryDelegationRewardsRequest{ DelegatorAddress: delegatorAddr, ValidatorAddress: valAddr, @@ -109,21 +109,21 @@ func (c *CosmosChain) DistributionQueryRewards(ctx context.Context, delegatorAdd // DistributionValidatorSlashes returns the validator's slashes func (c *CosmosChain) DistributionQueryValidatorSlashes(ctx context.Context, valAddr string) ([]distrtypes.ValidatorSlashEvent, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). ValidatorSlashes(ctx, &distrtypes.QueryValidatorSlashesRequest{ValidatorAddress: valAddr}) return res.Slashes, err } // DistributionValidatorDistributionInfo returns the validator's distribution info func (c *CosmosChain) DistributionQueryValidatorDistributionInfo(ctx context.Context, valAddr string) (*distrtypes.QueryValidatorDistributionInfoResponse, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). ValidatorDistributionInfo(ctx, &distrtypes.QueryValidatorDistributionInfoRequest{ValidatorAddress: valAddr}) return res, err } // DistributionValidatorOutstandingRewards returns the validator's outstanding rewards func (c *CosmosChain) DistributionQueryValidatorOutstandingRewards(ctx context.Context, valAddr string) (*distrtypes.ValidatorOutstandingRewards, error) { - res, err := distrtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := distrtypes.NewQueryClient(c.GetNodeGRPC()). ValidatorOutstandingRewards(ctx, &distrtypes.QueryValidatorOutstandingRewardsRequest{ValidatorAddress: valAddr}) return &res.Rewards, err } diff --git a/chain/cosmos/module_feegrant.go b/chain/cosmos/module_feegrant.go index 1406575f7..df93eb0ce 100644 --- a/chain/cosmos/module_feegrant.go +++ b/chain/cosmos/module_feegrant.go @@ -40,7 +40,7 @@ func (tn *ChainNode) FeeGrantRevoke(ctx context.Context, keyName, granterAddr, g // FeeGrantGetAllowance returns the allowance of a granter and grantee pair. func (c *CosmosChain) FeeGrantQueryAllowance(ctx context.Context, granter, grantee string) (*feegrant.Grant, error) { - res, err := feegrant.NewQueryClient(c.GetNode().GrpcConn).Allowance(ctx, &feegrant.QueryAllowanceRequest{ + res, err := feegrant.NewQueryClient(c.GetNodeGRPC()).Allowance(ctx, &feegrant.QueryAllowanceRequest{ Granter: granter, Grantee: grantee, }) @@ -49,7 +49,7 @@ func (c *CosmosChain) FeeGrantQueryAllowance(ctx context.Context, granter, grant // FeeGrantGetAllowances returns all allowances of a grantee. func (c *CosmosChain) FeeGrantQueryAllowances(ctx context.Context, grantee string) ([]*feegrant.Grant, error) { - res, err := feegrant.NewQueryClient(c.GetNode().GrpcConn).Allowances(ctx, &feegrant.QueryAllowancesRequest{ + res, err := feegrant.NewQueryClient(c.GetNodeGRPC()).Allowances(ctx, &feegrant.QueryAllowancesRequest{ Grantee: grantee, }) return res.Allowances, err @@ -57,7 +57,7 @@ func (c *CosmosChain) FeeGrantQueryAllowances(ctx context.Context, grantee strin // FeeGrantGetAllowancesByGranter returns all allowances of a granter. func (c *CosmosChain) FeeGrantQueryAllowancesByGranter(ctx context.Context, granter string) ([]*feegrant.Grant, error) { - res, err := feegrant.NewQueryClient(c.GetNode().GrpcConn).AllowancesByGranter(ctx, &feegrant.QueryAllowancesByGranterRequest{ + res, err := feegrant.NewQueryClient(c.GetNodeGRPC()).AllowancesByGranter(ctx, &feegrant.QueryAllowancesByGranterRequest{ Granter: granter, }) return res.Allowances, err diff --git a/chain/cosmos/module_gov.go b/chain/cosmos/module_gov.go index d9fac35c1..92b567ae4 100644 --- a/chain/cosmos/module_gov.go +++ b/chain/cosmos/module_gov.go @@ -170,7 +170,7 @@ func (c *CosmosChain) BuildProposal(messages []ProtoMessage, title, summary, met // GovQueryProposal returns the state and details of a v1beta1 governance proposal. func (c *CosmosChain) GovQueryProposal(ctx context.Context, proposalID uint64) (*govv1beta1.Proposal, error) { - res, err := govv1beta1.NewQueryClient(c.GetNode().GrpcConn).Proposal(ctx, &govv1beta1.QueryProposalRequest{ProposalId: proposalID}) + res, err := govv1beta1.NewQueryClient(c.GetNodeGRPC()).Proposal(ctx, &govv1beta1.QueryProposalRequest{ProposalId: proposalID}) if err != nil { return nil, err } @@ -180,7 +180,7 @@ func (c *CosmosChain) GovQueryProposal(ctx context.Context, proposalID uint64) ( // GovQueryProposalV1 returns the state and details of a v1 governance proposal. func (c *CosmosChain) GovQueryProposalV1(ctx context.Context, proposalID uint64) (*govv1.Proposal, error) { - res, err := govv1.NewQueryClient(c.GetNode().GrpcConn).Proposal(ctx, &govv1.QueryProposalRequest{ProposalId: proposalID}) + res, err := govv1.NewQueryClient(c.GetNodeGRPC()).Proposal(ctx, &govv1.QueryProposalRequest{ProposalId: proposalID}) if err != nil { return nil, err } @@ -190,7 +190,7 @@ func (c *CosmosChain) GovQueryProposalV1(ctx context.Context, proposalID uint64) // GovQueryProposalsV1 returns all proposals with a given status. func (c *CosmosChain) GovQueryProposalsV1(ctx context.Context, status govv1.ProposalStatus) ([]*govv1.Proposal, error) { - res, err := govv1.NewQueryClient(c.GetNode().GrpcConn).Proposals(ctx, &govv1.QueryProposalsRequest{ + res, err := govv1.NewQueryClient(c.GetNodeGRPC()).Proposals(ctx, &govv1.QueryProposalsRequest{ ProposalStatus: status, }) if err != nil { @@ -202,7 +202,7 @@ func (c *CosmosChain) GovQueryProposalsV1(ctx context.Context, status govv1.Prop // GovQueryVote returns the vote for a proposal from a specific voter. func (c *CosmosChain) GovQueryVote(ctx context.Context, proposalID uint64, voter string) (*govv1.Vote, error) { - res, err := govv1.NewQueryClient(c.GetNode().GrpcConn).Vote(ctx, &govv1.QueryVoteRequest{ + res, err := govv1.NewQueryClient(c.GetNodeGRPC()).Vote(ctx, &govv1.QueryVoteRequest{ ProposalId: proposalID, Voter: voter, }) @@ -215,7 +215,7 @@ func (c *CosmosChain) GovQueryVote(ctx context.Context, proposalID uint64, voter // GovQueryVotes returns all votes for a proposal. func (c *CosmosChain) GovQueryVotes(ctx context.Context, proposalID uint64) ([]*govv1.Vote, error) { - res, err := govv1.NewQueryClient(c.GetNode().GrpcConn).Votes(ctx, &govv1.QueryVotesRequest{ + res, err := govv1.NewQueryClient(c.GetNodeGRPC()).Votes(ctx, &govv1.QueryVotesRequest{ ProposalId: proposalID, }) if err != nil { @@ -227,7 +227,7 @@ func (c *CosmosChain) GovQueryVotes(ctx context.Context, proposalID uint64) ([]* // GovQueryParams returns the current governance parameters. func (c *CosmosChain) GovQueryParams(ctx context.Context, paramsType string) (*govv1.Params, error) { - res, err := govv1.NewQueryClient(c.GetNode().GrpcConn).Params(ctx, &govv1.QueryParamsRequest{ + res, err := govv1.NewQueryClient(c.GetNodeGRPC()).Params(ctx, &govv1.QueryParamsRequest{ ParamsType: paramsType, }) if err != nil { diff --git a/chain/cosmos/module_slashing.go b/chain/cosmos/module_slashing.go index 3f5c98439..cca39f352 100644 --- a/chain/cosmos/module_slashing.go +++ b/chain/cosmos/module_slashing.go @@ -16,7 +16,7 @@ func (tn *ChainNode) SlashingUnJail(ctx context.Context, keyName string) error { // SlashingGetParams returns slashing params func (c *CosmosChain) SlashingQueryParams(ctx context.Context) (*slashingtypes.Params, error) { - res, err := slashingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := slashingtypes.NewQueryClient(c.GetNodeGRPC()). Params(ctx, &slashingtypes.QueryParamsRequest{}) if err != nil { return nil, err @@ -26,7 +26,7 @@ func (c *CosmosChain) SlashingQueryParams(ctx context.Context) (*slashingtypes.P // SlashingSigningInfo returns signing info for a validator func (c *CosmosChain) SlashingQuerySigningInfo(ctx context.Context, consAddress string) (*slashingtypes.ValidatorSigningInfo, error) { - res, err := slashingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := slashingtypes.NewQueryClient(c.GetNodeGRPC()). SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: consAddress}) if err != nil { return nil, err @@ -36,7 +36,7 @@ func (c *CosmosChain) SlashingQuerySigningInfo(ctx context.Context, consAddress // SlashingSigningInfos returns all signing infos func (c *CosmosChain) SlashingQuerySigningInfos(ctx context.Context) ([]slashingtypes.ValidatorSigningInfo, error) { - res, err := slashingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := slashingtypes.NewQueryClient(c.GetNodeGRPC()). SigningInfos(ctx, &slashingtypes.QuerySigningInfosRequest{}) if err != nil { return nil, err diff --git a/chain/cosmos/module_staking.go b/chain/cosmos/module_staking.go index ce3afbb22..52d733164 100644 --- a/chain/cosmos/module_staking.go +++ b/chain/cosmos/module_staking.go @@ -82,7 +82,7 @@ func (tn *ChainNode) StakingCreateValidatorFile( // StakingQueryDelegation returns a delegation. func (c *CosmosChain) StakingQueryDelegation(ctx context.Context, valAddr string, delegator string) (*stakingtypes.DelegationResponse, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). Delegation(ctx, &stakingtypes.QueryDelegationRequest{DelegatorAddr: delegator, ValidatorAddr: valAddr}) if err != nil { return nil, err @@ -92,7 +92,7 @@ func (c *CosmosChain) StakingQueryDelegation(ctx context.Context, valAddr string // StakingQueryDelegations returns all delegations for a delegator. func (c *CosmosChain) StakingQueryDelegations(ctx context.Context, delegator string) ([]stakingtypes.DelegationResponse, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). DelegatorDelegations(ctx, &stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: delegator, Pagination: nil}) if err != nil { return nil, err @@ -102,7 +102,7 @@ func (c *CosmosChain) StakingQueryDelegations(ctx context.Context, delegator str // StakingQueryDelegationsTo returns all delegations to a validator. func (c *CosmosChain) StakingQueryDelegationsTo(ctx context.Context, validator string) ([]*stakingtypes.DelegationResponse, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). ValidatorDelegations(ctx, &stakingtypes.QueryValidatorDelegationsRequest{ValidatorAddr: validator}) if err != nil { return nil, err @@ -118,7 +118,7 @@ func (c *CosmosChain) StakingQueryDelegationsTo(ctx context.Context, validator s // StakingQueryDelegatorValidator returns a validator for a delegator. func (c *CosmosChain) StakingQueryDelegatorValidator(ctx context.Context, delegator string, validator string) (*stakingtypes.Validator, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). DelegatorValidator(ctx, &stakingtypes.QueryDelegatorValidatorRequest{DelegatorAddr: delegator, ValidatorAddr: validator}) if err != nil { return nil, err @@ -128,7 +128,7 @@ func (c *CosmosChain) StakingQueryDelegatorValidator(ctx context.Context, delega // StakingQueryDelegatorValidators returns all validators for a delegator. func (c *CosmosChain) StakingQueryDelegatorValidators(ctx context.Context, delegator string) ([]stakingtypes.Validator, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). DelegatorValidators(ctx, &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator}) if err != nil { return nil, err @@ -138,7 +138,7 @@ func (c *CosmosChain) StakingQueryDelegatorValidators(ctx context.Context, deleg // StakingQueryHistoricalInfo returns the historical info at the given height. func (c *CosmosChain) StakingQueryHistoricalInfo(ctx context.Context, height int64) (*stakingtypes.HistoricalInfo, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). HistoricalInfo(ctx, &stakingtypes.QueryHistoricalInfoRequest{Height: height}) if err != nil { return nil, err @@ -148,7 +148,7 @@ func (c *CosmosChain) StakingQueryHistoricalInfo(ctx context.Context, height int // StakingQueryParams returns the staking parameters. func (c *CosmosChain) StakingQueryParams(ctx context.Context) (*stakingtypes.Params, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). Params(ctx, &stakingtypes.QueryParamsRequest{}) if err != nil { return nil, err @@ -158,7 +158,7 @@ func (c *CosmosChain) StakingQueryParams(ctx context.Context) (*stakingtypes.Par // StakingQueryPool returns the current staking pool values. func (c *CosmosChain) StakingQueryPool(ctx context.Context) (*stakingtypes.Pool, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). Pool(ctx, &stakingtypes.QueryPoolRequest{}) if err != nil { return nil, err @@ -168,7 +168,7 @@ func (c *CosmosChain) StakingQueryPool(ctx context.Context) (*stakingtypes.Pool, // StakingQueryRedelegation returns a redelegation. func (c *CosmosChain) StakingQueryRedelegation(ctx context.Context, delegator string, srcValAddr string, dstValAddr string) ([]stakingtypes.RedelegationResponse, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). Redelegations(ctx, &stakingtypes.QueryRedelegationsRequest{DelegatorAddr: delegator, SrcValidatorAddr: srcValAddr, DstValidatorAddr: dstValAddr}) if err != nil { return nil, err @@ -178,7 +178,7 @@ func (c *CosmosChain) StakingQueryRedelegation(ctx context.Context, delegator st // StakingQueryUnbondingDelegation returns an unbonding delegation. func (c *CosmosChain) StakingQueryUnbondingDelegation(ctx context.Context, delegator string, validator string) (*stakingtypes.UnbondingDelegation, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). UnbondingDelegation(ctx, &stakingtypes.QueryUnbondingDelegationRequest{DelegatorAddr: delegator, ValidatorAddr: validator}) if err != nil { return nil, err @@ -188,7 +188,7 @@ func (c *CosmosChain) StakingQueryUnbondingDelegation(ctx context.Context, deleg // StakingQueryUnbondingDelegations returns all unbonding delegations for a delegator. func (c *CosmosChain) StakingQueryUnbondingDelegations(ctx context.Context, delegator string) ([]stakingtypes.UnbondingDelegation, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). DelegatorUnbondingDelegations(ctx, &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{DelegatorAddr: delegator}) if err != nil { return nil, err @@ -198,7 +198,7 @@ func (c *CosmosChain) StakingQueryUnbondingDelegations(ctx context.Context, dele // StakingQueryUnbondingDelegationsFrom returns all unbonding delegations from a validator. func (c *CosmosChain) StakingQueryUnbondingDelegationsFrom(ctx context.Context, validator string) ([]stakingtypes.UnbondingDelegation, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). ValidatorUnbondingDelegations(ctx, &stakingtypes.QueryValidatorUnbondingDelegationsRequest{ValidatorAddr: validator}) if err != nil { return nil, err @@ -208,7 +208,7 @@ func (c *CosmosChain) StakingQueryUnbondingDelegationsFrom(ctx context.Context, // StakingQueryValidator returns a validator. func (c *CosmosChain) StakingQueryValidator(ctx context.Context, validator string) (*stakingtypes.Validator, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn). + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()). Validator(ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: validator}) if err != nil { return nil, err @@ -218,7 +218,7 @@ func (c *CosmosChain) StakingQueryValidator(ctx context.Context, validator strin // StakingQueryValidators returns all validators. func (c *CosmosChain) StakingQueryValidators(ctx context.Context, status string) ([]stakingtypes.Validator, error) { - res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).Validators(ctx, &stakingtypes.QueryValidatorsRequest{ + res, err := stakingtypes.NewQueryClient(c.GetNodeGRPC()).Validators(ctx, &stakingtypes.QueryValidatorsRequest{ Status: status, }) if err != nil { diff --git a/chain/cosmos/module_upgrade.go b/chain/cosmos/module_upgrade.go index f0b0d071b..2cb009fd1 100644 --- a/chain/cosmos/module_upgrade.go +++ b/chain/cosmos/module_upgrade.go @@ -39,13 +39,13 @@ func (tn *ChainNode) UpgradeCancel(ctx context.Context, keyName string, extraFla // UpgradeQueryPlan queries the current upgrade plan. func (c *CosmosChain) UpgradeQueryPlan(ctx context.Context) (*upgradetypes.Plan, error) { - res, err := upgradetypes.NewQueryClient(c.GetNode().GrpcConn).CurrentPlan(ctx, &upgradetypes.QueryCurrentPlanRequest{}) + res, err := upgradetypes.NewQueryClient(c.GetNodeGRPC()).CurrentPlan(ctx, &upgradetypes.QueryCurrentPlanRequest{}) return res.Plan, err } // UpgradeQueryAppliedPlan queries a previously applied upgrade plan by its name. func (c *CosmosChain) UpgradeQueryAppliedPlan(ctx context.Context, name string) (*upgradetypes.QueryAppliedPlanResponse, error) { - res, err := upgradetypes.NewQueryClient(c.GetNode().GrpcConn).AppliedPlan(ctx, &upgradetypes.QueryAppliedPlanRequest{ + res, err := upgradetypes.NewQueryClient(c.GetNodeGRPC()).AppliedPlan(ctx, &upgradetypes.QueryAppliedPlanRequest{ Name: name, }) return res, err @@ -54,19 +54,19 @@ func (c *CosmosChain) UpgradeQueryAppliedPlan(ctx context.Context, name string) // UpgradeQueryAuthority returns the account with authority to conduct upgrades func (c *CosmosChain) UpgradeQueryAuthority(ctx context.Context) (string, error) { - res, err := upgradetypes.NewQueryClient(c.GetNode().GrpcConn).Authority(ctx, &upgradetypes.QueryAuthorityRequest{}) + res, err := upgradetypes.NewQueryClient(c.GetNodeGRPC()).Authority(ctx, &upgradetypes.QueryAuthorityRequest{}) return res.Address, err } // UpgradeQueryAllModuleVersions queries the list of module versions from state. func (c *CosmosChain) UpgradeQueryAllModuleVersions(ctx context.Context) ([]*upgradetypes.ModuleVersion, error) { - res, err := upgradetypes.NewQueryClient(c.GetNode().GrpcConn).ModuleVersions(ctx, &upgradetypes.QueryModuleVersionsRequest{}) + res, err := upgradetypes.NewQueryClient(c.GetNodeGRPC()).ModuleVersions(ctx, &upgradetypes.QueryModuleVersionsRequest{}) return res.ModuleVersions, err } // UpgradeQueryModuleVersion queries a specific module version from state. func (c *CosmosChain) UpgradeQueryModuleVersion(ctx context.Context, module string) (*upgradetypes.ModuleVersion, error) { - res, err := upgradetypes.NewQueryClient(c.GetNode().GrpcConn).ModuleVersions(ctx, &upgradetypes.QueryModuleVersionsRequest{ + res, err := upgradetypes.NewQueryClient(c.GetNodeGRPC()).ModuleVersions(ctx, &upgradetypes.QueryModuleVersionsRequest{ ModuleName: module, }) if err != nil { diff --git a/chain/cosmos/poll.go b/chain/cosmos/poll.go index 04f642d9b..65f0bfd82 100644 --- a/chain/cosmos/poll.go +++ b/chain/cosmos/poll.go @@ -58,7 +58,7 @@ func PollForMessage[T any](ctx context.Context, chain *CosmosChain, registry cod } doPoll := func(ctx context.Context, height int64) (T, error) { h := int64(height) - block, err := chain.getFullNode().Client.Block(ctx, &h) + block, err := chain.getFullNode().ConsensusClient.Block(ctx, &h) if err != nil { return zero, err } diff --git a/chain/thorchain/api_query.go b/chain/thorchain/api_query.go index 559243664..34faf67e8 100644 --- a/chain/thorchain/api_query.go +++ b/chain/thorchain/api_query.go @@ -195,7 +195,7 @@ func get(url string, target interface{}) error { errResp := ErrorResponse{} err = json.Unmarshal(buf, &errResp) if err == nil && errResp.Error != "" { - return fmt.Errorf(errResp.Error) + return fmt.Errorf("api error: %s", errResp.Error) } // decode response diff --git a/examples/cosmos/chain_gordian_test.go b/examples/cosmos/chain_gordian_test.go new file mode 100644 index 000000000..e94679c38 --- /dev/null +++ b/examples/cosmos/chain_gordian_test.go @@ -0,0 +1,116 @@ +package cosmos_test + +import ( + "context" + "os" + "testing" + + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" + + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +// go test -timeout 3000s -run ^TestChainGordian$ github.com/strangelove-ventures/interchaintest/v8/examples/cosmos -v +func TestChainGordian(t *testing.T) { + // TODO: this test is only local for now. Will add CI in the future + if os.Getenv("IS_LOCAL_TESTING_GORDIAN") == "" { + t.Skip("skipping test; set IS_LOCAL_TESTING_GORDIAN to run this test") + } + + if testing.Short() { + t.Skip("skipping in short mode") + } + t.Parallel() + + cosmos.SetSDKConfig(baseBech32) + + sdk47Genesis := []cosmos.GenesisKV{ + cosmos.NewGenesisKV("app_state.gov.params.voting_period", "15s"), + cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", "10s"), + cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.denom", "token"), + cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.amount", "1"), + cosmos.NewGenesisKV("app_state.bank.denom_metadata", []banktypes.Metadata{denomMetadata}), + } + + decimals := int64(6) + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "gordianproject", + ChainName: "gordianproject", + Version: "local", // spawn -> gordian, modify docker file, build + ChainConfig: ibc.ChainConfig{ + Images: []ibc.DockerImage{ + { + Repository: "gordianproject", + Version: "local", + UidGid: "1025:1025", + }, + }, + Type: "cosmos", + Name: "gordian", + ChainID: "gordian-1", + GasPrices: "0.0" + denomMetadata.Base, + CoinDecimals: &decimals, + Bin: "appd", + TrustingPeriod: "330h", + AdditionalStartArgs: []string{ + "--g-http-addr", ":26657", + "--g-grpc-addr", ":9092", // gRPC 9090 is already used by the SDK. + }, + Denom: denomMetadata.Base, + Bech32Prefix: baseBech32, + CoinType: "118", + ModifyGenesis: cosmos.ModifyGenesis(sdk47Genesis), + GasAdjustment: 1.5, + }, + NumValidators: &numValsOne, + NumFullNodes: &numFullNodesZero, + }, + }) + + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + + chain := chains[0].(*cosmos.CosmosChain) + + ic := interchaintest.NewInterchain(). + AddChain(chain) + + ctx := context.Background() + client, network := interchaintest.DockerSetup(t) + + require.NoError(t, ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + SkipPathCreation: true, + })) + t.Cleanup(func() { + _ = ic.Close() + }) + + // TODO: gordian does not yet accept standard tx commands, it requires a manual broadcast of a generate only. Need to submit the raw bytes properly + // users := interchaintest.GetAndFundTestUsers(t, ctx, "default", genesisAmt, chain, chain) + // user1 := users[1].FormattedAddress() + // fmt.Println("user1", user1, "yuh") + + // b2, err := chain.BankQueryBalance(ctx, user1, chain.Config().Denom) + // require.NoError(t, err) + + // fmt.Println("b2", b2) + + // send 1 token + // sendAmt := int64(1) + // _, err = sendTokens(ctx, chain, users[0], users[1], "", sendAmt) + // require.NoError(t, err) + + // // check balances + // b2New, err := chain.GetBalance(ctx, user1, chain.Config().Denom) + // require.NoError(t, err) + // require.Equal(t, b2.Add(sdkmath.NewInt(sendAmt)), b2New) + +} diff --git a/examples/cosmos/chain_miscellaneous_test.go b/examples/cosmos/chain_miscellaneous_test.go index 6203fb901..a0a6d1fc6 100644 --- a/examples/cosmos/chain_miscellaneous_test.go +++ b/examples/cosmos/chain_miscellaneous_test.go @@ -251,7 +251,7 @@ func testRangeBlockMessages(ctx context.Context, t *testing.T, chain *cosmos.Cos require.NoError(t, err) var bankMsgs []*banktypes.MsgSend - err = cosmos.RangeBlockMessages(ctx, chain.Config().EncodingConfig.InterfaceRegistry, chain.Validators[0].Client, height+1, func(msg sdk.Msg) bool { + err = cosmos.RangeBlockMessages(ctx, chain.Config().EncodingConfig.InterfaceRegistry, chain.Validators[0].ConsensusClient, height+1, func(msg sdk.Msg) bool { found, ok := msg.(*banktypes.MsgSend) if ok { bankMsgs = append(bankMsgs, found)