Skip to content

Commit

Permalink
Merge "FAB-10292 Update protobuf to v1.1.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Jul 16, 2018
2 parents e34dac4 + 03104e7 commit e9ed0db
Show file tree
Hide file tree
Showing 114 changed files with 16,825 additions and 6,609 deletions.
6 changes: 4 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ignored = [

[[constraint]]
name = "github.com/golang/protobuf"
revision = "fec3b39b059c0f88fa6b20f5ed012b1aa203a8b4"
version = "1.1.0"

[[constraint]]
name = "github.com/gorilla/mux"
Expand Down
7 changes: 4 additions & 3 deletions common/deliver/deliver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"time"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/hyperledger/fabric/common/deliver"
"github.com/hyperledger/fabric/common/deliver/mock"
Expand Down Expand Up @@ -190,7 +191,7 @@ var _ = Describe("Deliver", func() {
Expect(fakeInspector.InspectCallCount()).To(Equal(1))
ctx, header := fakeInspector.InspectArgsForCall(0)
Expect(ctx).To(Equal(context.Background()))
Expect(header).To(Equal(channelHeader))
Expect(proto.Equal(header, channelHeader)).To(BeTrue())
})

Context("when channel header validation fails", func() {
Expand Down Expand Up @@ -230,7 +231,7 @@ var _ = Describe("Deliver", func() {

Expect(fakePolicyChecker.CheckPolicyCallCount()).To(BeNumerically(">=", 1))
e, cid := fakePolicyChecker.CheckPolicyArgsForCall(0)
Expect(e).To(Equal(envelope))
Expect(proto.Equal(e, envelope)).To(BeTrue())
Expect(cid).To(Equal("chain-id"))
})

Expand All @@ -240,7 +241,7 @@ var _ = Describe("Deliver", func() {

Expect(fakeBlockReader.IteratorCallCount()).To(Equal(1))
startPosition := fakeBlockReader.IteratorArgsForCall(0)
Expect(startPosition).To(Equal(seekInfo.Start))
Expect(proto.Equal(startPosition, seekInfo.Start)).To(BeTrue())
})

Context("when multiple blocks are requested", func() {
Expand Down
10 changes: 10 additions & 0 deletions common/ledger/testutil/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"reflect"
"runtime"
"testing"

"github.com/golang/protobuf/proto"
)

// AssertNil varifies that the value is nil
Expand Down Expand Up @@ -63,6 +65,14 @@ func AssertEquals(t testing.TB, actual interface{}, expected interface{}) {
actual = convertJSONToMap(actual)
expected = convertJSONToMap(expected)

if pa, ok := actual.(proto.Message); ok {
if pe, ok := actual.(proto.Message); ok {
if proto.Equal(pa, pe) {
return
}
}
}

if !reflect.DeepEqual(actual, expected) {
t.Fatalf("Values are not equal.\n Actual=[%#v], \n Expected=[%#v]\n %s", actual, expected, getCallerInfo())
}
Expand Down
5 changes: 4 additions & 1 deletion common/policies/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ func TestPrincipalUniqueSet(t *testing.T) {
v := reflect.Indirect(reflect.ValueOf(msp.MSPPrincipal{}))
// Ensure msp.MSPPrincipal has only 2 fields.
// This is essential for 'UniqueSet' to work properly
assert.Equal(t, 2, v.NumField())
// XXX This is a rather brittle check and brittle way to fix the test
// There seems to be an assumption that the number of fields in the proto
// struct matches the number of fields in the proto message
assert.Equal(t, 5, v.NumField())
}

func TestPrincipalSetContainingOnly(t *testing.T) {
Expand Down
11 changes: 9 additions & 2 deletions common/tools/configtxlator/rest/protolator_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ var (
Data: &cb.BlockData{
Data: [][]byte{
utils.MarshalOrPanic(&cb.Envelope{
Payload: utils.MarshalOrPanic(&cb.Payload{
Header: &cb.Header{
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
Type: int32(cb.HeaderType_CONFIG),
}),
},
}),
Signature: []byte("bar"),
}),
},
},
}

testOutput = `{"data":{"data":[{"signature":"YmFy"}]},"header":{"number":"0","previous_hash":"Zm9v"}}`
testOutput = `{"data":{"data":[{"payload":{"data":{"config":null,"last_update":null},"header":{"channel_header":{"channel_id":"","epoch":"0","extension":null,"timestamp":null,"tls_cert_hash":null,"tx_id":"","type":1,"version":0},"signature_header":{"creator":{"id_bytes":null,"mspid":""},"nonce":null}}},"signature":"YmFy"}]},"header":{"data_hash":null,"number":"0","previous_hash":"Zm9v"},"metadata":null}`
)

func TestProtolatorDecode(t *testing.T) {
Expand Down Expand Up @@ -82,7 +89,7 @@ func TestProtolatorEncode(t *testing.T) {

err := proto.Unmarshal(rec.Body.Bytes(), outputMsg)
assert.NoError(t, err)
assert.Equal(t, testProto, outputMsg)
assert.True(t, proto.Equal(testProto, outputMsg))
}

func TestProtolatorDecodeNonExistantProto(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions common/tools/protolator/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package protolator_test

import (
"bytes"
"os"
"testing"

"github.com/hyperledger/fabric/common/tools/configtxgen/configtxgentest"
Expand Down Expand Up @@ -73,3 +74,21 @@ func TestGenesisBlock(t *testing.T) {

bidirectionalMarshal(t, gb)
}

func TestEmitDefaultsBug(t *testing.T) {
block := &cb.Block{
Header: &cb.BlockHeader{
PreviousHash: []byte("foo"),
},
Data: &cb.BlockData{
Data: [][]byte{
utils.MarshalOrPanic(&cb.Envelope{
Signature: []byte("bar"),
}),
},
},
}

err := DeepMarshalJSON(os.Stdout, block)
assert.NoError(t, err)
}
12 changes: 12 additions & 0 deletions common/tools/protolator/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type plainField struct {
}

func (pf *plainField) PopulateFrom(source interface{}) error {
if source == nil {
return nil
}

if !reflect.TypeOf(source).AssignableTo(pf.fType) {
return fmt.Errorf("expected field %s for message %T to be assignable from %v but was not. Is %T", pf.name, pf.msg, pf.fType, source)
}
Expand All @@ -94,6 +98,11 @@ func (pf *plainField) PopulateTo() (interface{}, error) {
if !pf.value.Type().AssignableTo(pf.vType) {
return nil, fmt.Errorf("expected field %s for message %T to be assignable to %v but was not. Got %T.", pf.name, pf.msg, pf.fType, pf.value)
}

if pf.value.Type().Kind() == reflect.Ptr && pf.value.IsNil() {
return nil, nil
}

value, err := pf.populateTo(pf.value)
if err != nil {
return nil, fmt.Errorf("error in PopulateTo for field %s for message %T: %s", pf.name, pf.msg, err)
Expand Down Expand Up @@ -213,6 +222,9 @@ func stringInSlice(target string, slice []string) bool {

// protoToJSON is a simple shortcut wrapper around the proto JSON marshaler
func protoToJSON(msg proto.Message) ([]byte, error) {
if reflect.ValueOf(msg).IsNil() {
panic("We're nil here")
}
var b bytes.Buffer
m := jsonpb.Marshaler{
EnumsAsInts: false,
Expand Down
Loading

0 comments on commit e9ed0db

Please sign in to comment.