From 51d7cf4aba42a40c2714abbd486dee0bf138ae55 Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 29 Feb 2024 14:50:04 +0100 Subject: [PATCH] Add tests for creating new core context with config chain params --- .../core_context/zeta_core_context_test.go | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/zetaclient/core_context/zeta_core_context_test.go b/zetaclient/core_context/zeta_core_context_test.go index a0705f3538..fdf57ce881 100644 --- a/zetaclient/core_context/zeta_core_context_test.go +++ b/zetaclient/core_context/zeta_core_context_test.go @@ -14,10 +14,10 @@ func TestNewZetaCoreContext(t *testing.T) { testCfg := config.NewConfig() zetaContext := NewZetaCoreContext(testCfg) - require.NotNil(t, zetaContext) - keyGen, keyGenFound := zetaContext.GetKeygen() + // assert keygen + keyGen, keyGenFound := zetaContext.GetKeygen() require.False(t, keyGenFound) require.Equal(t, observertypes.Keygen{}, keyGen) @@ -37,4 +37,65 @@ func TestNewZetaCoreContext(t *testing.T) { allEVMChainParams := zetaContext.GetAllEVMChainParams() require.Empty(t, allEVMChainParams) }) + + t.Run("should create new zeta core context with config containing evm chain params", func(t *testing.T) { + testCfg := config.NewConfig() + testCfg.EVMChainConfigs = map[int64]*config.EVMConfig{ + 1: { + Chain: common.Chain{ + ChainName: 1, + ChainId: 1, + }, + }, + 2: { + Chain: common.Chain{ + ChainName: 2, + ChainId: 2, + }, + }, + } + zetaContext := NewZetaCoreContext(testCfg) + require.NotNil(t, zetaContext) + + // assert evm chain params + allEVMChainParams := zetaContext.GetAllEVMChainParams() + require.Equal(t, 2, len(allEVMChainParams)) + require.Equal(t, &observertypes.ChainParams{}, allEVMChainParams[1]) + require.Equal(t, &observertypes.ChainParams{}, allEVMChainParams[2]) + + evmChainParams1, found := zetaContext.GetEVMChainParams(1) + require.True(t, found) + require.Equal(t, &observertypes.ChainParams{}, evmChainParams1) + + evmChainParams2, found := zetaContext.GetEVMChainParams(2) + require.True(t, found) + require.Equal(t, &observertypes.ChainParams{}, evmChainParams2) + }) + + t.Run("should create new zeta core context with config containing btc config", func(t *testing.T) { + testCfg := config.NewConfig() + testCfg.BitcoinConfig = &config.BTCConfig{ + RPCUsername: "test username", + RPCPassword: "test password", + RPCHost: "test host", + RPCParams: "test params", + } + zetaContext := NewZetaCoreContext(testCfg) + require.NotNil(t, zetaContext) + + // assert btc chain params panic because chain params are not yet updated + assertPanic(t, func() { + zetaContext.GetBTCChainParams() + }, "BTCChain is missing for chainID 0") + }) +} + +func assertPanic(t *testing.T, f func(), errorLog string) { + defer func() { + r := recover() + if r != nil { + require.Contains(t, r, errorLog) + } + }() + f() }