Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jun 26, 2024
1 parent 0a6f256 commit 994020a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/chains/chain_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chains_test

import (
"github.com/zeta-chain/zetacore/testutil/sample"
"testing"

"github.com/btcsuite/btcd/chaincfg"
Expand Down Expand Up @@ -231,6 +232,49 @@ func TestIsZetaChain(t *testing.T) {
}
}

func TestDecodeAddressFromChainID(t *testing.T) {
ethAddr := sample.EthAddress()

tests := []struct {
name string
chainID int64
addr string
want []byte
wantErr bool
}{
{
name: "Ethereum",
chainID: chains.Ethereum.ChainId,
addr: ethAddr.Hex(),
want: ethAddr.Bytes(),
},
{
name: "Bitcoin",
chainID: chains.BitcoinMainnet.ChainId,
addr: "bc1qk0cc73p8m7hswn8y2q080xa4e5pxapnqgp7h9c",
want: []byte("bc1qk0cc73p8m7hswn8y2q080xa4e5pxapnqgp7h9c"),
},
{
name: "Non-supported chain",
chainID: 9999,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := chains.DecodeAddressFromChainID(tt.chainID, tt.addr, []chains.Chain{})
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tt.want, got)
})

}
}

func TestIsEVMChain(t *testing.T) {
tests := []struct {
name string
Expand Down
7 changes: 7 additions & 0 deletions x/observer/types/chain_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func (s *UpdateChainParamsSuite) TestCommonParams() {
s.Validate(s.btcParams)
}

func (s *UpdateChainParamsSuite) TestBTCParamsInvalid() {
copy := *s.btcParams
copy.WatchUtxoTicker = 301
err := types.ValidateChainParams(&copy)
require.NotNil(s.T(), err)
}

func (s *UpdateChainParamsSuite) TestCoreContractAddresses() {
copy := *s.evmParams
copy.ZetaTokenContractAddress = "0x123"
Expand Down
24 changes: 24 additions & 0 deletions zetaclient/zetacore/query_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zetacore

import (
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
"net"
"testing"

Expand Down Expand Up @@ -874,6 +875,29 @@ func TestZetacore_GetSupportedChains(t *testing.T) {
require.Equal(t, expectedOutput.Chains, resp)
}

func TestZetacore_GetAdditionalChains(t *testing.T) {
expectedOutput := authoritytypes.QueryGetChainInfoResponse{
ChainInfo: authoritytypes.ChainInfo{
Chains: []chains.Chain{
chains.BitcoinMainnet,
chains.Ethereum,
},
},
}
input := observertypes.QuerySupportedChains{}
method := "/zetachain.zetacore.authority.Query/ChainInfo"
server := setupMockServer(t, authoritytypes.RegisterQueryServer, method, input, expectedOutput)
server.Serve()
defer closeMockServer(t, server)

client, err := setupZetacoreClient()
require.NoError(t, err)

resp, err := client.GetAdditionalChains()
require.NoError(t, err)
require.Equal(t, expectedOutput.ChainInfo.Chains, resp)
}

func TestZetacore_GetPendingNonces(t *testing.T) {
expectedOutput := observertypes.QueryAllPendingNoncesResponse{
PendingNonces: []observertypes.PendingNonces{
Expand Down

0 comments on commit 994020a

Please sign in to comment.