Skip to content

Commit

Permalink
remove FindTxs() commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Sep 14, 2024
1 parent 151fd85 commit 8aa0eb0
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 197 deletions.
80 changes: 0 additions & 80 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"hash/fnv"
Expand All @@ -22,7 +21,6 @@ import (
"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"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -37,13 +35,11 @@ import (
"github.com/docker/go-connections/nat"
"go.uber.org/zap"
"golang.org/x/mod/semver"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

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"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -427,82 +423,6 @@ func (tn *ChainNode) Height(ctx context.Context) (int64, error) {
return height, nil
}

// FindTxs implements blockdb.BlockSaver.
func (tn *ChainNode) FindTxs(ctx context.Context, height int64) ([]blockdb.Tx, error) {
h := int64(height)
var eg errgroup.Group
var blockRes *coretypes.ResultBlockResults
var block *coretypes.ResultBlock
eg.Go(func() (err error) {
blockRes, err = tn.Client.BlockResults(ctx, &h)
return err
})
eg.Go(func() (err error) {
block, err = tn.Client.Block(ctx, &h)
return err
})
if err := eg.Wait(); err != nil {
return nil, err
}
interfaceRegistry := tn.Chain.Config().EncodingConfig.InterfaceRegistry
txs := make([]blockdb.Tx, 0, len(block.Block.Txs)+2)
for i, tx := range block.Block.Txs {
var newTx blockdb.Tx
newTx.Data = []byte(fmt.Sprintf(`{"data":"%s"}`, hex.EncodeToString(tx)))

sdkTx, err := decodeTX(interfaceRegistry, tx)
if err != nil {
tn.logger().Info("Failed to decode tx", zap.Int64("height", height), zap.Error(err))
continue
}
b, err := encodeTxToJSON(interfaceRegistry, sdkTx)
if err != nil {
tn.logger().Info("Failed to marshal tx to json", zap.Int64("height", height), zap.Error(err))
continue
}
newTx.Data = b

rTx := blockRes.TxsResults[i]

newTx.Events = make([]blockdb.Event, len(rTx.Events))
for j, e := range rTx.Events {
attrs := make([]blockdb.EventAttribute, len(e.Attributes))
for k, attr := range e.Attributes {
attrs[k] = blockdb.EventAttribute{
Key: string(attr.Key),
Value: string(attr.Value),
}
}
newTx.Events[j] = blockdb.Event{
Type: e.Type,
Attributes: attrs,
}
}
txs = append(txs, newTx)
}
if len(blockRes.FinalizeBlockEvents) > 0 {
finalizeBlockTx := blockdb.Tx{
Data: []byte(`{"data":"finalize_block","note":"this is a transaction artificially created for debugging purposes"}`),
}
finalizeBlockTx.Events = make([]blockdb.Event, len(blockRes.FinalizeBlockEvents))
for i, e := range blockRes.FinalizeBlockEvents {
attrs := make([]blockdb.EventAttribute, len(e.Attributes))
for j, attr := range e.Attributes {
attrs[j] = blockdb.EventAttribute{
Key: string(attr.Key),
Value: string(attr.Value),
}
}
finalizeBlockTx.Events[i] = blockdb.Event{
Type: e.Type,
Attributes: attrs,
}
}
txs = append(txs, finalizeBlockTx)
}
return txs, nil
}

// TxCommand is a helper to retrieve a full command for broadcasting a tx
// with the chain node binary.
func (tn *ChainNode) TxCommand(keyName string, command ...string) []string {
Expand Down
9 changes: 0 additions & 9 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
dockertypes "github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/strangelove-ventures/interchaintest/v8/blockdb"
wasmtypes "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/08-wasm-types"
"github.com/strangelove-ventures/interchaintest/v8/chain/internal/tendermint"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
Expand Down Expand Up @@ -1139,14 +1138,6 @@ func (c *CosmosChain) Timeouts(ctx context.Context, height int64) ([]ibc.PacketT
return ibcTimeouts, nil
}

// FindTxs implements blockdb.BlockSaver.
func (c *CosmosChain) FindTxs(ctx context.Context, height int64) ([]blockdb.Tx, error) {
fn := c.getFullNode()
c.findTxMu.Lock()
defer c.findTxMu.Unlock()
return fn.FindTxs(ctx, height)
}

// StopAllNodes stops and removes all long running containers (validators and full nodes)
func (c *CosmosChain) StopAllNodes(ctx context.Context) error {
var eg errgroup.Group
Expand Down
6 changes: 0 additions & 6 deletions chain/polkadot/polkadot_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
p2pcrypto "github.com/libp2p/go-libp2p/core/crypto"
"github.com/misko9/go-substrate-rpc-client/v4/signature"
gstypes "github.com/misko9/go-substrate-rpc-client/v4/types"
"github.com/strangelove-ventures/interchaintest/v8/blockdb"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"go.uber.org/zap"
Expand Down Expand Up @@ -847,11 +846,6 @@ func (c *PolkadotChain) GetKeyringPair(keyName string) (signature.KeyringPair, e
return kp, nil
}

// FindTxs implements blockdb.BlockSaver (Not implemented yet for polkadot, but we don't want to exit)
func (c *PolkadotChain) FindTxs(ctx context.Context, height int64) ([]blockdb.Tx, error) {
return []blockdb.Tx{}, nil
}

// GetIbcBalance returns the Coins type of ibc coins in account
func (c *PolkadotChain) GetIbcBalance(ctx context.Context, address string, denom uint64) (sdktypes.Coin, error) {
return c.ParachainNodes[0][0].GetIbcBalance(ctx, address, denom)
Expand Down
9 changes: 0 additions & 9 deletions chain/thorchain/thorchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
dockertypes "github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/strangelove-ventures/interchaintest/v8/blockdb"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -1120,14 +1119,6 @@ func (c *Thorchain) Timeouts(ctx context.Context, height int64) ([]ibc.PacketTim
return ibcTimeouts, nil
}

// FindTxs implements blockdb.BlockSaver.
func (c *Thorchain) FindTxs(ctx context.Context, height int64) ([]blockdb.Tx, error) {
fn := c.getFullNode()
c.findTxMu.Lock()
defer c.findTxMu.Unlock()
return fn.FindTxs(ctx, height)
}

// StopAllNodes stops and removes all long running containers (validators and full nodes)
func (c *Thorchain) StopAllNodes(ctx context.Context) error {
var eg errgroup.Group
Expand Down
80 changes: 0 additions & 80 deletions chain/thorchain/thornode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"hash/fnv"
Expand All @@ -21,7 +20,6 @@ import (
"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"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -34,11 +32,9 @@ import (
"github.com/icza/dyno"
"go.uber.org/zap"
"golang.org/x/mod/semver"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/strangelove-ventures/interchaintest/v8/blockdb"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -404,82 +400,6 @@ func (tn *ChainNode) Height(ctx context.Context) (int64, error) {
return height, nil
}

// FindTxs implements blockdb.BlockSaver.
func (tn *ChainNode) FindTxs(ctx context.Context, height int64) ([]blockdb.Tx, error) {
h := int64(height)
var eg errgroup.Group
var blockRes *coretypes.ResultBlockResults
var block *coretypes.ResultBlock
eg.Go(func() (err error) {
blockRes, err = tn.Client.BlockResults(ctx, &h)
return err
})
eg.Go(func() (err error) {
block, err = tn.Client.Block(ctx, &h)
return err
})
if err := eg.Wait(); err != nil {
return nil, err
}
interfaceRegistry := tn.Chain.Config().EncodingConfig.InterfaceRegistry
txs := make([]blockdb.Tx, 0, len(block.Block.Txs)+2)
for i, tx := range block.Block.Txs {
var newTx blockdb.Tx
newTx.Data = []byte(fmt.Sprintf(`{"data":"%s"}`, hex.EncodeToString(tx)))

sdkTx, err := decodeTX(interfaceRegistry, tx)
if err != nil {
tn.logger().Info("Failed to decode tx", zap.Int64("height", height), zap.Error(err))
continue
}
b, err := encodeTxToJSON(interfaceRegistry, sdkTx)
if err != nil {
tn.logger().Info("Failed to marshal tx to json", zap.Int64("height", height), zap.Error(err))
continue
}
newTx.Data = b

rTx := blockRes.TxsResults[i]

newTx.Events = make([]blockdb.Event, len(rTx.Events))
for j, e := range rTx.Events {
attrs := make([]blockdb.EventAttribute, len(e.Attributes))
for k, attr := range e.Attributes {
attrs[k] = blockdb.EventAttribute{
Key: string(attr.Key),
Value: string(attr.Value),
}
}
newTx.Events[j] = blockdb.Event{
Type: e.Type,
Attributes: attrs,
}
}
txs = append(txs, newTx)
}
if len(blockRes.FinalizeBlockEvents) > 0 {
finalizeBlockTx := blockdb.Tx{
Data: []byte(`{"data":"finalize_block","note":"this is a transaction artificially created for debugging purposes"}`),
}
finalizeBlockTx.Events = make([]blockdb.Event, len(blockRes.FinalizeBlockEvents))
for i, e := range blockRes.FinalizeBlockEvents {
attrs := make([]blockdb.EventAttribute, len(e.Attributes))
for j, attr := range e.Attributes {
attrs[j] = blockdb.EventAttribute{
Key: string(attr.Key),
Value: string(attr.Value),
}
}
finalizeBlockTx.Events[i] = blockdb.Event{
Type: e.Type,
Attributes: attrs,
}
}
txs = append(txs, finalizeBlockTx)
}
return txs, nil
}

// TxCommand is a helper to retrieve a full command for broadcasting a tx
// with the chain node binary.
func (tn *ChainNode) TxCommand(keyName string, command ...string) []string {
Expand Down
13 changes: 0 additions & 13 deletions examples/cosmos/chain_miscellaneous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func TestICTestMiscellaneous(t *testing.T) {
testBuildDependencies(ctx, t, chain)
testWalletKeys(ctx, t, chain)
testSendingTokens(ctx, t, chain, users)
testFindTxs(ctx, t, chain, users) // not supported with CometMock
testPollForBalance(ctx, t, chain, users)
testRangeBlockMessages(ctx, t, chain, users)
testBroadcaster(ctx, t, chain, users)
Expand Down Expand Up @@ -208,18 +207,6 @@ func testSendingTokens(ctx context.Context, t *testing.T, chain *cosmos.CosmosCh
require.Equal(t, b2.Add(math.NewInt(sendAmt)), b2New)
}

func testFindTxs(ctx context.Context, t *testing.T, chain *cosmos.CosmosChain, users []ibc.Wallet) {
height, _ := chain.Height(ctx)

_, err := sendTokens(ctx, chain, users[0], users[1], "", 1)
require.NoError(t, err)

txs, err := chain.FindTxs(ctx, height+1)
require.NoError(t, err)
require.NotEmpty(t, txs)
require.Equal(t, txs[0].Events[0].Type, "coin_spent")
}

func testPollForBalance(ctx context.Context, t *testing.T, chain *cosmos.CosmosChain, users []ibc.Wallet) {
bal2, err := chain.GetBalance(ctx, users[1].FormattedAddress(), chain.Config().Denom)
require.NoError(t, err)
Expand Down

0 comments on commit 8aa0eb0

Please sign in to comment.