From 0ee1e6046c00eda7be9b8607f035463450b0ecd9 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Fri, 21 Jun 2024 15:58:09 -0500 Subject: [PATCH] update changelog PR number and added unit test for Stop() method --- changelog.md | 2 +- zetaclient/chains/base/observer.go | 8 +++++--- zetaclient/chains/base/observer_test.go | 11 +++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 4c8998411a..c601f74028 100644 --- a/changelog.md +++ b/changelog.md @@ -51,7 +51,7 @@ * [2340](https://github.com/zeta-chain/node/pull/2340) - add ValidateInbound method for cctx orchestrator * [2344](https://github.com/zeta-chain/node/pull/2344) - group common data of EVM/Bitcoin signer and observer using base structs * [2357](https://github.com/zeta-chain/node/pull/2357) - integrate base Signer structure into EVM/Bitcoin Signer -* [2359](https://github.com/zeta-chain/node/pull/2357) - integrate base Observer structure into EVM/Bitcoin Observer +* [2359](https://github.com/zeta-chain/node/pull/2359) - integrate base Observer structure into EVM/Bitcoin Observer ### Tests diff --git a/zetaclient/chains/base/observer.go b/zetaclient/chains/base/observer.go index 6bf2ec9e6a..2716637656 100644 --- a/zetaclient/chains/base/observer.go +++ b/zetaclient/chains/base/observer.go @@ -135,9 +135,11 @@ func (ob *Observer) Stop() { close(ob.stop) // close database - err := ob.CloseDB() - if err != nil { - ob.Logger().Chain.Error().Err(err).Msgf("CloseDB failed for chain %d", ob.Chain().ChainId) + if ob.db != nil { + err := ob.CloseDB() + if err != nil { + ob.Logger().Chain.Error().Err(err).Msgf("CloseDB failed for chain %d", ob.Chain().ChainId) + } } ob.Logger().Chain.Info().Msgf("observer stopped for chain %d", ob.Chain().ChainId) } diff --git a/zetaclient/chains/base/observer_test.go b/zetaclient/chains/base/observer_test.go index 5ba2044505..065283d25d 100644 --- a/zetaclient/chains/base/observer_test.go +++ b/zetaclient/chains/base/observer_test.go @@ -132,6 +132,17 @@ func TestNewObserver(t *testing.T) { } } +func TestStop(t *testing.T) { + t.Run("should be able to stop observer", func(t *testing.T) { + // create observer and initialize db + ob := createObserver(t) + ob.OpenDB(sample.CreateTempDir(t), "") + + // stop observer + ob.Stop() + }) +} + func TestObserverGetterAndSetter(t *testing.T) { t.Run("should be able to update chain", func(t *testing.T) { ob := createObserver(t)