Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Apr 10, 2024
1 parent 53331fe commit fab7dce
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions zetaclient/core_context/zeta_core_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/testutil/sample"
lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
clientcommon "github.com/zeta-chain/zetacore/zetaclient/common"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand All @@ -26,7 +27,9 @@ func assertPanic(t *testing.T, f func(), errorLog string) {
func getTestCoreContext(
evmChain chains.Chain,
evmChainParams *observertypes.ChainParams,
ccFlags observertypes.CrosschainFlags) *corecontext.ZetaCoreContext {
ccFlags observertypes.CrosschainFlags,
verificationFlags lightclienttypes.VerificationFlags,
) *corecontext.ZetaCoreContext {
// create config
cfg := config.NewConfig()
cfg.EVMChainConfigs[evmChain.ChainId] = config.EVMConfig{
Expand All @@ -45,6 +48,7 @@ func getTestCoreContext(
nil,
"",
ccFlags,
verificationFlags,
true,
zerolog.Logger{},
)
Expand Down Expand Up @@ -318,27 +322,28 @@ func TestIsOutboundObservationEnabled(t *testing.T) {
// create test chain params and flags
evmChain := chains.EthChain()
ccFlags := *sample.CrosschainFlags()
verificationFlags := sample.VerificationFlags()
chainParams := &observertypes.ChainParams{
ChainId: evmChain.ChainId,
IsSupported: true,
}

t.Run("should return true if chain is supported and outbound flag is enabled", func(t *testing.T) {
coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags)
coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags, verificationFlags)
require.True(t, corecontext.IsOutboundObservationEnabled(coreCTX, *chainParams))
})
t.Run("should return false if chain is not supported yet", func(t *testing.T) {
paramsUnsupported := &observertypes.ChainParams{
ChainId: evmChain.ChainId,
IsSupported: false,
}
coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags)
coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags, verificationFlags)
require.False(t, corecontext.IsOutboundObservationEnabled(coreCTXUnsupported, *paramsUnsupported))
})
t.Run("should return false if outbound flag is disabled", func(t *testing.T) {
flagsDisabled := ccFlags
flagsDisabled.IsOutboundEnabled = false
coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled)
coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled, verificationFlags)
require.False(t, corecontext.IsOutboundObservationEnabled(coreCTXDisabled, *chainParams))
})
}
Expand All @@ -347,27 +352,28 @@ func TestIsInboundObservationEnabled(t *testing.T) {
// create test chain params and flags
evmChain := chains.EthChain()
ccFlags := *sample.CrosschainFlags()
verificationFlags := sample.VerificationFlags()
chainParams := &observertypes.ChainParams{
ChainId: evmChain.ChainId,
IsSupported: true,
}

t.Run("should return true if chain is supported and inbound flag is enabled", func(t *testing.T) {
coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags)
coreCTX := getTestCoreContext(evmChain, chainParams, ccFlags, verificationFlags)
require.True(t, corecontext.IsInboundObservationEnabled(coreCTX, *chainParams))
})
t.Run("should return false if chain is not supported yet", func(t *testing.T) {
paramsUnsupported := &observertypes.ChainParams{
ChainId: evmChain.ChainId,
IsSupported: false,
}
coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags)
coreCTXUnsupported := getTestCoreContext(evmChain, paramsUnsupported, ccFlags, verificationFlags)
require.False(t, corecontext.IsInboundObservationEnabled(coreCTXUnsupported, *paramsUnsupported))
})
t.Run("should return false if inbound flag is disabled", func(t *testing.T) {
flagsDisabled := ccFlags
flagsDisabled.IsInboundEnabled = false
coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled)
coreCTXDisabled := getTestCoreContext(evmChain, chainParams, flagsDisabled, verificationFlags)
require.False(t, corecontext.IsInboundObservationEnabled(coreCTXDisabled, *chainParams))
})
}

0 comments on commit fab7dce

Please sign in to comment.