From 21a2d9c05d0918d796e9d1ac8e4991a31fea6c53 Mon Sep 17 00:00:00 2001 From: SamMayWork Date: Thu, 19 Sep 2024 18:17:14 +0100 Subject: [PATCH 1/4] fix: check error before return Signed-off-by: SamMayWork --- internal/contracts/manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/contracts/manager.go b/internal/contracts/manager.go index ab45cf18e..753ab7e54 100644 --- a/internal/contracts/manager.go +++ b/internal/contracts/manager.go @@ -160,7 +160,12 @@ func NewContractManager(ctx context.Context, ns string, di database.Plugin, bi b // cause recreation of all the listeners (noting that listeners that were specified to start // from latest, will start from the new latest rather than replaying from the block they // started from before they were deleted). - return cm, cm.verifyListeners(ctx) + err = cm.verifyListeners(ctx) + if err != nil { + return nil, err + } + + return cm, nil } func (cm *contractManager) Name() string { From dc3c67086d2e5655330e7c336fbb2706dbcf602f Mon Sep 17 00:00:00 2001 From: SamMayWork Date: Fri, 20 Sep 2024 09:42:55 +0100 Subject: [PATCH 2/4] fix: UTs and patch another hole Signed-off-by: SamMayWork --- internal/contracts/manager_test.go | 27 +++++++++++++++++++++++++++ internal/definitions/sender.go | 6 +++++- internal/definitions/sender_test.go | 20 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/internal/contracts/manager_test.go b/internal/contracts/manager_test.go index d022d3157..4455f1368 100644 --- a/internal/contracts/manager_test.go +++ b/internal/contracts/manager_test.go @@ -98,6 +98,33 @@ func TestName(t *testing.T) { assert.Equal(t, "ContractManager", cm.Name()) } +func TestNewContractManagerVerifyListenersFails(t *testing.T) { + mdi := &databasemocks.Plugin{} + mdm := &datamocks.Manager{} + mbm := &broadcastmocks.Manager{} + mpm := &privatemessagingmocks.Manager{} + mbp := &batchmocks.Manager{} + mim := &identitymanagermocks.Manager{} + mbi := &blockchainmocks.Plugin{} + mom := &operationmocks.Manager{} + txw := &txwritermocks.Writer{} + cmi := &cachemocks.Manager{} + msa := &syncasyncmocks.Bridge{} + + ctx := context.Background() + + cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(ctx, 100, 5*time.Minute), nil) + txHelper, _ := txcommon.NewTransactionHelper(ctx, "ns1", mdi, mdm, cmi) + mbi.On("GetFFIParamValidator", mock.Anything).Return(nil, nil) + mom.On("RegisterHandler", mock.Anything, mock.Anything, mock.Anything) + mbi.On("Name").Return("mockblockchain").Maybe() + mdi.On("GetContractListeners", mock.Anything, "ns1", mock.Anything).Return(nil, nil, fmt.Errorf("KABOOM!")).Once() + + cm, err := NewContractManager(context.Background(), "ns1", mdi, mbi, mdm, mbm, mpm, mbp, mim, mom, txHelper, txw, msa, cmi) + assert.Nil(t, cm) + assert.NotNil(t, err) +} + func TestNewContractManagerFFISchemaLoaderFail(t *testing.T) { mdi := &databasemocks.Plugin{} mdm := &datamocks.Manager{} diff --git a/internal/definitions/sender.go b/internal/definitions/sender.go index 3d998c3a8..7423d2006 100644 --- a/internal/definitions/sender.go +++ b/internal/definitions/sender.go @@ -93,8 +93,12 @@ func NewDefinitionSender(ctx context.Context, ns *core.Namespace, multiparty boo tokenBroadcastNames: tokenBroadcastNames, } dh, err := newDefinitionHandler(ctx, ns, multiparty, di, bi, dx, dm, im, am, cm, reverseMap(tokenBroadcastNames)) + if err != nil { + return nil, nil, err + } + ds.handler = dh - return ds, dh, err + return ds, dh, nil } // reverseMap reverses the key/values of a given map diff --git a/internal/definitions/sender_test.go b/internal/definitions/sender_test.go index b7a8f4149..8eb0bc587 100644 --- a/internal/definitions/sender_test.go +++ b/internal/definitions/sender_test.go @@ -105,6 +105,26 @@ func TestInitSenderFail(t *testing.T) { assert.Regexp(t, "FF10128", err) } +func TestNewDefinitionSenderHandlerThrows(t *testing.T) { + mdi := &databasemocks.Plugin{} + mbi := &blockchainmocks.Plugin{} + mdx := &dataexchangemocks.Plugin{} + mbm := &broadcastmocks.Manager{} + mim := &identitymanagermocks.Manager{} + mdm := &datamocks.Manager{} + mcm := &contractmocks.Manager{} + + tokenBroadcastNames := make(map[string]string) + tokenBroadcastNames["connector1"] = "remote1" + + ctx := context.Background() + ns := &core.Namespace{Name: "ns1", NetworkName: "ns1"} + ds, dh, err := NewDefinitionSender(ctx, ns, false, mdi, mbi, mdx, mbm, mim, mdm, nil, mcm, tokenBroadcastNames) + assert.Nil(t, ds) + assert.Nil(t, dh) + assert.NotNil(t, err) +} + func TestName(t *testing.T) { ds := newTestDefinitionSender(t) defer ds.cleanup(t) From da90614e746c2e94ba471bd4ef875f5e77e6d7b1 Mon Sep 17 00:00:00 2001 From: SamMayWork Date: Mon, 23 Sep 2024 10:02:38 +0100 Subject: [PATCH 3/4] fix: bump the version of PostreSQL Signed-off-by: SamMayWork --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e0d17b93d..eca7e012b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -75,7 +75,7 @@ ARG UI_TAG ARG UI_RELEASE RUN apk add --update --no-cache \ sqlite=3.44.2-r0 \ - postgresql16-client=16.3-r0 \ + postgresql16-client=16.4-r0 \ curl=8.9.1-r0 \ jq=1.7.1-r0 WORKDIR /firefly From 4822087cd9bb0d4c2d21058d3e77360fccd36b97 Mon Sep 17 00:00:00 2001 From: SamMayWork Date: Mon, 23 Sep 2024 10:21:08 +0100 Subject: [PATCH 4/4] fix: copyright fixes Signed-off-by: SamMayWork --- internal/contracts/manager_test.go | 2 +- internal/definitions/sender.go | 2 +- internal/definitions/sender_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/contracts/manager_test.go b/internal/contracts/manager_test.go index 4455f1368..e936fb28d 100644 --- a/internal/contracts/manager_test.go +++ b/internal/contracts/manager_test.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // diff --git a/internal/definitions/sender.go b/internal/definitions/sender.go index 7423d2006..70f366409 100644 --- a/internal/definitions/sender.go +++ b/internal/definitions/sender.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // diff --git a/internal/definitions/sender_test.go b/internal/definitions/sender_test.go index 8eb0bc587..261c5c357 100644 --- a/internal/definitions/sender_test.go +++ b/internal/definitions/sender_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 //