cached gateway routing
This commit is contained in:
@@ -2,11 +2,13 @@ package wallet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/gateway/chain/internal/service/gateway/shared"
|
||||
"github.com/tech/sendico/gateway/chain/storage/model"
|
||||
"github.com/tech/sendico/pkg/api/routers/gsresponse"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
|
||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
@@ -45,8 +47,15 @@ func (c *listManagedWalletsCommand) Execute(ctx context.Context, req *chainv1.Li
|
||||
|
||||
result, err := c.deps.Storage.Wallets().List(ctx, filter)
|
||||
if err != nil {
|
||||
c.deps.Logger.Warn("Storage list failed", zap.Error(err))
|
||||
return gsresponse.Auto[chainv1.ListManagedWalletsResponse](c.deps.Logger, mservice.ChainGateway, err)
|
||||
if errors.Is(err, merrors.ErrNoData) {
|
||||
result = &model.ManagedWalletList{}
|
||||
} else {
|
||||
c.deps.Logger.Warn("Storage list failed", zap.Error(err))
|
||||
return gsresponse.Auto[chainv1.ListManagedWalletsResponse](c.deps.Logger, mservice.ChainGateway, err)
|
||||
}
|
||||
}
|
||||
if result == nil {
|
||||
result = &model.ManagedWalletList{}
|
||||
}
|
||||
|
||||
protoWallets := make([]*chainv1.ManagedWallet, 0, len(result.Items))
|
||||
|
||||
@@ -127,6 +127,20 @@ func TestListAccounts_OrganizationRefFilters(t *testing.T) {
|
||||
require.Equal(t, "org-1", orgField.GetStringValue())
|
||||
}
|
||||
|
||||
func TestListAccounts_NoWalletsNotError(t *testing.T) {
|
||||
baseRepo := newInMemoryRepository()
|
||||
svc := newTestServiceWithRepository(t, &walletsNoDataRepository{inMemoryRepository: baseRepo})
|
||||
ctx := context.Background()
|
||||
|
||||
resp, err := svc.ListAccounts(ctx, &connectorv1.ListAccountsRequest{
|
||||
OrganizationRef: "org-1",
|
||||
Kind: connectorv1.AccountKind_CHAIN_MANAGED_WALLET,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
require.Empty(t, resp.GetAccounts())
|
||||
}
|
||||
|
||||
func TestSubmitTransfer_ManagedDestination(t *testing.T) {
|
||||
svc, repo := newTestService(t)
|
||||
ctx := context.Background()
|
||||
@@ -253,6 +267,22 @@ func newInMemoryRepository() *inMemoryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
type walletsNoDataRepository struct {
|
||||
*inMemoryRepository
|
||||
}
|
||||
|
||||
func (r *walletsNoDataRepository) Wallets() storage.WalletsStore {
|
||||
return &walletsNoDataStore{WalletsStore: r.inMemoryRepository.wallets}
|
||||
}
|
||||
|
||||
type walletsNoDataStore struct {
|
||||
storage.WalletsStore
|
||||
}
|
||||
|
||||
func (w *walletsNoDataStore) List(context.Context, model.ManagedWalletFilter) (*model.ManagedWalletList, error) {
|
||||
return nil, merrors.NoData("no wallets")
|
||||
}
|
||||
|
||||
func (r *inMemoryRepository) Ping(context.Context) error { return nil }
|
||||
func (r *inMemoryRepository) Wallets() storage.WalletsStore { return r.wallets }
|
||||
func (r *inMemoryRepository) Transfers() storage.TransfersStore { return r.transfers }
|
||||
@@ -625,6 +655,11 @@ func sanitizeLimit(requested int32, def, max int64) int64 {
|
||||
|
||||
func newTestService(t *testing.T) (*Service, *inMemoryRepository) {
|
||||
repo := newInMemoryRepository()
|
||||
svc := newTestServiceWithRepository(t, repo)
|
||||
return svc, repo
|
||||
}
|
||||
|
||||
func newTestServiceWithRepository(t *testing.T, repo storage.Repository) *Service {
|
||||
logger := zap.NewNop()
|
||||
networks := []shared.Network{{
|
||||
Name: "ethereum_mainnet",
|
||||
@@ -641,7 +676,7 @@ func newTestService(t *testing.T) (*Service, *inMemoryRepository) {
|
||||
WithServiceWallet(shared.ServiceWallet{Network: "ethereum_mainnet", Address: "0xservice"}),
|
||||
WithDriverRegistry(driverRegistry),
|
||||
)
|
||||
return svc, repo
|
||||
return svc
|
||||
}
|
||||
|
||||
type fakeKeyManager struct{}
|
||||
|
||||
Reference in New Issue
Block a user