diff --git a/Makefile b/Makefile index 5f609bf9b0..0c1bf19248 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ GOGC=30 all: build test go-mod-tidy test: deps lint - $(VGO) test ./internal/... ./pkg/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=10s + $(VGO) test ./internal/... ./pkg/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s coverage.html: $(VGO) tool cover -html=coverage.txt coverage: test coverage.html diff --git a/internal/events/dx_callbacks.go b/internal/events/dx_callbacks.go index 908ace27cc..5ecaedd248 100644 --- a/internal/events/dx_callbacks.go +++ b/internal/events/dx_callbacks.go @@ -75,7 +75,7 @@ func (em *eventManager) checkReceivedOffchainIdentity(ctx context.Context, peerI } // Find the identity in the mesage - org, retryable, err := em.identity.CachedIdentityLookup(ctx, author) + org, retryable, err := em.identity.CachedIdentityLookupMustExist(ctx, author) if err != nil && retryable { l.Errorf("Failed to retrieve org: %v", err) return nil, err // retryable error diff --git a/internal/events/dx_callbacks_test.go b/internal/events/dx_callbacks_test.go index 114c0881b2..d86b73fe2f 100644 --- a/internal/events/dx_callbacks_test.go +++ b/internal/events/dx_callbacks_test.go @@ -96,7 +96,7 @@ func TestPinnedReceiveOK(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertDataArray", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertMessages", em.ctx, mock.Anything).Return(nil, nil) @@ -136,7 +136,7 @@ func TestMessageReceiveOkBadBatchIgnored(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) m, err := em.MessageReceived(mdx, "peer1", b) assert.NoError(t, err) @@ -162,7 +162,7 @@ func TestMessageReceivePersistBatchError(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(fmt.Errorf("pop")) m, err := em.MessageReceived(mdx, "peer1", b) assert.Regexp(t, "FF10158", err) @@ -279,7 +279,7 @@ func TestMessageReceiveGetCandidateOrgFail(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(nil, true, fmt.Errorf("pop")) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(nil, true, fmt.Errorf("pop")) m, err := em.MessageReceived(mdx, "peer1", b) assert.Regexp(t, "FF10158", err) assert.Empty(t, m) @@ -304,7 +304,7 @@ func TestMessageReceiveGetCandidateOrgNotFound(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(nil, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(nil, false, nil) m, err := em.MessageReceived(mdx, "peer1", b) assert.NoError(t, err) assert.Empty(t, m) @@ -329,7 +329,7 @@ func TestMessageReceiveGetCandidateOrgNotMatch(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(newTestOrg("org2"), false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(newTestOrg("org2"), false, nil) m, err := em.MessageReceived(mdx, "peer1", b) assert.NoError(t, err) assert.Empty(t, m) @@ -661,7 +661,7 @@ func TestMessageReceiveMessageIdentityFail(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org2, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org2, false, nil) mim.On("CachedIdentityLookupByID", em.ctx, org2.Parent).Return(nil, fmt.Errorf("pop")) m, err := em.MessageReceived(mdx, "peer1", b) @@ -693,7 +693,7 @@ func TestMessageReceiveMessageIdentityParentNotFound(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org2, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org2, false, nil) mim.On("CachedIdentityLookupByID", em.ctx, org2.Parent).Return(nil, nil) m, err := em.MessageReceived(mdx, "peer1", b) @@ -726,7 +726,7 @@ func TestMessageReceiveMessageIdentityIncorrect(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org2, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org2, false, nil) mim.On("CachedIdentityLookupByID", em.ctx, org2.Parent).Return(org3, nil) m, err := em.MessageReceived(mdx, "peer1", b) @@ -757,7 +757,7 @@ func TestMessageReceiveMessagePersistMessageFail(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertDataArray", em.ctx, mock.Anything).Return(nil) mdi.On("InsertMessages", em.ctx, mock.Anything).Return(fmt.Errorf("optimization fail")) @@ -791,7 +791,7 @@ func TestMessageReceiveMessagePersistDataFail(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertDataArray", em.ctx, mock.Anything).Return(fmt.Errorf("optimization miss")) mdi.On("UpsertData", em.ctx, mock.Anything, database.UpsertOptimizationExisting).Return(fmt.Errorf("pop")) @@ -824,7 +824,7 @@ func TestMessageReceiveUnpinnedBatchOk(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertDataArray", em.ctx, mock.Anything).Return(nil) mdi.On("InsertMessages", em.ctx, mock.Anything).Return(nil) @@ -862,7 +862,7 @@ func TestMessageReceiveUnpinnedBatchConfirmMessagesFail(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertDataArray", em.ctx, mock.Anything).Return(nil) mdi.On("InsertMessages", em.ctx, mock.Anything).Return(nil) @@ -899,7 +899,7 @@ func TestMessageReceiveUnpinnedBatchPersistEventFail(t *testing.T) { Type: fftypes.VerifierTypeFFDXPeerID, Value: "peer1", }).Return(node1, nil) - mim.On("CachedIdentityLookup", em.ctx, "signingOrg").Return(org1, false, nil) + mim.On("CachedIdentityLookupMustExist", em.ctx, "signingOrg").Return(org1, false, nil) mdi.On("UpsertBatch", em.ctx, mock.Anything).Return(nil, nil) mdi.On("InsertDataArray", em.ctx, mock.Anything).Return(nil) mdi.On("InsertMessages", em.ctx, mock.Anything).Return(nil) diff --git a/internal/i18n/en_translations.go b/internal/i18n/en_translations.go index 639af16e4e..7d609b767a 100644 --- a/internal/i18n/en_translations.go +++ b/internal/i18n/en_translations.go @@ -193,8 +193,7 @@ var ( MsgTokensRESTErr = ffm("FF10274", "Error from tokens service: %s") MsgTokenPoolDuplicate = ffm("FF10275", "Duplicate token pool") MsgTokenPoolRejected = ffm("FF10276", "Token pool with ID '%s' was rejected. Please check the FireFly logs for more information") - MsgIdentityNotFoundByString = ffm("FF10277", "Identity could not be resolved via DID '%s'") - MsgAuthorOrgNotFoundByName = ffm("FF10278", "Author organization could not be resolved via name '%s'") + MsgIdentityNotFoundByString = ffm("FF10277", "Identity could not be resolved via lookup string '%s'") MsgAuthorOrgSigningKeyMismatch = ffm("FF10279", "Author organization '%s' is not associated with signing key '%s'") MsgCannotTransferToSelf = ffm("FF10280", "From and to addresses must be different", 400) MsgLocalOrgLookupFailed = ffm("FF10281", "Unable resolve the local org '%s' by the configured signing key on the node. Please confirm the org is registered with key '%s'", 500) diff --git a/internal/identity/identitymanager.go b/internal/identity/identitymanager.go index b0554c7ee5..8b8ebcba14 100644 --- a/internal/identity/identitymanager.go +++ b/internal/identity/identitymanager.go @@ -45,7 +45,8 @@ type Manager interface { FindIdentityForVerifier(ctx context.Context, iTypes []fftypes.IdentityType, namespace string, verifier *fftypes.VerifierRef) (identity *fftypes.Identity, err error) ResolveIdentitySigner(ctx context.Context, identity *fftypes.Identity) (parentSigner *fftypes.SignerRef, err error) CachedIdentityLookupByID(ctx context.Context, id *fftypes.UUID) (identity *fftypes.Identity, err error) - CachedIdentityLookup(ctx context.Context, did string) (identity *fftypes.Identity, retryable bool, err error) + CachedIdentityLookupMustExist(ctx context.Context, did string) (identity *fftypes.Identity, retryable bool, err error) + CachedIdentityLookupNilOK(ctx context.Context, did string) (identity *fftypes.Identity, retryable bool, err error) CachedVerifierLookup(ctx context.Context, vType fftypes.VerifierType, ns, value string) (verifier *fftypes.Verifier, err error) GetNodeOwnerBlockchainKey(ctx context.Context) (*fftypes.VerifierRef, error) GetNodeOwnerOrg(ctx context.Context) (*fftypes.Identity, error) @@ -157,7 +158,7 @@ func (im *identityManager) ResolveInputSigningIdentity(ctx context.Context, name return i18n.NewError(ctx, i18n.MsgAuthorRegistrationMismatch, verifier.Value, msgSignerRef.Author, identity.DID) } case msgSignerRef.Author != "": - identity, _, err := im.CachedIdentityLookup(ctx, msgSignerRef.Author) + identity, _, err := im.CachedIdentityLookupMustExist(ctx, msgSignerRef.Author) if err != nil { return err } @@ -168,7 +169,7 @@ func (im *identityManager) ResolveInputSigningIdentity(ctx context.Context, name case msgSignerRef.Author != "": // Author must be non-empty (see above), so we want to find that identity and then // use the first blockchain key that's associated with it. - identity, _, err := im.CachedIdentityLookup(ctx, msgSignerRef.Author) + identity, _, err := im.CachedIdentityLookupMustExist(ctx, msgSignerRef.Author) if err != nil { return err } @@ -395,7 +396,7 @@ func (im *identityManager) cachedIdentityLookupByVerifierRef(ctx context.Context return identity, nil } -func (im *identityManager) CachedIdentityLookup(ctx context.Context, didLookupStr string) (identity *fftypes.Identity, retryable bool, err error) { +func (im *identityManager) CachedIdentityLookupNilOK(ctx context.Context, didLookupStr string) (identity *fftypes.Identity, retryable bool, err error) { // Use an LRU cache for the author identity, as it's likely for the same identity to be re-used over and over cacheKey := fmt.Sprintf("did=%s", didLookupStr) defer func() { @@ -422,21 +423,28 @@ func (im *identityManager) CachedIdentityLookup(ctx context.Context, didLookupSt } } } - if identity == nil { - return nil, false, i18n.NewError(ctx, i18n.MsgIdentityNotFoundByString, didLookupStr) - } } else { // If there is just a name in there, then it could be an Org type identity (from the very original usage of the field) if identity, err = im.database.GetIdentityByName(ctx, fftypes.IdentityTypeOrg, fftypes.SystemNamespace, didLookupStr); err != nil { return nil, true /* DB Error */, err } - if identity == nil { - return nil, false, i18n.NewError(ctx, i18n.MsgAuthorOrgNotFoundByName, didLookupStr) - } } - // Cache the result - im.identityCache.Set(cacheKey, identity, im.identityCacheTTL) + if identity != nil { + // Cache the result + im.identityCache.Set(cacheKey, identity, im.identityCacheTTL) + } + } + return identity, false, nil +} + +func (im *identityManager) CachedIdentityLookupMustExist(ctx context.Context, didLookupStr string) (identity *fftypes.Identity, retryable bool, err error) { + identity, retryable, err = im.CachedIdentityLookupNilOK(ctx, didLookupStr) + if err != nil { + return nil, retryable, err + } + if identity == nil { + return nil, false, i18n.NewError(ctx, i18n.MsgIdentityNotFoundByString, didLookupStr) } return identity, false, nil } diff --git a/internal/identity/identitymanager_test.go b/internal/identity/identitymanager_test.go index fed4b3f041..7e9709d866 100644 --- a/internal/identity/identitymanager_test.go +++ b/internal/identity/identitymanager_test.go @@ -368,7 +368,7 @@ func TestResolveInputSigningIdentityByOrgLookkupNotFound(t *testing.T) { Author: "org1", } err := im.ResolveInputSigningIdentity(ctx, "ns1", msgIdentity) - assert.Regexp(t, "FF10278", err) + assert.Regexp(t, "FF10277", err) mdi.AssertExpectations(t) @@ -777,7 +777,7 @@ func TestCachedIdentityLookupByVerifierRefNotFound(t *testing.T) { } -func TestCachedIdentityLookupCaching(t *testing.T) { +func TestCachedIdentityLookupMustExistCaching(t *testing.T) { ctx, im := newTestIdentityManager(t) @@ -793,33 +793,33 @@ func TestCachedIdentityLookupCaching(t *testing.T) { mdi := im.database.(*databasemocks.Plugin) mdi.On("GetIdentityByDID", ctx, "did:firefly:node/peer1").Return(id, nil).Once() - v1, _, err := im.CachedIdentityLookup(ctx, "did:firefly:node/peer1") + v1, _, err := im.CachedIdentityLookupMustExist(ctx, "did:firefly:node/peer1") assert.NoError(t, err) assert.Equal(t, id, v1) - v2, _, err := im.CachedIdentityLookup(ctx, "did:firefly:node/peer1") + v2, _, err := im.CachedIdentityLookupMustExist(ctx, "did:firefly:node/peer1") assert.NoError(t, err) assert.Equal(t, id, v2) } -func TestCachedIdentityLookupUnknownResolver(t *testing.T) { +func TestCachedIdentityLookupMustExistUnknownResolver(t *testing.T) { ctx, im := newTestIdentityManager(t) - _, retryable, err := im.CachedIdentityLookup(ctx, "did:random:anything") + _, retryable, err := im.CachedIdentityLookupMustExist(ctx, "did:random:anything") assert.Regexp(t, "FF10349", err) assert.False(t, retryable) } -func TestCachedIdentityLookupGetIDFail(t *testing.T) { +func TestCachedIdentityLookupMustExistGetIDFail(t *testing.T) { ctx, im := newTestIdentityManager(t) mdi := im.database.(*databasemocks.Plugin) mdi.On("GetIdentityByDID", ctx, "did:firefly:node/peer1").Return(nil, fmt.Errorf("pop")) - _, retryable, err := im.CachedIdentityLookup(ctx, "did:firefly:node/peer1") + _, retryable, err := im.CachedIdentityLookupMustExist(ctx, "did:firefly:node/peer1") assert.Regexp(t, "pop", err) assert.True(t, retryable) @@ -838,7 +838,7 @@ func TestCachedIdentityLookupByVerifierByOldDIDFail(t *testing.T) { return uuid.Equals(orgUUID) })).Return(nil, fmt.Errorf("pop")) - _, retryable, err := im.CachedIdentityLookup(ctx, did) + _, retryable, err := im.CachedIdentityLookupMustExist(ctx, did) assert.Regexp(t, "pop", err) assert.True(t, retryable) diff --git a/internal/networkmap/data_query.go b/internal/networkmap/data_query.go index d150c6a5f3..9c8cdc9545 100644 --- a/internal/networkmap/data_query.go +++ b/internal/networkmap/data_query.go @@ -97,7 +97,7 @@ func (nm *networkMap) GetIdentityByID(ctx context.Context, ns, id string) (*ffty } func (nm *networkMap) GetIdentityByDID(ctx context.Context, did string) (*fftypes.Identity, error) { - identity, _, err := nm.identity.CachedIdentityLookup(ctx, did) + identity, _, err := nm.identity.CachedIdentityLookupMustExist(ctx, did) if err != nil { return nil, err } diff --git a/internal/networkmap/data_query_test.go b/internal/networkmap/data_query_test.go index 364a270062..11f14e9011 100644 --- a/internal/networkmap/data_query_test.go +++ b/internal/networkmap/data_query_test.go @@ -291,7 +291,7 @@ func TestGetVerifierByHashBadUUID(t *testing.T) { func TestGetVerifierByDIDOk(t *testing.T) { nm, cancel := newTestNetworkmap(t) defer cancel() - nm.identity.(*identitymanagermocks.Manager).On("CachedIdentityLookup", nm.ctx, "did:firefly:org/abc"). + nm.identity.(*identitymanagermocks.Manager).On("CachedIdentityLookupMustExist", nm.ctx, "did:firefly:org/abc"). Return(testOrg("abc"), true, nil) id, err := nm.GetIdentityByDID(nm.ctx, "did:firefly:org/abc") assert.NoError(t, err) @@ -301,7 +301,7 @@ func TestGetVerifierByDIDOk(t *testing.T) { func TestGetVerifierByDIDNotFound(t *testing.T) { nm, cancel := newTestNetworkmap(t) defer cancel() - nm.identity.(*identitymanagermocks.Manager).On("CachedIdentityLookup", nm.ctx, "did:firefly:org/abc"). + nm.identity.(*identitymanagermocks.Manager).On("CachedIdentityLookupMustExist", nm.ctx, "did:firefly:org/abc"). Return(nil, true, nil) id, err := nm.GetIdentityByDID(nm.ctx, "did:firefly:org/abc") assert.Regexp(t, "FF10109", err) @@ -311,7 +311,7 @@ func TestGetVerifierByDIDNotFound(t *testing.T) { func TestGetVerifierByDIDNotErr(t *testing.T) { nm, cancel := newTestNetworkmap(t) defer cancel() - nm.identity.(*identitymanagermocks.Manager).On("CachedIdentityLookup", nm.ctx, "did:firefly:org/abc"). + nm.identity.(*identitymanagermocks.Manager).On("CachedIdentityLookupMustExist", nm.ctx, "did:firefly:org/abc"). Return(nil, true, fmt.Errorf("pop")) id, err := nm.GetIdentityByDID(nm.ctx, "did:firefly:org/abc") assert.Regexp(t, "pop", err) diff --git a/internal/networkmap/register_identity.go b/internal/networkmap/register_identity.go index 8cd0fb5aea..a47019b161 100644 --- a/internal/networkmap/register_identity.go +++ b/internal/networkmap/register_identity.go @@ -31,7 +31,7 @@ func (nm *networkMap) RegisterIdentity(ctx context.Context, ns string, dto *ffty parent, err = fftypes.ParseUUID(ctx, dto.Parent) if err != nil { // Or a DID - parentIdentity, _, err := nm.identity.CachedIdentityLookup(ctx, dto.Parent) + parentIdentity, _, err := nm.identity.CachedIdentityLookupMustExist(ctx, dto.Parent) if err != nil { return nil, err } diff --git a/internal/networkmap/register_identity_test.go b/internal/networkmap/register_identity_test.go index f578e43af7..3f6d41b709 100644 --- a/internal/networkmap/register_identity_test.go +++ b/internal/networkmap/register_identity_test.go @@ -142,7 +142,7 @@ func TestRegisterIdentityCustomWithParentFail(t *testing.T) { mim := nm.identity.(*identitymanagermocks.Manager) mim.On("VerifyIdentityChain", nm.ctx, mock.AnythingOfType("*fftypes.Identity")).Return(parentIdentity, false, nil) - mim.On("CachedIdentityLookup", nm.ctx, "did:firefly:org/parent1").Return(&fftypes.Identity{ + mim.On("CachedIdentityLookupMustExist", nm.ctx, "did:firefly:org/parent1").Return(&fftypes.Identity{ IdentityBase: fftypes.IdentityBase{ ID: fftypes.NewUUID(), DID: "did:firefly:org/parent1", @@ -271,7 +271,7 @@ func TestRegisterIdentityBadParent(t *testing.T) { defer cancel() mim := nm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", nm.ctx, "did:firefly:org/1").Return(nil, false, fmt.Errorf("pop")) + mim.On("CachedIdentityLookupMustExist", nm.ctx, "did:firefly:org/1").Return(nil, false, fmt.Errorf("pop")) _, err := nm.RegisterIdentity(nm.ctx, "ns1", &fftypes.IdentityCreateDTO{ Name: "custom1", diff --git a/internal/orchestrator/status.go b/internal/orchestrator/status.go index 35e3293f32..cdb7206eaa 100644 --- a/internal/orchestrator/status.go +++ b/internal/orchestrator/status.go @@ -65,7 +65,7 @@ func (or *orchestrator) GetStatus(ctx context.Context) (status *fftypes.NodeStat status.Org.ID = org.ID status.Org.DID = org.DID - node, _, err := or.identity.CachedIdentityLookup(ctx, fmt.Sprintf("%s%s", fftypes.FireFlyNodeDIDPrefix, status.Node.Name)) + node, _, err := or.identity.CachedIdentityLookupNilOK(ctx, fmt.Sprintf("%s%s", fftypes.FireFlyNodeDIDPrefix, status.Node.Name)) if err != nil { return nil, err } diff --git a/internal/orchestrator/status_test.go b/internal/orchestrator/status_test.go index 43880a76a0..d76f9ce400 100644 --- a/internal/orchestrator/status_test.go +++ b/internal/orchestrator/status_test.go @@ -45,7 +45,7 @@ func TestGetStatusRegistered(t *testing.T) { DID: "did:firefly:org/org1", }, }, nil) - mim.On("CachedIdentityLookup", or.ctx, "did:firefly:node/node1").Return(&fftypes.Identity{ + mim.On("CachedIdentityLookupNilOK", or.ctx, "did:firefly:node/node1").Return(&fftypes.Identity{ IdentityBase: fftypes.IdentityBase{ ID: nodeID, Name: "node1", @@ -91,7 +91,7 @@ func TestGetStatusWrongNodeOwner(t *testing.T) { DID: "did:firefly:org/org1", }, }, nil) - mim.On("CachedIdentityLookup", or.ctx, "did:firefly:node/node1").Return(&fftypes.Identity{ + mim.On("CachedIdentityLookupNilOK", or.ctx, "did:firefly:node/node1").Return(&fftypes.Identity{ IdentityBase: fftypes.IdentityBase{ ID: nodeID, Name: "node1", @@ -159,7 +159,7 @@ func TestGetStatusOrgOnlyRegistered(t *testing.T) { DID: "did:firefly:org/org1", }, }, nil) - mim.On("CachedIdentityLookup", or.ctx, "did:firefly:node/node1").Return(nil, false, nil) + mim.On("CachedIdentityLookupNilOK", or.ctx, "did:firefly:node/node1").Return(nil, false, nil) status, err := or.GetStatus(or.ctx) assert.NoError(t, err) @@ -195,7 +195,7 @@ func TestGetStatusNodeError(t *testing.T) { DID: "did:firefly:org/org1", }, }, nil) - mim.On("CachedIdentityLookup", or.ctx, "did:firefly:node/node1").Return(nil, false, fmt.Errorf("pop")) + mim.On("CachedIdentityLookupNilOK", or.ctx, "did:firefly:node/node1").Return(nil, false, fmt.Errorf("pop")) _, err := or.GetStatus(or.ctx) assert.EqualError(t, err, "pop") diff --git a/internal/privatemessaging/message_test.go b/internal/privatemessaging/message_test.go index ff8f49cb8c..062c230507 100644 --- a/internal/privatemessaging/message_test.go +++ b/internal/privatemessaging/message_test.go @@ -81,7 +81,7 @@ func TestSendConfirmMessageE2EOk(t *testing.T) { localNode := newTestNode("node1", intermediateOrg) mim.On("ResolveInputSigningIdentity", pm.ctx, "ns1", mock.Anything).Return(nil) mim.On("GetNodeOwnerOrg", pm.ctx).Return(intermediateOrg, nil) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(intermediateOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(intermediateOrg, false, nil) mim.On("CachedIdentityLookupByID", pm.ctx, rootOrg.ID).Return(rootOrg, nil) mdm := pm.data.(*datamocks.Manager) @@ -228,7 +228,7 @@ func TestResolveAndSendBadInlineData(t *testing.T) { identity.Author = "localorg" identity.Key = "localkey" }).Return(nil) - mim.On("CachedIdentityLookup", pm.ctx, "localorg").Return(localOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "localorg").Return(localOrg, false, nil) mdi := pm.database.(*databasemocks.Plugin) mdi.On("GetIdentities", pm.ctx, mock.Anything).Return([]*fftypes.Identity{localNode}, nil, nil).Once() @@ -345,7 +345,7 @@ func TestMessagePrepare(t *testing.T) { identity.Author = "localorg" identity.Key = "localkey" }).Return(nil) - mim.On("CachedIdentityLookup", pm.ctx, "localorg").Return(localOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "localorg").Return(localOrg, false, nil) mdi := pm.database.(*databasemocks.Plugin) mdi.On("GetIdentities", pm.ctx, mock.Anything).Return([]*fftypes.Identity{localNode}, nil, nil).Once() diff --git a/internal/privatemessaging/recipients.go b/internal/privatemessaging/recipients.go index 90606863cc..d6fe835463 100644 --- a/internal/privatemessaging/recipients.go +++ b/internal/privatemessaging/recipients.go @@ -77,7 +77,7 @@ func (pm *privateMessaging) getFirstNodeForOrg(ctx context.Context, identity *ff func (pm *privateMessaging) resolveNode(ctx context.Context, identity *fftypes.Identity, nodeInput string) (node *fftypes.Identity, err error) { retryable := true if nodeInput != "" { - node, retryable, err = pm.identity.CachedIdentityLookup(ctx, nodeInput) + node, retryable, err = pm.identity.CachedIdentityLookupMustExist(ctx, nodeInput) } else { // Find any node owned by this organization inputIdentityDebugInfo := fmt.Sprintf("%s (%s)", identity.DID, identity.ID) @@ -119,7 +119,7 @@ func (pm *privateMessaging) getRecipients(ctx context.Context, in *fftypes.Messa } for i, rInput := range in.Group.Members { // Resolve the identity - identity, _, err := pm.identity.CachedIdentityLookup(ctx, rInput.Identity) + identity, _, err := pm.identity.CachedIdentityLookupMustExist(ctx, rInput.Identity) if err != nil { return nil, err } diff --git a/internal/privatemessaging/recipients_test.go b/internal/privatemessaging/recipients_test.go index 33ff8daaa5..b4e4d4237f 100644 --- a/internal/privatemessaging/recipients_test.go +++ b/internal/privatemessaging/recipients_test.go @@ -47,7 +47,7 @@ func TestResolveMemberListNewGroupE2E(t *testing.T) { mdi.On("UpsertGroup", pm.ctx, mock.Anything, database.UpsertOptimizationNew).Return(nil) mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "remoteorg").Return(remoteOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "remoteorg").Return(remoteOrg, false, nil) mim.On("GetNodeOwnerOrg", pm.ctx).Return(localOrg, nil) ud := mdi.On("UpsertData", pm.ctx, mock.Anything, database.UpsertOptimizationNew).Return(nil) ud.RunFn = func(a mock.Arguments) { @@ -116,7 +116,7 @@ func TestResolveMemberListExistingGroup(t *testing.T) { mdi.On("GetIdentities", pm.ctx, mock.Anything).Return([]*fftypes.Identity{localNode}, nil, nil) mdi.On("GetGroupByHash", pm.ctx, mock.Anything, mock.Anything).Return(&fftypes.Group{Hash: fftypes.NewRandB32()}, nil, nil).Once() mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(localOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(localOrg, false, nil) mim.On("GetNodeOwnerOrg", pm.ctx).Return(localNode, nil) err := pm.resolveRecipientList(pm.ctx, &fftypes.MessageInOut{ @@ -148,7 +148,7 @@ func TestResolveMemberListLookupFail(t *testing.T) { localNode := newTestNode("node1", localOrg) mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(nil, true, fmt.Errorf("pop")) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(nil, true, fmt.Errorf("pop")) mim.On("GetNodeOwnerOrg", pm.ctx).Return(localNode, nil) err := pm.resolveRecipientList(pm.ctx, &fftypes.MessageInOut{ @@ -182,7 +182,7 @@ func TestResolveMemberListGetGroupsFail(t *testing.T) { mdi.On("GetIdentities", pm.ctx, mock.Anything).Return([]*fftypes.Identity{localNode}, nil, nil) mdi.On("GetGroupByHash", pm.ctx, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("pop")) mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(localOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(localOrg, false, nil) mim.On("GetNodeOwnerOrg", pm.ctx).Return(localNode, nil) err := pm.resolveRecipientList(pm.ctx, &fftypes.MessageInOut{ @@ -248,7 +248,7 @@ func TestResolveMemberListMissingLocalMemberLookupFailed(t *testing.T) { mdi.On("GetIdentities", pm.ctx, mock.Anything).Return([]*fftypes.Identity{localNode}, nil, fmt.Errorf("pop")).Once() mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(localOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(localOrg, false, nil) mim.On("GetNodeOwnerOrg", pm.ctx).Return(localNode, nil) err := pm.resolveRecipientList(pm.ctx, &fftypes.MessageInOut{ @@ -283,7 +283,7 @@ func TestResolveMemberListNodeNotFound(t *testing.T) { mdi.On("GetIdentities", pm.ctx, mock.Anything).Return([]*fftypes.Identity{}, nil, nil).Once() mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(localOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(localOrg, false, nil) mim.On("GetNodeOwnerOrg", pm.ctx).Return(localNode, nil) err := pm.resolveRecipientList(pm.ctx, &fftypes.MessageInOut{ @@ -322,7 +322,7 @@ func TestResolveMemberNodeOwnedParentOrg(t *testing.T) { mdi.On("GetGroupByHash", pm.ctx, mock.Anything, mock.Anything).Return(&fftypes.Group{Hash: fftypes.NewRandB32()}, nil, nil).Once() mim := pm.identity.(*identitymanagermocks.Manager) mim.On("GetNodeOwnerOrg", pm.ctx).Return(parentOrg, nil) - mim.On("CachedIdentityLookup", pm.ctx, "org1").Return(childOrg, false, nil) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "org1").Return(childOrg, false, nil) mim.On("CachedIdentityLookupByID", pm.ctx, parentOrg.ID).Return(parentOrg, nil) err := pm.resolveRecipientList(pm.ctx, &fftypes.MessageInOut{ @@ -350,7 +350,7 @@ func TestGetNodeFail(t *testing.T) { defer cancel() mim := pm.identity.(*identitymanagermocks.Manager) - mim.On("CachedIdentityLookup", pm.ctx, "id-node1").Return(nil, true, fmt.Errorf("pop")) + mim.On("CachedIdentityLookupMustExist", pm.ctx, "id-node1").Return(nil, true, fmt.Errorf("pop")) _, err := pm.resolveNode(pm.ctx, newTestOrg("org1"), "id-node1") assert.Regexp(t, "pop", err) diff --git a/manifest.json b/manifest.json index d0df8de19a..00650d720e 100644 --- a/manifest.json +++ b/manifest.json @@ -21,8 +21,8 @@ }, "tokens-erc20-erc721": { "image": "ghcr.io/hyperledger/firefly-tokens-erc20-erc721", - "tag": "v0.2.0", - "sha": "a30a40ff4912931d06e008a354b3f9409defea98a5344303d663628d5e4a8629" + "tag": "v0.2.1", + "sha": "829df7fc94a4bdeba09925ee016a820616ffa0dadd28a9a9f19f9888c56e87c0" }, "build": { "firefly-builder": { diff --git a/mocks/identitymanagermocks/manager.go b/mocks/identitymanagermocks/manager.go index 7bb3dc823e..625d517803 100644 --- a/mocks/identitymanagermocks/manager.go +++ b/mocks/identitymanagermocks/manager.go @@ -15,8 +15,31 @@ type Manager struct { mock.Mock } -// CachedIdentityLookup provides a mock function with given fields: ctx, did -func (_m *Manager) CachedIdentityLookup(ctx context.Context, did string) (*fftypes.Identity, bool, error) { +// CachedIdentityLookupByID provides a mock function with given fields: ctx, id +func (_m *Manager) CachedIdentityLookupByID(ctx context.Context, id *fftypes.UUID) (*fftypes.Identity, error) { + ret := _m.Called(ctx, id) + + var r0 *fftypes.Identity + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *fftypes.Identity); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*fftypes.Identity) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *fftypes.UUID) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CachedIdentityLookupMustExist provides a mock function with given fields: ctx, did +func (_m *Manager) CachedIdentityLookupMustExist(ctx context.Context, did string) (*fftypes.Identity, bool, error) { ret := _m.Called(ctx, did) var r0 *fftypes.Identity @@ -45,27 +68,34 @@ func (_m *Manager) CachedIdentityLookup(ctx context.Context, did string) (*fftyp return r0, r1, r2 } -// CachedIdentityLookupByID provides a mock function with given fields: ctx, id -func (_m *Manager) CachedIdentityLookupByID(ctx context.Context, id *fftypes.UUID) (*fftypes.Identity, error) { - ret := _m.Called(ctx, id) +// CachedIdentityLookupNilOK provides a mock function with given fields: ctx, did +func (_m *Manager) CachedIdentityLookupNilOK(ctx context.Context, did string) (*fftypes.Identity, bool, error) { + ret := _m.Called(ctx, did) var r0 *fftypes.Identity - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *fftypes.Identity); ok { - r0 = rf(ctx, id) + if rf, ok := ret.Get(0).(func(context.Context, string) *fftypes.Identity); ok { + r0 = rf(ctx, did) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*fftypes.Identity) } } - var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *fftypes.UUID) error); ok { - r1 = rf(ctx, id) + var r1 bool + if rf, ok := ret.Get(1).(func(context.Context, string) bool); ok { + r1 = rf(ctx, did) } else { - r1 = ret.Error(1) + r1 = ret.Get(1).(bool) } - return r0, r1 + var r2 error + if rf, ok := ret.Get(2).(func(context.Context, string) error); ok { + r2 = rf(ctx, did) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // CachedVerifierLookup provides a mock function with given fields: ctx, vType, ns, value