Skip to content

Commit

Permalink
Merge pull request #115 from kaleido-io/cherry-pick
Browse files Browse the repository at this point in the history
Port over fix for Observed NPEs during contract invoke
  • Loading branch information
EnriqueL8 authored Sep 30, 2024
2 parents c718ca2 + b2f2c78 commit 709bbba
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
7 changes: 6 additions & 1 deletion internal/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 28 additions & 1 deletion internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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{}
Expand Down
8 changes: 6 additions & 2 deletions internal/definitions/sender.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion internal/definitions/sender_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -111,6 +111,26 @@ func TestName(t *testing.T) {
assert.Equal(t, "DefinitionSender", ds.Name())
}

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 TestCreateDefinitionConfirm(t *testing.T) {
ds := newTestDefinitionSender(t)
defer ds.cleanup(t)
Expand Down

0 comments on commit 709bbba

Please sign in to comment.