From dd2868aacb76a483a4940ce4573dbf5fce121619 Mon Sep 17 00:00:00 2001 From: Sudesh Shetty Date: Mon, 14 May 2018 20:58:04 -0400 Subject: [PATCH] [FAB-9983] fixing endpointconfig channels -Handling condition where no channel config found for given channel ID. -Changes needed from abondoned code push related to FAB-10001 Change-Id: If74e8c05e60363ddcda686e91b03def60cce05d7 Signed-off-by: Sudesh Shetty --- pkg/fab/channel/transactor.go | 4 ++++ pkg/fab/channel/transactor_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/fab/channel/transactor.go b/pkg/fab/channel/transactor.go index 93da6b0bdb..4b04732ceb 100644 --- a/pkg/fab/channel/transactor.go +++ b/pkg/fab/channel/transactor.go @@ -117,6 +117,10 @@ func orderersFromChannel(ctx context.Client, channelID string) ([]fab.Orderer, e chNetworkConfig, err := ctx.EndpointConfig().ChannelConfig(channelID) if err != nil { + s, ok := status.FromError(err) + if ok && s.Code == status.NoMatchingChannelEntity.ToInt32() { + return []fab.Orderer{}, nil + } return nil, errors.WithMessage(err, "failed to get channel network config") } diff --git a/pkg/fab/channel/transactor_test.go b/pkg/fab/channel/transactor_test.go index eaf2f22ed5..ef1765c469 100644 --- a/pkg/fab/channel/transactor_test.go +++ b/pkg/fab/channel/transactor_test.go @@ -130,6 +130,18 @@ func TestOrderersFromChannelCfg(t *testing.T) { assert.NotEmpty(t, o) } +// TestOrderersFromChannel - tests scenario where err should not be returned if channel config is not found +//instead, empty orderers list should be returned +func TestOrderersFromChannel(t *testing.T) { + user := mspmocks.NewMockSigningIdentity("test", "test") + ctx := mocks.NewMockContext(user) + + o, err := orderersFromChannel(ctx, "invalid-channel-id") + assert.Nil(t, err) + assert.NotNil(t, o) + assert.Zero(t, len(o)) +} + // TestOrderersFromChannelCfg uses an orderer that does not exist in the configuration. func TestOrderersFromChannelCfgBadTLS(t *testing.T) { user := mspmocks.NewMockSigningIdentity("test", "test")