From 43ed4a7d9e37ba61ae23f297493c8c055adcf879 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Wed, 22 Jun 2022 15:59:14 -0400 Subject: [PATCH] Remove namespace from more manager calls Signed-off-by: Andrew Richardson --- .../apiserver/route_get_chart_histogram.go | 2 +- .../route_get_chart_histogram_test.go | 2 +- internal/apiserver/route_get_data_blob.go | 2 +- .../apiserver/route_get_data_blob_test.go | 2 +- internal/apiserver/route_post_data.go | 4 +- internal/apiserver/route_post_data_test.go | 12 ++-- internal/apiserver/route_post_new_datatype.go | 2 +- .../apiserver/route_post_new_datatype_test.go | 4 +- internal/apiserver/route_post_op_retry.go | 2 +- .../apiserver/route_post_op_retry_test.go | 2 +- internal/apiserver/routes.go | 8 --- internal/apiserver/server.go | 29 ++++---- internal/broadcast/datatype.go | 8 +-- internal/broadcast/datatype_test.go | 20 +++--- internal/broadcast/definition.go | 18 ++--- internal/broadcast/definition_test.go | 11 ++- internal/broadcast/manager.go | 10 +-- internal/broadcast/tokenpool.go | 4 +- internal/broadcast/tokenpool_test.go | 8 +-- internal/contracts/manager.go | 4 +- internal/contracts/manager_test.go | 16 ++--- internal/data/blobstore.go | 21 +++--- internal/data/blobstore_test.go | 50 +++++-------- internal/data/data_manager.go | 45 ++++++------ internal/data/data_manager_test.go | 28 ++++---- .../definition_handler_datatype.go | 2 +- .../definition_handler_datatype_test.go | 12 ++-- internal/events/batch_pin_complete.go | 2 +- internal/events/batch_pin_complete_test.go | 8 +-- internal/events/event_manager.go | 2 +- internal/events/persist_batch.go | 2 +- internal/events/ss_callbacks.go | 6 +- internal/events/ss_callbacks_test.go | 9 +-- internal/events/token_pool_created.go | 2 +- internal/events/token_pool_created_test.go | 2 +- internal/namespace/manager.go | 2 +- internal/namespace/manager_test.go | 2 +- internal/networkmap/register_identity.go | 4 +- internal/networkmap/register_identity_test.go | 7 -- internal/networkmap/register_node_test.go | 1 - internal/networkmap/register_org_test.go | 1 - internal/networkmap/update_identity.go | 2 +- internal/networkmap/update_identity_test.go | 2 - internal/operations/manager.go | 24 +++---- internal/operations/manager_test.go | 16 ++--- internal/orchestrator/bound_callbacks.go | 4 +- internal/orchestrator/bound_callbacks_test.go | 4 +- internal/orchestrator/chart.go | 4 +- internal/orchestrator/chart_test.go | 14 ++-- internal/orchestrator/orchestrator.go | 2 +- internal/shareddownload/download_manager.go | 22 +++--- .../shareddownload/download_manager_test.go | 10 +-- internal/shareddownload/operations.go | 36 ++++------ internal/shareddownload/operations_test.go | 7 +- mocks/blockchainmocks/plugin.go | 10 +-- mocks/broadcastmocks/manager.go | 70 +++++++++---------- mocks/datamocks/manager.go | 56 +++++++-------- mocks/eventmocks/event_manager.go | 14 ++-- mocks/operationmocks/manager.go | 24 +++---- mocks/orchestratormocks/orchestrator.go | 14 ++-- mocks/shareddownloadmocks/callbacks.go | 14 ++-- mocks/shareddownloadmocks/manager.go | 20 +++--- 62 files changed, 348 insertions(+), 399 deletions(-) diff --git a/internal/apiserver/route_get_chart_histogram.go b/internal/apiserver/route_get_chart_histogram.go index 0dedc515b..025cb24d0 100644 --- a/internal/apiserver/route_get_chart_histogram.go +++ b/internal/apiserver/route_get_chart_histogram.go @@ -58,7 +58,7 @@ var getChartHistogram = &ffapi.Route{ if err != nil { return nil, i18n.NewError(cr.ctx, coremsgs.MsgInvalidChartNumberParam, "buckets") } - return cr.or.GetChartHistogram(cr.ctx, extractNamespace(r.PP), startTime.UnixNano(), endTime.UnixNano(), buckets, database.CollectionName(r.PP["collection"])) + return cr.or.GetChartHistogram(cr.ctx, startTime.UnixNano(), endTime.UnixNano(), buckets, database.CollectionName(r.PP["collection"])) }, }, } diff --git a/internal/apiserver/route_get_chart_histogram_test.go b/internal/apiserver/route_get_chart_histogram_test.go index 9c5de8add..d9c6575fa 100644 --- a/internal/apiserver/route_get_chart_histogram_test.go +++ b/internal/apiserver/route_get_chart_histogram_test.go @@ -69,7 +69,7 @@ func TestGetChartHistogramSuccess(t *testing.T) { startTime, _ := fftypes.ParseTimeString("1234567890") endtime, _ := fftypes.ParseTimeString("1234567891") - o.On("GetChartHistogram", mock.Anything, "mynamespace", startTime.UnixNano(), endtime.UnixNano(), int64(30), database.CollectionName("test")). + o.On("GetChartHistogram", mock.Anything, startTime.UnixNano(), endtime.UnixNano(), int64(30), database.CollectionName("test")). Return([]*core.ChartHistogram{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_get_data_blob.go b/internal/apiserver/route_get_data_blob.go index 43d779bcc..3cd7388ff 100644 --- a/internal/apiserver/route_get_data_blob.go +++ b/internal/apiserver/route_get_data_blob.go @@ -41,7 +41,7 @@ var getDataBlob = &ffapi.Route{ Extensions: &coreExtensions{ FilterFactory: database.MessageQueryFactory, CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - blob, reader, err := cr.or.Data().DownloadBlob(cr.ctx, extractNamespace(r.PP), r.PP["dataid"]) + blob, reader, err := cr.or.Data().DownloadBlob(cr.ctx, r.PP["dataid"]) if err == nil { r.ResponseHeaders.Set(core.HTTPHeadersBlobHashSHA256, blob.Hash.String()) if blob.Size > 0 { diff --git a/internal/apiserver/route_get_data_blob_test.go b/internal/apiserver/route_get_data_blob_test.go index c76a4ed86..9e823a435 100644 --- a/internal/apiserver/route_get_data_blob_test.go +++ b/internal/apiserver/route_get_data_blob_test.go @@ -38,7 +38,7 @@ func TestGetDataBlob(t *testing.T) { res := httptest.NewRecorder() blobHash := fftypes.NewRandB32() - mdm.On("DownloadBlob", mock.Anything, "mynamespace", "abcd1234"). + mdm.On("DownloadBlob", mock.Anything, "abcd1234"). Return(&core.Blob{ Hash: blobHash, Size: 12345, diff --git a/internal/apiserver/route_post_data.go b/internal/apiserver/route_post_data.go index da5d39caf..46e031211 100644 --- a/internal/apiserver/route_post_data.go +++ b/internal/apiserver/route_post_data.go @@ -47,7 +47,7 @@ var postData = &ffapi.Route{ JSONOutputCodes: []int{http.StatusCreated}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - output, err = cr.or.Data().UploadJSON(cr.ctx, extractNamespace(r.PP), r.Input.(*core.DataRefOrValue)) + output, err = cr.or.Data().UploadJSON(cr.ctx, r.Input.(*core.DataRefOrValue)) return output, err }, CoreFormUploadHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { @@ -71,7 +71,7 @@ var postData = &ffapi.Route{ } data.Value = fftypes.JSONAnyPtr(metadata) } - output, err = cr.or.Data().UploadBlob(cr.ctx, extractNamespace(r.PP), data, r.Part, strings.EqualFold(r.FP["autometa"], "true")) + output, err = cr.or.Data().UploadBlob(cr.ctx, data, r.Part, strings.EqualFold(r.FP["autometa"], "true")) return output, err }, }, diff --git a/internal/apiserver/route_post_data_test.go b/internal/apiserver/route_post_data_test.go index cc0563a09..9068f6159 100644 --- a/internal/apiserver/route_post_data_test.go +++ b/internal/apiserver/route_post_data_test.go @@ -42,7 +42,7 @@ func TestPostDataJSON(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mdm.On("UploadJSON", mock.Anything, "ns1", mock.AnythingOfType("*core.DataRefOrValue")). + mdm.On("UploadJSON", mock.Anything, mock.AnythingOfType("*core.DataRefOrValue")). Return(&core.Data{}, nil) r.ServeHTTP(res, req) @@ -60,7 +60,7 @@ func TestPostDataJSONDefaultNS(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mdm.On("UploadJSON", mock.Anything, "default", mock.AnythingOfType("*core.DataRefOrValue")). + mdm.On("UploadJSON", mock.Anything, mock.AnythingOfType("*core.DataRefOrValue")). Return(&core.Data{}, nil) r.ServeHTTP(res, req) @@ -85,7 +85,7 @@ func TestPostDataBinary(t *testing.T) { res := httptest.NewRecorder() - mdm.On("UploadBlob", mock.Anything, "ns1", mock.AnythingOfType("*core.DataRefOrValue"), mock.AnythingOfType("*ffapi.Multipart"), false). + mdm.On("UploadBlob", mock.Anything, mock.AnythingOfType("*core.DataRefOrValue"), mock.AnythingOfType("*ffapi.Multipart"), false). Return(&core.Data{}, nil) r.ServeHTTP(res, req) @@ -125,7 +125,7 @@ func TestPostDataBinaryObjAutoMeta(t *testing.T) { res := httptest.NewRecorder() - mdm.On("UploadBlob", mock.Anything, "ns1", mock.MatchedBy(func(d *core.DataRefOrValue) bool { + mdm.On("UploadBlob", mock.Anything, mock.MatchedBy(func(d *core.DataRefOrValue) bool { assert.Equal(t, `{"filename":"anything"}`, string(*d.Value)) assert.Equal(t, core.ValidatorTypeJSON, d.Validator) assert.Equal(t, "fileinfo", d.Datatype.Name) @@ -159,7 +159,7 @@ func TestPostDataBinaryStringMetadata(t *testing.T) { res := httptest.NewRecorder() - mdm.On("UploadBlob", mock.Anything, "ns1", mock.MatchedBy(func(d *core.DataRefOrValue) bool { + mdm.On("UploadBlob", mock.Anything, mock.MatchedBy(func(d *core.DataRefOrValue) bool { assert.Equal(t, `"string metadata"`, string(*d.Value)) assert.Equal(t, "", string(d.Validator)) assert.Nil(t, d.Datatype) @@ -192,7 +192,7 @@ func TestPostDataTrailingMetadata(t *testing.T) { res := httptest.NewRecorder() - mdm.On("UploadBlob", mock.Anything, "ns1", mock.Anything, mock.AnythingOfType("*ffapi.Multipart"), false). + mdm.On("UploadBlob", mock.Anything, mock.Anything, mock.AnythingOfType("*ffapi.Multipart"), false). Return(&core.Data{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_new_datatype.go b/internal/apiserver/route_post_new_datatype.go index fd50a3a47..53e591247 100644 --- a/internal/apiserver/route_post_new_datatype.go +++ b/internal/apiserver/route_post_new_datatype.go @@ -41,7 +41,7 @@ var postNewDatatype = &ffapi.Route{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { waitConfirm := strings.EqualFold(r.QP["confirm"], "true") r.SuccessStatus = syncRetcode(waitConfirm) - _, err = cr.or.Broadcast().BroadcastDatatype(cr.ctx, extractNamespace(r.PP), r.Input.(*core.Datatype), waitConfirm) + _, err = cr.or.Broadcast().BroadcastDatatype(cr.ctx, r.Input.(*core.Datatype), waitConfirm) return r.Input, err }, }, diff --git a/internal/apiserver/route_post_new_datatype_test.go b/internal/apiserver/route_post_new_datatype_test.go index a670d4d07..c047b42bc 100644 --- a/internal/apiserver/route_post_new_datatype_test.go +++ b/internal/apiserver/route_post_new_datatype_test.go @@ -39,7 +39,7 @@ func TestPostNewDatatypes(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mbm.On("BroadcastDatatype", mock.Anything, "ns1", mock.AnythingOfType("*core.Datatype"), false). + mbm.On("BroadcastDatatype", mock.Anything, mock.AnythingOfType("*core.Datatype"), false). Return(&core.Message{}, nil) r.ServeHTTP(res, req) @@ -57,7 +57,7 @@ func TestPostNewDatatypesSync(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mbm.On("BroadcastDatatype", mock.Anything, "ns1", mock.AnythingOfType("*core.Datatype"), true). + mbm.On("BroadcastDatatype", mock.Anything, mock.AnythingOfType("*core.Datatype"), true). Return(&core.Message{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/route_post_op_retry.go b/internal/apiserver/route_post_op_retry.go index 6336668a2..5c8cedddc 100644 --- a/internal/apiserver/route_post_op_retry.go +++ b/internal/apiserver/route_post_op_retry.go @@ -43,7 +43,7 @@ var postOpRetry = &ffapi.Route{ if err != nil { return nil, err } - return cr.or.Operations().RetryOperation(cr.ctx, extractNamespace(r.PP), opid) + return cr.or.Operations().RetryOperation(cr.ctx, opid) }, }, } diff --git a/internal/apiserver/route_post_op_retry_test.go b/internal/apiserver/route_post_op_retry_test.go index a96336b94..308dc4d76 100644 --- a/internal/apiserver/route_post_op_retry_test.go +++ b/internal/apiserver/route_post_op_retry_test.go @@ -41,7 +41,7 @@ func TestPostOpRetry(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mom.On("RetryOperation", mock.Anything, "ns1", opID). + mom.On("RetryOperation", mock.Anything, opID). Return(&core.Operation{}, nil) r.ServeHTTP(res, req) diff --git a/internal/apiserver/routes.go b/internal/apiserver/routes.go index 780656371..094ab816e 100644 --- a/internal/apiserver/routes.go +++ b/internal/apiserver/routes.go @@ -19,7 +19,6 @@ package apiserver import ( "context" - "github.com/hyperledger/firefly-common/pkg/config" "github.com/hyperledger/firefly-common/pkg/ffapi" "github.com/hyperledger/firefly/internal/coreconfig" "github.com/hyperledger/firefly/internal/coremsgs" @@ -176,10 +175,3 @@ func namespacedRoutes(routes []*ffapi.Route) []*ffapi.Route { } return append(routes, newRoutes...) } - -func extractNamespace(pathParams map[string]string) string { - if ns, ok := pathParams["ns"]; ok { - return ns - } - return config.GetString(coreconfig.NamespacesDefault) -} diff --git a/internal/apiserver/server.go b/internal/apiserver/server.go index 1dc914961..32dcdb65e 100644 --- a/internal/apiserver/server.go +++ b/internal/apiserver/server.go @@ -218,6 +218,19 @@ func (as *apiServer) contractSwaggerGenerator(mgr namespace.Manager, apiBaseURL } } +func getOrchestrator(mgr namespace.Manager, tag string, r *ffapi.APIRequest) orchestrator.Orchestrator { + if tag == routeTagDefaultNamespace { + return mgr.Orchestrator(config.GetString(coreconfig.NamespacesDefault)) + } + if tag == routeTagNonDefaultNamespace { + vars := mux.Vars(r.Req) + if ns, ok := vars["ns"]; ok { + return mgr.Orchestrator(ns) + } + } + return nil +} + func (as *apiServer) routeHandler(hf *ffapi.HandlerFactory, mgr namespace.Manager, apiBaseURL string, route *ffapi.Route) http.HandlerFunc { // We extend the base ffapi functionality, with standardized DB filter support for all core resources. // We also pass the Orchestrator context through @@ -231,15 +244,9 @@ func (as *apiServer) routeHandler(hf *ffapi.HandlerFactory, mgr namespace.Manage } } - var or orchestrator.Orchestrator - if route.Tag == routeTagDefaultNamespace || route.Tag == routeTagNonDefaultNamespace { - vars := mux.Vars(r.Req) - or = mgr.Orchestrator(extractNamespace(vars)) - } - cr := &coreRequest{ mgr: mgr, - or: or, + or: getOrchestrator(mgr, route.Tag, r), ctx: r.Req.Context(), filter: filter, apiBaseURL: apiBaseURL, @@ -248,15 +255,9 @@ func (as *apiServer) routeHandler(hf *ffapi.HandlerFactory, mgr namespace.Manage } if ce.CoreFormUploadHandler != nil { route.FormUploadHandler = func(r *ffapi.APIRequest) (output interface{}, err error) { - var or orchestrator.Orchestrator - if route.Tag == routeTagDefaultNamespace || route.Tag == routeTagNonDefaultNamespace { - vars := mux.Vars(r.Req) - or = mgr.Orchestrator(extractNamespace(vars)) - } - cr := &coreRequest{ mgr: mgr, - or: or, + or: getOrchestrator(mgr, route.Tag, r), ctx: r.Req.Context(), apiBaseURL: apiBaseURL, } diff --git a/internal/broadcast/datatype.go b/internal/broadcast/datatype.go index 988bddf15..2255bfa1a 100644 --- a/internal/broadcast/datatype.go +++ b/internal/broadcast/datatype.go @@ -23,12 +23,12 @@ import ( "github.com/hyperledger/firefly/pkg/core" ) -func (bm *broadcastManager) BroadcastDatatype(ctx context.Context, ns string, datatype *core.Datatype, waitConfirm bool) (*core.Message, error) { +func (bm *broadcastManager) BroadcastDatatype(ctx context.Context, datatype *core.Datatype, waitConfirm bool) (*core.Message, error) { // Validate the input data definition data datatype.ID = fftypes.NewUUID() datatype.Created = fftypes.Now() - datatype.Namespace = ns + datatype.Namespace = bm.namespace if datatype.Validator == "" { datatype.Validator = core.ValidatorTypeJSON } @@ -41,10 +41,10 @@ func (bm *broadcastManager) BroadcastDatatype(ctx context.Context, ns string, da datatype.Hash = datatype.Value.Hash() // Verify the data type is now all valid, before we broadcast it - if err := bm.data.CheckDatatype(ctx, ns, datatype); err != nil { + if err := bm.data.CheckDatatype(ctx, datatype); err != nil { return nil, err } - msg, err := bm.BroadcastDefinitionAsNode(ctx, ns, datatype, core.SystemTagDefineDatatype, waitConfirm) + msg, err := bm.BroadcastDefinitionAsNode(ctx, datatype, core.SystemTagDefineDatatype, waitConfirm) if msg != nil { datatype.Message = msg.Header.ID } diff --git a/internal/broadcast/datatype_test.go b/internal/broadcast/datatype_test.go index 6878330cb..9b28e42d5 100644 --- a/internal/broadcast/datatype_test.go +++ b/internal/broadcast/datatype_test.go @@ -34,7 +34,7 @@ import ( func TestBroadcastDatatypeBadType(t *testing.T) { bm, cancel := newTestBroadcast(t) defer cancel() - _, err := bm.BroadcastDatatype(context.Background(), "ns1", &core.Datatype{ + _, err := bm.BroadcastDatatype(context.Background(), &core.Datatype{ Validator: core.ValidatorType("wrong"), }, false) assert.Regexp(t, "FF00111.*validator", err) @@ -45,7 +45,7 @@ func TestBroadcastDatatypeNSGetFail(t *testing.T) { defer cancel() mdm := bm.data.(*datamocks.Manager) mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(fmt.Errorf("pop")) - _, err := bm.BroadcastDatatype(context.Background(), "ns1", &core.Datatype{ + _, err := bm.BroadcastDatatype(context.Background(), &core.Datatype{ Name: "name1", Namespace: "ns1", Version: "0.0.1", @@ -59,10 +59,10 @@ func TestBroadcastDatatypeBadValue(t *testing.T) { defer cancel() mdm := bm.data.(*datamocks.Manager) mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(nil) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mim := bm.identity.(*identitymanagermocks.Manager) mim.On("ResolveInputSigningIdentity", mock.Anything, mock.Anything).Return(nil) - _, err := bm.BroadcastDatatype(context.Background(), "ns1", &core.Datatype{ + _, err := bm.BroadcastDatatype(context.Background(), &core.Datatype{ Namespace: "ns1", Name: "ent1", Version: "0.0.1", @@ -80,9 +80,9 @@ func TestBroadcastUpsertFail(t *testing.T) { mim.On("ResolveInputSigningIdentity", mock.Anything, mock.Anything).Return(nil) mdm.On("WriteNewMessage", mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(nil) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) - _, err := bm.BroadcastDatatype(context.Background(), "ns1", &core.Datatype{ + _, err := bm.BroadcastDatatype(context.Background(), &core.Datatype{ Namespace: "ns1", Name: "ent1", Version: "0.0.1", @@ -104,9 +104,9 @@ func TestBroadcastDatatypeInvalid(t *testing.T) { mim.On("ResolveInputIdentity", mock.Anything, mock.Anything).Return(nil) mdi.On("UpsertData", mock.Anything, mock.Anything, database.UpsertOptimizationNew).Return(nil) mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(nil) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(fmt.Errorf("pop")) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) - _, err := bm.BroadcastDatatype(context.Background(), "ns1", &core.Datatype{ + _, err := bm.BroadcastDatatype(context.Background(), &core.Datatype{ Namespace: "ns1", Name: "ent1", Version: "0.0.1", @@ -123,10 +123,10 @@ func TestBroadcastOk(t *testing.T) { mim.On("ResolveInputSigningIdentity", mock.Anything, mock.Anything).Return(nil) mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(nil) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mdm.On("WriteNewMessage", mock.Anything, mock.Anything, mock.Anything).Return(nil) - _, err := bm.BroadcastDatatype(context.Background(), "ns1", &core.Datatype{ + _, err := bm.BroadcastDatatype(context.Background(), &core.Datatype{ Namespace: "ns1", Name: "ent1", Version: "0.0.1", diff --git a/internal/broadcast/definition.go b/internal/broadcast/definition.go index ae47e6519..361b08784 100644 --- a/internal/broadcast/definition.go +++ b/internal/broadcast/definition.go @@ -28,39 +28,39 @@ import ( "github.com/hyperledger/firefly/pkg/core" ) -func (bm *broadcastManager) BroadcastDefinitionAsNode(ctx context.Context, ns string, def core.Definition, tag string, waitConfirm bool) (msg *core.Message, err error) { - return bm.BroadcastDefinition(ctx, ns, def, &core.SignerRef{ /* resolve to node default */ }, tag, waitConfirm) +func (bm *broadcastManager) BroadcastDefinitionAsNode(ctx context.Context, def core.Definition, tag string, waitConfirm bool) (msg *core.Message, err error) { + return bm.BroadcastDefinition(ctx, def, &core.SignerRef{ /* resolve to node default */ }, tag, waitConfirm) } -func (bm *broadcastManager) BroadcastDefinition(ctx context.Context, ns string, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) { +func (bm *broadcastManager) BroadcastDefinition(ctx context.Context, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) { err = bm.identity.ResolveInputSigningIdentity(ctx, signingIdentity) if err != nil { return nil, err } - return bm.broadcastDefinitionCommon(ctx, ns, def, signingIdentity, tag, waitConfirm) + return bm.broadcastDefinitionCommon(ctx, def, signingIdentity, tag, waitConfirm) } // BroadcastIdentityClaim is a special form of BroadcastDefinitionAsNode where the signing identity does not need to have been pre-registered // The blockchain "key" will be normalized, but the "author" will pass through unchecked -func (bm *broadcastManager) BroadcastIdentityClaim(ctx context.Context, ns string, def *core.IdentityClaim, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) { +func (bm *broadcastManager) BroadcastIdentityClaim(ctx context.Context, def *core.IdentityClaim, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) { signingIdentity.Key, err = bm.identity.NormalizeSigningKey(ctx, signingIdentity.Key, identity.KeyNormalizationBlockchainPlugin) if err != nil { return nil, err } - return bm.broadcastDefinitionCommon(ctx, ns, def, signingIdentity, tag, waitConfirm) + return bm.broadcastDefinitionCommon(ctx, def, signingIdentity, tag, waitConfirm) } -func (bm *broadcastManager) broadcastDefinitionCommon(ctx context.Context, ns string, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (*core.Message, error) { +func (bm *broadcastManager) broadcastDefinitionCommon(ctx context.Context, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (*core.Message, error) { // Serialize it into a data object, as a piece of data we can write to a message d := &core.Data{ Validator: core.ValidatorTypeSystemDefinition, ID: fftypes.NewUUID(), - Namespace: ns, + Namespace: bm.namespace, Created: fftypes.Now(), } b, err := json.Marshal(&def) @@ -77,7 +77,7 @@ func (bm *broadcastManager) broadcastDefinitionCommon(ctx context.Context, ns st Message: &core.MessageInOut{ Message: core.Message{ Header: core.MessageHeader{ - Namespace: ns, + Namespace: bm.namespace, Type: core.MessageTypeDefinition, SignerRef: *signingIdentity, Topics: core.FFStringArray{def.Topic()}, diff --git a/internal/broadcast/definition_test.go b/internal/broadcast/definition_test.go index 5eac2968e..40f4f2593 100644 --- a/internal/broadcast/definition_test.go +++ b/internal/broadcast/definition_test.go @@ -38,7 +38,7 @@ func TestBroadcastDefinitionAsNodeConfirm(t *testing.T) { mim.On("ResolveInputSigningIdentity", mock.Anything, mock.Anything).Return(nil) msa.On("WaitForMessage", bm.ctx, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("pop")) - _, err := bm.BroadcastDefinitionAsNode(bm.ctx, "ns1", &core.Namespace{}, core.SystemTagDefineNamespace, true) + _, err := bm.BroadcastDefinitionAsNode(bm.ctx, &core.Namespace{}, core.SystemTagDefineNamespace, true) assert.EqualError(t, err, "pop") msa.AssertExpectations(t) @@ -55,7 +55,7 @@ func TestBroadcastIdentityClaim(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "0x1234", identity.KeyNormalizationBlockchainPlugin).Return("", nil) msa.On("WaitForMessage", bm.ctx, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("pop")) - _, err := bm.BroadcastIdentityClaim(bm.ctx, "ns1", &core.IdentityClaim{ + _, err := bm.BroadcastIdentityClaim(bm.ctx, &core.IdentityClaim{ Identity: &core.Identity{}, }, &core.SignerRef{ Key: "0x1234", @@ -74,7 +74,7 @@ func TestBroadcastIdentityClaimFail(t *testing.T) { mim.On("NormalizeSigningKey", mock.Anything, "0x1234", identity.KeyNormalizationBlockchainPlugin).Return("", fmt.Errorf("pop")) - _, err := bm.BroadcastIdentityClaim(bm.ctx, "ns1", &core.IdentityClaim{ + _, err := bm.BroadcastIdentityClaim(bm.ctx, &core.IdentityClaim{ Identity: &core.Identity{}, }, &core.SignerRef{ Key: "0x1234", @@ -90,12 +90,11 @@ func TestBroadcastDatatypeDefinitionAsNodeConfirm(t *testing.T) { msa := bm.syncasync.(*syncasyncmocks.Bridge) mim := bm.identity.(*identitymanagermocks.Manager) - ns := "customNamespace" mim.On("ResolveInputSigningIdentity", mock.Anything, mock.Anything).Return(nil) msa.On("WaitForMessage", bm.ctx, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("pop")) - _, err := bm.BroadcastDefinitionAsNode(bm.ctx, ns, &core.Datatype{}, core.SystemTagDefineNamespace, true) + _, err := bm.BroadcastDefinitionAsNode(bm.ctx, &core.Datatype{}, core.SystemTagDefineNamespace, true) assert.EqualError(t, err, "pop") msa.AssertExpectations(t) @@ -108,7 +107,7 @@ func TestBroadcastDefinitionBadIdentity(t *testing.T) { mim := bm.identity.(*identitymanagermocks.Manager) mim.On("ResolveInputSigningIdentity", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) - _, err := bm.BroadcastDefinition(bm.ctx, "ns1", &core.Namespace{}, &core.SignerRef{ + _, err := bm.BroadcastDefinition(bm.ctx, &core.Namespace{}, &core.SignerRef{ Author: "wrong", Key: "wrong", }, core.SystemTagDefineNamespace, false) diff --git a/internal/broadcast/manager.go b/internal/broadcast/manager.go index a012d0b04..580e54915 100644 --- a/internal/broadcast/manager.go +++ b/internal/broadcast/manager.go @@ -46,12 +46,12 @@ type Manager interface { core.Named NewBroadcast(in *core.MessageInOut) sysmessaging.MessageSender - BroadcastDatatype(ctx context.Context, ns string, datatype *core.Datatype, waitConfirm bool) (msg *core.Message, err error) + BroadcastDatatype(ctx context.Context, datatype *core.Datatype, waitConfirm bool) (msg *core.Message, err error) BroadcastMessage(ctx context.Context, in *core.MessageInOut, waitConfirm bool) (out *core.Message, err error) - BroadcastDefinitionAsNode(ctx context.Context, ns string, def core.Definition, tag string, waitConfirm bool) (msg *core.Message, err error) - BroadcastDefinition(ctx context.Context, ns string, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) - BroadcastIdentityClaim(ctx context.Context, ns string, def *core.IdentityClaim, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) - BroadcastTokenPool(ctx context.Context, ns string, pool *core.TokenPoolAnnouncement, waitConfirm bool) (msg *core.Message, err error) + BroadcastDefinitionAsNode(ctx context.Context, def core.Definition, tag string, waitConfirm bool) (msg *core.Message, err error) + BroadcastDefinition(ctx context.Context, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) + BroadcastIdentityClaim(ctx context.Context, def *core.IdentityClaim, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (msg *core.Message, err error) + BroadcastTokenPool(ctx context.Context, pool *core.TokenPoolAnnouncement, waitConfirm bool) (msg *core.Message, err error) Start() error WaitStop() diff --git a/internal/broadcast/tokenpool.go b/internal/broadcast/tokenpool.go index b848f96e7..5a6dc400a 100644 --- a/internal/broadcast/tokenpool.go +++ b/internal/broadcast/tokenpool.go @@ -22,7 +22,7 @@ import ( "github.com/hyperledger/firefly/pkg/core" ) -func (bm *broadcastManager) BroadcastTokenPool(ctx context.Context, ns string, pool *core.TokenPoolAnnouncement, waitConfirm bool) (msg *core.Message, err error) { +func (bm *broadcastManager) BroadcastTokenPool(ctx context.Context, pool *core.TokenPoolAnnouncement, waitConfirm bool) (msg *core.Message, err error) { if err := pool.Pool.Validate(ctx); err != nil { return nil, err } @@ -30,7 +30,7 @@ func (bm *broadcastManager) BroadcastTokenPool(ctx context.Context, ns string, p return nil, err } - msg, err = bm.BroadcastDefinitionAsNode(ctx, ns, pool, core.SystemTagDefinePool, waitConfirm) + msg, err = bm.BroadcastDefinitionAsNode(ctx, pool, core.SystemTagDefinePool, waitConfirm) if msg != nil { pool.Pool.Message = msg.Header.ID } diff --git a/internal/broadcast/tokenpool_test.go b/internal/broadcast/tokenpool_test.go index afada1625..aaeaa1904 100644 --- a/internal/broadcast/tokenpool_test.go +++ b/internal/broadcast/tokenpool_test.go @@ -48,7 +48,7 @@ func TestBroadcastTokenPoolNSGetFail(t *testing.T) { mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(fmt.Errorf("pop")) - _, err := bm.BroadcastTokenPool(context.Background(), "ns1", pool, false) + _, err := bm.BroadcastTokenPool(context.Background(), pool, false) assert.EqualError(t, err, "pop") mdm.AssertExpectations(t) @@ -71,7 +71,7 @@ func TestBroadcastTokenPoolInvalid(t *testing.T) { }, } - _, err := bm.BroadcastTokenPool(context.Background(), "ns1", pool, false) + _, err := bm.BroadcastTokenPool(context.Background(), pool, false) assert.Regexp(t, "FF00140", err) mdi.AssertExpectations(t) @@ -99,7 +99,7 @@ func TestBroadcastTokenPoolBroadcastFail(t *testing.T) { mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(nil) mdm.On("WriteNewMessage", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) - _, err := bm.BroadcastTokenPool(context.Background(), "ns1", pool, false) + _, err := bm.BroadcastTokenPool(context.Background(), pool, false) assert.EqualError(t, err, "pop") mdm.AssertExpectations(t) @@ -127,7 +127,7 @@ func TestBroadcastTokenPoolOk(t *testing.T) { mdm.On("VerifyNamespaceExists", mock.Anything, "ns1").Return(nil) mdm.On("WriteNewMessage", mock.Anything, mock.Anything).Return(nil) - _, err := bm.BroadcastTokenPool(context.Background(), "ns1", pool, false) + _, err := bm.BroadcastTokenPool(context.Background(), pool, false) assert.NoError(t, err) mdm.AssertExpectations(t) diff --git a/internal/contracts/manager.go b/internal/contracts/manager.go index 3d6537f76..6cc9c3e2e 100644 --- a/internal/contracts/manager.go +++ b/internal/contracts/manager.go @@ -139,7 +139,7 @@ func (cm *contractManager) BroadcastFFI(ctx context.Context, ffi *core.FFI, wait } output = ffi - msg, err := cm.broadcast.BroadcastDefinitionAsNode(ctx, cm.namespace, ffi, core.SystemTagDefineFFI, waitConfirm) + msg, err := cm.broadcast.BroadcastDefinitionAsNode(ctx, ffi, core.SystemTagDefineFFI, waitConfirm) if err != nil { return nil, err } @@ -373,7 +373,7 @@ func (cm *contractManager) BroadcastContractAPI(ctx context.Context, httpServerU return nil, err } - msg, err := cm.broadcast.BroadcastDefinitionAsNode(ctx, cm.namespace, api, core.SystemTagDefineContractAPI, waitConfirm) + msg, err := cm.broadcast.BroadcastDefinitionAsNode(ctx, api, core.SystemTagDefineContractAPI, waitConfirm) if err != nil { return nil, err } diff --git a/internal/contracts/manager_test.go b/internal/contracts/manager_test.go index d23b8aefc..743d95268 100644 --- a/internal/contracts/manager_test.go +++ b/internal/contracts/manager_test.go @@ -119,7 +119,7 @@ func TestBroadcastFFI(t *testing.T) { ID: fftypes.NewUUID(), }, } - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) ffi := &core.FFI{ Name: "test", Version: "1.0.0", @@ -153,7 +153,7 @@ func TestBroadcastFFIInvalid(t *testing.T) { ID: fftypes.NewUUID(), }, } - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) ffi := &core.FFI{ Name: "test", Version: "1.0.0", @@ -186,7 +186,7 @@ func TestBroadcastFFIExists(t *testing.T) { ID: fftypes.NewUUID(), }, } - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) ffi := &core.FFI{ Name: "test", Version: "1.0.0", @@ -205,7 +205,7 @@ func TestBroadcastFFIFail(t *testing.T) { mdb.On("GetFFI", mock.Anything, "ns1", "test", "1.0.0").Return(nil, nil) mim.On("GetOrgKey", mock.Anything).Return("key", nil) - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(nil, fmt.Errorf("pop")) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(nil, fmt.Errorf("pop")) ffi := &core.FFI{ Name: "test", Version: "1.0.0", @@ -1946,7 +1946,7 @@ func TestBroadcastContractAPI(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(&core.FFI{}, nil) - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) api, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) @@ -2017,7 +2017,7 @@ func TestBroadcastContractAPIExisting(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(existing, nil) mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(&core.FFI{}, nil) - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) @@ -2090,7 +2090,7 @@ func TestBroadcastContractAPIInterfaceName(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(&core.FFI{ID: interfaceID}, nil) - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) @@ -2121,7 +2121,7 @@ func TestBroadcastContractAPIFail(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) mdb.On("GetFFIByID", mock.Anything, "ns1", api.Interface.ID).Return(&core.FFI{}, nil) - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(nil, fmt.Errorf("pop")) + mbm.On("BroadcastDefinitionAsNode", mock.Anything, mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(nil, fmt.Errorf("pop")) _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", api, false) diff --git a/internal/data/blobstore.go b/internal/data/blobstore.go index 9cfb032c6..f541de457 100644 --- a/internal/data/blobstore.go +++ b/internal/data/blobstore.go @@ -41,7 +41,7 @@ type blobStore struct { exchange dataexchange.Plugin } -func (bs *blobStore) uploadVerifyBlob(ctx context.Context, ns string, id *fftypes.UUID, reader io.Reader) (hash *fftypes.Bytes32, written int64, payloadRef string, err error) { +func (bs *blobStore) uploadVerifyBlob(ctx context.Context, id *fftypes.UUID, reader io.Reader) (hash *fftypes.Bytes32, written int64, payloadRef string, err error) { hashCalc := sha256.New() dxReader, dx := io.Pipe() storeAndHash := io.MultiWriter(hashCalc, dx) @@ -55,7 +55,7 @@ func (bs *blobStore) uploadVerifyBlob(ctx context.Context, ns string, id *fftype copyDone <- err }() - payloadRef, uploadHash, uploadSize, dxErr := bs.exchange.UploadBlob(ctx, ns, *id, dxReader) + payloadRef, uploadHash, uploadSize, dxErr := bs.exchange.UploadBlob(ctx, bs.dm.namespace, *id, dxReader) dxReader.Close() copyErr := <-copyDone if dxErr != nil { @@ -79,11 +79,11 @@ func (bs *blobStore) uploadVerifyBlob(ctx context.Context, ns string, id *fftype } -func (bs *blobStore) UploadBlob(ctx context.Context, ns string, inData *core.DataRefOrValue, mpart *ffapi.Multipart, autoMeta bool) (*core.Data, error) { +func (bs *blobStore) UploadBlob(ctx context.Context, inData *core.DataRefOrValue, mpart *ffapi.Multipart, autoMeta bool) (*core.Data, error) { data := &core.Data{ ID: fftypes.NewUUID(), - Namespace: ns, + Namespace: bs.dm.namespace, Created: fftypes.Now(), Validator: inData.Validator, Datatype: inData.Datatype, @@ -91,10 +91,10 @@ func (bs *blobStore) UploadBlob(ctx context.Context, ns string, inData *core.Dat } data.ID = fftypes.NewUUID() - data.Namespace = ns + data.Namespace = bs.dm.namespace data.Created = fftypes.Now() - hash, blobSize, payloadRef, err := bs.uploadVerifyBlob(ctx, ns, data.ID, mpart.Data) + hash, blobSize, payloadRef, err := bs.uploadVerifyBlob(ctx, data.ID, mpart.Data) if err != nil { return nil, err } @@ -119,7 +119,7 @@ func (bs *blobStore) UploadBlob(ctx context.Context, ns string, inData *core.Dat Created: fftypes.Now(), } - err = bs.dm.checkValidation(ctx, ns, data.Validator, data.Datatype, data.Value) + err = bs.dm.checkValidation(ctx, data.Validator, data.Datatype, data.Value) if err == nil { err = data.Seal(ctx, blob) } @@ -142,11 +142,8 @@ func (bs *blobStore) UploadBlob(ctx context.Context, ns string, inData *core.Dat return data, nil } -func (bs *blobStore) DownloadBlob(ctx context.Context, ns, dataID string) (*core.Blob, io.ReadCloser, error) { +func (bs *blobStore) DownloadBlob(ctx context.Context, dataID string) (*core.Blob, io.ReadCloser, error) { - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { - return nil, nil, err - } id, err := fftypes.ParseUUID(ctx, dataID) if err != nil { return nil, nil, err @@ -156,7 +153,7 @@ func (bs *blobStore) DownloadBlob(ctx context.Context, ns, dataID string) (*core if err != nil { return nil, nil, err } - if data == nil || data.Namespace != ns { + if data == nil { return nil, nil, i18n.NewError(ctx, coremsgs.Msg404NoResult) } if data.Blob == nil || data.Blob.Hash == nil { diff --git a/internal/data/blobstore_test.go b/internal/data/blobstore_test.go index ce3ee758c..c6246f27f 100644 --- a/internal/data/blobstore_test.go +++ b/internal/data/blobstore_test.go @@ -70,7 +70,7 @@ func TestUploadBlobOk(t *testing.T) { dxUpload.ReturnArguments = mock.Arguments{fmt.Sprintf("ns1/%s", uuid), &hash, int64(len(b)), err} } - data, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader(b)}, false) + data, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader(b)}, false) assert.NoError(t, err) // Check the hashes and other details of the data @@ -111,7 +111,7 @@ func TestUploadBlobAutoMetaOk(t *testing.T) { dxUpload.ReturnArguments = mock.Arguments{fmt.Sprintf("ns1/%s", uuid), &hash, int64(len(readBytes)), err} } - data, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{ + data, err := dm.UploadBlob(ctx, &core.DataRefOrValue{ Value: fftypes.JSONAnyPtr(`{"custom": "value1"}`), }, &ffapi.Multipart{ Data: bytes.NewReader([]byte(`hello`)), @@ -146,7 +146,7 @@ func TestUploadBlobBadValidator(t *testing.T) { dxUpload.ReturnArguments = mock.Arguments{fmt.Sprintf("ns1/%s", uuid), &hash, int64(len(readBytes)), err} } - _, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.UploadBlob(ctx, &core.DataRefOrValue{ Value: fftypes.JSONAnyPtr(`{"custom": "value1"}`), Validator: "wrong", }, &ffapi.Multipart{ @@ -172,7 +172,7 @@ func TestUploadBlobReadFail(t *testing.T) { assert.NoError(t, err) } - _, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{}, &ffapi.Multipart{Data: iotest.ErrReader(fmt.Errorf("pop"))}, false) + _, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: iotest.ErrReader(fmt.Errorf("pop"))}, false) assert.Regexp(t, "FF10217.*pop", err) } @@ -185,7 +185,7 @@ func TestUploadBlobWriteFailDoesNotRead(t *testing.T) { mdx := dm.exchange.(*dataexchangemocks.Plugin) mdx.On("UploadBlob", ctx, "ns1", mock.Anything, mock.Anything).Return("", nil, int64(0), fmt.Errorf("pop")) - _, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(`any old data`))}, false) + _, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(`any old data`))}, false) assert.Regexp(t, "pop", err) } @@ -203,7 +203,7 @@ func TestUploadBlobHashMismatchCalculated(t *testing.T) { assert.Nil(t, err) } - _, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(b))}, false) + _, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(b))}, false) assert.Regexp(t, "FF10238", err) } @@ -222,7 +222,7 @@ func TestUploadBlobSizeMismatch(t *testing.T) { assert.Nil(t, err) } - _, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(b))}, false) + _, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(b))}, false) assert.Regexp(t, "FF10323", err) } @@ -243,7 +243,7 @@ func TestUploadBlobUpsertFail(t *testing.T) { mdi := dm.database.(*databasemocks.Plugin) mdi.On("RunAsGroup", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) - _, err := dm.UploadBlob(ctx, "ns1", &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(b))}, false) + _, err := dm.UploadBlob(ctx, &core.DataRefOrValue{}, &ffapi.Multipart{Data: bytes.NewReader([]byte(b))}, false) assert.Regexp(t, "pop", err) } @@ -274,7 +274,7 @@ func TestDownloadBlobOk(t *testing.T) { ioutil.NopCloser(bytes.NewReader([]byte("some blob"))), nil) - blob, reader, err := dm.DownloadBlob(ctx, "ns1", dataID.String()) + blob, reader, err := dm.DownloadBlob(ctx, dataID.String()) assert.NoError(t, err) assert.Equal(t, blobHash.String(), blob.Hash.String()) b, err := ioutil.ReadAll(reader) @@ -301,7 +301,7 @@ func TestDownloadBlobNotFound(t *testing.T) { }, nil) mdi.On("GetBlobMatchingHash", ctx, blobHash).Return(nil, nil) - _, _, err := dm.DownloadBlob(ctx, "ns1", dataID.String()) + _, _, err := dm.DownloadBlob(ctx, dataID.String()) assert.Regexp(t, "FF10239", err) } @@ -324,7 +324,7 @@ func TestDownloadBlobLookupErr(t *testing.T) { }, nil) mdi.On("GetBlobMatchingHash", ctx, blobHash).Return(nil, fmt.Errorf("pop")) - _, _, err := dm.DownloadBlob(ctx, "ns1", dataID.String()) + _, _, err := dm.DownloadBlob(ctx, dataID.String()) assert.Regexp(t, "pop", err) } @@ -343,12 +343,12 @@ func TestDownloadBlobNoBlob(t *testing.T) { Blob: &core.BlobRef{}, }, nil) - _, _, err := dm.DownloadBlob(ctx, "ns1", dataID.String()) + _, _, err := dm.DownloadBlob(ctx, dataID.String()) assert.Regexp(t, "FF10241", err) } -func TestDownloadBlobNSMismatch(t *testing.T) { +func TestDownloadBlobNoData(t *testing.T) { dm, ctx, cancel := newTestDataManager(t) defer cancel() @@ -356,13 +356,9 @@ func TestDownloadBlobNSMismatch(t *testing.T) { dataID := fftypes.NewUUID() mdi := dm.database.(*databasemocks.Plugin) - mdi.On("GetDataByID", ctx, "ns1", dataID, false).Return(&core.Data{ - ID: dataID, - Namespace: "ns2", - Blob: &core.BlobRef{}, - }, nil) + mdi.On("GetDataByID", ctx, "ns1", dataID, false).Return(nil, nil) - _, _, err := dm.DownloadBlob(ctx, "ns1", dataID.String()) + _, _, err := dm.DownloadBlob(ctx, dataID.String()) assert.Regexp(t, "FF10143", err) } @@ -377,29 +373,17 @@ func TestDownloadBlobDataLookupErr(t *testing.T) { mdi := dm.database.(*databasemocks.Plugin) mdi.On("GetDataByID", ctx, "ns1", dataID, false).Return(nil, fmt.Errorf("pop")) - _, _, err := dm.DownloadBlob(ctx, "ns1", dataID.String()) + _, _, err := dm.DownloadBlob(ctx, dataID.String()) assert.Regexp(t, "pop", err) } -func TestDownloadBlobBadNS(t *testing.T) { - - dm, ctx, cancel := newTestDataManager(t) - defer cancel() - - dataID := fftypes.NewUUID() - - _, _, err := dm.DownloadBlob(ctx, "!wrong", dataID.String()) - assert.Regexp(t, "FF00140.*namespace", err) - -} - func TestDownloadBlobBadID(t *testing.T) { dm, ctx, cancel := newTestDataManager(t) defer cancel() - _, _, err := dm.DownloadBlob(ctx, "ns1", "!uuid") + _, _, err := dm.DownloadBlob(ctx, "!uuid") assert.Regexp(t, "FF00138", err) } diff --git a/internal/data/data_manager.go b/internal/data/data_manager.go index d311a2cea..d7b3b7276 100644 --- a/internal/data/data_manager.go +++ b/internal/data/data_manager.go @@ -37,7 +37,7 @@ import ( ) type Manager interface { - CheckDatatype(ctx context.Context, ns string, datatype *core.Datatype) error + CheckDatatype(ctx context.Context, datatype *core.Datatype) error ValidateAll(ctx context.Context, data core.DataArray) (valid bool, err error) GetMessageWithDataCached(ctx context.Context, msgID *fftypes.UUID, options ...CacheReadOption) (msg *core.Message, data core.DataArray, foundAllData bool, err error) GetMessageDataCached(ctx context.Context, msg *core.Message, options ...CacheReadOption) (data core.DataArray, foundAll bool, err error) @@ -49,9 +49,9 @@ type Manager interface { WriteNewMessage(ctx context.Context, newMsg *NewMessage) error VerifyNamespaceExists(ctx context.Context, ns string) error - UploadJSON(ctx context.Context, ns string, inData *core.DataRefOrValue) (*core.Data, error) - UploadBlob(ctx context.Context, ns string, inData *core.DataRefOrValue, blob *ffapi.Multipart, autoMeta bool) (*core.Data, error) - DownloadBlob(ctx context.Context, ns, dataID string) (*core.Blob, io.ReadCloser, error) + UploadJSON(ctx context.Context, inData *core.DataRefOrValue) (*core.Data, error) + UploadBlob(ctx context.Context, inData *core.DataRefOrValue, blob *ffapi.Multipart, autoMeta bool) (*core.Data, error) + DownloadBlob(ctx context.Context, dataID string) (*core.Blob, io.ReadCloser, error) HydrateBatch(ctx context.Context, persistedBatch *core.BatchPersisted) (*core.Batch, error) WaitStop() } @@ -139,8 +139,8 @@ func NewDataManager(ctx context.Context, ns string, di database.Plugin, pi share return dm, nil } -func (dm *dataManager) CheckDatatype(ctx context.Context, ns string, datatype *core.Datatype) error { - _, err := newJSONValidator(ctx, ns, datatype) +func (dm *dataManager) CheckDatatype(ctx context.Context, datatype *core.Datatype) error { + _, err := newJSONValidator(ctx, dm.namespace, datatype) return err } @@ -172,32 +172,32 @@ func (dm *dataManager) VerifyNamespaceExists(ctx context.Context, ns string) err } // getValidatorForDatatype only returns database errors - not found (of all kinds) is a nil -func (dm *dataManager) getValidatorForDatatype(ctx context.Context, ns string, validator core.ValidatorType, datatypeRef *core.DatatypeRef) (Validator, error) { +func (dm *dataManager) getValidatorForDatatype(ctx context.Context, validator core.ValidatorType, datatypeRef *core.DatatypeRef) (Validator, error) { if validator == "" { validator = core.ValidatorTypeJSON } - if ns == "" || datatypeRef == nil || datatypeRef.Name == "" || datatypeRef.Version == "" { - log.L(ctx).Warnf("Invalid datatype reference '%s:%s:%s'", validator, ns, datatypeRef) + if datatypeRef == nil || datatypeRef.Name == "" || datatypeRef.Version == "" { + log.L(ctx).Warnf("Invalid datatype reference '%s:%s:%s'", validator, dm.namespace, datatypeRef) return nil, nil } - key := fmt.Sprintf("%s:%s:%s", validator, ns, datatypeRef) + key := fmt.Sprintf("%s:%s:%s", validator, dm.namespace, datatypeRef) if cached := dm.validatorCache.Get(key); cached != nil { cached.Extend(dm.validatorCacheTTL) return cached.Value().(Validator), nil } - datatype, err := dm.database.GetDatatypeByName(ctx, ns, datatypeRef.Name, datatypeRef.Version) + datatype, err := dm.database.GetDatatypeByName(ctx, dm.namespace, datatypeRef.Name, datatypeRef.Version) if err != nil { return nil, err } if datatype == nil { return nil, nil } - v, err := newJSONValidator(ctx, ns, datatype) + v, err := newJSONValidator(ctx, dm.namespace, datatype) if err != nil { - log.L(ctx).Errorf("Invalid validator stored for '%s:%s:%s': %s", validator, ns, datatypeRef, err) + log.L(ctx).Errorf("Invalid validator stored for '%s:%s:%s': %s", validator, dm.namespace, datatypeRef, err) return nil, nil } @@ -336,7 +336,7 @@ func (dm *dataManager) getMessageData(ctx context.Context, msg *core.Message) (d func (dm *dataManager) ValidateAll(ctx context.Context, data core.DataArray) (valid bool, err error) { for _, d := range data { if d.Datatype != nil && d.Validator != core.ValidatorTypeNone { - v, err := dm.getValidatorForDatatype(ctx, d.Namespace, d.Validator, d.Datatype) + v, err := dm.getValidatorForDatatype(ctx, d.Validator, d.Datatype) if err != nil { return false, err } @@ -388,7 +388,7 @@ func (dm *dataManager) resolveBlob(ctx context.Context, blobRef *core.BlobRef) ( return nil, nil } -func (dm *dataManager) checkValidation(ctx context.Context, ns string, validator core.ValidatorType, datatype *core.DatatypeRef, value *fftypes.JSONAny) error { +func (dm *dataManager) checkValidation(ctx context.Context, validator core.ValidatorType, datatype *core.DatatypeRef, value *fftypes.JSONAny) error { if validator == "" { validator = core.ValidatorTypeJSON } @@ -401,7 +401,7 @@ func (dm *dataManager) checkValidation(ctx context.Context, ns string, validator return i18n.NewError(ctx, coremsgs.MsgDatatypeNotFound, datatype) } if validator != core.ValidatorTypeNone { - v, err := dm.getValidatorForDatatype(ctx, ns, validator, datatype) + v, err := dm.getValidatorForDatatype(ctx, validator, datatype) if err != nil { return err } @@ -417,14 +417,14 @@ func (dm *dataManager) checkValidation(ctx context.Context, ns string, validator return nil } -func (dm *dataManager) validateInputData(ctx context.Context, ns string, inData *core.DataRefOrValue) (data *core.Data, err error) { +func (dm *dataManager) validateInputData(ctx context.Context, inData *core.DataRefOrValue) (data *core.Data, err error) { validator := inData.Validator datatype := inData.Datatype value := inData.Value blobRef := inData.Blob - if err := dm.checkValidation(ctx, ns, validator, datatype, value); err != nil { + if err := dm.checkValidation(ctx, validator, datatype, value); err != nil { return nil, err } @@ -437,7 +437,7 @@ func (dm *dataManager) validateInputData(ctx context.Context, ns string, inData data = &core.Data{ Validator: validator, Datatype: datatype, - Namespace: ns, + Namespace: dm.namespace, Value: value, Blob: blobRef, } @@ -448,8 +448,8 @@ func (dm *dataManager) validateInputData(ctx context.Context, ns string, inData return data, nil } -func (dm *dataManager) UploadJSON(ctx context.Context, ns string, inData *core.DataRefOrValue) (*core.Data, error) { - data, err := dm.validateInputData(ctx, ns, inData) +func (dm *dataManager) UploadJSON(ctx context.Context, inData *core.DataRefOrValue) (*core.Data, error) { + data, err := dm.validateInputData(ctx, inData) if err != nil { return nil, err } @@ -470,7 +470,6 @@ func (dm *dataManager) ResolveInlineData(ctx context.Context, newMessage *NewMes } inData := newMessage.Message.InlineData - msg := newMessage.Message newMessage.AllData = make(core.DataArray, len(newMessage.Message.InlineData)) for i, dataOrValue := range inData { var d *core.Data @@ -489,7 +488,7 @@ func (dm *dataManager) ResolveInlineData(ctx context.Context, newMessage *NewMes } case dataOrValue.Value != nil || dataOrValue.Blob != nil: // We've got a Value, so we can validate + store it - if d, err = dm.validateInputData(ctx, msg.Header.Namespace, dataOrValue); err != nil { + if d, err = dm.validateInputData(ctx, dataOrValue); err != nil { return err } newMessage.NewData = append(newMessage.NewData, d) diff --git a/internal/data/data_manager_test.go b/internal/data/data_manager_test.go index 6fad794e6..d2376a2fa 100644 --- a/internal/data/data_manager_test.go +++ b/internal/data/data_manager_test.go @@ -105,7 +105,7 @@ func TestValidateE2E(t *testing.T) { assert.Regexp(t, "FF10198", err) assert.False(t, isValid) - v, err := dm.getValidatorForDatatype(ctx, data.Namespace, data.Validator, data.Datatype) + v, err := dm.getValidatorForDatatype(ctx, data.Validator, data.Datatype) err = v.Validate(ctx, data) assert.Regexp(t, "FF10198", err) @@ -141,7 +141,7 @@ func TestWriteNewMessageE2E(t *testing.T) { }).Return(nil) mdi.On("InsertDataArray", mock.Anything, mock.Anything).Return(nil).Once() - data1, err := dm.UploadJSON(ctx, "ns1", &core.DataRefOrValue{ + data1, err := dm.UploadJSON(ctx, &core.DataRefOrValue{ Value: fftypes.JSONAnyPtr(`"message 1 - data A"`), Validator: core.ValidatorTypeJSON, Datatype: &core.DatatypeRef{ @@ -235,11 +235,11 @@ func TestValidatorLookupCached(t *testing.T) { Namespace: "0.0.1", } mdi.On("GetDatatypeByName", mock.Anything, "ns1", "customer", "0.0.1").Return(dt, nil).Once() - lookup1, err := dm.getValidatorForDatatype(ctx, "ns1", core.ValidatorTypeJSON, ref) + lookup1, err := dm.getValidatorForDatatype(ctx, core.ValidatorTypeJSON, ref) assert.NoError(t, err) assert.Equal(t, "customer", lookup1.(*jsonValidator).datatype.Name) - lookup2, err := dm.getValidatorForDatatype(ctx, "ns1", core.ValidatorTypeJSON, ref) + lookup2, err := dm.getValidatorForDatatype(ctx, core.ValidatorTypeJSON, ref) assert.NoError(t, err) assert.Equal(t, lookup1, lookup2) @@ -378,7 +378,7 @@ func TestCheckDatatypeVerifiesTheSchema(t *testing.T) { dm, ctx, cancel := newTestDataManager(t) defer cancel() - err := dm.CheckDatatype(ctx, "ns1", &core.Datatype{}) + err := dm.CheckDatatype(ctx, &core.Datatype{}) assert.Regexp(t, "FF10196", err) } @@ -611,7 +611,7 @@ func TestUploadJSONLoadDatatypeFail(t *testing.T) { mdi := dm.database.(*databasemocks.Plugin) mdi.On("GetDatatypeByName", ctx, "ns1", "customer", "0.0.1").Return(nil, fmt.Errorf("pop")) - _, err := dm.UploadJSON(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.UploadJSON(ctx, &core.DataRefOrValue{ Datatype: &core.DatatypeRef{ Name: "customer", Version: "0.0.1", @@ -624,7 +624,7 @@ func TestUploadJSONLoadInsertDataFail(t *testing.T) { dm, ctx, cancel := newTestDataManager(t) defer cancel() dm.messageWriter.close() - _, err := dm.UploadJSON(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.UploadJSON(ctx, &core.DataRefOrValue{ Value: fftypes.JSONAnyPtr(`{}`), }) assert.Regexp(t, "FF00154", err) @@ -634,7 +634,7 @@ func TestValidateAndStoreLoadNilRef(t *testing.T) { dm, ctx, cancel := newTestDataManager(t) defer cancel() - _, err := dm.validateInputData(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.validateInputData(ctx, &core.DataRefOrValue{ Validator: core.ValidatorTypeJSON, Datatype: nil, }) @@ -647,7 +647,7 @@ func TestValidateAndStoreLoadValidatorUnknown(t *testing.T) { defer cancel() mdi := dm.database.(*databasemocks.Plugin) mdi.On("GetDatatypeByName", mock.Anything, "ns1", "customer", "0.0.1").Return(nil, nil) - _, err := dm.validateInputData(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.validateInputData(ctx, &core.DataRefOrValue{ Validator: "wrong!", Datatype: &core.DatatypeRef{ Name: "customer", @@ -664,7 +664,7 @@ func TestValidateAndStoreLoadBadRef(t *testing.T) { defer cancel() mdi := dm.database.(*databasemocks.Plugin) mdi.On("GetDatatypeByName", mock.Anything, "ns1", "customer", "0.0.1").Return(nil, nil) - _, err := dm.validateInputData(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.validateInputData(ctx, &core.DataRefOrValue{ Datatype: &core.DatatypeRef{ // Missing name }, @@ -678,7 +678,7 @@ func TestValidateAndStoreNotFound(t *testing.T) { defer cancel() mdi := dm.database.(*databasemocks.Plugin) mdi.On("GetDatatypeByName", mock.Anything, "ns1", "customer", "0.0.1").Return(nil, nil) - _, err := dm.validateInputData(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.validateInputData(ctx, &core.DataRefOrValue{ Datatype: &core.DatatypeRef{ Name: "customer", Version: "0.0.1", @@ -694,7 +694,7 @@ func TestValidateAndStoreBlobError(t *testing.T) { mdi := dm.database.(*databasemocks.Plugin) blobHash := fftypes.NewRandB32() mdi.On("GetBlobMatchingHash", mock.Anything, blobHash).Return(nil, fmt.Errorf("pop")) - _, err := dm.validateInputData(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.validateInputData(ctx, &core.DataRefOrValue{ Blob: &core.BlobRef{ Hash: blobHash, }, @@ -709,7 +709,7 @@ func TestValidateAndStoreBlobNotFound(t *testing.T) { mdi := dm.database.(*databasemocks.Plugin) blobHash := fftypes.NewRandB32() mdi.On("GetBlobMatchingHash", mock.Anything, blobHash).Return(nil, nil) - _, err := dm.validateInputData(ctx, "ns1", &core.DataRefOrValue{ + _, err := dm.validateInputData(ctx, &core.DataRefOrValue{ Blob: &core.BlobRef{ Hash: blobHash, }, @@ -742,7 +742,7 @@ func TestGetValidatorForDatatypeNilRef(t *testing.T) { dm, ctx, cancel := newTestDataManager(t) defer cancel() - v, err := dm.getValidatorForDatatype(ctx, "", "", nil) + v, err := dm.getValidatorForDatatype(ctx, "", nil) assert.Nil(t, v) assert.NoError(t, err) diff --git a/internal/definitions/definition_handler_datatype.go b/internal/definitions/definition_handler_datatype.go index 5da9820e4..0f6c79a00 100644 --- a/internal/definitions/definition_handler_datatype.go +++ b/internal/definitions/definition_handler_datatype.go @@ -34,7 +34,7 @@ func (dh *definitionHandlers) handleDatatypeBroadcast(ctx context.Context, state if err := dt.Validate(ctx, true); err != nil { return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedValidateFail, "datatype", dt.ID, err) } - if err := dh.data.CheckDatatype(ctx, dt.Namespace, &dt); err != nil { + if err := dh.data.CheckDatatype(ctx, &dt); err != nil { return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedSchemaFail, "datatype", dt.ID, err) } diff --git a/internal/definitions/definition_handler_datatype_test.go b/internal/definitions/definition_handler_datatype_test.go index cdbb4f132..a901bde15 100644 --- a/internal/definitions/definition_handler_datatype_test.go +++ b/internal/definitions/definition_handler_datatype_test.go @@ -49,7 +49,7 @@ func TestHandleDefinitionBroadcastDatatypeOk(t *testing.T) { } mdm := dh.data.(*datamocks.Manager) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mbi := dh.database.(*databasemocks.Plugin) mbi.On("GetDatatypeByName", mock.Anything, "ns1", "name1", "ver1").Return(nil, nil) mbi.On("UpsertDatatype", mock.Anything, mock.Anything, false).Return(nil) @@ -87,7 +87,7 @@ func TestHandleDefinitionBroadcastDatatypeEventFail(t *testing.T) { } mdm := dh.data.(*datamocks.Manager) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mbi := dh.database.(*databasemocks.Plugin) mbi.On("GetDatatypeByName", mock.Anything, "ns1", "name1", "ver1").Return(nil, nil) mbi.On("UpsertDatatype", mock.Anything, mock.Anything, false).Return(nil) @@ -152,7 +152,7 @@ func TestHandleDefinitionBroadcastBadSchema(t *testing.T) { } mdm := dh.data.(*datamocks.Manager) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(fmt.Errorf("pop")) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) action, err := dh.HandleDefinitionBroadcast(context.Background(), bs, &core.Message{ Header: core.MessageHeader{ Tag: core.SystemTagDefineDatatype, @@ -207,7 +207,7 @@ func TestHandleDefinitionBroadcastDatatypeLookupFail(t *testing.T) { } mdm := dh.data.(*datamocks.Manager) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mbi := dh.database.(*databasemocks.Plugin) mbi.On("GetDatatypeByName", mock.Anything, "ns1", "name1", "ver1").Return(nil, fmt.Errorf("pop")) action, err := dh.HandleDefinitionBroadcast(context.Background(), bs, &core.Message{ @@ -243,7 +243,7 @@ func TestHandleDefinitionBroadcastUpsertFail(t *testing.T) { } mdm := dh.data.(*datamocks.Manager) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mbi := dh.database.(*databasemocks.Plugin) mbi.On("GetDatatypeByName", mock.Anything, "ns1", "name1", "ver1").Return(nil, nil) mbi.On("UpsertDatatype", mock.Anything, mock.Anything, false).Return(fmt.Errorf("pop")) @@ -279,7 +279,7 @@ func TestHandleDefinitionBroadcastDatatypeDuplicate(t *testing.T) { } mdm := dh.data.(*datamocks.Manager) - mdm.On("CheckDatatype", mock.Anything, "ns1", mock.Anything).Return(nil) + mdm.On("CheckDatatype", mock.Anything, mock.Anything).Return(nil) mbi := dh.database.(*databasemocks.Plugin) mbi.On("GetDatatypeByName", mock.Anything, "ns1", "name1", "ver1").Return(dt, nil) action, err := dh.HandleDefinitionBroadcast(context.Background(), bs, &core.Message{ diff --git a/internal/events/batch_pin_complete.go b/internal/events/batch_pin_complete.go index 8ff025762..7f16ab7bd 100644 --- a/internal/events/batch_pin_complete.go +++ b/internal/events/batch_pin_complete.go @@ -83,7 +83,7 @@ func (em *eventManager) BatchPinComplete(batchPin *blockchain.BatchPin, signingK } // Kick off a download for broadcast batches if the batch isn't already persisted if !private && batch == nil { - if err := em.sharedDownload.InitiateDownloadBatch(ctx, batchPin.Namespace, batchPin.TransactionID, batchPin.BatchPayloadRef); err != nil { + if err := em.sharedDownload.InitiateDownloadBatch(ctx, batchPin.TransactionID, batchPin.BatchPayloadRef); err != nil { return err } } diff --git a/internal/events/batch_pin_complete_test.go b/internal/events/batch_pin_complete_test.go index b2513c429..7ded6ccb8 100644 --- a/internal/events/batch_pin_complete_test.go +++ b/internal/events/batch_pin_complete_test.go @@ -135,7 +135,7 @@ func TestBatchPinCompleteOkBroadcast(t *testing.T) { mdi.On("InsertPins", mock.Anything, mock.Anything).Return(nil).Once() msd := em.sharedDownload.(*shareddownloadmocks.Manager) mdi.On("GetBatchByID", mock.Anything, "ns1", mock.Anything).Return(nil, nil) - msd.On("InitiateDownloadBatch", mock.Anything, "ns1", batchPin.TransactionID, batchPin.BatchPayloadRef).Return(nil) + msd.On("InitiateDownloadBatch", mock.Anything, batchPin.TransactionID, batchPin.BatchPayloadRef).Return(nil) err := em.BatchPinComplete(batchPin, &core.VerifierRef{ Type: core.VerifierTypeEthAddress, @@ -358,7 +358,7 @@ func TestSequencedBroadcastInitiateDownloadFail(t *testing.T) { mdi.On("InsertPins", mock.Anything, mock.Anything).Return(nil) mdi.On("GetBatchByID", mock.Anything, "ns1", mock.Anything).Return(nil, nil) msd := em.sharedDownload.(*shareddownloadmocks.Manager) - msd.On("InitiateDownloadBatch", mock.Anything, "ns1", batchPin.TransactionID, batchPin.BatchPayloadRef).Return(fmt.Errorf("pop")) + msd.On("InitiateDownloadBatch", mock.Anything, batchPin.TransactionID, batchPin.BatchPayloadRef).Return(fmt.Errorf("pop")) err := em.BatchPinComplete(batchPin, &core.VerifierRef{ Type: core.VerifierTypeEthAddress, @@ -753,7 +753,7 @@ func TestPersistBatchDataWithPublicInitiateDownload(t *testing.T) { mdi.On("GetBlobMatchingHash", mock.Anything, blob.Hash).Return(nil, nil) msd := em.sharedDownload.(*shareddownloadmocks.Manager) - msd.On("InitiateDownloadBlob", mock.Anything, batch.Namespace, batch.Payload.TX.ID, data.ID, "ref1").Return(nil) + msd.On("InitiateDownloadBlob", mock.Anything, batch.Payload.TX.ID, data.ID, "ref1").Return(nil) valid, err := em.checkAndInitiateBlobDownloads(context.Background(), batch, 0, data) assert.Nil(t, err) @@ -780,7 +780,7 @@ func TestPersistBatchDataWithPublicInitiateDownloadFail(t *testing.T) { mdi.On("GetBlobMatchingHash", mock.Anything, blob.Hash).Return(nil, nil) msd := em.sharedDownload.(*shareddownloadmocks.Manager) - msd.On("InitiateDownloadBlob", mock.Anything, batch.Namespace, batch.Payload.TX.ID, data.ID, "ref1").Return(fmt.Errorf("pop")) + msd.On("InitiateDownloadBlob", mock.Anything, batch.Payload.TX.ID, data.ID, "ref1").Return(fmt.Errorf("pop")) valid, err := em.checkAndInitiateBlobDownloads(context.Background(), batch, 0, data) assert.Regexp(t, "pop", err) diff --git a/internal/events/event_manager.go b/internal/events/event_manager.go index 65be588df..56a7c4001 100644 --- a/internal/events/event_manager.go +++ b/internal/events/event_manager.go @@ -73,7 +73,7 @@ type EventManager interface { DXEvent(dx dataexchange.Plugin, event dataexchange.DXEvent) // Bound sharedstorage callbacks - SharedStorageBatchDownloaded(ss sharedstorage.Plugin, ns, payloadRef string, data []byte) (*fftypes.UUID, error) + SharedStorageBatchDownloaded(ss sharedstorage.Plugin, payloadRef string, data []byte) (*fftypes.UUID, error) SharedStorageBlobDownloaded(ss sharedstorage.Plugin, hash fftypes.Bytes32, size int64, payloadRef string) // Bound token callbacks diff --git a/internal/events/persist_batch.go b/internal/events/persist_batch.go index 1fa6553b6..ca6a1aa16 100644 --- a/internal/events/persist_batch.go +++ b/internal/events/persist_batch.go @@ -173,7 +173,7 @@ func (em *eventManager) checkAndInitiateBlobDownloads(ctx context.Context, batch log.L(ctx).Errorf("Invalid data entry %d id=%s in batch '%s' - missing public blob reference", i, data.ID, batch.ID) return false, nil } - if err = em.sharedDownload.InitiateDownloadBlob(ctx, data.Namespace, batch.Payload.TX.ID, data.ID, data.Blob.Public); err != nil { + if err = em.sharedDownload.InitiateDownloadBlob(ctx, batch.Payload.TX.ID, data.ID, data.Blob.Public); err != nil { return false, err } } diff --git a/internal/events/ss_callbacks.go b/internal/events/ss_callbacks.go index 5e9744814..906fdddf4 100644 --- a/internal/events/ss_callbacks.go +++ b/internal/events/ss_callbacks.go @@ -26,7 +26,7 @@ import ( "github.com/hyperledger/firefly/pkg/sharedstorage" ) -func (em *eventManager) SharedStorageBatchDownloaded(ss sharedstorage.Plugin, ns, payloadRef string, data []byte) (*fftypes.UUID, error) { +func (em *eventManager) SharedStorageBatchDownloaded(ss sharedstorage.Plugin, payloadRef string, data []byte) (*fftypes.UUID, error) { l := log.L(em.ctx) @@ -39,8 +39,8 @@ func (em *eventManager) SharedStorageBatchDownloaded(ss sharedstorage.Plugin, ns } l.Infof("Shared storage batch downloaded from %s '%s' id=%s (len=%d)", ss.Name(), payloadRef, batch.ID, len(data)) - if batch.Namespace != ns { - l.Errorf("Invalid batch '%s'. Namespace in batch '%s' does not match pin namespace '%s'", batch.ID, batch.Namespace, ns) + if batch.Namespace != em.namespace { + l.Errorf("Invalid batch '%s'. Namespace in batch '%s' does not match pin namespace '%s'", batch.ID, batch.Namespace, em.namespace) return nil, nil // This is not retryable. skip this batch } diff --git a/internal/events/ss_callbacks_test.go b/internal/events/ss_callbacks_test.go index 223c6dbb5..86bef1388 100644 --- a/internal/events/ss_callbacks_test.go +++ b/internal/events/ss_callbacks_test.go @@ -51,7 +51,7 @@ func TestSharedStorageBatchDownloadedOk(t *testing.T) { mdm := em.data.(*datamocks.Manager) mdm.On("UpdateMessageCache", mock.Anything, mock.Anything).Return() - bid, err := em.SharedStorageBatchDownloaded(mss, batch.Namespace, "payload1", b) + bid, err := em.SharedStorageBatchDownloaded(mss, "payload1", b) assert.NoError(t, err) assert.Equal(t, batch.ID, bid) @@ -78,7 +78,7 @@ func TestSharedStorageBatchDownloadedPersistFail(t *testing.T) { mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(fmt.Errorf("pop")) mss.On("Name").Return("utdx").Maybe() - _, err := em.SharedStorageBatchDownloaded(mss, batch.Namespace, "payload1", b) + _, err := em.SharedStorageBatchDownloaded(mss, "payload1", b) assert.Regexp(t, "FF00154", err) mdi.AssertExpectations(t) @@ -98,7 +98,8 @@ func TestSharedStorageBatchDownloadedNSMismatch(t *testing.T) { mss := em.sharedstorage.(*sharedstoragemocks.Plugin) mss.On("Name").Return("utdx").Maybe() - _, err := em.SharedStorageBatchDownloaded(mss, "srong", "payload1", b) + em.namespace = "ns2" + _, err := em.SharedStorageBatchDownloaded(mss, "payload1", b) assert.NoError(t, err) mss.AssertExpectations(t) @@ -113,7 +114,7 @@ func TestSharedStorageBatchDownloadedBadData(t *testing.T) { mss := em.sharedstorage.(*sharedstoragemocks.Plugin) mss.On("Name").Return("utdx").Maybe() - _, err := em.SharedStorageBatchDownloaded(mss, "srong", "payload1", []byte("!json")) + _, err := em.SharedStorageBatchDownloaded(mss, "payload1", []byte("!json")) assert.NoError(t, err) mss.AssertExpectations(t) diff --git a/internal/events/token_pool_created.go b/internal/events/token_pool_created.go index 2ba21c771..3ebd5e7a6 100644 --- a/internal/events/token_pool_created.go +++ b/internal/events/token_pool_created.go @@ -195,7 +195,7 @@ func (em *eventManager) TokenPoolCreated(ti tokens.Plugin, pool *tokens.TokenPoo Pool: announcePool, } log.L(em.ctx).Infof("Announcing token pool, id=%s", announcePool.ID) - _, err = em.broadcast.BroadcastTokenPool(em.ctx, announcePool.Namespace, broadcast, false) + _, err = em.broadcast.BroadcastTokenPool(em.ctx, broadcast, false) } } diff --git a/internal/events/token_pool_created_test.go b/internal/events/token_pool_created_test.go index d46ff9369..d42d57c8a 100644 --- a/internal/events/token_pool_created_test.go +++ b/internal/events/token_pool_created_test.go @@ -505,7 +505,7 @@ func TestTokenPoolCreatedAnnounce(t *testing.T) { mdi.On("GetTokenPoolByLocator", em.ctx, "ns1", "erc1155", "123").Return(nil, nil).Times(2) mdi.On("GetOperations", em.ctx, "ns1", mock.Anything).Return(nil, nil, fmt.Errorf("pop")).Once() mdi.On("GetOperations", em.ctx, "ns1", mock.Anything).Return(operations, nil, nil).Once() - mbm.On("BroadcastTokenPool", em.ctx, "ns1", mock.MatchedBy(func(pool *core.TokenPoolAnnouncement) bool { + mbm.On("BroadcastTokenPool", em.ctx, mock.MatchedBy(func(pool *core.TokenPoolAnnouncement) bool { return pool.Pool.Namespace == "ns1" && pool.Pool.Name == "my-pool" && *pool.Pool.ID == *poolID }), false).Return(nil, nil) diff --git a/internal/namespace/manager.go b/internal/namespace/manager.go index 6c93271c4..9822eeaff 100644 --- a/internal/namespace/manager.go +++ b/internal/namespace/manager.go @@ -879,7 +879,7 @@ func (nm *namespaceManager) ResolveOperationByNamespacedID(ctx context.Context, if or == nil { return i18n.NewError(ctx, coremsgs.Msg404NotFound) } - return or.Operations().ResolveOperationByID(ctx, ns, u, op) + return or.Operations().ResolveOperationByID(ctx, u, op) } func (nm *namespaceManager) getEventPlugins(ctx context.Context) (plugins map[string]eventsPlugin, err error) { diff --git a/internal/namespace/manager_test.go b/internal/namespace/manager_test.go index f591ab5b0..a021aa485 100644 --- a/internal/namespace/manager_test.go +++ b/internal/namespace/manager_test.go @@ -1256,7 +1256,7 @@ func TestResolveOperationByNamespacedID(t *testing.T) { opID := fftypes.NewUUID() mo.On("Operations").Return(mom) - mom.On("ResolveOperationByID", context.Background(), "default", opID, mock.Anything).Return(nil) + mom.On("ResolveOperationByID", context.Background(), opID, mock.Anything).Return(nil) err := nm.ResolveOperationByNamespacedID(context.Background(), "default:"+opID.String(), &core.OperationUpdateDTO{}) assert.Nil(t, err) diff --git a/internal/networkmap/register_identity.go b/internal/networkmap/register_identity.go index ac7502989..3423ae7c7 100644 --- a/internal/networkmap/register_identity.go +++ b/internal/networkmap/register_identity.go @@ -113,7 +113,7 @@ func (nm *networkMap) RegisterIdentity(ctx context.Context, dto *core.IdentityCr func (nm *networkMap) sendIdentityRequest(ctx context.Context, identity *core.Identity, claimSigner *core.SignerRef, parentSigner *core.SignerRef) error { // Send the claim - we disable the check on the DID author here, as we are registering the identity so it will not exist - claimMsg, err := nm.broadcast.BroadcastIdentityClaim(ctx, identity.Namespace, &core.IdentityClaim{ + claimMsg, err := nm.broadcast.BroadcastIdentityClaim(ctx, &core.IdentityClaim{ Identity: identity, }, claimSigner, core.SystemTagIdentityClaim, false) if err != nil { @@ -123,7 +123,7 @@ func (nm *networkMap) sendIdentityRequest(ctx context.Context, identity *core.Id // Send the verification if one is required. if parentSigner != nil { - verifyMsg, err := nm.broadcast.BroadcastDefinition(ctx, identity.Namespace, &core.IdentityVerification{ + verifyMsg, err := nm.broadcast.BroadcastDefinition(ctx, &core.IdentityVerification{ Claim: core.MessageRef{ ID: claimMsg.Header.ID, Hash: claimMsg.Hash, diff --git a/internal/networkmap/register_identity_test.go b/internal/networkmap/register_identity_test.go index 90f087611..28dadc722 100644 --- a/internal/networkmap/register_identity_test.go +++ b/internal/networkmap/register_identity_test.go @@ -53,7 +53,6 @@ func TestRegisterIdentityOrgWithParentOk(t *testing.T) { mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastIdentityClaim", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityClaim"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" @@ -61,7 +60,6 @@ func TestRegisterIdentityOrgWithParentOk(t *testing.T) { core.SystemTagIdentityClaim, false).Return(mockMsg1, nil) mbm.On("BroadcastDefinition", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityVerification"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x23456" @@ -113,7 +111,6 @@ func TestRegisterIdentityOrgWithParentWaitConfirmOk(t *testing.T) { mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastIdentityClaim", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityClaim"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" @@ -121,7 +118,6 @@ func TestRegisterIdentityOrgWithParentWaitConfirmOk(t *testing.T) { core.SystemTagIdentityClaim, false).Return(mockMsg1, nil) mbm.On("BroadcastDefinition", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityVerification"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x23456" @@ -194,7 +190,6 @@ func TestRegisterIdentityCustomWithParentFail(t *testing.T) { mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastIdentityClaim", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityClaim"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" @@ -202,7 +197,6 @@ func TestRegisterIdentityCustomWithParentFail(t *testing.T) { core.SystemTagIdentityClaim, false).Return(mockMsg, nil) mbm.On("BroadcastDefinition", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityVerification"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x23456" @@ -259,7 +253,6 @@ func TestRegisterIdentityRootBroadcastFail(t *testing.T) { mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastIdentityClaim", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityClaim"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" diff --git a/internal/networkmap/register_node_test.go b/internal/networkmap/register_node_test.go index c6714fc56..484375ae7 100644 --- a/internal/networkmap/register_node_test.go +++ b/internal/networkmap/register_node_test.go @@ -61,7 +61,6 @@ func TestRegisterNodeOk(t *testing.T) { mockMsg := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID()}} mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastIdentityClaim", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityClaim"), signerRef, core.SystemTagIdentityClaim, false).Return(mockMsg, nil) diff --git a/internal/networkmap/register_org_test.go b/internal/networkmap/register_org_test.go index b0d6ec54c..f120e09c5 100644 --- a/internal/networkmap/register_org_test.go +++ b/internal/networkmap/register_org_test.go @@ -69,7 +69,6 @@ func TestRegisterNodeOrgOk(t *testing.T) { mockMsg := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID()}} mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastIdentityClaim", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityClaim"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" diff --git a/internal/networkmap/update_identity.go b/internal/networkmap/update_identity.go index c48f80f02..6e0d6d741 100644 --- a/internal/networkmap/update_identity.go +++ b/internal/networkmap/update_identity.go @@ -56,7 +56,7 @@ func (nm *networkMap) updateIdentityID(ctx context.Context, id *fftypes.UUID, dt } // Send the update - updateMsg, err := nm.broadcast.BroadcastDefinition(ctx, identity.Namespace, &core.IdentityUpdate{ + updateMsg, err := nm.broadcast.BroadcastDefinition(ctx, &core.IdentityUpdate{ Identity: identity.IdentityBase, Updates: dto.IdentityProfile, }, updateSigner, core.SystemTagIdentityUpdate, waitConfirm) diff --git a/internal/networkmap/update_identity_test.go b/internal/networkmap/update_identity_test.go index 5b949654a..593bb1df6 100644 --- a/internal/networkmap/update_identity_test.go +++ b/internal/networkmap/update_identity_test.go @@ -44,7 +44,6 @@ func TestUpdateIdentityProfileOk(t *testing.T) { mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastDefinition", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityUpdate"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" @@ -78,7 +77,6 @@ func TestUpdateIdentityProfileBroadcastFail(t *testing.T) { mbm := nm.broadcast.(*broadcastmocks.Manager) mbm.On("BroadcastDefinition", nm.ctx, - "ns1", mock.AnythingOfType("*core.IdentityUpdate"), mock.MatchedBy(func(sr *core.SignerRef) bool { return sr.Key == "0x12345" diff --git a/internal/operations/manager.go b/internal/operations/manager.go index a02208609..355e4a15c 100644 --- a/internal/operations/manager.go +++ b/internal/operations/manager.go @@ -41,11 +41,11 @@ type Manager interface { RegisterHandler(ctx context.Context, handler OperationHandler, ops []core.OpType) PrepareOperation(ctx context.Context, op *core.Operation) (*core.PreparedOperation, error) RunOperation(ctx context.Context, op *core.PreparedOperation, options ...RunOperationOption) (fftypes.JSONObject, error) - RetryOperation(ctx context.Context, ns string, opID *fftypes.UUID) (*core.Operation, error) + RetryOperation(ctx context.Context, opID *fftypes.UUID) (*core.Operation, error) AddOrReuseOperation(ctx context.Context, op *core.Operation) error SubmitOperationUpdate(plugin core.Named, update *OperationUpdate) TransferResult(dx dataexchange.Plugin, event dataexchange.DXEvent) - ResolveOperationByID(ctx context.Context, ns string, opID *fftypes.UUID, op *core.OperationUpdateDTO) error + ResolveOperationByID(ctx context.Context, opID *fftypes.UUID, op *core.OperationUpdateDTO) error Start() error WaitStop() } @@ -110,10 +110,10 @@ func (om *operationsManager) RunOperation(ctx context.Context, op *core.Prepared log.L(ctx).Tracef("Operation detail: %+v", op) outputs, complete, err := handler.RunOperation(ctx, op) if err != nil { - om.writeOperationFailure(ctx, op.Namespace, op.ID, outputs, err, failState) + om.writeOperationFailure(ctx, op.ID, outputs, err, failState) return nil, err } else if complete { - om.writeOperationSuccess(ctx, op.Namespace, op.ID, outputs) + om.writeOperationSuccess(ctx, op.ID, outputs) } return outputs, nil } @@ -129,7 +129,7 @@ func (om *operationsManager) findLatestRetry(ctx context.Context, opID *fftypes. return om.findLatestRetry(ctx, op.Retry) } -func (om *operationsManager) RetryOperation(ctx context.Context, ns string, opID *fftypes.UUID) (op *core.Operation, err error) { +func (om *operationsManager) RetryOperation(ctx context.Context, opID *fftypes.UUID) (op *core.Operation, err error) { var po *core.PreparedOperation err = om.database.RunAsGroup(ctx, func(ctx context.Context) error { op, err = om.findLatestRetry(ctx, opID) @@ -150,7 +150,7 @@ func (om *operationsManager) RetryOperation(ctx context.Context, ns string, opID // Update the old operation to point to the new one update := database.OperationQueryFactory.NewUpdate(ctx).Set("retry", op.ID) - if err = om.database.UpdateOperation(ctx, ns, opID, update); err != nil { + if err = om.database.UpdateOperation(ctx, om.namespace, opID, update); err != nil { return err } @@ -196,22 +196,22 @@ func (om *operationsManager) TransferResult(dx dataexchange.Plugin, event dataex om.SubmitOperationUpdate(dx, opUpdate) } -func (om *operationsManager) writeOperationSuccess(ctx context.Context, ns string, opID *fftypes.UUID, outputs fftypes.JSONObject) { +func (om *operationsManager) writeOperationSuccess(ctx context.Context, opID *fftypes.UUID, outputs fftypes.JSONObject) { emptyString := "" - if err := om.database.ResolveOperation(ctx, ns, opID, core.OpStatusSucceeded, &emptyString, outputs); err != nil { + if err := om.database.ResolveOperation(ctx, om.namespace, opID, core.OpStatusSucceeded, &emptyString, outputs); err != nil { log.L(ctx).Errorf("Failed to update operation %s: %s", opID, err) } } -func (om *operationsManager) writeOperationFailure(ctx context.Context, ns string, opID *fftypes.UUID, outputs fftypes.JSONObject, err error, newStatus core.OpStatus) { +func (om *operationsManager) writeOperationFailure(ctx context.Context, opID *fftypes.UUID, outputs fftypes.JSONObject, err error, newStatus core.OpStatus) { errMsg := err.Error() - if err := om.database.ResolveOperation(ctx, ns, opID, newStatus, &errMsg, outputs); err != nil { + if err := om.database.ResolveOperation(ctx, om.namespace, opID, newStatus, &errMsg, outputs); err != nil { log.L(ctx).Errorf("Failed to update operation %s: %s", opID, err) } } -func (om *operationsManager) ResolveOperationByID(ctx context.Context, ns string, opID *fftypes.UUID, op *core.OperationUpdateDTO) error { - return om.database.ResolveOperation(ctx, ns, opID, op.Status, op.Error, op.Output) +func (om *operationsManager) ResolveOperationByID(ctx context.Context, opID *fftypes.UUID, op *core.OperationUpdateDTO) error { + return om.database.ResolveOperation(ctx, om.namespace, opID, op.Status, op.Error, op.Output) } func (om *operationsManager) SubmitOperationUpdate(plugin core.Named, update *OperationUpdate) { diff --git a/internal/operations/manager_test.go b/internal/operations/manager_test.go index cafe25cf8..c53bd8db9 100644 --- a/internal/operations/manager_test.go +++ b/internal/operations/manager_test.go @@ -245,7 +245,7 @@ func TestRetryOperationSuccess(t *testing.T) { })).Return(nil) om.RegisterHandler(ctx, &mockHandler{Prepared: po}, []core.OpType{core.OpTypeBlockchainPinBatch}) - newOp, err := om.RetryOperation(ctx, "ns1", op.ID) + newOp, err := om.RetryOperation(ctx, op.ID) assert.NoError(t, err) assert.NotNil(t, newOp) @@ -274,7 +274,7 @@ func TestRetryOperationGetFail(t *testing.T) { mdi.On("GetOperationByID", ctx, "ns1", opID).Return(op, fmt.Errorf("pop")) om.RegisterHandler(ctx, &mockHandler{Prepared: po}, []core.OpType{core.OpTypeBlockchainPinBatch}) - _, err := om.RetryOperation(ctx, "ns1", op.ID) + _, err := om.RetryOperation(ctx, op.ID) assert.EqualError(t, err, "pop") @@ -312,7 +312,7 @@ func TestRetryTwiceOperationInsertFail(t *testing.T) { mdi.On("InsertOperation", ctx, mock.Anything).Return(fmt.Errorf("pop")) om.RegisterHandler(ctx, &mockHandler{Prepared: po}, []core.OpType{core.OpTypeBlockchainPinBatch}) - _, err := om.RetryOperation(ctx, "ns1", op.ID) + _, err := om.RetryOperation(ctx, op.ID) assert.EqualError(t, err, "pop") @@ -341,7 +341,7 @@ func TestRetryOperationInsertFail(t *testing.T) { mdi.On("InsertOperation", ctx, mock.Anything).Return(fmt.Errorf("pop")) om.RegisterHandler(ctx, &mockHandler{Prepared: po}, []core.OpType{core.OpTypeBlockchainPinBatch}) - _, err := om.RetryOperation(ctx, "ns1", op.ID) + _, err := om.RetryOperation(ctx, op.ID) assert.EqualError(t, err, "pop") @@ -372,7 +372,7 @@ func TestRetryOperationUpdateFail(t *testing.T) { mdi.On("UpdateOperation", ctx, "ns1", op.ID, mock.Anything).Return(fmt.Errorf("pop")) om.RegisterHandler(ctx, &mockHandler{Prepared: po}, []core.OpType{core.OpTypeBlockchainPinBatch}) - _, err := om.RetryOperation(ctx, "ns1", op.ID) + _, err := om.RetryOperation(ctx, op.ID) assert.EqualError(t, err, "pop") @@ -389,7 +389,7 @@ func TestWriteOperationSuccess(t *testing.T) { mdi := om.database.(*databasemocks.Plugin) mdi.On("ResolveOperation", ctx, "ns1", opID, core.OpStatusSucceeded, mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) - om.writeOperationSuccess(ctx, "ns1", opID, nil) + om.writeOperationSuccess(ctx, opID, nil) mdi.AssertExpectations(t) } @@ -405,7 +405,7 @@ func TestWriteOperationFailure(t *testing.T) { errStr := "pop" mdi.On("ResolveOperation", ctx, "ns1", opID, core.OpStatusFailed, &errStr, mock.Anything).Return(fmt.Errorf("pop")) - om.writeOperationFailure(ctx, "ns1", opID, nil, fmt.Errorf("pop"), core.OpStatusFailed) + om.writeOperationFailure(ctx, opID, nil, fmt.Errorf("pop"), core.OpStatusFailed) mdi.AssertExpectations(t) } @@ -565,7 +565,7 @@ func TestResolveOperationByNamespacedIDOk(t *testing.T) { "my": "data", }).Return(nil) - err := om.ResolveOperationByID(ctx, "ns1", opID, opUpdate) + err := om.ResolveOperationByID(ctx, opID, opUpdate) assert.NoError(t, err) diff --git a/internal/orchestrator/bound_callbacks.go b/internal/orchestrator/bound_callbacks.go index 43fe81ba1..9acaa1701 100644 --- a/internal/orchestrator/bound_callbacks.go +++ b/internal/orchestrator/bound_callbacks.go @@ -89,8 +89,8 @@ func (bc *boundCallbacks) TokensApproved(plugin tokens.Plugin, approval *tokens. return bc.ei.TokensApproved(plugin, approval) } -func (bc *boundCallbacks) SharedStorageBatchDownloaded(ns, payloadRef string, data []byte) (*fftypes.UUID, error) { - return bc.ei.SharedStorageBatchDownloaded(bc.ss, ns, payloadRef, data) +func (bc *boundCallbacks) SharedStorageBatchDownloaded(payloadRef string, data []byte) (*fftypes.UUID, error) { + return bc.ei.SharedStorageBatchDownloaded(bc.ss, payloadRef, data) } func (bc *boundCallbacks) SharedStorageBlobDownloaded(hash fftypes.Bytes32, size int64, payloadRef string) { diff --git a/internal/orchestrator/bound_callbacks_test.go b/internal/orchestrator/bound_callbacks_test.go index dfdf3fc3b..187027a67 100644 --- a/internal/orchestrator/bound_callbacks_test.go +++ b/internal/orchestrator/bound_callbacks_test.go @@ -103,8 +103,8 @@ func TestBoundCallbacks(t *testing.T) { err = bc.BlockchainEvent(&blockchain.EventWithSubscription{}) assert.EqualError(t, err, "pop") - mei.On("SharedStorageBatchDownloaded", mss, "ns1", "payload1", []byte(`{}`)).Return(nil, fmt.Errorf("pop")) - _, err = bc.SharedStorageBatchDownloaded("ns1", "payload1", []byte(`{}`)) + mei.On("SharedStorageBatchDownloaded", mss, "payload1", []byte(`{}`)).Return(nil, fmt.Errorf("pop")) + _, err = bc.SharedStorageBatchDownloaded("payload1", []byte(`{}`)) assert.EqualError(t, err, "pop") mei.On("SharedStorageBlobDownloaded", mss, *hash, int64(12345), "payload1").Return() diff --git a/internal/orchestrator/chart.go b/internal/orchestrator/chart.go index dc47cc1a7..b5b34df13 100644 --- a/internal/orchestrator/chart.go +++ b/internal/orchestrator/chart.go @@ -39,7 +39,7 @@ func (or *orchestrator) getHistogramIntervals(startTime int64, endTime int64, nu return intervals } -func (or *orchestrator) GetChartHistogram(ctx context.Context, ns string, startTime int64, endTime int64, buckets int64, collection database.CollectionName) ([]*core.ChartHistogram, error) { +func (or *orchestrator) GetChartHistogram(ctx context.Context, startTime int64, endTime int64, buckets int64, collection database.CollectionName) ([]*core.ChartHistogram, error) { if buckets > core.ChartHistogramMaxBuckets || buckets < core.ChartHistogramMinBuckets { return nil, i18n.NewError(ctx, coremsgs.MsgInvalidNumberOfIntervals, core.ChartHistogramMinBuckets, core.ChartHistogramMaxBuckets) } @@ -49,7 +49,7 @@ func (or *orchestrator) GetChartHistogram(ctx context.Context, ns string, startT intervals := or.getHistogramIntervals(startTime, endTime, buckets) - histogram, err := or.database().GetChartHistogram(ctx, ns, intervals, collection) + histogram, err := or.database().GetChartHistogram(ctx, or.namespace, intervals, collection) if err != nil { return nil, err } diff --git a/internal/orchestrator/chart_test.go b/internal/orchestrator/chart_test.go index 0dac78071..06e3887bf 100644 --- a/internal/orchestrator/chart_test.go +++ b/internal/orchestrator/chart_test.go @@ -40,27 +40,27 @@ func makeTestIntervals(start int, numIntervals int) (intervals []core.ChartHisto func TestGetHistogramBadIntervalMin(t *testing.T) { or := newTestOrchestrator() - _, err := or.GetChartHistogram(context.Background(), "ns1", 1234567890, 9876543210, core.ChartHistogramMinBuckets-1, database.CollectionName("test")) + _, err := or.GetChartHistogram(context.Background(), 1234567890, 9876543210, core.ChartHistogramMinBuckets-1, database.CollectionName("test")) assert.Regexp(t, "FF10298", err) } func TestGetHistogramBadIntervalMax(t *testing.T) { or := newTestOrchestrator() - _, err := or.GetChartHistogram(context.Background(), "ns1", 1234567890, 9876543210, core.ChartHistogramMaxBuckets+1, database.CollectionName("test")) + _, err := or.GetChartHistogram(context.Background(), 1234567890, 9876543210, core.ChartHistogramMaxBuckets+1, database.CollectionName("test")) assert.Regexp(t, "FF10298", err) } func TestGetHistogramBadStartEndTimes(t *testing.T) { or := newTestOrchestrator() - _, err := or.GetChartHistogram(context.Background(), "ns1", 9876543210, 1234567890, 10, database.CollectionName("test")) + _, err := or.GetChartHistogram(context.Background(), 9876543210, 1234567890, 10, database.CollectionName("test")) assert.Regexp(t, "FF10300", err) } func TestGetHistogramFailDB(t *testing.T) { or := newTestOrchestrator() intervals := makeTestIntervals(1000000000, 10) - or.mdi.On("GetChartHistogram", mock.Anything, "ns1", intervals, database.CollectionName("test")).Return(nil, fmt.Errorf("pop")) - _, err := or.GetChartHistogram(context.Background(), "ns1", 1000000000, 1000000010, 10, database.CollectionName("test")) + or.mdi.On("GetChartHistogram", mock.Anything, "ns", intervals, database.CollectionName("test")).Return(nil, fmt.Errorf("pop")) + _, err := or.GetChartHistogram(context.Background(), 1000000000, 1000000010, 10, database.CollectionName("test")) assert.EqualError(t, err, "pop") } @@ -69,7 +69,7 @@ func TestGetHistogramSuccess(t *testing.T) { intervals := makeTestIntervals(1000000000, 10) mockHistogram := []*core.ChartHistogram{} - or.mdi.On("GetChartHistogram", mock.Anything, "ns1", intervals, database.CollectionName("test")).Return(mockHistogram, nil) - _, err := or.GetChartHistogram(context.Background(), "ns1", 1000000000, 1000000010, 10, database.CollectionName("test")) + or.mdi.On("GetChartHistogram", mock.Anything, "ns", intervals, database.CollectionName("test")).Return(mockHistogram, nil) + _, err := or.GetChartHistogram(context.Background(), 1000000000, 1000000010, 10, database.CollectionName("test")) assert.NoError(t, err) } diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go index 7c5d20377..220830f7c 100644 --- a/internal/orchestrator/orchestrator.go +++ b/internal/orchestrator/orchestrator.go @@ -108,7 +108,7 @@ type Orchestrator interface { GetPins(ctx context.Context, filter database.AndFilter) ([]*core.Pin, *database.FilterResult, error) // Charts - GetChartHistogram(ctx context.Context, ns string, startTime int64, endTime int64, buckets int64, tableName database.CollectionName) ([]*core.ChartHistogram, error) + GetChartHistogram(ctx context.Context, startTime int64, endTime int64, buckets int64, tableName database.CollectionName) ([]*core.ChartHistogram, error) // Message Routing RequestReply(ctx context.Context, msg *core.MessageInOut) (reply *core.MessageInOut, err error) diff --git a/internal/shareddownload/download_manager.go b/internal/shareddownload/download_manager.go index 1b5b1bfd5..1ba1e7003 100644 --- a/internal/shareddownload/download_manager.go +++ b/internal/shareddownload/download_manager.go @@ -39,8 +39,8 @@ type Manager interface { Start() error WaitStop() - InitiateDownloadBatch(ctx context.Context, ns string, tx *fftypes.UUID, payloadRef string) error - InitiateDownloadBlob(ctx context.Context, ns string, tx *fftypes.UUID, dataID *fftypes.UUID, payloadRef string) error + InitiateDownloadBatch(ctx context.Context, tx *fftypes.UUID, payloadRef string) error + InitiateDownloadBlob(ctx context.Context, tx *fftypes.UUID, dataID *fftypes.UUID, payloadRef string) error } // downloadManager operates a number of workers that can perform downloads/retries. Each download @@ -75,7 +75,7 @@ type downloadWork struct { } type Callbacks interface { - SharedStorageBatchDownloaded(ns string, payloadRef string, data []byte) (batchID *fftypes.UUID, err error) + SharedStorageBatchDownloaded(payloadRef string, data []byte) (batchID *fftypes.UUID, err error) SharedStorageBlobDownloaded(hash fftypes.Bytes32, size int64, payloadRef string) } @@ -221,16 +221,16 @@ func (dm *downloadManager) waitAndRetryDownload(work *downloadWork) { dm.dispatchWork(work) } -func (dm *downloadManager) InitiateDownloadBatch(ctx context.Context, ns string, tx *fftypes.UUID, payloadRef string) error { - op := core.NewOperation(dm.sharedstorage, ns, tx, core.OpTypeSharedStorageDownloadBatch) - addDownloadBatchInputs(op, ns, payloadRef) - return dm.createAndDispatchOp(ctx, op, opDownloadBatch(op, ns, payloadRef)) +func (dm *downloadManager) InitiateDownloadBatch(ctx context.Context, tx *fftypes.UUID, payloadRef string) error { + op := core.NewOperation(dm.sharedstorage, dm.namespace, tx, core.OpTypeSharedStorageDownloadBatch) + addDownloadBatchInputs(op, payloadRef) + return dm.createAndDispatchOp(ctx, op, opDownloadBatch(op, payloadRef)) } -func (dm *downloadManager) InitiateDownloadBlob(ctx context.Context, ns string, tx *fftypes.UUID, dataID *fftypes.UUID, payloadRef string) error { - op := core.NewOperation(dm.sharedstorage, ns, tx, core.OpTypeSharedStorageDownloadBlob) - addDownloadBlobInputs(op, ns, dataID, payloadRef) - return dm.createAndDispatchOp(ctx, op, opDownloadBlob(op, ns, dataID, payloadRef)) +func (dm *downloadManager) InitiateDownloadBlob(ctx context.Context, tx *fftypes.UUID, dataID *fftypes.UUID, payloadRef string) error { + op := core.NewOperation(dm.sharedstorage, dm.namespace, tx, core.OpTypeSharedStorageDownloadBlob) + addDownloadBlobInputs(op, dataID, payloadRef) + return dm.createAndDispatchOp(ctx, op, opDownloadBlob(op, dataID, payloadRef)) } func (dm *downloadManager) createAndDispatchOp(ctx context.Context, op *core.Operation, preparedOp *core.PreparedOperation) error { diff --git a/internal/shareddownload/download_manager_test.go b/internal/shareddownload/download_manager_test.go index c980dc645..407f6a87e 100644 --- a/internal/shareddownload/download_manager_test.go +++ b/internal/shareddownload/download_manager_test.go @@ -97,9 +97,9 @@ func TestDownloadBatchE2EOk(t *testing.T) { }).Return(nil) mci := dm.callbacks.(*shareddownloadmocks.Callbacks) - mci.On("SharedStorageBatchDownloaded", "ns1", "ref1", []byte("some batch data")).Return(batchID, nil) + mci.On("SharedStorageBatchDownloaded", "ref1", []byte("some batch data")).Return(batchID, nil) - err := dm.InitiateDownloadBatch(dm.ctx, "ns1", txID, "ref1") + err := dm.InitiateDownloadBatch(dm.ctx, txID, "ref1") assert.NoError(t, err) <-called @@ -151,7 +151,7 @@ func TestDownloadBlobWithRetryOk(t *testing.T) { mci := dm.callbacks.(*shareddownloadmocks.Callbacks) mci.On("SharedStorageBlobDownloaded", *blobHash, int64(12345), "privateRef1").Return() - err := dm.InitiateDownloadBlob(dm.ctx, "ns1", txID, dataID, "ref1") + err := dm.InitiateDownloadBlob(dm.ctx, txID, dataID, "ref1") assert.NoError(t, err) <-called @@ -177,7 +177,7 @@ func TestDownloadBlobInsertOpFail(t *testing.T) { mdi := dm.database.(*databasemocks.Plugin) mdi.On("InsertOperation", mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("pop")) - err := dm.InitiateDownloadBlob(dm.ctx, "ns1", txID, dataID, "ref1") + err := dm.InitiateDownloadBlob(dm.ctx, txID, dataID, "ref1") assert.Regexp(t, "pop", err) mdi.AssertExpectations(t) @@ -253,7 +253,7 @@ func TestDownloadManagerStartupRecoveryCombinations(t *testing.T) { }).Return(nil) mci := dm.callbacks.(*shareddownloadmocks.Callbacks) - mci.On("SharedStorageBatchDownloaded", "ns1", "ref2", []byte("some batch data")).Return(batchID, nil) + mci.On("SharedStorageBatchDownloaded", "ref2", []byte("some batch data")).Return(batchID, nil) err := dm.Start() assert.NoError(t, err) diff --git a/internal/shareddownload/operations.go b/internal/shareddownload/operations.go index 6eb8bfe88..8bf3c4654 100644 --- a/internal/shareddownload/operations.go +++ b/internal/shareddownload/operations.go @@ -31,19 +31,16 @@ import ( ) type downloadBatchData struct { - Namespace string `json:"namespace"` PayloadRef string `json:"payloadRef"` } type downloadBlobData struct { - Namespace string `json:"namespace"` DataID *fftypes.UUID `json:"dataId"` PayloadRef string `json:"payloadRef"` } -func addDownloadBatchInputs(op *core.Operation, ns, payloadRef string) { +func addDownloadBatchInputs(op *core.Operation, payloadRef string) { op.Input = fftypes.JSONObject{ - "namespace": ns, "payloadRef": payloadRef, } } @@ -54,9 +51,8 @@ func getDownloadBatchOutputs(batchID *fftypes.UUID) fftypes.JSONObject { } } -func addDownloadBlobInputs(op *core.Operation, ns string, dataID *fftypes.UUID, payloadRef string) { +func addDownloadBlobInputs(op *core.Operation, dataID *fftypes.UUID, payloadRef string) { op.Input = fftypes.JSONObject{ - "namespace": ns, "dataId": dataID.String(), "payloadRef": payloadRef, } @@ -70,16 +66,14 @@ func getDownloadBlobOutputs(hash *fftypes.Bytes32, size int64, dxPayloadRef stri } } -func retrieveDownloadBatchInputs(op *core.Operation) (string, string) { - return op.Input.GetString("namespace"), - op.Input.GetString("payloadRef") +func retrieveDownloadBatchInputs(op *core.Operation) (payloadRef string) { + return op.Input.GetString("payloadRef") } -func retrieveDownloadBlobInputs(ctx context.Context, op *core.Operation) (namespace string, dataID *fftypes.UUID, payloadRef string, err error) { - namespace = op.Input.GetString("namespace") +func retrieveDownloadBlobInputs(ctx context.Context, op *core.Operation) (dataID *fftypes.UUID, payloadRef string, err error) { dataID, err = fftypes.ParseUUID(ctx, op.Input.GetString("dataId")) if err != nil { - return "", nil, "", err + return nil, "", err } payloadRef = op.Input.GetString("payloadRef") return @@ -89,15 +83,15 @@ func (dm *downloadManager) PrepareOperation(ctx context.Context, op *core.Operat switch op.Type { case core.OpTypeSharedStorageDownloadBatch: - namespace, payloadRef := retrieveDownloadBatchInputs(op) - return opDownloadBatch(op, namespace, payloadRef), nil + payloadRef := retrieveDownloadBatchInputs(op) + return opDownloadBatch(op, payloadRef), nil case core.OpTypeSharedStorageDownloadBlob: - namespace, dataID, payloadRef, err := retrieveDownloadBlobInputs(ctx, op) + dataID, payloadRef, err := retrieveDownloadBlobInputs(ctx, op) if err != nil { return nil, err } - return opDownloadBlob(op, namespace, dataID, payloadRef), nil + return opDownloadBlob(op, dataID, payloadRef), nil default: return nil, i18n.NewError(ctx, coremsgs.MsgOperationNotSupported, op.Type) @@ -138,7 +132,7 @@ func (dm *downloadManager) downloadBatch(ctx context.Context, data downloadBatch } // Parse and store the batch - batchID, err := dm.callbacks.SharedStorageBatchDownloaded(data.Namespace, data.PayloadRef, batchBytes) + batchID, err := dm.callbacks.SharedStorageBatchDownloaded(data.PayloadRef, batchBytes) if err != nil { return nil, false, err } @@ -155,7 +149,7 @@ func (dm *downloadManager) downloadBlob(ctx context.Context, data downloadBlobDa defer reader.Close() // ... to data exchange - dxPayloadRef, hash, blobSize, err := dm.dataexchange.UploadBlob(ctx, data.Namespace, *data.DataID, reader) + dxPayloadRef, hash, blobSize, err := dm.dataexchange.UploadBlob(ctx, dm.namespace, *data.DataID, reader) if err != nil { return nil, false, i18n.WrapError(ctx, err, coremsgs.MsgDownloadSharedFailed, data.PayloadRef) } @@ -171,25 +165,23 @@ func (dm *downloadManager) OnOperationUpdate(ctx context.Context, op *core.Opera return nil } -func opDownloadBatch(op *core.Operation, ns string, payloadRef string) *core.PreparedOperation { +func opDownloadBatch(op *core.Operation, payloadRef string) *core.PreparedOperation { return &core.PreparedOperation{ ID: op.ID, Namespace: op.Namespace, Type: op.Type, Data: downloadBatchData{ - Namespace: ns, PayloadRef: payloadRef, }, } } -func opDownloadBlob(op *core.Operation, ns string, dataID *fftypes.UUID, payloadRef string) *core.PreparedOperation { +func opDownloadBlob(op *core.Operation, dataID *fftypes.UUID, payloadRef string) *core.PreparedOperation { return &core.PreparedOperation{ ID: op.ID, Namespace: op.Namespace, Type: op.Type, Data: downloadBlobData{ - Namespace: ns, DataID: dataID, PayloadRef: payloadRef, }, diff --git a/internal/shareddownload/operations_test.go b/internal/shareddownload/operations_test.go index 793a5bba4..f6c71e1d6 100644 --- a/internal/shareddownload/operations_test.go +++ b/internal/shareddownload/operations_test.go @@ -42,7 +42,6 @@ func TestDownloadBatchDownloadDataFail(t *testing.T) { mss.On("DownloadData", mock.Anything, "ref1").Return(nil, fmt.Errorf("pop")) _, _, err := dm.downloadBatch(dm.ctx, downloadBatchData{ - Namespace: "ns1", PayloadRef: "ref1", }) assert.Regexp(t, "FF10376", err) @@ -61,7 +60,6 @@ func TestDownloadBatchDownloadDataReadFail(t *testing.T) { mss.On("DownloadData", mock.Anything, "ref1").Return(reader, nil) _, _, err := dm.downloadBatch(dm.ctx, downloadBatchData{ - Namespace: "ns1", PayloadRef: "ref1", }) assert.Regexp(t, "FF10376", err) @@ -81,7 +79,6 @@ func TestDownloadBatchDownloadDataReadMaxedOut(t *testing.T) { mss.On("DownloadData", mock.Anything, "ref1").Return(reader, nil) _, _, err := dm.downloadBatch(dm.ctx, downloadBatchData{ - Namespace: "ns1", PayloadRef: "ref1", }) assert.Regexp(t, "FF10377", err) @@ -100,10 +97,9 @@ func TestDownloadBatchDownloadCallbackFailed(t *testing.T) { mss.On("DownloadData", mock.Anything, "ref1").Return(reader, nil) mci := dm.callbacks.(*shareddownloadmocks.Callbacks) - mci.On("SharedStorageBatchDownloaded", "ns1", "ref1", []byte("some batch data")).Return(nil, fmt.Errorf("pop")) + mci.On("SharedStorageBatchDownloaded", "ref1", []byte("some batch data")).Return(nil, fmt.Errorf("pop")) _, _, err := dm.downloadBatch(dm.ctx, downloadBatchData{ - Namespace: "ns1", PayloadRef: "ref1", }) assert.Regexp(t, "pop", err) @@ -126,7 +122,6 @@ func TestDownloadBlobDownloadDataReadFail(t *testing.T) { mdx.On("UploadBlob", mock.Anything, "ns1", mock.Anything, reader).Return("", nil, int64(-1), fmt.Errorf("pop")) _, _, err := dm.downloadBlob(dm.ctx, downloadBlobData{ - Namespace: "ns1", PayloadRef: "ref1", DataID: fftypes.NewUUID(), }) diff --git a/mocks/blockchainmocks/plugin.go b/mocks/blockchainmocks/plugin.go index bc6cf7a69..e90c53882 100644 --- a/mocks/blockchainmocks/plugin.go +++ b/mocks/blockchainmocks/plugin.go @@ -312,11 +312,6 @@ func (_m *Plugin) QueryContract(ctx context.Context, location *fftypes.JSONAny, return r0, r1 } -// SetHandler provides a mock function with given fields: handler -func (_m *Plugin) SetHandler(handler blockchain.Callbacks) { - _m.Called(handler) -} - // RemoveFireflySubscription provides a mock function with given fields: ctx, subID func (_m *Plugin) RemoveFireflySubscription(ctx context.Context, subID string) error { ret := _m.Called(ctx, subID) @@ -331,6 +326,11 @@ func (_m *Plugin) RemoveFireflySubscription(ctx context.Context, subID string) e return r0 } +// SetHandler provides a mock function with given fields: handler +func (_m *Plugin) SetHandler(handler blockchain.Callbacks) { + _m.Called(handler) +} + // Start provides a mock function with given fields: func (_m *Plugin) Start() error { ret := _m.Called() diff --git a/mocks/broadcastmocks/manager.go b/mocks/broadcastmocks/manager.go index 94d171d20..522802d6e 100644 --- a/mocks/broadcastmocks/manager.go +++ b/mocks/broadcastmocks/manager.go @@ -18,13 +18,13 @@ type Manager struct { mock.Mock } -// BroadcastDatatype provides a mock function with given fields: ctx, ns, datatype, waitConfirm -func (_m *Manager) BroadcastDatatype(ctx context.Context, ns string, datatype *core.Datatype, waitConfirm bool) (*core.Message, error) { - ret := _m.Called(ctx, ns, datatype, waitConfirm) +// BroadcastDatatype provides a mock function with given fields: ctx, datatype, waitConfirm +func (_m *Manager) BroadcastDatatype(ctx context.Context, datatype *core.Datatype, waitConfirm bool) (*core.Message, error) { + ret := _m.Called(ctx, datatype, waitConfirm) var r0 *core.Message - if rf, ok := ret.Get(0).(func(context.Context, string, *core.Datatype, bool) *core.Message); ok { - r0 = rf(ctx, ns, datatype, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, *core.Datatype, bool) *core.Message); ok { + r0 = rf(ctx, datatype, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Message) @@ -32,8 +32,8 @@ func (_m *Manager) BroadcastDatatype(ctx context.Context, ns string, datatype *c } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.Datatype, bool) error); ok { - r1 = rf(ctx, ns, datatype, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, *core.Datatype, bool) error); ok { + r1 = rf(ctx, datatype, waitConfirm) } else { r1 = ret.Error(1) } @@ -41,13 +41,13 @@ func (_m *Manager) BroadcastDatatype(ctx context.Context, ns string, datatype *c return r0, r1 } -// BroadcastDefinition provides a mock function with given fields: ctx, ns, def, signingIdentity, tag, waitConfirm -func (_m *Manager) BroadcastDefinition(ctx context.Context, ns string, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (*core.Message, error) { - ret := _m.Called(ctx, ns, def, signingIdentity, tag, waitConfirm) +// BroadcastDefinition provides a mock function with given fields: ctx, def, signingIdentity, tag, waitConfirm +func (_m *Manager) BroadcastDefinition(ctx context.Context, def core.Definition, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (*core.Message, error) { + ret := _m.Called(ctx, def, signingIdentity, tag, waitConfirm) var r0 *core.Message - if rf, ok := ret.Get(0).(func(context.Context, string, core.Definition, *core.SignerRef, string, bool) *core.Message); ok { - r0 = rf(ctx, ns, def, signingIdentity, tag, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, core.Definition, *core.SignerRef, string, bool) *core.Message); ok { + r0 = rf(ctx, def, signingIdentity, tag, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Message) @@ -55,8 +55,8 @@ func (_m *Manager) BroadcastDefinition(ctx context.Context, ns string, def core. } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, core.Definition, *core.SignerRef, string, bool) error); ok { - r1 = rf(ctx, ns, def, signingIdentity, tag, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, core.Definition, *core.SignerRef, string, bool) error); ok { + r1 = rf(ctx, def, signingIdentity, tag, waitConfirm) } else { r1 = ret.Error(1) } @@ -64,13 +64,13 @@ func (_m *Manager) BroadcastDefinition(ctx context.Context, ns string, def core. return r0, r1 } -// BroadcastDefinitionAsNode provides a mock function with given fields: ctx, ns, def, tag, waitConfirm -func (_m *Manager) BroadcastDefinitionAsNode(ctx context.Context, ns string, def core.Definition, tag string, waitConfirm bool) (*core.Message, error) { - ret := _m.Called(ctx, ns, def, tag, waitConfirm) +// BroadcastDefinitionAsNode provides a mock function with given fields: ctx, def, tag, waitConfirm +func (_m *Manager) BroadcastDefinitionAsNode(ctx context.Context, def core.Definition, tag string, waitConfirm bool) (*core.Message, error) { + ret := _m.Called(ctx, def, tag, waitConfirm) var r0 *core.Message - if rf, ok := ret.Get(0).(func(context.Context, string, core.Definition, string, bool) *core.Message); ok { - r0 = rf(ctx, ns, def, tag, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, core.Definition, string, bool) *core.Message); ok { + r0 = rf(ctx, def, tag, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Message) @@ -78,8 +78,8 @@ func (_m *Manager) BroadcastDefinitionAsNode(ctx context.Context, ns string, def } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, core.Definition, string, bool) error); ok { - r1 = rf(ctx, ns, def, tag, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, core.Definition, string, bool) error); ok { + r1 = rf(ctx, def, tag, waitConfirm) } else { r1 = ret.Error(1) } @@ -87,13 +87,13 @@ func (_m *Manager) BroadcastDefinitionAsNode(ctx context.Context, ns string, def return r0, r1 } -// BroadcastIdentityClaim provides a mock function with given fields: ctx, ns, def, signingIdentity, tag, waitConfirm -func (_m *Manager) BroadcastIdentityClaim(ctx context.Context, ns string, def *core.IdentityClaim, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (*core.Message, error) { - ret := _m.Called(ctx, ns, def, signingIdentity, tag, waitConfirm) +// BroadcastIdentityClaim provides a mock function with given fields: ctx, def, signingIdentity, tag, waitConfirm +func (_m *Manager) BroadcastIdentityClaim(ctx context.Context, def *core.IdentityClaim, signingIdentity *core.SignerRef, tag string, waitConfirm bool) (*core.Message, error) { + ret := _m.Called(ctx, def, signingIdentity, tag, waitConfirm) var r0 *core.Message - if rf, ok := ret.Get(0).(func(context.Context, string, *core.IdentityClaim, *core.SignerRef, string, bool) *core.Message); ok { - r0 = rf(ctx, ns, def, signingIdentity, tag, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, *core.IdentityClaim, *core.SignerRef, string, bool) *core.Message); ok { + r0 = rf(ctx, def, signingIdentity, tag, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Message) @@ -101,8 +101,8 @@ func (_m *Manager) BroadcastIdentityClaim(ctx context.Context, ns string, def *c } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.IdentityClaim, *core.SignerRef, string, bool) error); ok { - r1 = rf(ctx, ns, def, signingIdentity, tag, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, *core.IdentityClaim, *core.SignerRef, string, bool) error); ok { + r1 = rf(ctx, def, signingIdentity, tag, waitConfirm) } else { r1 = ret.Error(1) } @@ -133,13 +133,13 @@ func (_m *Manager) BroadcastMessage(ctx context.Context, in *core.MessageInOut, return r0, r1 } -// BroadcastTokenPool provides a mock function with given fields: ctx, ns, pool, waitConfirm -func (_m *Manager) BroadcastTokenPool(ctx context.Context, ns string, pool *core.TokenPoolAnnouncement, waitConfirm bool) (*core.Message, error) { - ret := _m.Called(ctx, ns, pool, waitConfirm) +// BroadcastTokenPool provides a mock function with given fields: ctx, pool, waitConfirm +func (_m *Manager) BroadcastTokenPool(ctx context.Context, pool *core.TokenPoolAnnouncement, waitConfirm bool) (*core.Message, error) { + ret := _m.Called(ctx, pool, waitConfirm) var r0 *core.Message - if rf, ok := ret.Get(0).(func(context.Context, string, *core.TokenPoolAnnouncement, bool) *core.Message); ok { - r0 = rf(ctx, ns, pool, waitConfirm) + if rf, ok := ret.Get(0).(func(context.Context, *core.TokenPoolAnnouncement, bool) *core.Message); ok { + r0 = rf(ctx, pool, waitConfirm) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Message) @@ -147,8 +147,8 @@ func (_m *Manager) BroadcastTokenPool(ctx context.Context, ns string, pool *core } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.TokenPoolAnnouncement, bool) error); ok { - r1 = rf(ctx, ns, pool, waitConfirm) + if rf, ok := ret.Get(1).(func(context.Context, *core.TokenPoolAnnouncement, bool) error); ok { + r1 = rf(ctx, pool, waitConfirm) } else { r1 = ret.Error(1) } diff --git a/mocks/datamocks/manager.go b/mocks/datamocks/manager.go index ea2294476..d74159d3e 100644 --- a/mocks/datamocks/manager.go +++ b/mocks/datamocks/manager.go @@ -22,13 +22,13 @@ type Manager struct { mock.Mock } -// CheckDatatype provides a mock function with given fields: ctx, ns, datatype -func (_m *Manager) CheckDatatype(ctx context.Context, ns string, datatype *core.Datatype) error { - ret := _m.Called(ctx, ns, datatype) +// CheckDatatype provides a mock function with given fields: ctx, datatype +func (_m *Manager) CheckDatatype(ctx context.Context, datatype *core.Datatype) error { + ret := _m.Called(ctx, datatype) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, *core.Datatype) error); ok { - r0 = rf(ctx, ns, datatype) + if rf, ok := ret.Get(0).(func(context.Context, *core.Datatype) error); ok { + r0 = rf(ctx, datatype) } else { r0 = ret.Error(0) } @@ -36,13 +36,13 @@ func (_m *Manager) CheckDatatype(ctx context.Context, ns string, datatype *core. return r0 } -// DownloadBlob provides a mock function with given fields: ctx, ns, dataID -func (_m *Manager) DownloadBlob(ctx context.Context, ns string, dataID string) (*core.Blob, io.ReadCloser, error) { - ret := _m.Called(ctx, ns, dataID) +// DownloadBlob provides a mock function with given fields: ctx, dataID +func (_m *Manager) DownloadBlob(ctx context.Context, dataID string) (*core.Blob, io.ReadCloser, error) { + ret := _m.Called(ctx, dataID) var r0 *core.Blob - if rf, ok := ret.Get(0).(func(context.Context, string, string) *core.Blob); ok { - r0 = rf(ctx, ns, dataID) + if rf, ok := ret.Get(0).(func(context.Context, string) *core.Blob); ok { + r0 = rf(ctx, dataID) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Blob) @@ -50,8 +50,8 @@ func (_m *Manager) DownloadBlob(ctx context.Context, ns string, dataID string) ( } var r1 io.ReadCloser - if rf, ok := ret.Get(1).(func(context.Context, string, string) io.ReadCloser); ok { - r1 = rf(ctx, ns, dataID) + if rf, ok := ret.Get(1).(func(context.Context, string) io.ReadCloser); ok { + r1 = rf(ctx, dataID) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(io.ReadCloser) @@ -59,8 +59,8 @@ func (_m *Manager) DownloadBlob(ctx context.Context, ns string, dataID string) ( } var r2 error - if rf, ok := ret.Get(2).(func(context.Context, string, string) error); ok { - r2 = rf(ctx, ns, dataID) + if rf, ok := ret.Get(2).(func(context.Context, string) error); ok { + r2 = rf(ctx, dataID) } else { r2 = ret.Error(2) } @@ -235,13 +235,13 @@ func (_m *Manager) UpdateMessageStateIfCached(ctx context.Context, id *fftypes.U _m.Called(ctx, id, state, confirmed) } -// UploadBlob provides a mock function with given fields: ctx, ns, inData, blob, autoMeta -func (_m *Manager) UploadBlob(ctx context.Context, ns string, inData *core.DataRefOrValue, blob *ffapi.Multipart, autoMeta bool) (*core.Data, error) { - ret := _m.Called(ctx, ns, inData, blob, autoMeta) +// UploadBlob provides a mock function with given fields: ctx, inData, blob, autoMeta +func (_m *Manager) UploadBlob(ctx context.Context, inData *core.DataRefOrValue, blob *ffapi.Multipart, autoMeta bool) (*core.Data, error) { + ret := _m.Called(ctx, inData, blob, autoMeta) var r0 *core.Data - if rf, ok := ret.Get(0).(func(context.Context, string, *core.DataRefOrValue, *ffapi.Multipart, bool) *core.Data); ok { - r0 = rf(ctx, ns, inData, blob, autoMeta) + if rf, ok := ret.Get(0).(func(context.Context, *core.DataRefOrValue, *ffapi.Multipart, bool) *core.Data); ok { + r0 = rf(ctx, inData, blob, autoMeta) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Data) @@ -249,8 +249,8 @@ func (_m *Manager) UploadBlob(ctx context.Context, ns string, inData *core.DataR } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.DataRefOrValue, *ffapi.Multipart, bool) error); ok { - r1 = rf(ctx, ns, inData, blob, autoMeta) + if rf, ok := ret.Get(1).(func(context.Context, *core.DataRefOrValue, *ffapi.Multipart, bool) error); ok { + r1 = rf(ctx, inData, blob, autoMeta) } else { r1 = ret.Error(1) } @@ -258,13 +258,13 @@ func (_m *Manager) UploadBlob(ctx context.Context, ns string, inData *core.DataR return r0, r1 } -// UploadJSON provides a mock function with given fields: ctx, ns, inData -func (_m *Manager) UploadJSON(ctx context.Context, ns string, inData *core.DataRefOrValue) (*core.Data, error) { - ret := _m.Called(ctx, ns, inData) +// UploadJSON provides a mock function with given fields: ctx, inData +func (_m *Manager) UploadJSON(ctx context.Context, inData *core.DataRefOrValue) (*core.Data, error) { + ret := _m.Called(ctx, inData) var r0 *core.Data - if rf, ok := ret.Get(0).(func(context.Context, string, *core.DataRefOrValue) *core.Data); ok { - r0 = rf(ctx, ns, inData) + if rf, ok := ret.Get(0).(func(context.Context, *core.DataRefOrValue) *core.Data); ok { + r0 = rf(ctx, inData) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Data) @@ -272,8 +272,8 @@ func (_m *Manager) UploadJSON(ctx context.Context, ns string, inData *core.DataR } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.DataRefOrValue) error); ok { - r1 = rf(ctx, ns, inData) + if rf, ok := ret.Get(1).(func(context.Context, *core.DataRefOrValue) error); ok { + r1 = rf(ctx, inData) } else { r1 = ret.Error(1) } diff --git a/mocks/eventmocks/event_manager.go b/mocks/eventmocks/event_manager.go index f309d3451..da4e2f52b 100644 --- a/mocks/eventmocks/event_manager.go +++ b/mocks/eventmocks/event_manager.go @@ -196,13 +196,13 @@ func (_m *EventManager) NewSubscriptions() chan<- *fftypes.UUID { return r0 } -// SharedStorageBatchDownloaded provides a mock function with given fields: ss, ns, payloadRef, data -func (_m *EventManager) SharedStorageBatchDownloaded(ss sharedstorage.Plugin, ns string, payloadRef string, data []byte) (*fftypes.UUID, error) { - ret := _m.Called(ss, ns, payloadRef, data) +// SharedStorageBatchDownloaded provides a mock function with given fields: ss, payloadRef, data +func (_m *EventManager) SharedStorageBatchDownloaded(ss sharedstorage.Plugin, payloadRef string, data []byte) (*fftypes.UUID, error) { + ret := _m.Called(ss, payloadRef, data) var r0 *fftypes.UUID - if rf, ok := ret.Get(0).(func(sharedstorage.Plugin, string, string, []byte) *fftypes.UUID); ok { - r0 = rf(ss, ns, payloadRef, data) + if rf, ok := ret.Get(0).(func(sharedstorage.Plugin, string, []byte) *fftypes.UUID); ok { + r0 = rf(ss, payloadRef, data) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.UUID) @@ -210,8 +210,8 @@ func (_m *EventManager) SharedStorageBatchDownloaded(ss sharedstorage.Plugin, ns } var r1 error - if rf, ok := ret.Get(1).(func(sharedstorage.Plugin, string, string, []byte) error); ok { - r1 = rf(ss, ns, payloadRef, data) + if rf, ok := ret.Get(1).(func(sharedstorage.Plugin, string, []byte) error); ok { + r1 = rf(ss, payloadRef, data) } else { r1 = ret.Error(1) } diff --git a/mocks/operationmocks/manager.go b/mocks/operationmocks/manager.go index 635d59e68..f0642aab4 100644 --- a/mocks/operationmocks/manager.go +++ b/mocks/operationmocks/manager.go @@ -62,13 +62,13 @@ func (_m *Manager) RegisterHandler(ctx context.Context, handler operations.Opera _m.Called(ctx, handler, ops) } -// ResolveOperationByID provides a mock function with given fields: ctx, ns, opID, op -func (_m *Manager) ResolveOperationByID(ctx context.Context, ns string, opID *fftypes.UUID, op *core.OperationUpdateDTO) error { - ret := _m.Called(ctx, ns, opID, op) +// ResolveOperationByID provides a mock function with given fields: ctx, opID, op +func (_m *Manager) ResolveOperationByID(ctx context.Context, opID *fftypes.UUID, op *core.OperationUpdateDTO) error { + ret := _m.Called(ctx, opID, op) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, *core.OperationUpdateDTO) error); ok { - r0 = rf(ctx, ns, opID, op) + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID, *core.OperationUpdateDTO) error); ok { + r0 = rf(ctx, opID, op) } else { r0 = ret.Error(0) } @@ -76,13 +76,13 @@ func (_m *Manager) ResolveOperationByID(ctx context.Context, ns string, opID *ff return r0 } -// RetryOperation provides a mock function with given fields: ctx, ns, opID -func (_m *Manager) RetryOperation(ctx context.Context, ns string, opID *fftypes.UUID) (*core.Operation, error) { - ret := _m.Called(ctx, ns, opID) +// RetryOperation provides a mock function with given fields: ctx, opID +func (_m *Manager) RetryOperation(ctx context.Context, opID *fftypes.UUID) (*core.Operation, error) { + ret := _m.Called(ctx, opID) var r0 *core.Operation - if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID) *core.Operation); ok { - r0 = rf(ctx, ns, opID) + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *core.Operation); ok { + r0 = rf(ctx, opID) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*core.Operation) @@ -90,8 +90,8 @@ func (_m *Manager) RetryOperation(ctx context.Context, ns string, opID *fftypes. } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *fftypes.UUID) error); ok { - r1 = rf(ctx, ns, opID) + if rf, ok := ret.Get(1).(func(context.Context, *fftypes.UUID) error); ok { + r1 = rf(ctx, opID) } else { r1 = ret.Error(1) } diff --git a/mocks/orchestratormocks/orchestrator.go b/mocks/orchestratormocks/orchestrator.go index fce2e6f54..c31c137a2 100644 --- a/mocks/orchestratormocks/orchestrator.go +++ b/mocks/orchestratormocks/orchestrator.go @@ -302,13 +302,13 @@ func (_m *Orchestrator) GetBlockchainEvents(ctx context.Context, filter database return r0, r1, r2 } -// GetChartHistogram provides a mock function with given fields: ctx, ns, startTime, endTime, buckets, tableName -func (_m *Orchestrator) GetChartHistogram(ctx context.Context, ns string, startTime int64, endTime int64, buckets int64, tableName database.CollectionName) ([]*core.ChartHistogram, error) { - ret := _m.Called(ctx, ns, startTime, endTime, buckets, tableName) +// GetChartHistogram provides a mock function with given fields: ctx, startTime, endTime, buckets, tableName +func (_m *Orchestrator) GetChartHistogram(ctx context.Context, startTime int64, endTime int64, buckets int64, tableName database.CollectionName) ([]*core.ChartHistogram, error) { + ret := _m.Called(ctx, startTime, endTime, buckets, tableName) var r0 []*core.ChartHistogram - if rf, ok := ret.Get(0).(func(context.Context, string, int64, int64, int64, database.CollectionName) []*core.ChartHistogram); ok { - r0 = rf(ctx, ns, startTime, endTime, buckets, tableName) + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64, database.CollectionName) []*core.ChartHistogram); ok { + r0 = rf(ctx, startTime, endTime, buckets, tableName) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*core.ChartHistogram) @@ -316,8 +316,8 @@ func (_m *Orchestrator) GetChartHistogram(ctx context.Context, ns string, startT } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, int64, int64, int64, database.CollectionName) error); ok { - r1 = rf(ctx, ns, startTime, endTime, buckets, tableName) + if rf, ok := ret.Get(1).(func(context.Context, int64, int64, int64, database.CollectionName) error); ok { + r1 = rf(ctx, startTime, endTime, buckets, tableName) } else { r1 = ret.Error(1) } diff --git a/mocks/shareddownloadmocks/callbacks.go b/mocks/shareddownloadmocks/callbacks.go index d29a924a4..8bb219a38 100644 --- a/mocks/shareddownloadmocks/callbacks.go +++ b/mocks/shareddownloadmocks/callbacks.go @@ -12,13 +12,13 @@ type Callbacks struct { mock.Mock } -// SharedStorageBatchDownloaded provides a mock function with given fields: ns, payloadRef, data -func (_m *Callbacks) SharedStorageBatchDownloaded(ns string, payloadRef string, data []byte) (*fftypes.UUID, error) { - ret := _m.Called(ns, payloadRef, data) +// SharedStorageBatchDownloaded provides a mock function with given fields: payloadRef, data +func (_m *Callbacks) SharedStorageBatchDownloaded(payloadRef string, data []byte) (*fftypes.UUID, error) { + ret := _m.Called(payloadRef, data) var r0 *fftypes.UUID - if rf, ok := ret.Get(0).(func(string, string, []byte) *fftypes.UUID); ok { - r0 = rf(ns, payloadRef, data) + if rf, ok := ret.Get(0).(func(string, []byte) *fftypes.UUID); ok { + r0 = rf(payloadRef, data) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.UUID) @@ -26,8 +26,8 @@ func (_m *Callbacks) SharedStorageBatchDownloaded(ns string, payloadRef string, } var r1 error - if rf, ok := ret.Get(1).(func(string, string, []byte) error); ok { - r1 = rf(ns, payloadRef, data) + if rf, ok := ret.Get(1).(func(string, []byte) error); ok { + r1 = rf(payloadRef, data) } else { r1 = ret.Error(1) } diff --git a/mocks/shareddownloadmocks/manager.go b/mocks/shareddownloadmocks/manager.go index 582168806..dc90f998b 100644 --- a/mocks/shareddownloadmocks/manager.go +++ b/mocks/shareddownloadmocks/manager.go @@ -14,13 +14,13 @@ type Manager struct { mock.Mock } -// InitiateDownloadBatch provides a mock function with given fields: ctx, ns, tx, payloadRef -func (_m *Manager) InitiateDownloadBatch(ctx context.Context, ns string, tx *fftypes.UUID, payloadRef string) error { - ret := _m.Called(ctx, ns, tx, payloadRef) +// InitiateDownloadBatch provides a mock function with given fields: ctx, tx, payloadRef +func (_m *Manager) InitiateDownloadBatch(ctx context.Context, tx *fftypes.UUID, payloadRef string) error { + ret := _m.Called(ctx, tx, payloadRef) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, string) error); ok { - r0 = rf(ctx, ns, tx, payloadRef) + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID, string) error); ok { + r0 = rf(ctx, tx, payloadRef) } else { r0 = ret.Error(0) } @@ -28,13 +28,13 @@ func (_m *Manager) InitiateDownloadBatch(ctx context.Context, ns string, tx *fft return r0 } -// InitiateDownloadBlob provides a mock function with given fields: ctx, ns, tx, dataID, payloadRef -func (_m *Manager) InitiateDownloadBlob(ctx context.Context, ns string, tx *fftypes.UUID, dataID *fftypes.UUID, payloadRef string) error { - ret := _m.Called(ctx, ns, tx, dataID, payloadRef) +// InitiateDownloadBlob provides a mock function with given fields: ctx, tx, dataID, payloadRef +func (_m *Manager) InitiateDownloadBlob(ctx context.Context, tx *fftypes.UUID, dataID *fftypes.UUID, payloadRef string) error { + ret := _m.Called(ctx, tx, dataID, payloadRef) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, *fftypes.UUID, string) error); ok { - r0 = rf(ctx, ns, tx, dataID, payloadRef) + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID, *fftypes.UUID, string) error); ok { + r0 = rf(ctx, tx, dataID, payloadRef) } else { r0 = ret.Error(0) }