Skip to content

Commit

Permalink
Merge branch 'test-common-package' into refactor-common-package-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Mar 22, 2024
2 parents 8d32488 + 238fbbc commit 0155866
Show file tree
Hide file tree
Showing 53 changed files with 2,794 additions and 356 deletions.
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ install-zetaclient-race-test-only-build: go.sum
@echo "--> Installing zetaclientd"
@go install -race -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd

install-zetatool: go.sum
@echo "--> Installing zetatool"
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetatool

###############################################################################
### Local network ###
###############################################################################
Expand Down Expand Up @@ -286,4 +290,17 @@ mainnet-bitcoind-node:
cd contrib/mainnet/bitcoind && DOCKER_TAG=$(DOCKER_TAG) docker-compose up

athens3-zetarpc-node:
cd contrib/athens3/zetacored && DOCKER_TAG=$(DOCKER_TAG) docker-compose up
cd contrib/athens3/zetacored && DOCKER_TAG=$(DOCKER_TAG) docker-compose up

###############################################################################
### Debug Tools ###
###############################################################################

filter-missed-btc: install-zetatool
zetatool filterdeposit btc --config ./tool/filter_missed_deposits/zetatool_config.json

filter-missed-eth: install-zetatool
zetatool filterdeposit eth \
--config ./tool/filter_missed_deposits/zetatool_config.json \
--evm-max-range 1000 \
--evm-start-block 19464041
11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* [1789](https://github.com/zeta-chain/node/issues/1789) - block cross-chain transactions that involve restricted addresses
* [1755](https://github.com/zeta-chain/node/issues/1755) - use evm JSON RPC for inbound tx (including blob tx) observation.
* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions
* [1884](https://github.com/zeta-chain/node/pull/1884) - added zetatool cmd, added subcommand to filter deposits

### Tests

Expand All @@ -45,6 +46,8 @@
### Fixes

* [1861](https://github.com/zeta-chain/node/pull/1861) - fix `ObserverSlashAmount` invalid read
* [1880](https://github.com/zeta-chain/node/issues/1880) - lower the gas price multiplier for EVM chains.
* [1633](https://github.com/zeta-chain/node/issues/1633) - zetaclient should be able to pick up new connector and erc20Custody addresses

### Chores

Expand All @@ -56,7 +59,13 @@
* [1891](https://github.com/zeta-chain/node/pull/1891) - fix typo that was introduced to docker-compose and a typo in start.sh for the docker start script for full nodes.
* [1894](https://github.com/zeta-chain/node/pull/1894) - added download binaries and configs to the start sequence so it will download binaries that don't exist

## Version: v14
## Version: v15.0.0

### Features

*[1912](https://github.com/zeta-chain/node/pull/1912) - add reset chain nonces msg

## Version: v14.0.1

- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet

Expand Down
21 changes: 10 additions & 11 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/pkg"
"github.com/zeta-chain/zetacore/pkg/cosmos"
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
"github.com/zeta-chain/zetacore/zetaclient/authz"
Expand Down Expand Up @@ -55,8 +54,8 @@ func CreateSignerMap(
tss interfaces.TSSSigner,
loggers clientcommon.ClientLogger,
ts *metrics.TelemetryServer,
) (map[pkg.Chain]interfaces.ChainSigner, error) {
signerMap := make(map[pkg.Chain]interfaces.ChainSigner)
) (map[int64]interfaces.ChainSigner, error) {
signerMap := make(map[int64]interfaces.ChainSigner)
// EVM signers
for _, evmConfig := range appContext.Config().GetAllEVMConfigs() {
if evmConfig.Chain.IsZetaChain() {
Expand All @@ -77,7 +76,7 @@ func CreateSignerMap(
loggers.Std.Error().Err(err).Msgf("NewEVMSigner error for chain %s", evmConfig.Chain.String())
continue
}
signerMap[evmConfig.Chain] = signer
signerMap[evmConfig.Chain.ChainId] = signer
}
// BTC signer
btcChain, btcConfig, enabled := appContext.GetBTCChainAndConfig()
Expand All @@ -86,7 +85,7 @@ func CreateSignerMap(
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewBTCSigner error for chain %s", btcChain.String())
} else {
signerMap[btcChain] = signer
signerMap[btcChain.ChainId] = signer
}
}

Expand All @@ -100,8 +99,8 @@ func CreateChainClientMap(
dbpath string,
loggers clientcommon.ClientLogger,
ts *metrics.TelemetryServer,
) (map[pkg.Chain]interfaces.ChainClient, error) {
clientMap := make(map[pkg.Chain]interfaces.ChainClient)
) (map[int64]interfaces.ChainClient, error) {
clientMap := make(map[int64]interfaces.ChainClient)
// EVM clients
for _, evmConfig := range appContext.Config().GetAllEVMConfigs() {
if evmConfig.Chain.IsZetaChain() {
Expand All @@ -120,17 +119,17 @@ func CreateChainClientMap(
loggers.Std.Error().Err(err).Msgf("NewEVMChainClient error for chain %s", evmConfig.Chain.String())
continue
}
clientMap[evmConfig.Chain] = co
clientMap[evmConfig.Chain.ChainId] = co
}
// BTC client
btcChain, _, enabled := appContext.GetBTCChainAndConfig()
btcChain, btcConfig, enabled := appContext.GetBTCChainAndConfig()
if enabled {
co, err := bitcoin.NewBitcoinClient(appContext, btcChain, bridge, tss, dbpath, loggers, ts)
co, err := bitcoin.NewBitcoinClient(appContext, btcChain, bridge, tss, dbpath, loggers, btcConfig, ts)
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewBitcoinClient error for chain %s", btcChain.String())

} else {
clientMap[btcChain] = co
clientMap[btcChain.ChainId] = co
}
}

Expand Down
71 changes: 71 additions & 0 deletions cmd/zetatool/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package config

import (
"encoding/json"

"github.com/spf13/afero"
)

var AppFs = afero.NewOsFs()

const (
FlagConfig = "config"
defaultCfgFileName = "zetatool_config.json"
ZetaURL = "127.0.0.1:1317"
BtcExplorerURL = "https://blockstream.info/api/"
EthRPCURL = "https://ethereum-rpc.publicnode.com"
ConnectorAddress = "0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a"
CustodyAddress = "0x0000030Ec64DF25301d8414eE5a29588C4B0dE10"
)

// Config is a struct the defines the configuration fields used by zetatool
type Config struct {
ZetaURL string
BtcExplorerURL string
EthRPCURL string
EtherscanAPIkey string
ConnectorAddress string
CustodyAddress string
}

func DefaultConfig() *Config {
return &Config{
ZetaURL: ZetaURL,
BtcExplorerURL: BtcExplorerURL,
EthRPCURL: EthRPCURL,
ConnectorAddress: ConnectorAddress,
CustodyAddress: CustodyAddress,
}
}

func (c *Config) Save() error {
file, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}
err = afero.WriteFile(AppFs, defaultCfgFileName, file, 0600)
return err
}

func (c *Config) Read(filename string) error {
data, err := afero.ReadFile(AppFs, filename)
if err != nil {
return err
}
err = json.Unmarshal(data, c)
return err
}

func GetConfig(filename string) (*Config, error) {
//Check if cfgFile is empty, if so return default Config and save to file
if filename == "" {
cfg := DefaultConfig()
err := cfg.Save()
return cfg, err
}

//if file is specified, open file and return struct
cfg := &Config{}
err := cfg.Read(filename)
return cfg, err
}
77 changes: 77 additions & 0 deletions cmd/zetatool/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package config

import (
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/require"
)

func TestDefaultConfig(t *testing.T) {
cfg := DefaultConfig()
require.Equal(t, cfg.EthRPCURL, EthRPCURL)
require.Equal(t, cfg.ZetaURL, ZetaURL)
require.Equal(t, cfg.BtcExplorerURL, BtcExplorerURL)
require.Equal(t, cfg.ConnectorAddress, ConnectorAddress)
require.Equal(t, cfg.CustodyAddress, CustodyAddress)
}

func TestGetConfig(t *testing.T) {
AppFs = afero.NewMemMapFs()
defaultCfg := DefaultConfig()

t.Run("No config file specified", func(t *testing.T) {
cfg, err := GetConfig("")
require.NoError(t, err)
require.Equal(t, cfg, defaultCfg)

exists, err := afero.Exists(AppFs, defaultCfgFileName)
require.NoError(t, err)
require.True(t, exists)
})

t.Run("config file specified", func(t *testing.T) {
cfg, err := GetConfig(defaultCfgFileName)
require.NoError(t, err)
require.Equal(t, cfg, defaultCfg)
})
}

func TestConfig_Read(t *testing.T) {
AppFs = afero.NewMemMapFs()
cfg, err := GetConfig("")
require.NoError(t, err)

t.Run("read existing file", func(t *testing.T) {
c := &Config{}
err := c.Read(defaultCfgFileName)
require.NoError(t, err)
require.Equal(t, c, cfg)
})

t.Run("read non-existent file", func(t *testing.T) {
err := AppFs.Remove(defaultCfgFileName)
require.NoError(t, err)
c := &Config{}
err = c.Read(defaultCfgFileName)
require.ErrorContains(t, err, "file does not exist")
require.NotEqual(t, c, cfg)
})
}

func TestConfig_Save(t *testing.T) {
AppFs = afero.NewMemMapFs()
cfg := DefaultConfig()
cfg.EtherscanAPIkey = "DIFFERENTAPIKEY"

t.Run("save modified cfg", func(t *testing.T) {
err := cfg.Save()
require.NoError(t, err)

newCfg, err := GetConfig(defaultCfgFileName)
require.NoError(t, err)
require.Equal(t, cfg, newCfg)
})

// Should test invalid json encoding but currently not able to without interface
}
Loading

0 comments on commit 0155866

Please sign in to comment.