Skip to content

Commit

Permalink
ci: add rpcimportable test
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Sep 3, 2024
1 parent 74f1ab5 commit 2fc5c8a
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 78 deletions.
12 changes: 12 additions & 0 deletions contrib/rpcimportable/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/zeta-chain/node/contrib/rpcimportable

go 1.22.5

require github.com/zeta-chain/node v0.0.0-20240903163921-74f1ab59c658 // indirect

replace (
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
)

// uncomment this for local testing/development
// replace github.com/zeta-chain/node => ../..
3 changes: 3 additions & 0 deletions contrib/rpcimportable/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github.com/zeta-chain/node v0.0.0-20240903163921-74f1ab59c658 h1:+KzsEBBWfxAMqMjwOcivdpSHPncDSMU3yw7oIG5YJAw=
github.com/zeta-chain/node v0.0.0-20240903163921-74f1ab59c658/go.mod h1:XJj15D2+sgtX3wqx1O85A0bKUI3srKyZwkxdcfgoK6I=
github.com/zeta-chain/node v1.2.1/go.mod h1:z72YVX6jPPst8K06l0LTKORJXN7XB1RKUiliU52Cwk0=
11 changes: 11 additions & 0 deletions contrib/rpcimportable/rpcimportable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package rpcimportable

import (
"testing"

"github.com/zeta-chain/node/pkg/rpc"
)

func TestRPCImportable(t *testing.T) {
_ = rpc.Clients{}
}
38 changes: 0 additions & 38 deletions pkg/rpc/clients_crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package rpc

import (
"context"
"sort"

"cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"google.golang.org/grpc"

"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/x/crosschain/types"
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
)

// 32MB
Expand Down Expand Up @@ -157,38 +154,3 @@ func (c *Clients) GetInboundTrackersForChain(ctx context.Context, chainID int64)

return resp.InboundTracker, nil
}

// GetAllOutboundTrackerByChain returns all outbound trackers for a chain
func (c *Clients) GetAllOutboundTrackerByChain(
ctx context.Context,
chainID int64,
order interfaces.Order,
) ([]types.OutboundTracker, error) {
in := &types.QueryAllOutboundTrackerByChainRequest{
Chain: chainID,
Pagination: &query.PageRequest{
Key: nil,
Offset: 0,
Limit: 2000,
CountTotal: false,
Reverse: false,
},
}

resp, err := c.Crosschain.OutboundTrackerAllByChain(ctx, in)
if err != nil {
return nil, errors.Wrap(err, "failed to get all outbound trackers")
}

if order == interfaces.Ascending {
sort.SliceStable(resp.OutboundTracker, func(i, j int) bool {
return resp.OutboundTracker[i].Nonce < resp.OutboundTracker[j].Nonce
})
} else if order == interfaces.Descending {
sort.SliceStable(resp.OutboundTracker, func(i, j int) bool {
return resp.OutboundTracker[i].Nonce > resp.OutboundTracker[j].Nonce
})
}

return resp.OutboundTracker, nil
}
40 changes: 0 additions & 40 deletions pkg/rpc/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
tmtypes "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/stretchr/testify/require"
Expand All @@ -27,7 +26,6 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
lightclienttypes "github.com/zeta-chain/node/x/lightclient/types"
observertypes "github.com/zeta-chain/node/x/observer/types"
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
)

const skipMethod = "skip"
Expand Down Expand Up @@ -688,44 +686,6 @@ func TestZetacore_GetOutboundTracker(t *testing.T) {
require.Equal(t, expectedOutput.OutboundTracker, *resp)
}

