Skip to content

Commit

Permalink
[FAB-9871] reverting devstable int-test workarounds
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
sudeshrshetty committed May 4, 2018
1 parent 3dc32a2 commit 914555e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
14 changes: 14 additions & 0 deletions pkg/fab/peer/peerendorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/comm"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
protos_utils "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/utils"
)
Expand Down Expand Up @@ -167,7 +168,11 @@ func (p *peerEndorser) sendProposal(ctx reqContext.Context, proposal fab.Process
err = status.NewFromExtractedChaincodeError(code, message)
}
}
} else {
//check error from response (for :fabric v1.2 and later)
err = extractChaincodeErrorFromResponse(resp)
}

return resp, err
}

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

//extractChaincodeErrorFromResponse extracts chaincode error from proposal response
func extractChaincodeErrorFromResponse(resp *pb.ProposalResponse) error {
if resp.Response.Status != int32(common.Status_SUCCESS) {
details := []interface{}{resp.Endorsement, resp.Response.Payload}
return status.New(status.ChaincodeStatus, resp.Response.Status, resp.Response.Message, details)
}
return nil
}

func checkMessage(status *grpcstatus.Status, messageLength int, message string) string {
if strings.Contains(status.Message(), "message:") {
i := strings.Index(status.Message(), "message:")
Expand Down
22 changes: 22 additions & 0 deletions pkg/fab/peer/peerendorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,25 @@ func TestExtractPrematureExecError(t *testing.T) {
assert.EqualValues(t, int32(status.PrematureChaincodeExecution), code, "Expected premature execution error")
assert.EqualValues(t, "premature execution - chaincode (somecc:v1) launched and waiting for registration", message, "Invalid message")
}

func TestChaincodeStatusFromResponse(t *testing.T) {
//For error response
response := &pb.ProposalResponse{
Response: &pb.Response{Status: 500, Payload: []byte("Unknown function"), Message: "Chaincode error"},
}
err := extractChaincodeErrorFromResponse(response)
s, ok := status.FromError(err)
assert.True(t, ok)
assert.Equal(t, "Chaincode error", s.Message)
assert.Equal(t, int32(500), s.Code)
assert.Equal(t, status.ChaincodeStatus, s.Group)
assert.Equal(t, []byte("Unknown function"), s.Details[1])

//For successful response
response = &pb.ProposalResponse{
Response: &pb.Response{Status: 200, Payload: []byte("TEST"), Message: "Success"},
}
err = extractChaincodeErrorFromResponse(response)
assert.True(t, ok)
assert.Nil(t, err)
}
19 changes: 4 additions & 15 deletions test/integration/orgs/multiple_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package orgs

import (
"math"
"os"
"path"
"strconv"
"strings"
Expand Down Expand Up @@ -332,23 +331,13 @@ func verifyErrorFromCC(chClientOrg1User *channel.Client, t *testing.T) {
t.Logf("verifyErrorFromCC status.FromError s: %s, ok: %t", s, ok)

require.True(t, ok, "expected status error")
// current DEVSTABLE Fabric version (v1.2) has a different error structure,
// below condition will work for DEV, PREV or PRERELEASE
// TODO remove the whole if condition when PREV becomes v1.2 and keep code in else condition
if os.Getenv("FABRIC_FIXTURE_VERSION") != "v1.2" {
require.Equal(t, s.Code, int32(status.MultipleErrors))

for _, err := range err.(multi.Errors) {
s, ok := status.FromError(err)
require.True(t, ok, "expected status error")
require.EqualValues(t, int32(500), s.Code)
require.Equal(t, status.ChaincodeStatus, s.Group)
}
} else {
// in v1.2, the error is not of type multi.Errors slice but rather 1 instance of errors.withMessage
require.Equal(t, s.Code, int32(status.MultipleErrors))

for _, err := range err.(multi.Errors) {
s, ok := status.FromError(err)
require.True(t, ok, "expected status error")
require.EqualValues(t, int32(500), s.Code)
require.Equal(t, status.ChaincodeStatus, s.Group)
}
}

Expand Down
8 changes: 1 addition & 7 deletions test/integration/sdk/channel_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package sdk

import (
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -303,12 +302,7 @@ func testChaincodeError(ccID string, client *channel.Client, t *testing.T) {
require.Error(t, err)
s, ok := status.FromError(err)
require.True(t, ok, "expected status error")
// current DEVSTABLE Fabric version (v1.2) has a different error structure,
// below condition will work for DEV, PREV or PRERELEASE
// TODO remove this if condition when PREV becomes v1.2
if os.Getenv("FABRIC_FIXTURE_VERSION") != "v1.2" {
require.EqualValues(t, status.ChaincodeStatus, s.Group, "expected ChaincodeStatus")
}
require.EqualValues(t, status.ChaincodeStatus, s.Group, "expected ChaincodeStatus")
require.Equal(t, int32(500), s.Code)
require.Equal(t, "Unknown function call", s.Message)
}
Expand Down

0 comments on commit 914555e

Please sign in to comment.