diff --git a/internal/blockchain/tezos/tezos_test.go b/internal/blockchain/tezos/tezos_test.go index 897ce9174b..a66dc61071 100644 --- a/internal/blockchain/tezos/tezos_test.go +++ b/internal/blockchain/tezos/tezos_test.go @@ -1882,3 +1882,17 @@ func TestSubmitBatchPin(t *testing.T) { err := tz.SubmitBatchPin(context.Background(), "", "", singer, nil, location) assert.NoError(t, err) } + +func TestStartNamespace(t *testing.T) { + tz, cancel := newTestTezos() + defer cancel() + err := tz.StartNamespace(context.Background(), "ns1") + assert.NoError(t, err) +} + +func TestStopNamespace(t *testing.T) { + tz, cancel := newTestTezos() + defer cancel() + err := tz.StopNamespace(context.Background(), "ns1") + assert.NoError(t, err) +} diff --git a/internal/tokens/fftokens/fftokens.go b/internal/tokens/fftokens/fftokens.go index 0a789a2ab0..0864ffdccb 100644 --- a/internal/tokens/fftokens/fftokens.go +++ b/internal/tokens/fftokens/fftokens.go @@ -316,9 +316,11 @@ func (ft *FFTokens) Init(ctx context.Context, cancelCtx context.CancelFunc, name } func (ft *FFTokens) StartNamespace(ctx context.Context, namespace string) (err error) { - ft.wsconn[namespace], err = wsclient.New(ctx, ft.wsConfig, nil, nil) - if err != nil { - return err + if ft.wsconn[namespace] == nil { + ft.wsconn[namespace], err = wsclient.New(ctx, ft.wsConfig, nil, nil) + if err != nil { + return err + } } err = ft.wsconn[namespace].Connect() diff --git a/internal/tokens/fftokens/fftokens_test.go b/internal/tokens/fftokens/fftokens_test.go index e4ecb0b40d..d5abeeb4b5 100644 --- a/internal/tokens/fftokens/fftokens_test.go +++ b/internal/tokens/fftokens/fftokens_test.go @@ -138,19 +138,6 @@ func TestStopNamespace(t *testing.T) { assert.Nil(t, h.wsconn["ns1"]) } -func TestInitBackgroundStart1(t *testing.T) { - coreconfig.Reset() - h := &FFTokens{} - h.InitConfig(ffTokensConfig) - - ffTokensConfig.AddKnownKey(ffresty.HTTPConfigURL, "http://localhost:8080") - ffTokensConfig.Set(FFTBackgroundStart, true) - - ctx, cancelCtx := context.WithCancel(context.Background()) - err := h.Init(ctx, cancelCtx, "testtokens", ffTokensConfig) - assert.NoError(t, err) -} - func TestInitBadTLS(t *testing.T) { coreconfig.Reset() h := &FFTokens{} @@ -1605,6 +1592,21 @@ func TestEventLoopSendClosed(t *testing.T) { assert.True(t, called) } +func TestStartNamespaceSendClosed(t *testing.T) { + wsm := &wsmocks.WSClient{} + h := &FFTokens{ + ctx: context.Background(), + wsconn: map[string]wsclient.WSClient{"ns1": wsm}, + retry: &retry.Retry{}, + } + // r := make(chan []byte, 1) + // r <- []byte(`{"id":"1"}`) // ignored but ackeåd + wsm.On("Connect").Return(nil) + wsm.On("Send", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) + err := h.StartNamespace(context.Background(), "ns1") + assert.Regexp(t, "pop", err) +} + func TestEventLoopClosedContext(t *testing.T) { wsm := &wsmocks.WSClient{} ctx, cancel := context.WithCancel(context.Background())