Skip to content

Commit

Permalink
ci: add rpcimportable test (#2817)
Browse files Browse the repository at this point in the history
* ci: add rpcimportable test

* add ci

* fmt

* use github.com/btcsuite/btcd/btcutil in pkg/chains

* remove app imports types tests

* use standalone sdkconfig package

* fix policies test

* move crosschain keeper tests from types to keeper

* never seal config in tests

* use zeta-chain/ethermint#126

* add some comments

* use merged ethermint hash

* show resulting go.mod
  • Loading branch information
gartnera authored Sep 27, 2024
1 parent 0e5bca6 commit f789138
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 303 deletions.
39 changes: 37 additions & 2 deletions .github/workflows/build.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Testing
name: ci

on:
push:
Expand All @@ -9,7 +9,7 @@ on:
pull_request:

concurrency:
group: pr-testing-${{ github.head_ref || github.run_id }}
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
Expand Down Expand Up @@ -93,3 +93,38 @@ jobs:
if: always()
shell: bash
run: rm -rf *
rpcimportable:
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: go get node
working-directory: contrib/rpcimportable
run: go get github.com/zeta-chain/node@${{github.event.pull_request.head.sha || github.sha}}
env:
GOPROXY: direct
- name: go mod tidy
working-directory: contrib/rpcimportable
run: go mod tidy
- name: show go.mod
working-directory: contrib/rpcimportable
run: cat go.mod
- name: go test
working-directory: contrib/rpcimportable
run: go test ./...
ci-ok:
runs-on: ubuntu-22.04
needs:
- build-and-test
- rpcimportable
if: always()
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: |
echo "One of the jobs failed or was cancelled"
exit 1
15 changes: 15 additions & 0 deletions contrib/rpcimportable/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/zeta-chain/node/contrib/rpcimportable

go 1.22.5

// this go.mod should be empty when committed
// the go.sum should not be committed

// this replacement is unavoidable until we upgrade cosmos sdk >=v0.50
// but we should not tolerate any other replacements
replace (
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
)

// uncomment this for local development/testing/debugging
// replace github.com/zeta-chain/node => ../..
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{}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.9.0
github.com/zeta-chain/ethermint v0.0.0-20240909234716-2fad916e7179
github.com/zeta-chain/ethermint v0.0.0-20240927155358-f34e2a4a86f1
github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20240924201108-3a274ce7bad0
gitlab.com/thorchain/tss/go-tss v1.6.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4172,8 +4172,8 @@ github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPS
github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
github.com/zeta-chain/ethermint v0.0.0-20240909234716-2fad916e7179 h1:HykzQOeqBYFHPQCLrj7VAhoGOONtYJnt8IvyHNb9/d8=
github.com/zeta-chain/ethermint v0.0.0-20240909234716-2fad916e7179/go.mod h1:NeQEwcKBpKAUxIsii2F+jfyOD94jN/3fzPMv/1kVF9M=
github.com/zeta-chain/ethermint v0.0.0-20240927155358-f34e2a4a86f1 h1:o0Sh6Y2PKcG634hWqRWmWqBteSuoQUDxIR04OX9Llr8=
github.com/zeta-chain/ethermint v0.0.0-20240927155358-f34e2a4a86f1/go.mod h1:NeQEwcKBpKAUxIsii2F+jfyOD94jN/3fzPMv/1kVF9M=
github.com/zeta-chain/go-ethereum v1.10.26-spc h1:NvY4rR9yw52wfxWt7YoFsWbaIwVMyOtTsWKqGAXk+sE=
github.com/zeta-chain/go-ethereum v1.10.26-spc/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo=
github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4 h1:FmO3HfVdZ7LzxBUfg6sVzV7ilKElQU2DZm8PxJ7KcYI=
Expand Down
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
36 changes: 36 additions & 0 deletions pkg/sdkconfig/sdkconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package sdkconfig

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
AccountAddressPrefix = "zeta"
)

var (
AccountPubKeyPrefix = AccountAddressPrefix + "pub"
ValidatorAddressPrefix = AccountAddressPrefix + "valoper"
ValidatorPubKeyPrefix = AccountAddressPrefix + "valoperpub"
ConsNodeAddressPrefix = AccountAddressPrefix + "valcons"
ConsNodePubKeyPrefix = AccountAddressPrefix + "valconspub"
)

func SetDefault(seal bool) {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)
if seal {
config.Seal()
}
}

func Set(config *sdk.Config, seal bool) {
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)
if seal {
config.Seal()
}
}
22 changes: 0 additions & 22 deletions testutil/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,6 @@ import (
observertypes "github.com/zeta-chain/node/x/observer/types"
)

const (
AccountAddressPrefix = "zeta"
)

var (
AccountPubKeyPrefix = AccountAddressPrefix + "pub"
ValidatorAddressPrefix = AccountAddressPrefix + "valoper"
ValidatorPubKeyPrefix = AccountAddressPrefix + "valoperpub"
ConsNodeAddressPrefix = AccountAddressPrefix + "valcons"
ConsNodePubKeyPrefix = AccountAddressPrefix + "valconspub"
)

func SetConfig(seal bool) {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)
if seal {
config.Seal()
}
}

func StoreKeys() (
map[string]*storetypes.KVStoreKey,
map[string]*storetypes.MemoryStoreKey,
Expand Down
3 changes: 2 additions & 1 deletion testutil/keeper/emissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/pkg/sdkconfig"
emissionsmocks "github.com/zeta-chain/node/testutil/keeper/mocks/emissions"
"github.com/zeta-chain/node/x/emissions/keeper"
"github.com/zeta-chain/node/x/emissions/types"
Expand All @@ -32,7 +33,7 @@ func EmissionKeeperWithMockOptions(
t testing.TB,
mockOptions EmissionMockOptions,
) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) {
SetConfig(false)
sdkconfig.SetDefault(false)
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

Expand Down
3 changes: 2 additions & 1 deletion x/authority/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/pkg/sdkconfig"
"github.com/zeta-chain/node/testutil/sample"
"github.com/zeta-chain/node/x/authority/types"
)

func TestGenesisState_Validate(t *testing.T) {
setConfig(t)
sdkconfig.SetDefault(false)

tests := []struct {
name string
Expand Down
17 changes: 2 additions & 15 deletions x/authority/types/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,15 @@ package types_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/app"
"github.com/zeta-chain/node/pkg/sdkconfig"
"github.com/zeta-chain/node/testutil/sample"
"github.com/zeta-chain/node/x/authority/types"
)

// setConfig sets the global config to use zeta chain's bech32 prefixes
func setConfig(t *testing.T) {
defer func(t *testing.T) {
if r := recover(); r != nil {
t.Log("config is already sealed", r)
}
}(t)
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cfg.Seal()
}

func TestPolicies_Validate(t *testing.T) {
setConfig(t)
sdkconfig.SetDefault(false)
// use table driven tests to test the validation of policies
tests := []struct {
name string
Expand Down
Loading

0 comments on commit f789138

Please sign in to comment.