Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 914555e

Browse files
committed
[FAB-9871] reverting devstable int-test workarounds
- reverted devstable temporary fixes, looks like existing code has no issues with devstable v1.2 - extracting error from proposal response in peer endorser Change-Id: I1cf00e5c7f09b29f6bb98649ab81c29550940840 Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
1 parent 3dc32a2 commit 914555e

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

pkg/fab/peer/peerendorser.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/hyperledger/fabric-sdk-go/pkg/context"
2727
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/comm"
2828
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
29+
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
2930
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
3031
protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils"
3132
)
@@ -167,7 +168,11 @@ func (p *peerEndorser) sendProposal(ctx reqContext.Context, proposal fab.Process
167168
err = status.NewFromExtractedChaincodeError(code, message)
168169
}
169170
}
171+
} else {
172+
//check error from response (for :fabric v1.2 and later)
173+
err = extractChaincodeErrorFromResponse(resp)
170174
}
175+
171176
return resp, err
172177
}
173178

@@ -199,6 +204,15 @@ func extractChaincodeError(status *grpcstatus.Status) (int, string, error) {
199204
return code, message, errors.Errorf("Unable to parse GRPC Status Message Code: %v Message: %v", code, message)
200205
}
201206

207+
//extractChaincodeErrorFromResponse extracts chaincode error from proposal response
208+
func extractChaincodeErrorFromResponse(resp *pb.ProposalResponse) error {
209+
if resp.Response.Status != int32(common.Status_SUCCESS) {
210+
details := []interface{}{resp.Endorsement, resp.Response.Payload}
211+
return status.New(status.ChaincodeStatus, resp.Response.Status, resp.Response.Message, details)
212+
}
213+
return nil
214+
}
215+
202216
func checkMessage(status *grpcstatus.Status, messageLength int, message string) string {
203217
if strings.Contains(status.Message(), "message:") {
204218
i := strings.Index(status.Message(), "message:")

pkg/fab/peer/peerendorser_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,25 @@ func TestExtractPrematureExecError(t *testing.T) {
312312
assert.EqualValues(t, int32(status.PrematureChaincodeExecution), code, "Expected premature execution error")
313313
assert.EqualValues(t, "premature execution - chaincode (somecc:v1) launched and waiting for registration", message, "Invalid message")
314314
}
315+
316+
func TestChaincodeStatusFromResponse(t *testing.T) {
317+
//For error response
318+
response := &pb.ProposalResponse{
319+
Response: &pb.Response{Status: 500, Payload: []byte("Unknown function"), Message: "Chaincode error"},
320+
}
321+
err := extractChaincodeErrorFromResponse(response)
322+
s, ok := status.FromError(err)
323+
assert.True(t, ok)
324+
assert.Equal(t, "Chaincode error", s.Message)
325+
assert.Equal(t, int32(500), s.Code)
326+
assert.Equal(t, status.ChaincodeStatus, s.Group)
327+
assert.Equal(t, []byte("Unknown function"), s.Details[1])
328+
329+
//For successful response
330+
response = &pb.ProposalResponse{
331+
Response: &pb.Response{Status: 200, Payload: []byte("TEST"), Message: "Success"},
332+
}
333+
err = extractChaincodeErrorFromResponse(response)
334+
assert.True(t, ok)
335+
assert.Nil(t, err)
336+
}

test/integration/orgs/multiple_orgs_test.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package orgs
88

99
import (
1010
"math"
11-
"os"
1211
"path"
1312
"strconv"
1413
"strings"
@@ -332,23 +331,13 @@ func verifyErrorFromCC(chClientOrg1User *channel.Client, t *testing.T) {
332331
t.Logf("verifyErrorFromCC status.FromError s: %s, ok: %t", s, ok)
333332

334333
require.True(t, ok, "expected status error")
335-
// current DEVSTABLE Fabric version (v1.2) has a different error structure,
336-
// below condition will work for DEV, PREV or PRERELEASE
337-
// TODO remove the whole if condition when PREV becomes v1.2 and keep code in else condition
338-
if os.Getenv("FABRIC_FIXTURE_VERSION") != "v1.2" {
339-
require.Equal(t, s.Code, int32(status.MultipleErrors))
340-
341-
for _, err := range err.(multi.Errors) {
342-
s, ok := status.FromError(err)
343-
require.True(t, ok, "expected status error")
344-
require.EqualValues(t, int32(500), s.Code)
345-
require.Equal(t, status.ChaincodeStatus, s.Group)
346-
}
347-
} else {
348-
// in v1.2, the error is not of type multi.Errors slice but rather 1 instance of errors.withMessage
334+
require.Equal(t, s.Code, int32(status.MultipleErrors))
335+
336+
for _, err := range err.(multi.Errors) {
349337
s, ok := status.FromError(err)
350338
require.True(t, ok, "expected status error")
351339
require.EqualValues(t, int32(500), s.Code)
340+
require.Equal(t, status.ChaincodeStatus, s.Group)
352341
}
353342
}
354343

test/integration/sdk/channel_client_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package sdk
88

99
import (
10-
"os"
1110
"strings"
1211
"testing"
1312
"time"
@@ -303,12 +302,7 @@ func testChaincodeError(ccID string, client *channel.Client, t *testing.T) {
303302
require.Error(t, err)
304303
s, ok := status.FromError(err)
305304
require.True(t, ok, "expected status error")
306-
// current DEVSTABLE Fabric version (v1.2) has a different error structure,
307-
// below condition will work for DEV, PREV or PRERELEASE
308-
// TODO remove this if condition when PREV becomes v1.2
309-
if os.Getenv("FABRIC_FIXTURE_VERSION") != "v1.2" {
310-
require.EqualValues(t, status.ChaincodeStatus, s.Group, "expected ChaincodeStatus")
311-
}
305+
require.EqualValues(t, status.ChaincodeStatus, s.Group, "expected ChaincodeStatus")
312306
require.Equal(t, int32(500), s.Code)
313307
require.Equal(t, "Unknown function call", s.Message)
314308
}

0 commit comments

Comments
 (0)