func TestZetacore_GetAllOutboundTrackerByChain(t *testing.T) {
ctx := context.Background()

chain := chains.BscMainnet
expectedOutput := crosschaintypes.QueryAllOutboundTrackerByChainResponse{
OutboundTracker: []crosschaintypes.OutboundTracker{
{
Index: "tracker23456",
ChainId: chain.ChainId,
Nonce: 123456,
HashList: nil,
},
},
}
input := crosschaintypes.QueryAllOutboundTrackerByChainRequest{
Chain: chain.ChainId,
Pagination: &query.PageRequest{
Key: nil,
Offset: 0,
Limit: 2000,
CountTotal: false,
Reverse: false,
},
}
method := "/zetachain.zetacore.crosschain.Query/OutboundTrackerAllByChain"
setupMockServer(t, crosschaintypes.RegisterQueryServer, method, input, expectedOutput)

client := setupZetacoreClients(t)

resp, err := client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Ascending)
require.NoError(t, err)
require.Equal(t, expectedOutput.OutboundTracker, resp)

resp, err = client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Descending)
require.NoError(t, err)
require.Equal(t, expectedOutput.OutboundTracker, resp)
}

func TestZetacore_GetPendingNoncesByChain(t *testing.T) {
ctx := context.Background()

Expand Down
46 changes: 46 additions & 0 deletions zetaclient/zetacore/client_crosschain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package zetacore

import (
"context"
"sort"

"cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/zeta-chain/node/x/crosschain/types"
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
)

// GetAllOutboundTrackerByChain returns all outbound trackers for a chain
func (c *Client) GetAllOutboundTrackerByChain(
ctx context.Context,
chainID int64,
order interfaces.Order,
) ([]types.OutboundTracker, error) {
in := &types.QueryAllOutboundTrackerByChainRequest{
Chain: chainID,
Pagination: &query.PageRequest{
Key: nil,
Offset: 0,
Limit: 2000,
CountTotal: false,
Reverse: false,
},
}

resp, err := c.Crosschain.OutboundTrackerAllByChain(ctx, in)
if err != nil {
return nil, errors.Wrap(err, "failed to get all outbound trackers")
}

if order == interfaces.Ascending {
sort.SliceStable(resp.OutboundTracker, func(i, j int) bool {
return resp.OutboundTracker[i].Nonce < resp.OutboundTracker[j].Nonce
})
} else if order == interfaces.Descending {
sort.SliceStable(resp.OutboundTracker, func(i, j int) bool {
return resp.OutboundTracker[i].Nonce > resp.OutboundTracker[j].Nonce
})
}

return resp.OutboundTracker, nil
}
41 changes: 41 additions & 0 deletions zetaclient/zetacore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import (
cosmosclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/golang/mock/gomock"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
keyinterfaces "github.com/zeta-chain/node/zetaclient/keys/interfaces"
"go.nhat.io/grpcmock"
"go.nhat.io/grpcmock/planner"
Expand Down Expand Up @@ -189,3 +192,41 @@ func TestZetacore_GetZetaHotKeyBalance(t *testing.T) {
require.Error(t, err)
require.Equal(t, types.ZeroInt(), resp)
}

func TestZetacore_GetAllOutboundTrackerByChain(t *testing.T) {
ctx := context.Background()

chain := chains.BscMainnet
expectedOutput := crosschaintypes.QueryAllOutboundTrackerByChainResponse{
OutboundTracker: []crosschaintypes.OutboundTracker{
{
Index: "tracker23456",
ChainId: chain.ChainId,
Nonce: 123456,
HashList: nil,
},
},
}
input := crosschaintypes.QueryAllOutboundTrackerByChainRequest{
Chain: chain.ChainId,
Pagination: &query.PageRequest{
Key: nil,
Offset: 0,
Limit: 2000,
CountTotal: false,
Reverse: false,
},
}
method := "/zetachain.zetacore.crosschain.Query/OutboundTrackerAllByChain"
setupMockServer(t, crosschaintypes.RegisterQueryServer, method, input, expectedOutput)

client := setupZetacoreClient(t)

resp, err := client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Ascending)
require.NoError(t, err)
require.Equal(t, expectedOutput.OutboundTracker, resp)

resp, err = client.GetAllOutboundTrackerByChain(ctx, chain.ChainId, interfaces.Descending)
require.NoError(t, err)
require.Equal(t, expectedOutput.OutboundTracker, resp)
}

0 comments on commit 2fc5c8a

Please sign in to comment.