From 38959c47cd052edbcc14ece7876d0032d42b6074 Mon Sep 17 00:00:00 2001 From: David Echelberger Date: Wed, 20 Oct 2021 20:55:18 -0400 Subject: [PATCH 1/2] tokens-by-id getTokenPoolByNameOrID() and getTokenTransfersByID() Signed-off-by: David Echelberger --- docs/swagger/swagger.yaml | 215 ++++++++++++++++++ .../route_get_token_pool_by_name_or_id.go | 46 ++++ ...route_get_token_pool_by_name_or_id_test.go | 42 ++++ .../route_get_token_transfers_by_id.go | 46 ++++ .../route_get_token_transfers_by_id_test.go | 42 ++++ internal/apiserver/routes.go | 2 + internal/assets/manager.go | 2 + internal/assets/token_pool.go | 24 ++ internal/assets/token_pool_test.go | 69 ++++++ internal/assets/token_transfer.go | 9 + internal/assets/token_transfer_test.go | 24 ++ mocks/assetmocks/manager.go | 149 ++++++++---- 12 files changed, 623 insertions(+), 47 deletions(-) create mode 100644 internal/apiserver/route_get_token_pool_by_name_or_id.go create mode 100644 internal/apiserver/route_get_token_pool_by_name_or_id_test.go create mode 100644 internal/apiserver/route_get_token_transfers_by_id.go create mode 100644 internal/apiserver/route_get_token_transfers_by_id_test.go diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index 760a09548f..62ef454cd7 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -5849,6 +5849,69 @@ paths: description: Success default: description: "" + /namespaces/{ns}/tokens/pools/{nameOrID}: + get: + description: 'TODO: Description' + operationId: getTokenPoolByNameOrID + parameters: + - description: 'TODO: Description' + in: path + name: ns + required: true + schema: + example: default + type: string + - description: 'TODO: Description' + in: path + name: nameOrID + required: true + schema: + type: string + - description: Server-side request timeout (millseconds, or set a custom suffix + like 10s) + in: header + name: Request-Timeout + schema: + default: 120s + type: string + responses: + "200": + content: + application/json: + schema: + properties: + config: + additionalProperties: {} + type: object + connector: + type: string + created: {} + id: {} + key: + type: string + message: {} + name: + type: string + namespace: + type: string + protocolId: + type: string + standard: + type: string + symbol: + type: string + tx: + properties: + id: {} + type: + type: string + type: object + type: + type: string + type: object + description: Success + default: + description: "" /namespaces/{ns}/tokens/transfers: get: description: 'TODO: Description' @@ -5995,6 +6058,158 @@ paths: description: Success default: description: "" + /namespaces/{ns}/tokens/transfers/{transferID}: + get: + description: 'TODO: Description' + operationId: getTokenTransfersByID + parameters: + - description: 'TODO: Description' + in: path + name: ns + required: true + schema: + example: default + type: string + - description: 'TODO: Description' + in: path + name: transferID + required: true + schema: + type: string + - description: Server-side request timeout (millseconds, or set a custom suffix + like 10s) + in: header + name: Request-Timeout + schema: + default: 120s + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: amount + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: connector + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: created + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: from + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: key + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: localid + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: messagehash + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: poolprotocolid + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: protocolid + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: to + schema: + type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: tokenindex + schema: + type: string + - description: Sort field. For multi-field sort use comma separated values (or + multiple query values) with '-' prefix for descending + in: query + name: sort + schema: + type: string + - description: Ascending sort order (overrides all fields in a multi-field sort) + in: query + name: ascending + schema: + type: string + - description: Descending sort order (overrides all fields in a multi-field + sort) + in: query + name: descending + schema: + type: string + - description: 'The number of records to skip (max: 1,000). Unsuitable for bulk + operations' + in: query + name: skip + schema: + type: string + - description: 'The maximum number of records to return (max: 1,000)' + in: query + name: limit + schema: + example: "25" + type: string + - description: Return a total count as well as items (adds extra database processing) + in: query + name: count + schema: + type: string + responses: + "200": + content: + application/json: + schema: + items: + properties: + amount: {} + connector: + type: string + created: {} + from: + type: string + key: + type: string + localId: {} + messageHash: {} + poolProtocolId: + type: string + protocolId: + type: string + to: + type: string + tokenIndex: + type: string + tx: + properties: + id: {} + type: + type: string + type: object + type: + type: string + type: object + type: array + description: Success + default: + description: "" /namespaces/{ns}/transactions: get: description: 'TODO: Description' diff --git a/internal/apiserver/route_get_token_pool_by_name_or_id.go b/internal/apiserver/route_get_token_pool_by_name_or_id.go new file mode 100644 index 0000000000..1fcddc7926 --- /dev/null +++ b/internal/apiserver/route_get_token_pool_by_name_or_id.go @@ -0,0 +1,46 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// 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 apiserver + +import ( + "net/http" + + "github.com/hyperledger/firefly/internal/config" + "github.com/hyperledger/firefly/internal/i18n" + "github.com/hyperledger/firefly/internal/oapispec" + "github.com/hyperledger/firefly/pkg/fftypes" +) + +var getTokenPoolByNameOrID = &oapispec.Route{ + Name: "getTokenPoolByNameOrID", + Path: "namespaces/{ns}/tokens/pools/{nameOrID}", + Method: http.MethodGet, + PathParams: []*oapispec.PathParam{ + {Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD}, + {Name: "nameOrID", Description: i18n.MsgTBD}, + }, + QueryParams: nil, + FilterFactory: nil, + Description: i18n.MsgTBD, + JSONInputValue: nil, + JSONOutputValue: func() interface{} { return &fftypes.TokenPool{} }, + JSONOutputCodes: []int{http.StatusOK}, + JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { + output, err = r.Or.Assets().GetTokenPoolByNameOrID(r.Ctx, r.PP["ns"], r.PP["nameOrID"]) + return output, err + }, +} diff --git a/internal/apiserver/route_get_token_pool_by_name_or_id_test.go b/internal/apiserver/route_get_token_pool_by_name_or_id_test.go new file mode 100644 index 0000000000..eea8b8a4fe --- /dev/null +++ b/internal/apiserver/route_get_token_pool_by_name_or_id_test.go @@ -0,0 +1,42 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// 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 apiserver + +import ( + "net/http/httptest" + "testing" + + "github.com/hyperledger/firefly/mocks/assetmocks" + "github.com/hyperledger/firefly/pkg/fftypes" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestGetTokenPoolByNameOrID(t *testing.T) { + o, r := newTestAPIServer() + mam := &assetmocks.Manager{} + o.On("Assets").Return(mam) + req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/tokens/pools/abc", nil) + req.Header.Set("Content-Type", "application/json; charset=utf-8") + res := httptest.NewRecorder() + + mam.On("GetTokenPoolByNameOrID", mock.Anything, "ns1", "abc"). + Return(&fftypes.TokenPool{}, nil) + r.ServeHTTP(res, req) + + assert.Equal(t, 200, res.Result().StatusCode) +} diff --git a/internal/apiserver/route_get_token_transfers_by_id.go b/internal/apiserver/route_get_token_transfers_by_id.go new file mode 100644 index 0000000000..40f3895c29 --- /dev/null +++ b/internal/apiserver/route_get_token_transfers_by_id.go @@ -0,0 +1,46 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// 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 apiserver + +import ( + "net/http" + + "github.com/hyperledger/firefly/internal/config" + "github.com/hyperledger/firefly/internal/i18n" + "github.com/hyperledger/firefly/internal/oapispec" + "github.com/hyperledger/firefly/pkg/database" + "github.com/hyperledger/firefly/pkg/fftypes" +) + +var getTokenTransfersByID = &oapispec.Route{ + Name: "getTokenTransfersByID", + Path: "namespaces/{ns}/tokens/transfers/{transferID}", + Method: http.MethodGet, + PathParams: []*oapispec.PathParam{ + {Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD}, + {Name: "transferID", Description: i18n.MsgTBD}, + }, + QueryParams: nil, + FilterFactory: database.TokenTransferQueryFactory, + Description: i18n.MsgTBD, + JSONInputValue: nil, + JSONOutputValue: func() interface{} { return []*fftypes.TokenTransfer{} }, + JSONOutputCodes: []int{http.StatusOK}, + JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { + return filterResult(r.Or.Assets().GetTokenTransfersByID(r.Ctx, r.PP["ns"], r.PP["transferID"], r.Filter)) + }, +} diff --git a/internal/apiserver/route_get_token_transfers_by_id_test.go b/internal/apiserver/route_get_token_transfers_by_id_test.go new file mode 100644 index 0000000000..b32cad37db --- /dev/null +++ b/internal/apiserver/route_get_token_transfers_by_id_test.go @@ -0,0 +1,42 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// 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 apiserver + +import ( + "net/http/httptest" + "testing" + + "github.com/hyperledger/firefly/mocks/assetmocks" + "github.com/hyperledger/firefly/pkg/fftypes" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestGetTokenTransfersByID(t *testing.T) { + o, r := newTestAPIServer() + mam := &assetmocks.Manager{} + o.On("Assets").Return(mam) + req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/tokens/transfers/id1", nil) + req.Header.Set("Content-Type", "application/json; charset=utf-8") + res := httptest.NewRecorder() + + mam.On("GetTokenTransfersByID", mock.Anything, "ns1", "id1", mock.Anything). + Return([]*fftypes.TokenTransfer{}, nil, nil) + r.ServeHTTP(res, req) + + assert.Equal(t, 200, res.Result().StatusCode) +} diff --git a/internal/apiserver/routes.go b/internal/apiserver/routes.go index 1ba4f56692..67071fdef5 100644 --- a/internal/apiserver/routes.go +++ b/internal/apiserver/routes.go @@ -80,10 +80,12 @@ var routes = []*oapispec.Route{ postTokenPool, getTokenPools, getTokenPoolsByType, + getTokenPoolByNameOrID, getTokenPoolByName, getTokenAccounts, getTokenAccountsByPool, getTokenTransfers, + getTokenTransfersByID, getTokenTransfersByPool, postTokenMint, postTokenBurn, diff --git a/internal/assets/manager.go b/internal/assets/manager.go index 94e86afc97..4114129fea 100644 --- a/internal/assets/manager.go +++ b/internal/assets/manager.go @@ -39,10 +39,12 @@ type Manager interface { GetTokenPools(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenPool, *database.FilterResult, error) GetTokenPoolsByType(ctx context.Context, ns, connector string, filter database.AndFilter) ([]*fftypes.TokenPool, *database.FilterResult, error) GetTokenPool(ctx context.Context, ns, connector, poolName string) (*fftypes.TokenPool, error) + GetTokenPoolByNameOrID(ctx context.Context, ns string, poolNameOrID string) (*fftypes.TokenPool, error) ValidateTokenPoolTx(ctx context.Context, pool *fftypes.TokenPool, protocolTxID string) error GetTokenAccounts(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) GetTokenAccountsByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) GetTokenTransfers(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) + GetTokenTransfersByID(ctx context.Context, ns, id string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) GetTokenTransfersByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) NewTransfer(ns, connector, poolName string, transfer *fftypes.TokenTransferInput) sysmessaging.MessageSender MintTokens(ctx context.Context, ns, connector, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) diff --git a/internal/assets/token_pool.go b/internal/assets/token_pool.go index d16eb442a5..9425ffe81f 100644 --- a/internal/assets/token_pool.go +++ b/internal/assets/token_pool.go @@ -157,6 +157,30 @@ func (am *assetManager) GetTokenPool(ctx context.Context, ns, connector, poolNam return pool, nil } +func (am *assetManager) GetTokenPoolByNameOrID(ctx context.Context, ns, poolNameOrID string) (*fftypes.TokenPool, error) { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + return nil, err + } + + var pool *fftypes.TokenPool + + poolID, err := fftypes.ParseUUID(ctx, poolNameOrID) + if err != nil { + if err := fftypes.ValidateFFNameField(ctx, poolNameOrID, "name"); err != nil { + return nil, err + } + if pool, err = am.database.GetTokenPool(ctx, ns, poolNameOrID); err != nil { + return nil, err + } + } else if pool, err = am.database.GetTokenPoolByID(ctx, poolID); err != nil { + return nil, err + } + if pool == nil { + return nil, i18n.NewError(ctx, i18n.Msg404NotFound) + } + return pool, nil +} + func (am *assetManager) ValidateTokenPoolTx(ctx context.Context, pool *fftypes.TokenPool, protocolTxID string) error { // TODO: validate that the given token pool was created with the given protocolTxId return nil diff --git a/internal/assets/token_pool_test.go b/internal/assets/token_pool_test.go index 9c1a0a560d..08826a12d9 100644 --- a/internal/assets/token_pool_test.go +++ b/internal/assets/token_pool_test.go @@ -202,6 +202,75 @@ func TestGetTokenPoolBadName(t *testing.T) { assert.Regexp(t, "FF10131", err) } +func TestGetTokenPoolByID(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + u := fftypes.NewUUID() + mdi := am.database.(*databasemocks.Plugin) + mdi.On("GetTokenPoolByID", context.Background(), u).Return(&fftypes.TokenPool{}, nil) + _, err := am.GetTokenPoolByNameOrID(context.Background(), "ns1", u.String()) + assert.NoError(t, err) +} + +func TestGetTokenPoolByIDBadNamespace(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + _, err := am.GetTokenPoolByNameOrID(context.Background(), "", "") + assert.Regexp(t, "FF10131", err) +} + +func TestGetTokenPoolByIDBadID(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + u := fftypes.NewUUID() + mdi := am.database.(*databasemocks.Plugin) + mdi.On("GetTokenPoolByID", context.Background(), u).Return(nil, fmt.Errorf("pop")) + _, err := am.GetTokenPoolByNameOrID(context.Background(), "ns1", u.String()) + assert.EqualError(t, err, "pop") +} + +func TestGetTokenPoolByIDNilPool(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + u := fftypes.NewUUID() + mdi := am.database.(*databasemocks.Plugin) + mdi.On("GetTokenPoolByID", context.Background(), u).Return(nil, nil) + _, err := am.GetTokenPoolByNameOrID(context.Background(), "ns1", u.String()) + assert.Regexp(t, "FF10109", err) +} + +func TestGetTokenPoolByName(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + mdi := am.database.(*databasemocks.Plugin) + mdi.On("GetTokenPool", context.Background(), "ns1", "abc").Return(&fftypes.TokenPool{}, nil) + _, err := am.GetTokenPoolByNameOrID(context.Background(), "ns1", "abc") + assert.NoError(t, err) +} + +func TestGetTokenPoolByNameBadName(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + _, err := am.GetTokenPoolByNameOrID(context.Background(), "ns1", "") + assert.Regexp(t, "FF10131", err) +} + +func TestGetTokenPoolByNameNilPool(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + mdi := am.database.(*databasemocks.Plugin) + mdi.On("GetTokenPool", context.Background(), "ns1", "abc").Return(nil, fmt.Errorf("pop")) + _, err := am.GetTokenPoolByNameOrID(context.Background(), "ns1", "abc") + assert.EqualError(t, err, "pop") +} + func TestGetTokenPools(t *testing.T) { am, cancel := newTestAssets(t) defer cancel() diff --git a/internal/assets/token_transfer.go b/internal/assets/token_transfer.go index 51758a70e5..81b5857eba 100644 --- a/internal/assets/token_transfer.go +++ b/internal/assets/token_transfer.go @@ -37,6 +37,15 @@ func (am *assetManager) GetTokenTransfers(ctx context.Context, ns string, filter return am.database.GetTokenTransfers(ctx, filter) } +func (am *assetManager) GetTokenTransfersByID(ctx context.Context, ns, id string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { + transferID, err := fftypes.ParseUUID(ctx, id) + if err != nil { + return nil, nil, err + } + + return am.database.GetTokenTransfers(ctx, filter.Condition(filter.Builder().Eq("localid", transferID))) +} + func (am *assetManager) GetTokenTransfersByPool(ctx context.Context, ns, connector, name string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { pool, err := am.GetTokenPool(ctx, ns, connector, name) if err != nil { diff --git a/internal/assets/token_transfer_test.go b/internal/assets/token_transfer_test.go index 543481bc52..acc0cd6b4e 100644 --- a/internal/assets/token_transfer_test.go +++ b/internal/assets/token_transfer_test.go @@ -47,6 +47,30 @@ func TestGetTokenTransfers(t *testing.T) { assert.NoError(t, err) } +func TestGetTokenTransfersByID(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + u := fftypes.NewUUID() + mdi := am.database.(*databasemocks.Plugin) + fb := database.TokenTransferQueryFactory.NewFilter(context.Background()) + f := fb.And(fb.Eq("localid", u)) + mdi.On("GetTokenTransfers", context.Background(), f).Return([]*fftypes.TokenTransfer{}, nil, nil) + _, _, err := am.GetTokenTransfersByID(context.Background(), "ns1", u.String(), f) + assert.NoError(t, err) +} + +func TestGetTokenTransfersByIDBadID(t *testing.T) { + am, cancel := newTestAssets(t) + defer cancel() + + u := fftypes.NewUUID() + fb := database.TokenTransferQueryFactory.NewFilter(context.Background()) + f := fb.And(fb.Eq("localid", u)) + _, _, err := am.GetTokenTransfersByID(context.Background(), "ns1", "badUUID", f) + assert.Regexp(t, "FF10142", err) +} + func TestGetTokenTransfersByPool(t *testing.T) { am, cancel := newTestAssets(t) defer cancel() diff --git a/mocks/assetmocks/manager.go b/mocks/assetmocks/manager.go index 564d2e649c..6ab1162da3 100644 --- a/mocks/assetmocks/manager.go +++ b/mocks/assetmocks/manager.go @@ -20,13 +20,13 @@ type Manager struct { mock.Mock } -// BurnTokens provides a mock function with given fields: ctx, ns, typeName, poolName, transfer, waitConfirm -func (_m *Manager) BurnTokens(ctx context.Context, ns string, typeName string, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) { - ret := _m.Called(ctx, ns, typeName, poolName, transfer, waitConfirm) +// BurnTokens provides a mock function with given fields: ctx, ns, connector, poolName, transfer, waitConfirm +func (_m *Manager) BurnTokens(ctx context.Context, ns string, connector string, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) { + ret := _m.Called(ctx, ns, connector, poolName, transfer, waitConfirm) var r0 *fftypes.TokenTransfer if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *fftypes.TokenTransferInput, bool) *fftypes.TokenTransfer); ok { - r0 = rf(ctx, ns, typeName, poolName, transfer, waitConfirm) + r0 = rf(ctx, ns, connector, poolName, transfer, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.TokenTransfer) @@ -35,7 +35,7 @@ func (_m *Manager) BurnTokens(ctx context.Context, ns string, typeName string, p var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, string, *fftypes.TokenTransferInput, bool) error); ok { - r1 = rf(ctx, ns, typeName, poolName, transfer, waitConfirm) + r1 = rf(ctx, ns, connector, poolName, transfer, waitConfirm) } else { r1 = ret.Error(1) } @@ -43,13 +43,13 @@ func (_m *Manager) BurnTokens(ctx context.Context, ns string, typeName string, p return r0, r1 } -// CreateTokenPool provides a mock function with given fields: ctx, ns, typeName, pool, waitConfirm -func (_m *Manager) CreateTokenPool(ctx context.Context, ns string, typeName string, pool *fftypes.TokenPool, waitConfirm bool) (*fftypes.TokenPool, error) { - ret := _m.Called(ctx, ns, typeName, pool, waitConfirm) +// CreateTokenPool provides a mock function with given fields: ctx, ns, connector, pool, waitConfirm +func (_m *Manager) CreateTokenPool(ctx context.Context, ns string, connector string, pool *fftypes.TokenPool, waitConfirm bool) (*fftypes.TokenPool, error) { + ret := _m.Called(ctx, ns, connector, pool, waitConfirm) var r0 *fftypes.TokenPool if rf, ok := ret.Get(0).(func(context.Context, string, string, *fftypes.TokenPool, bool) *fftypes.TokenPool); ok { - r0 = rf(ctx, ns, typeName, pool, waitConfirm) + r0 = rf(ctx, ns, connector, pool, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.TokenPool) @@ -58,7 +58,7 @@ func (_m *Manager) CreateTokenPool(ctx context.Context, ns string, typeName stri var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, *fftypes.TokenPool, bool) error); ok { - r1 = rf(ctx, ns, typeName, pool, waitConfirm) + r1 = rf(ctx, ns, connector, pool, waitConfirm) } else { r1 = ret.Error(1) } @@ -98,13 +98,13 @@ func (_m *Manager) GetTokenAccounts(ctx context.Context, ns string, filter datab return r0, r1, r2 } -// GetTokenAccountsByPool provides a mock function with given fields: ctx, ns, typeName, poolName, filter -func (_m *Manager) GetTokenAccountsByPool(ctx context.Context, ns string, typeName string, poolName string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) { - ret := _m.Called(ctx, ns, typeName, poolName, filter) +// GetTokenAccountsByPool provides a mock function with given fields: ctx, ns, connector, poolName, filter +func (_m *Manager) GetTokenAccountsByPool(ctx context.Context, ns string, connector string, poolName string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) { + ret := _m.Called(ctx, ns, connector, poolName, filter) var r0 []*fftypes.TokenAccount if rf, ok := ret.Get(0).(func(context.Context, string, string, string, database.AndFilter) []*fftypes.TokenAccount); ok { - r0 = rf(ctx, ns, typeName, poolName, filter) + r0 = rf(ctx, ns, connector, poolName, filter) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*fftypes.TokenAccount) @@ -113,7 +113,7 @@ func (_m *Manager) GetTokenAccountsByPool(ctx context.Context, ns string, typeNa var r1 *database.FilterResult if rf, ok := ret.Get(1).(func(context.Context, string, string, string, database.AndFilter) *database.FilterResult); ok { - r1 = rf(ctx, ns, typeName, poolName, filter) + r1 = rf(ctx, ns, connector, poolName, filter) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*database.FilterResult) @@ -122,7 +122,7 @@ func (_m *Manager) GetTokenAccountsByPool(ctx context.Context, ns string, typeNa var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string, string, database.AndFilter) error); ok { - r2 = rf(ctx, ns, typeName, poolName, filter) + r2 = rf(ctx, ns, connector, poolName, filter) } else { r2 = ret.Error(2) } @@ -153,13 +153,13 @@ func (_m *Manager) GetTokenConnectors(ctx context.Context, ns string) ([]*fftype return r0, r1 } -// GetTokenPool provides a mock function with given fields: ctx, ns, typeName, poolName -func (_m *Manager) GetTokenPool(ctx context.Context, ns string, typeName string, poolName string) (*fftypes.TokenPool, error) { - ret := _m.Called(ctx, ns, typeName, poolName) +// GetTokenPool provides a mock function with given fields: ctx, ns, connector, poolName +func (_m *Manager) GetTokenPool(ctx context.Context, ns string, connector string, poolName string) (*fftypes.TokenPool, error) { + ret := _m.Called(ctx, ns, connector, poolName) var r0 *fftypes.TokenPool if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *fftypes.TokenPool); ok { - r0 = rf(ctx, ns, typeName, poolName) + r0 = rf(ctx, ns, connector, poolName) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.TokenPool) @@ -168,7 +168,30 @@ func (_m *Manager) GetTokenPool(ctx context.Context, ns string, typeName string, var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { - r1 = rf(ctx, ns, typeName, poolName) + r1 = rf(ctx, ns, connector, poolName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetTokenPoolByNameOrID provides a mock function with given fields: ctx, ns, poolNameOrID +func (_m *Manager) GetTokenPoolByNameOrID(ctx context.Context, ns string, poolNameOrID string) (*fftypes.TokenPool, error) { + ret := _m.Called(ctx, ns, poolNameOrID) + + var r0 *fftypes.TokenPool + if rf, ok := ret.Get(0).(func(context.Context, string, string) *fftypes.TokenPool); ok { + r0 = rf(ctx, ns, poolNameOrID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*fftypes.TokenPool) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, ns, poolNameOrID) } else { r1 = ret.Error(1) } @@ -208,13 +231,13 @@ func (_m *Manager) GetTokenPools(ctx context.Context, ns string, filter database return r0, r1, r2 } -// GetTokenPoolsByType provides a mock function with given fields: ctx, ns, typeName, filter -func (_m *Manager) GetTokenPoolsByType(ctx context.Context, ns string, typeName string, filter database.AndFilter) ([]*fftypes.TokenPool, *database.FilterResult, error) { - ret := _m.Called(ctx, ns, typeName, filter) +// GetTokenPoolsByType provides a mock function with given fields: ctx, ns, connector, filter +func (_m *Manager) GetTokenPoolsByType(ctx context.Context, ns string, connector string, filter database.AndFilter) ([]*fftypes.TokenPool, *database.FilterResult, error) { + ret := _m.Called(ctx, ns, connector, filter) var r0 []*fftypes.TokenPool if rf, ok := ret.Get(0).(func(context.Context, string, string, database.AndFilter) []*fftypes.TokenPool); ok { - r0 = rf(ctx, ns, typeName, filter) + r0 = rf(ctx, ns, connector, filter) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*fftypes.TokenPool) @@ -223,7 +246,7 @@ func (_m *Manager) GetTokenPoolsByType(ctx context.Context, ns string, typeName var r1 *database.FilterResult if rf, ok := ret.Get(1).(func(context.Context, string, string, database.AndFilter) *database.FilterResult); ok { - r1 = rf(ctx, ns, typeName, filter) + r1 = rf(ctx, ns, connector, filter) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*database.FilterResult) @@ -232,7 +255,7 @@ func (_m *Manager) GetTokenPoolsByType(ctx context.Context, ns string, typeName var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string, database.AndFilter) error); ok { - r2 = rf(ctx, ns, typeName, filter) + r2 = rf(ctx, ns, connector, filter) } else { r2 = ret.Error(2) } @@ -272,13 +295,45 @@ func (_m *Manager) GetTokenTransfers(ctx context.Context, ns string, filter data return r0, r1, r2 } -// GetTokenTransfersByPool provides a mock function with given fields: ctx, ns, typeName, poolName, filter -func (_m *Manager) GetTokenTransfersByPool(ctx context.Context, ns string, typeName string, poolName string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { - ret := _m.Called(ctx, ns, typeName, poolName, filter) +// GetTokenTransfersByID provides a mock function with given fields: ctx, ns, id, filter +func (_m *Manager) GetTokenTransfersByID(ctx context.Context, ns string, id string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { + ret := _m.Called(ctx, ns, id, filter) + + var r0 []*fftypes.TokenTransfer + if rf, ok := ret.Get(0).(func(context.Context, string, string, database.AndFilter) []*fftypes.TokenTransfer); ok { + r0 = rf(ctx, ns, id, filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*fftypes.TokenTransfer) + } + } + + var r1 *database.FilterResult + if rf, ok := ret.Get(1).(func(context.Context, string, string, database.AndFilter) *database.FilterResult); ok { + r1 = rf(ctx, ns, id, filter) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*database.FilterResult) + } + } + + var r2 error + if rf, ok := ret.Get(2).(func(context.Context, string, string, database.AndFilter) error); ok { + r2 = rf(ctx, ns, id, filter) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// GetTokenTransfersByPool provides a mock function with given fields: ctx, ns, connector, poolName, filter +func (_m *Manager) GetTokenTransfersByPool(ctx context.Context, ns string, connector string, poolName string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { + ret := _m.Called(ctx, ns, connector, poolName, filter) var r0 []*fftypes.TokenTransfer if rf, ok := ret.Get(0).(func(context.Context, string, string, string, database.AndFilter) []*fftypes.TokenTransfer); ok { - r0 = rf(ctx, ns, typeName, poolName, filter) + r0 = rf(ctx, ns, connector, poolName, filter) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*fftypes.TokenTransfer) @@ -287,7 +342,7 @@ func (_m *Manager) GetTokenTransfersByPool(ctx context.Context, ns string, typeN var r1 *database.FilterResult if rf, ok := ret.Get(1).(func(context.Context, string, string, string, database.AndFilter) *database.FilterResult); ok { - r1 = rf(ctx, ns, typeName, poolName, filter) + r1 = rf(ctx, ns, connector, poolName, filter) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*database.FilterResult) @@ -296,7 +351,7 @@ func (_m *Manager) GetTokenTransfersByPool(ctx context.Context, ns string, typeN var r2 error if rf, ok := ret.Get(2).(func(context.Context, string, string, string, database.AndFilter) error); ok { - r2 = rf(ctx, ns, typeName, poolName, filter) + r2 = rf(ctx, ns, connector, poolName, filter) } else { r2 = ret.Error(2) } @@ -304,13 +359,13 @@ func (_m *Manager) GetTokenTransfersByPool(ctx context.Context, ns string, typeN return r0, r1, r2 } -// MintTokens provides a mock function with given fields: ctx, ns, typeName, poolName, transfer, waitConfirm -func (_m *Manager) MintTokens(ctx context.Context, ns string, typeName string, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) { - ret := _m.Called(ctx, ns, typeName, poolName, transfer, waitConfirm) +// MintTokens provides a mock function with given fields: ctx, ns, connector, poolName, transfer, waitConfirm +func (_m *Manager) MintTokens(ctx context.Context, ns string, connector string, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) { + ret := _m.Called(ctx, ns, connector, poolName, transfer, waitConfirm) var r0 *fftypes.TokenTransfer if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *fftypes.TokenTransferInput, bool) *fftypes.TokenTransfer); ok { - r0 = rf(ctx, ns, typeName, poolName, transfer, waitConfirm) + r0 = rf(ctx, ns, connector, poolName, transfer, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.TokenTransfer) @@ -319,7 +374,7 @@ func (_m *Manager) MintTokens(ctx context.Context, ns string, typeName string, p var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, string, *fftypes.TokenTransferInput, bool) error); ok { - r1 = rf(ctx, ns, typeName, poolName, transfer, waitConfirm) + r1 = rf(ctx, ns, connector, poolName, transfer, waitConfirm) } else { r1 = ret.Error(1) } @@ -327,13 +382,13 @@ func (_m *Manager) MintTokens(ctx context.Context, ns string, typeName string, p return r0, r1 } -// NewTransfer provides a mock function with given fields: ns, typeName, poolName, transfer -func (_m *Manager) NewTransfer(ns string, typeName string, poolName string, transfer *fftypes.TokenTransferInput) sysmessaging.MessageSender { - ret := _m.Called(ns, typeName, poolName, transfer) +// NewTransfer provides a mock function with given fields: ns, connector, poolName, transfer +func (_m *Manager) NewTransfer(ns string, connector string, poolName string, transfer *fftypes.TokenTransferInput) sysmessaging.MessageSender { + ret := _m.Called(ns, connector, poolName, transfer) var r0 sysmessaging.MessageSender if rf, ok := ret.Get(0).(func(string, string, string, *fftypes.TokenTransferInput) sysmessaging.MessageSender); ok { - r0 = rf(ns, typeName, poolName, transfer) + r0 = rf(ns, connector, poolName, transfer) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(sysmessaging.MessageSender) @@ -371,13 +426,13 @@ func (_m *Manager) TokenPoolCreated(tk tokens.Plugin, pool *fftypes.TokenPool, p return r0 } -// TransferTokens provides a mock function with given fields: ctx, ns, typeName, poolName, transfer, waitConfirm -func (_m *Manager) TransferTokens(ctx context.Context, ns string, typeName string, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) { - ret := _m.Called(ctx, ns, typeName, poolName, transfer, waitConfirm) +// TransferTokens provides a mock function with given fields: ctx, ns, connector, poolName, transfer, waitConfirm +func (_m *Manager) TransferTokens(ctx context.Context, ns string, connector string, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) { + ret := _m.Called(ctx, ns, connector, poolName, transfer, waitConfirm) var r0 *fftypes.TokenTransfer if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *fftypes.TokenTransferInput, bool) *fftypes.TokenTransfer); ok { - r0 = rf(ctx, ns, typeName, poolName, transfer, waitConfirm) + r0 = rf(ctx, ns, connector, poolName, transfer, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.TokenTransfer) @@ -386,7 +441,7 @@ func (_m *Manager) TransferTokens(ctx context.Context, ns string, typeName strin var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, string, *fftypes.TokenTransferInput, bool) error); ok { - r1 = rf(ctx, ns, typeName, poolName, transfer, waitConfirm) + r1 = rf(ctx, ns, connector, poolName, transfer, waitConfirm) } else { r1 = ret.Error(1) } From d382ca9eb7e547d4c6e049ea77dc3bacbdb8bfb7 Mon Sep 17 00:00:00 2001 From: David Echelberger Date: Thu, 21 Oct 2021 15:18:29 -0400 Subject: [PATCH 2/2] tokens-by-id renaming tokenTransfersByID() Signed-off-by: David Echelberger --- docs/swagger/swagger.yaml | 149 ++++-------------- .../route_get_token_transfers_by_id.go | 12 +- .../route_get_token_transfers_by_id_test.go | 6 +- internal/apiserver/routes.go | 2 +- internal/assets/manager.go | 2 +- internal/assets/token_transfer.go | 6 +- internal/assets/token_transfer_test.go | 15 +- mocks/assetmocks/manager.go | 51 +++--- 8 files changed, 69 insertions(+), 174 deletions(-) diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index 62ef454cd7..4e14fc88ac 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -6061,7 +6061,7 @@ paths: /namespaces/{ns}/tokens/transfers/{transferID}: get: description: 'TODO: Description' - operationId: getTokenTransfersByID + operationId: getTokenTransferByID parameters: - description: 'TODO: Description' in: path @@ -6083,130 +6083,39 @@ paths: schema: default: 120s type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: amount - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: connector - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: created - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: from - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: key - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: localid - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: messagehash - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: poolprotocolid - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: protocolid - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: to - schema: - type: string - - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' - in: query - name: tokenindex - schema: - type: string - - description: Sort field. For multi-field sort use comma separated values (or - multiple query values) with '-' prefix for descending - in: query - name: sort - schema: - type: string - - description: Ascending sort order (overrides all fields in a multi-field sort) - in: query - name: ascending - schema: - type: string - - description: Descending sort order (overrides all fields in a multi-field - sort) - in: query - name: descending - schema: - type: string - - description: 'The number of records to skip (max: 1,000). Unsuitable for bulk - operations' - in: query - name: skip - schema: - type: string - - description: 'The maximum number of records to return (max: 1,000)' - in: query - name: limit - schema: - example: "25" - type: string - - description: Return a total count as well as items (adds extra database processing) - in: query - name: count - schema: - type: string responses: "200": content: application/json: schema: - items: - properties: - amount: {} - connector: - type: string - created: {} - from: - type: string - key: - type: string - localId: {} - messageHash: {} - poolProtocolId: - type: string - protocolId: - type: string - to: - type: string - tokenIndex: - type: string - tx: - properties: - id: {} - type: - type: string - type: object - type: - type: string - type: object - type: array + properties: + amount: {} + connector: + type: string + created: {} + from: + type: string + key: + type: string + localId: {} + messageHash: {} + poolProtocolId: + type: string + protocolId: + type: string + to: + type: string + tokenIndex: + type: string + tx: + properties: + id: {} + type: + type: string + type: object + type: + type: string + type: object description: Success default: description: "" diff --git a/internal/apiserver/route_get_token_transfers_by_id.go b/internal/apiserver/route_get_token_transfers_by_id.go index 40f3895c29..09097fbcb1 100644 --- a/internal/apiserver/route_get_token_transfers_by_id.go +++ b/internal/apiserver/route_get_token_transfers_by_id.go @@ -22,12 +22,11 @@ import ( "github.com/hyperledger/firefly/internal/config" "github.com/hyperledger/firefly/internal/i18n" "github.com/hyperledger/firefly/internal/oapispec" - "github.com/hyperledger/firefly/pkg/database" "github.com/hyperledger/firefly/pkg/fftypes" ) -var getTokenTransfersByID = &oapispec.Route{ - Name: "getTokenTransfersByID", +var getTokenTransferByID = &oapispec.Route{ + Name: "getTokenTransferByID", Path: "namespaces/{ns}/tokens/transfers/{transferID}", Method: http.MethodGet, PathParams: []*oapispec.PathParam{ @@ -35,12 +34,13 @@ var getTokenTransfersByID = &oapispec.Route{ {Name: "transferID", Description: i18n.MsgTBD}, }, QueryParams: nil, - FilterFactory: database.TokenTransferQueryFactory, + FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: nil, - JSONOutputValue: func() interface{} { return []*fftypes.TokenTransfer{} }, + JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { - return filterResult(r.Or.Assets().GetTokenTransfersByID(r.Ctx, r.PP["ns"], r.PP["transferID"], r.Filter)) + output, err = r.Or.Assets().GetTokenTransferByID(r.Ctx, r.PP["ns"], r.PP["transferID"]) + return output, err }, } diff --git a/internal/apiserver/route_get_token_transfers_by_id_test.go b/internal/apiserver/route_get_token_transfers_by_id_test.go index b32cad37db..6b5044021a 100644 --- a/internal/apiserver/route_get_token_transfers_by_id_test.go +++ b/internal/apiserver/route_get_token_transfers_by_id_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/mock" ) -func TestGetTokenTransfersByID(t *testing.T) { +func TestGetTokenTransferByID(t *testing.T) { o, r := newTestAPIServer() mam := &assetmocks.Manager{} o.On("Assets").Return(mam) @@ -34,8 +34,8 @@ func TestGetTokenTransfersByID(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mam.On("GetTokenTransfersByID", mock.Anything, "ns1", "id1", mock.Anything). - Return([]*fftypes.TokenTransfer{}, nil, nil) + mam.On("GetTokenTransferByID", mock.Anything, "ns1", "id1"). + Return(&fftypes.TokenTransfer{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/routes.go b/internal/apiserver/routes.go index 67071fdef5..f1d981a0ab 100644 --- a/internal/apiserver/routes.go +++ b/internal/apiserver/routes.go @@ -85,8 +85,8 @@ var routes = []*oapispec.Route{ getTokenAccounts, getTokenAccountsByPool, getTokenTransfers, - getTokenTransfersByID, getTokenTransfersByPool, + getTokenTransferByID, postTokenMint, postTokenBurn, postTokenTransfer, diff --git a/internal/assets/manager.go b/internal/assets/manager.go index 4114129fea..d4afaf71a5 100644 --- a/internal/assets/manager.go +++ b/internal/assets/manager.go @@ -44,7 +44,7 @@ type Manager interface { GetTokenAccounts(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) GetTokenAccountsByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) GetTokenTransfers(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) - GetTokenTransfersByID(ctx context.Context, ns, id string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) + GetTokenTransferByID(ctx context.Context, ns, id string) (*fftypes.TokenTransfer, error) GetTokenTransfersByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) NewTransfer(ns, connector, poolName string, transfer *fftypes.TokenTransferInput) sysmessaging.MessageSender MintTokens(ctx context.Context, ns, connector, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error) diff --git a/internal/assets/token_transfer.go b/internal/assets/token_transfer.go index 81b5857eba..332530e64b 100644 --- a/internal/assets/token_transfer.go +++ b/internal/assets/token_transfer.go @@ -37,13 +37,13 @@ func (am *assetManager) GetTokenTransfers(ctx context.Context, ns string, filter return am.database.GetTokenTransfers(ctx, filter) } -func (am *assetManager) GetTokenTransfersByID(ctx context.Context, ns, id string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { +func (am *assetManager) GetTokenTransferByID(ctx context.Context, ns, id string) (*fftypes.TokenTransfer, error) { transferID, err := fftypes.ParseUUID(ctx, id) if err != nil { - return nil, nil, err + return nil, err } - return am.database.GetTokenTransfers(ctx, filter.Condition(filter.Builder().Eq("localid", transferID))) + return am.database.GetTokenTransfer(ctx, transferID) } func (am *assetManager) GetTokenTransfersByPool(ctx context.Context, ns, connector, name string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { diff --git a/internal/assets/token_transfer_test.go b/internal/assets/token_transfer_test.go index acc0cd6b4e..76248154ce 100644 --- a/internal/assets/token_transfer_test.go +++ b/internal/assets/token_transfer_test.go @@ -47,27 +47,22 @@ func TestGetTokenTransfers(t *testing.T) { assert.NoError(t, err) } -func TestGetTokenTransfersByID(t *testing.T) { +func TestGetTokenTransferByID(t *testing.T) { am, cancel := newTestAssets(t) defer cancel() u := fftypes.NewUUID() mdi := am.database.(*databasemocks.Plugin) - fb := database.TokenTransferQueryFactory.NewFilter(context.Background()) - f := fb.And(fb.Eq("localid", u)) - mdi.On("GetTokenTransfers", context.Background(), f).Return([]*fftypes.TokenTransfer{}, nil, nil) - _, _, err := am.GetTokenTransfersByID(context.Background(), "ns1", u.String(), f) + mdi.On("GetTokenTransfer", context.Background(), u).Return(&fftypes.TokenTransfer{}, nil) + _, err := am.GetTokenTransferByID(context.Background(), "ns1", u.String()) assert.NoError(t, err) } -func TestGetTokenTransfersByIDBadID(t *testing.T) { +func TestGetTokenTransferByIDBadID(t *testing.T) { am, cancel := newTestAssets(t) defer cancel() - u := fftypes.NewUUID() - fb := database.TokenTransferQueryFactory.NewFilter(context.Background()) - f := fb.And(fb.Eq("localid", u)) - _, _, err := am.GetTokenTransfersByID(context.Background(), "ns1", "badUUID", f) + _, err := am.GetTokenTransferByID(context.Background(), "ns1", "badUUID") assert.Regexp(t, "FF10142", err) } diff --git a/mocks/assetmocks/manager.go b/mocks/assetmocks/manager.go index 6ab1162da3..059502600a 100644 --- a/mocks/assetmocks/manager.go +++ b/mocks/assetmocks/manager.go @@ -263,45 +263,36 @@ func (_m *Manager) GetTokenPoolsByType(ctx context.Context, ns string, connector return r0, r1, r2 } -// GetTokenTransfers provides a mock function with given fields: ctx, ns, filter -func (_m *Manager) GetTokenTransfers(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { - ret := _m.Called(ctx, ns, filter) +// GetTokenTransferByID provides a mock function with given fields: ctx, ns, id +func (_m *Manager) GetTokenTransferByID(ctx context.Context, ns string, id string) (*fftypes.TokenTransfer, error) { + ret := _m.Called(ctx, ns, id) - var r0 []*fftypes.TokenTransfer - if rf, ok := ret.Get(0).(func(context.Context, string, database.AndFilter) []*fftypes.TokenTransfer); ok { - r0 = rf(ctx, ns, filter) + var r0 *fftypes.TokenTransfer + if rf, ok := ret.Get(0).(func(context.Context, string, string) *fftypes.TokenTransfer); ok { + r0 = rf(ctx, ns, id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*fftypes.TokenTransfer) - } - } - - var r1 *database.FilterResult - if rf, ok := ret.Get(1).(func(context.Context, string, database.AndFilter) *database.FilterResult); ok { - r1 = rf(ctx, ns, filter) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*database.FilterResult) + r0 = ret.Get(0).(*fftypes.TokenTransfer) } } - var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, database.AndFilter) error); ok { - r2 = rf(ctx, ns, filter) + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, ns, id) } else { - r2 = ret.Error(2) + r1 = ret.Error(1) } - return r0, r1, r2 + return r0, r1 } -// GetTokenTransfersByID provides a mock function with given fields: ctx, ns, id, filter -func (_m *Manager) GetTokenTransfersByID(ctx context.Context, ns string, id string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { - ret := _m.Called(ctx, ns, id, filter) +// GetTokenTransfers provides a mock function with given fields: ctx, ns, filter +func (_m *Manager) GetTokenTransfers(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) { + ret := _m.Called(ctx, ns, filter) var r0 []*fftypes.TokenTransfer - if rf, ok := ret.Get(0).(func(context.Context, string, string, database.AndFilter) []*fftypes.TokenTransfer); ok { - r0 = rf(ctx, ns, id, filter) + if rf, ok := ret.Get(0).(func(context.Context, string, database.AndFilter) []*fftypes.TokenTransfer); ok { + r0 = rf(ctx, ns, filter) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*fftypes.TokenTransfer) @@ -309,8 +300,8 @@ func (_m *Manager) GetTokenTransfersByID(ctx context.Context, ns string, id stri } var r1 *database.FilterResult - if rf, ok := ret.Get(1).(func(context.Context, string, string, database.AndFilter) *database.FilterResult); ok { - r1 = rf(ctx, ns, id, filter) + if rf, ok := ret.Get(1).(func(context.Context, string, database.AndFilter) *database.FilterResult); ok { + r1 = rf(ctx, ns, filter) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*database.FilterResult) @@ -318,8 +309,8 @@ func (_m *Manager) GetTokenTransfersByID(ctx context.Context, ns string, id stri } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, string, database.AndFilter) error); ok { - r2 = rf(ctx, ns, id, filter) + if rf, ok := ret.Get(2).(func(context.Context, string, database.AndFilter) error); ok { + r2 = rf(ctx, ns, filter) } else { r2 = ret.Error(2) }