Skip to content

Commit

Permalink
Show what do not match (#3012)
Browse files Browse the repository at this point in the history
* Show what do not match

Signed-off-by: gqqnbig <gqqnb2005@gmail.com>

* Print base64 string instead

Signed-off-by: gqqnbig <gqqnb2005@gmail.com>

* Finalize message format and fix unit tests

Signed-off-by: gqqnbig <gqqnb2005@gmail.com>

* Fix expected message

Signed-off-by: gqqnbig <gqqnb2005@gmail.com>
  • Loading branch information
gqqnbig committed Nov 5, 2021
1 parent 5113aa9 commit d67d421
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func TestEndorse(t *testing.T) {
"g2": {{endorser: peer2Mock, height: 5}}, // msp2
},
localResponse: "different_response",
errString: "rpc error: code = Aborted desc = failed to assemble transaction: ProposalResponsePayloads do not match",
errString: "rpc error: code = Aborted desc = failed to assemble transaction: ProposalResponsePayloads do not match (base64): 'EhQaEgjIARoNbW9ja19yZXNwb25zZQ==' vs 'EhkaFwjIARoSZGlmZmVyZW50X3Jlc3BvbnNl'",
},
{
name: "discovery fails",
Expand Down
4 changes: 3 additions & 1 deletion protoutil/txutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package protoutil
import (
"bytes"
"crypto/sha256"
b64 "encoding/base64"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
Expand Down Expand Up @@ -202,7 +203,8 @@ func createTx(
}

if !bytes.Equal(a1, r.Payload) {
return nil, errors.New("ProposalResponsePayloads do not match")
return nil, errors.Errorf("ProposalResponsePayloads do not match (base64): '%s' vs '%s'",
b64.StdEncoding.EncodeToString(r.Payload), b64.StdEncoding.EncodeToString(a1))
}
}

Expand Down
19 changes: 11 additions & 8 deletions protoutil/txutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/hex"
"errors"
"strconv"
"strings"
"testing"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -175,14 +176,6 @@ func TestCreateSignedTx(t *testing.T) {
responses []*pb.ProposalResponse
expectedError string
}{
// good responses, but different payloads
{
[]*pb.ProposalResponse{
{Payload: []byte("payload"), Response: &pb.Response{Status: int32(200)}},
{Payload: []byte("payload2"), Response: &pb.Response{Status: int32(200)}},
},
"ProposalResponsePayloads do not match",
},
// good response followed by bad response
{
[]*pb.ProposalResponse{
Expand All @@ -205,6 +198,16 @@ func TestCreateSignedTx(t *testing.T) {
require.EqualErrorf(t, err, nonMatchingTest.expectedError, "Expected non-matching response error '%v' for test %d", nonMatchingTest.expectedError, i)
}

// good responses, but different payloads
responses = []*pb.ProposalResponse{
{Payload: []byte("payload"), Response: &pb.Response{Status: int32(200)}},
{Payload: []byte("payload2"), Response: &pb.Response{Status: int32(200)}},
}
_, err = protoutil.CreateSignedTx(prop, signID, responses...)
if err == nil || strings.HasPrefix(err.Error(), "ProposalResponsePayloads do not match (base64):") == false {
require.FailNow(t, "Error is expected when response payloads do not match")
}

// no endorsement
responses = []*pb.ProposalResponse{{
Payload: []byte("payload"),
Expand Down

0 comments on commit d67d421

Please sign in to comment.