-
Notifications
You must be signed in to change notification settings - Fork 672
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
Add fee middleware test suite functions (E2E #5) #1710
Changes from 44 commits
47be6be
ce80411
bfbba03
4569fa5
272ad61
6afe90c
7497574
7091fbc
6ebcc6d
05d9a45
308eb0f
9ebacd7
c431850
3c4f62b
b5fff2a
abb0eca
f36025b
9039137
30591c9
b43d07e
b1bcc12
d740296
e94d35b
848f888
99328b1
35e454f
ccd9fd5
e154f09
236eb9f
11227eb
7541beb
e768a46
ce2828e
2f77cd3
0cfac25
5753fa4
9ebbed4
58a0fd5
9b2ffba
1c2e239
da2c8b9
3b87fd8
b253b8d
42e96be
196cfc7
24abfa1
b6a6d01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,16 @@ import ( | |
"context" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/strangelove-ventures/ibctest/broadcast" | ||
"github.com/strangelove-ventures/ibctest/chain/cosmos" | ||
"github.com/strangelove-ventures/ibctest/ibc" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"e2e/testsuite" | ||
|
||
feetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" | ||
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" | ||
) | ||
|
||
func TestFeeMiddlewareTestSuite(t *testing.T) { | ||
|
@@ -18,13 +24,51 @@ type FeeMiddlewareTestSuite struct { | |
testsuite.E2ETestSuite | ||
} | ||
|
||
// RegisterCounterPartyPayee broadcasts a MsgRegisterCounterpartyPayee message. | ||
func (s *FeeMiddlewareTestSuite) RegisterCounterPartyPayee(ctx context.Context, chain *cosmos.CosmosChain, user broadcast.User, portID, channelID, relayerAddr, counterpartyPayeeAddr string) (sdk.TxResponse, error) { | ||
msg := feetypes.NewMsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr) | ||
return s.BroadcastMessages(ctx, chain, user, msg) | ||
} | ||
|
||
// QueryCounterPartyPayee queries the counterparty payee of the given chain and relayer address on the specified channel. | ||
func (s *FeeMiddlewareTestSuite) QueryCounterPartyPayee(ctx context.Context, chain ibc.Chain, relayerAddress, channelID string) (string, error) { | ||
queryClient := s.GetChainGRCPClientSet(chain).FeeQueryClient | ||
res, err := queryClient.CounterpartyPayee(ctx, &feetypes.QueryCounterpartyPayeeRequest{ | ||
ChannelId: channelID, | ||
Relayer: relayerAddress, | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
return res.CounterpartyPayee, nil | ||
} | ||
|
||
// PayPacketFeeAsync broadcasts a MsgPayPacketFeeAsync message. | ||
func (s *FeeMiddlewareTestSuite) PayPacketFeeAsync(ctx context.Context, chain *cosmos.CosmosChain, user broadcast.User, packetID channeltypes.PacketId, packetFee feetypes.PacketFee) (sdk.TxResponse, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto on @crodriguezvega's point |
||
msg := feetypes.NewMsgPayPacketFeeAsync(packetID, packetFee) | ||
return s.BroadcastMessages(ctx, chain, user, msg) | ||
} | ||
|
||
// QueryIncentivizedPacketsForChannel queries the incentivized packets on the specified channel. | ||
func (s *FeeMiddlewareTestSuite) QueryIncentivizedPacketsForChannel(ctx context.Context, chain *cosmos.CosmosChain, portId, channelId string) ([]*feetypes.IdentifiedPacketFees, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto on @crodriguezvega's point |
||
queryClient := s.GetChainGRCPClientSet(chain).FeeQueryClient | ||
res, err := queryClient.IncentivizedPacketsForChannel(ctx, &feetypes.QueryIncentivizedPacketsForChannelRequest{ | ||
PortId: portId, | ||
ChannelId: channelId, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res.IncentivizedPackets, err | ||
} | ||
|
||
func (s *FeeMiddlewareTestSuite) TestPlaceholder() { | ||
ctx := context.Background() | ||
r := s.SetupChainsRelayerAndChannel(ctx, feeMiddlewareChannelOptions()) | ||
s.T().Run("start relayer", func(t *testing.T) { | ||
s.StartRelayer(r) | ||
}) | ||
|
||
} | ||
|
||
// feeMiddlewareChannelOptions configures both of the chains to have fee middleware enabled. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,23 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"e2e/testconfig" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
dockerclient "github.com/docker/docker/client" | ||
"github.com/strangelove-ventures/ibctest" | ||
"github.com/strangelove-ventures/ibctest/broadcast" | ||
"github.com/strangelove-ventures/ibctest/chain/cosmos" | ||
"github.com/strangelove-ventures/ibctest/ibc" | ||
"github.com/strangelove-ventures/ibctest/test" | ||
"github.com/strangelove-ventures/ibctest/testreporter" | ||
"github.com/stretchr/testify/suite" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zaptest" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"e2e/testconfig" | ||
feetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" | ||
) | ||
|
||
const ( | ||
|
@@ -29,13 +36,18 @@ const ( | |
// E2ETestSuite has methods and functionality which can be shared among all test suites. | ||
type E2ETestSuite struct { | ||
suite.Suite | ||
grpcClientSets map[string]GRPCClientSet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mega nit but should we add a line break after |
||
paths map[string]path | ||
logger *zap.Logger | ||
DockerClient *dockerclient.Client | ||
network string | ||
startRelayerFn func(relayer ibc.Relayer) | ||
} | ||
|
||
type GRPCClientSet struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think we should add godocs to all exported types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reasoning behind the naming of having the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intention is just that is a group of clients, however I can see where the confusion is coming from. After some searching it looks like the term clientSet isn't that common (used a lot in k8s ecosystem) I can rename to maybe just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep sounds good to me! :) Thanks 🤝 |
||
FeeQueryClient feetypes.QueryClient | ||
} | ||
|
||
// path is a pairing of two chains which will be used in a test. | ||
type path struct { | ||
chainA, chainB *cosmos.CosmosChain | ||
|
@@ -102,6 +114,9 @@ func (s *E2ETestSuite) SetupChainsRelayerAndChannel(ctx context.Context, channel | |
time.Sleep(time.Second * 10) | ||
} | ||
|
||
s.initClientSet(chainA) | ||
s.initClientSet(chainB) | ||
|
||
return r | ||
} | ||
|
||
|
@@ -129,6 +144,20 @@ func (s *E2ETestSuite) GetChains(chainOpts ...testconfig.ChainOptionConfiguratio | |
return path.chainA, path.chainB | ||
} | ||
|
||
// BroadcastMessages broadcasts the provided messages to the given chain and signs them on behalf of the provided user. | ||
// Once the broadcast response is returned, we wait for a few blocks to be created on both chain A and chain B. | ||
func (s *E2ETestSuite) BroadcastMessages(ctx context.Context, chain *cosmos.CosmosChain, user broadcast.User, msgs ...sdk.Msg) (sdk.TxResponse, error) { | ||
broadcaster := cosmos.NewBroadcaster(s.T(), chain) | ||
resp, err := ibctest.BroadcastTx(ctx, broadcaster, user, msgs...) | ||
if err != nil { | ||
return sdk.TxResponse{}, err | ||
} | ||
|
||
chainA, chainB := s.GetChains() | ||
err = test.WaitForBlocks(ctx, 2, chainA, chainB) | ||
return resp, err | ||
} | ||
|
||
// GetRelayerWallets returns the relayer wallets associated with the chains. | ||
func (s *E2ETestSuite) GetRelayerWallets(relayer ibc.Relayer) (ibc.RelayerWallet, ibc.RelayerWallet, error) { | ||
chainA, chainB := s.GetChains() | ||
|
@@ -196,6 +225,37 @@ func (s *E2ETestSuite) GetChainBNativeBalance(ctx context.Context, user *ibctest | |
return GetNativeChainBalance(ctx, chainB, user) | ||
} | ||
|
||
// GetChainGRCPClientSet gets the GRPC clientset associated with the given chain. | ||
func (s *E2ETestSuite) GetChainGRCPClientSet(chain ibc.Chain) GRPCClientSet { | ||
cs, ok := s.grpcClientSets[chain.Config().ChainID] | ||
s.Require().True(ok, "chain %s does not have a GRPC clientset", chain.Config().ChainID) | ||
return cs | ||
} | ||
|
||
// initClientSet establishes GRPC clients with the given chain. | ||
// The created GRPCClientSet can be retreived with GetChainGRCPClientSet. | ||
func (s *E2ETestSuite) initClientSet(chain *cosmos.CosmosChain) { | ||
// Create a connection to the gRPC server. | ||
grpcConn, err := grpc.Dial( | ||
chain.GetHostGRPCAddress(), | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
) | ||
s.Require().NoError(err) | ||
s.T().Cleanup(func() { | ||
if err := grpcConn.Close(); err != nil { | ||
s.T().Logf("failed closing GRPC connection to chain %s: %s", chain.Config().ChainID, err) | ||
} | ||
}) | ||
|
||
if s.grpcClientSets == nil { | ||
s.grpcClientSets = map[string]GRPCClientSet{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason that we should not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope! I can change it, I think |
||
} | ||
|
||
s.grpcClientSets[chain.Config().ChainID] = GRPCClientSet{ | ||
FeeQueryClient: feetypes.NewQueryClient(grpcConn), | ||
} | ||
} | ||
|
||
// createCosmosChains creates two separate chains in docker containers. | ||
// test and can be retrieved with GetChains. | ||
func (s *E2ETestSuite) createCosmosChains(chainOptions testconfig.ChainOptions) (*cosmos.CosmosChain, *cosmos.CosmosChain) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With so many arguments the line becomes quite long, should we split it in multiple lines for better readability?