rosetta-lbry/services/mempool_service_test.go

79 lines
2.2 KiB
Go
Raw Normal View History

2020-09-16 21:03:14 +02:00
// Copyright 2020 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package services
import (
"context"
"testing"
2020-10-16 20:04:55 +02:00
"github.com/coinbase/rosetta-bitcoin/configuration"
2020-09-19 03:04:37 +02:00
mocks "github.com/coinbase/rosetta-bitcoin/mocks/services"
"github.com/coinbase/rosetta-sdk-go/types"
2020-09-16 21:03:14 +02:00
"github.com/stretchr/testify/assert"
)
2020-10-16 20:04:55 +02:00
func TestMempoolEndpoints_Offline(t *testing.T) {
cfg := &configuration.Configuration{
Mode: configuration.Offline,
}
2020-09-19 03:04:37 +02:00
mockClient := &mocks.Client{}
2020-10-16 20:04:55 +02:00
servicer := NewMempoolAPIService(cfg, mockClient)
ctx := context.Background()
mem, err := servicer.Mempool(ctx, nil)
assert.Nil(t, mem)
assert.Equal(t, ErrUnavailableOffline.Code, err.Code)
assert.Equal(t, ErrUnavailableOffline.Message, err.Message)
memTransaction, err := servicer.MempoolTransaction(ctx, nil)
assert.Nil(t, memTransaction)
assert.Equal(t, ErrUnavailableOffline.Code, err.Code)
assert.Equal(t, ErrUnavailableOffline.Message, err.Message)
mockClient.AssertExpectations(t)
}
func TestMempoolEndpoints_Online(t *testing.T) {
cfg := &configuration.Configuration{
Mode: configuration.Online,
}
mockClient := &mocks.Client{}
servicer := NewMempoolAPIService(cfg, mockClient)
2020-09-16 21:03:14 +02:00
ctx := context.Background()
2020-09-19 03:04:37 +02:00
mockClient.On("RawMempool", ctx).Return([]string{
"tx1",
"tx2",
}, nil)
2020-09-16 21:03:14 +02:00
mem, err := servicer.Mempool(ctx, nil)
2020-09-19 03:04:37 +02:00
assert.Nil(t, err)
assert.Equal(t, &types.MempoolResponse{
TransactionIdentifiers: []*types.TransactionIdentifier{
{
Hash: "tx1",
},
{
Hash: "tx2",
},
},
}, mem)
2020-09-16 21:03:14 +02:00
memTransaction, err := servicer.MempoolTransaction(ctx, nil)
assert.Nil(t, memTransaction)
assert.Equal(t, ErrUnimplemented.Code, err.Code)
assert.Equal(t, ErrUnimplemented.Message, err.Message)
2020-09-19 03:04:37 +02:00
mockClient.AssertExpectations(t)
2020-09-16 21:03:14 +02:00
}