Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Mar 14, 2024
1 parent d3125e7 commit a7b7209
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewDefaultSubscriber(cfg config.NeutronQueryRelayerConfig, logRegistry *nlo
watchedMsgTypes = append(watchedMsgTypes, neutrontypes.InterchainQueryTypeTX)
}

subscriber, err := relaysubscriber.NewSubscriber(
sub, err := relaysubscriber.NewSubscriber(
&subscriber.SubscriberConfig{
RPCAddress: cfg.NeutronChain.RPCAddr,
RESTAddress: cfg.NeutronChain.RESTAddr,
Expand All @@ -77,7 +77,7 @@ func NewDefaultSubscriber(cfg config.NeutronQueryRelayerConfig, logRegistry *nlo
return nil, fmt.Errorf("failed to create a NewSubscriber: %s", err)
}

return subscriber, nil
return sub, nil
}

func NewDefaultTxSubmitChecker(cfg config.NeutronQueryRelayerConfig, logRegistry *nlogger.Registry,
Expand Down
40 changes: 40 additions & 0 deletions internal/subscriber/subscriber_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package subscriber_test

import (
"context"
"github.com/neutron-org/neutron-query-relayer/internal/subscriber"
neutrontypes "github.com/neutron-org/neutron/x/interchainqueries/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/stretchr/testify/assert"
"testing"
)

func TestDoneShouldEndSubscribe(t *testing.T) {
cfgLogger := zap.NewProductionConfig()
logger, err := cfgLogger.Build()
require.NoError(t, err)

queriesTasksQueue := make(chan neutrontypes.RegisteredQuery, 100)
cfg := subscriber.SubscriberConfig{
RPCAddress: "",
RESTAddress: "",
Timeout: 0,
ConnectionID: "",
WatchedTypes: nil,
Registry: nil,
}
s, err := subscriber.NewSubscriber(&cfg, logger)
assert.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())

go func() {
// should terminate Subscribe() function
cancel()
}()

err = s.Subscribe(ctx, queriesTasksQueue)
assert.Equal(t, err, nil)
}

0 comments on commit a7b7209

Please sign in to comment.