Skip to content

Commit

Permalink
Fix tests breaking with the latest protobuf
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Toulme <[email protected]>
  • Loading branch information
atoulme committed Oct 11, 2021
1 parent 0242782 commit 1df123b
Show file tree
Hide file tree
Showing 27 changed files with 74 additions and 69 deletions.
2 changes: 1 addition & 1 deletion common/cauthdsl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestNewPolicyErrorCase(t *testing.T) {
pol1, msg1, err1 := provider.NewPolicy([]byte{0})
require.Nil(t, pol1)
require.Nil(t, msg1)
require.EqualError(t, err1, "Error unmarshalling to SignaturePolicy: proto: common.SignaturePolicyEnvelope: illegal tag 0 (wire type 0)")
require.EqualError(t, err1, "Error unmarshalling to SignaturePolicy: proto: cannot parse invalid wire-format data")

sigPolicy2 := &cb.SignaturePolicyEnvelope{Version: -1}
data2 := marshalOrPanic(sigPolicy2)
Expand Down
22 changes: 11 additions & 11 deletions core/chaincode/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandlePutState(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -687,7 +687,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandlePutStateMetadata(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -813,7 +813,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleDelState(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -932,7 +932,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleGetState(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -1138,7 +1138,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleGetPrivateDataHash(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -1537,7 +1537,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleGetStateByRange(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -1649,7 +1649,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleQueryStateNext(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -1760,7 +1760,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleQueryStateClose(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -1951,7 +1951,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleGetQueryResult(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -2049,7 +2049,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleGetHistoryForKey(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down Expand Up @@ -2348,7 +2348,7 @@ var _ = Describe("Handler", func() {

It("returns an error", func() {
_, err := handler.HandleInvokeChaincode(incomingMessage, txContext)
Expect(err).To(MatchError("unmarshal failed: proto: can't skip unknown wire type 4"))
Expect(err).To(MatchError("unmarshal failed: proto: cannot parse invalid wire-format data"))
})
})

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ var _ = Describe("ExternalFunctions", func() {

It("returns an error", func() {
err := ef.ApproveChaincodeDefinitionForOrg("my-channel", "cc-name", testDefinition, "hash", fakePublicState, fakeOrgState)
Expect(err).To(MatchError("could not fetch metadata for current definition: could not unmarshal metadata for namespace namespaces/cc-name: proto: can't skip unknown wire type 7"))
Expect(err).To(MatchError("could not fetch metadata for current definition: could not unmarshal metadata for namespace namespaces/cc-name: proto: cannot parse invalid wire-format data"))
})
})

Expand Down
2 changes: 1 addition & 1 deletion core/dispatcher/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var _ = Describe("Dispatcher", func() {
Context("when the input bytes cannot be unmarshaled", func() {
It("wraps and returns the error", func() {
_, err := d.Dispatch([]byte("garbage"), "GoodFunc", testReceiver)
Expect(err).To(MatchError("could not decode input arg for dispatcher_test.TestReceiver.GoodFunc: proto: can't skip unknown wire type 7"))
Expect(err).To(MatchError("could not decode input arg for dispatcher_test.TestReceiver.GoodFunc: proto: cannot parse invalid wire-format data"))
})
})

Expand Down
4 changes: 2 additions & 2 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,11 @@ var _ = Describe("Endorser", func() {

It("wraps and returns an error and responds to the client", func() {
proposalResponse, err := e.ProcessProposal(context.Background(), signedProposal)
Expect(err).To(MatchError("error unmarshalling Proposal: proto: can't skip unknown wire type 7"))
Expect(err).To(MatchError("error unmarshalling Proposal: cannot parse invalid wire-format data"))
Expect(proposalResponse).To(Equal(&pb.ProposalResponse{
Response: &pb.Response{
Status: 500,
Message: "error unmarshalling Proposal: proto: can't skip unknown wire type 7",
Message: "error unmarshalling Proposal: cannot parse invalid wire-format data",
},
}))
})
Expand Down
2 changes: 1 addition & 1 deletion core/endorser/msgvalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var _ = Describe("UnpackProposal", func() {

It("wraps and returns an error", func() {
_, err := endorser.UnpackProposal(signedProposal)
Expect(err).To(MatchError("error unmarshalling Proposal: proto: can't skip unknown wire type 7"))
Expect(err).To(MatchError("error unmarshalling Proposal"))
})
})

Expand Down
4 changes: 2 additions & 2 deletions core/handlers/validation/builtin/v12/validation_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestValidateDeployFail(t *testing.T) {

b = &common.Block{Data: &common.BlockData{Data: [][]byte{envBytes}}}
err = v.Validate(b, "lscc", 0, 0, policy)
require.EqualError(t, err, "unmarhsalling of ChaincodeData failed, error unexpected EOF")
require.EqualError(t, err, "unmarhsalling of ChaincodeData failed, error proto: cannot parse invalid wire-format data")

/**********************/
/* test bad LSCC args */
Expand Down Expand Up @@ -577,7 +577,7 @@ func TestValidateDeployFail(t *testing.T) {

b = &common.Block{Data: &common.BlockData{Data: [][]byte{envBytes}}}
err = v.Validate(b, "lscc", 0, 0, policy)
require.EqualError(t, err, "GetChaincodeDeploymentSpec error error unmarshalling ChaincodeDeploymentSpec: unexpected EOF")
require.EqualError(t, err, "GetChaincodeDeploymentSpec error error unmarshalling ChaincodeDeploymentSpec: proto: cannot parse invalid wire-format data")

/***********************/
/* test bad cc version */
Expand Down
4 changes: 2 additions & 2 deletions core/handlers/validation/builtin/v13/validation_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func TestValidateDeployFail(t *testing.T) {

b = &common.Block{Data: &common.BlockData{Data: [][]byte{envBytes}}, Header: &common.BlockHeader{}}
err = v.Validate(b, "lscc", 0, 0, policy)
require.EqualError(t, err, "unmarhsalling of ChaincodeData failed, error unexpected EOF")
require.EqualError(t, err, "unmarhsalling of ChaincodeData failed, error proto: cannot parse invalid wire-format data")

/**********************/
/* test bad LSCC args */
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestValidateDeployFail(t *testing.T) {

b = &common.Block{Data: &common.BlockData{Data: [][]byte{envBytes}}, Header: &common.BlockHeader{}}
err = v.Validate(b, "lscc", 0, 0, policy)
require.EqualError(t, err, "GetChaincodeDeploymentSpec error error unmarshalling ChaincodeDeploymentSpec: unexpected EOF")
require.EqualError(t, err, "GetChaincodeDeploymentSpec error error unmarshalling ChaincodeDeploymentSpec: proto: cannot parse invalid wire-format data")

/***********************/
/* test bad cc version */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestToApplicationPolicyTranslator_Translate(t *testing.T) {

res, err = tr.Translate([]byte("barf"))
require.Error(t, err)
require.Contains(t, err.Error(), "could not unmarshal signature policy envelope: unexpected EOF")
require.Contains(t, err.Error(), "could not unmarshal signature policy envelope: proto: cannot parse invalid wire-format data")
require.Nil(t, res)

res, err = tr.Translate(protoutil.MarshalOrPanic(policydsl.SignedByMspMember("the right honourable member for Ipswich")))
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/kvledger/channelinfo_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestGetAllMSPIDs_NegativeTests(t *testing.T) {
configBlock.Metadata.Metadata[cb.BlockMetadataIndex_SIGNATURES] = []byte("invalid_bytes")
require.NoError(t, blkStore.AddBlock(configBlock))
_, err = channelInfoProvider.getAllMSPIDs()
require.EqualError(t, err, "failed to retrieve metadata: error unmarshalling metadata at index [SIGNATURES]: unexpected EOF")
require.EqualError(t, err, "failed to retrieve metadata: error unmarshalling metadata at index [SIGNATURES]: proto: cannot parse invalid wire-format data")

// test RetrieveBlockByNumber error (before calling GetLastConfigIndexFromBlock) by closing block store provider
blkStoreProvider.Close()
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/kvledger/kv_ledger_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ func TestLedgerMetataDataUnmarshalError(t *testing.T) {
require.NoError(t, provider.idStore.db.Put(metadataKey(ledgerID), []byte("invalid"), true))

_, err = provider.List()
require.EqualError(t, err, "error unmarshalling ledger metadata: unexpected EOF")
require.EqualError(t, err, "error unmarshalling ledger metadata: proto: cannot parse invalid wire-format data")

_, err = provider.Open(ledgerID)
require.EqualError(t, err, "error unmarshalling ledger metadata: unexpected EOF")
require.EqualError(t, err, "error unmarshalling ledger metadata: proto: cannot parse invalid wire-format data")
}

func TestNewProviderIdStoreFormatError(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/kvledger/pause_resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func TestPauseAndResumeErrors(t *testing.T) {

// error if metadata cannot be unmarshaled
err = PauseChannel(conf.RootFSPath, ledgerID)
require.EqualError(t, err, "error unmarshalling ledger metadata: unexpected EOF")
require.EqualError(t, err, "error unmarshalling ledger metadata: proto: cannot parse invalid wire-format data")

err = ResumeChannel(conf.RootFSPath, ledgerID)
require.EqualError(t, err, "error unmarshalling ledger metadata: unexpected EOF")
require.EqualError(t, err, "error unmarshalling ledger metadata: proto: cannot parse invalid wire-format data")
}

// verify status for paused ledgers and non-paused ledgers
Expand Down
2 changes: 1 addition & 1 deletion core/scc/lscc/lscc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func TestDeploy(t *testing.T) {

res = stub.MockInvokeWithSignedProposal("1", [][]byte{[]byte("deploy"), []byte("chain"), []byte("barf")}, nil)
require.NotEqual(t, int32(shim.OK), res.Status)
require.Equal(t, "error unmarshalling ChaincodeDeploymentSpec: unexpected EOF", res.Message)
require.Equal(t, "error unmarshalling ChaincodeDeploymentSpec: cannot parse invalid wire-format data", res.Message)

testDeploy(t, "example02", "1.0", path, false, false, true, "", scc, stub, nil)
testDeploy(t, "example02", "1.0", path, false, false, true, "chaincode with name 'example02' already exists", scc, stub, nil)
Expand Down
2 changes: 1 addition & 1 deletion core/scc/qscc/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestFailingCC2CC(t *testing.T) {
resetProvider(resources.Qscc_GetChainInfo, "testchannel", sProp, nil)
res := stub.MockInvokeWithSignedProposal("2", args, sProp)
require.Equal(t, int32(shim.ERROR), res.Status, "GetChainInfo must fail: %s", res.Message)
require.Contains(t, res.Message, "Failed to identify the called chaincode: could not unmarshal proposal: proto: can't skip unknown wire type 7")
require.Contains(t, res.Message, "Failed to identify the called chaincode: could not unmarshal proposal")
})

t.Run("DifferentInvokedCC", func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions core/tx/endorser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var _ = Describe("Parser", func() {

It("returns an error", func() {
pe, err := endorsertx.UnmarshalEndorserTxAndValidate(txenv)
Expect(err).To(MatchError("error unmarshalling Transaction: unexpected EOF"))
Expect(err).To(MatchError(MatchRegexp("error unmarshalling Transaction")))
Expect(pe).To(BeNil())
})
})
Expand Down Expand Up @@ -149,7 +149,7 @@ var _ = Describe("Parser", func() {

It("returns an error", func() {
pe, err := endorsertx.UnmarshalEndorserTxAndValidate(txenv)
Expect(err).To(MatchError("error unmarshalling ChaincodeActionPayload: unexpected EOF"))
Expect(err).To(MatchError(MatchRegexp("error unmarshalling ChaincodeActionPayload")))
Expect(pe).To(BeNil())
})
})
Expand Down Expand Up @@ -196,7 +196,7 @@ var _ = Describe("Parser", func() {

It("returns an error", func() {
pe, err := endorsertx.UnmarshalEndorserTxAndValidate(txenv)
Expect(err).To(MatchError("error unmarshalling ChaincodeHeaderExtension: unexpected EOF"))
Expect(err).To(MatchError(MatchRegexp("error unmarshalling ChaincodeHeaderExtension")))
Expect(pe).To(BeNil())
})
})
Expand All @@ -220,7 +220,7 @@ var _ = Describe("Parser", func() {

It("returns an error", func() {
pe, err := endorsertx.UnmarshalEndorserTxAndValidate(txenv)
Expect(err).To(MatchError("error unmarshalling ProposalResponsePayload: unexpected EOF"))
Expect(err).To(MatchError(MatchRegexp("error unmarshalling ProposalResponsePayload")))
Expect(pe).To(BeNil())
})
})
Expand All @@ -244,7 +244,7 @@ var _ = Describe("Parser", func() {

It("returns an error", func() {
pe, err := endorsertx.UnmarshalEndorserTxAndValidate(txenv)
Expect(err).To(MatchError("error unmarshalling ChaincodeAction: unexpected EOF"))
Expect(err).To(MatchError(MatchRegexp("error unmarshalling ChaincodeAction")))
Expect(pe).To(BeNil())
})
})
Expand Down
10 changes: 5 additions & 5 deletions core/tx/processor_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func TestBasicTxValidity(t *testing.T) {
},
{
[]byte("bad env"), &pkgtx.InvalidErr{
ActualErr: errors.New("error unmarshalling Envelope: unexpected EOF"),
ActualErr: errors.New("error unmarshalling Envelope: proto: cannot parse invalid wire-format data"),
ValidationCode: peer.TxValidationCode_INVALID_OTHER_REASON,
},
},
{
protoutil.MarshalOrPanic(&common.Envelope{Payload: []byte("bad payload"), Signature: []byte("signature")}), &pkgtx.InvalidErr{
ActualErr: errors.New("error unmarshalling Payload: unexpected EOF"),
ActualErr: errors.New("error unmarshalling Payload: proto: cannot parse invalid wire-format data"),
ValidationCode: peer.TxValidationCode_BAD_PAYLOAD,
},
},
Expand Down Expand Up @@ -81,21 +81,21 @@ func TestBasicTxValidity(t *testing.T) {
},
{
protoutil.MarshalOrPanic(&common.Envelope{Payload: protoutil.MarshalOrPanic(&common.Payload{Header: &common.Header{ChannelHeader: []byte("bad channel header"), SignatureHeader: protoutil.MarshalOrPanic(&common.SignatureHeader{Creator: []byte("creator"), Nonce: []byte("nonce")})}}), Signature: []byte("signature")}), &pkgtx.InvalidErr{
ActualErr: errors.New("error unmarshalling ChannelHeader: unexpected EOF"),
ActualErr: errors.New("error unmarshalling ChannelHeader: proto: cannot parse invalid wire-format data"),
ValidationCode: peer.TxValidationCode_BAD_PAYLOAD,
},
},
{
protoutil.MarshalOrPanic(&common.Envelope{Payload: protoutil.MarshalOrPanic(&common.Payload{Header: &common.Header{ChannelHeader: protoutil.MarshalOrPanic(&common.ChannelHeader{ChannelId: "myc", TxId: "tid"}), SignatureHeader: []byte("bad sig hdr")}}), Signature: []byte("signature")}), &pkgtx.InvalidErr{
ActualErr: errors.New("error unmarshalling SignatureHeader: unexpected EOF"),
ActualErr: errors.New("error unmarshalling SignatureHeader: proto: cannot parse invalid wire-format data"),
ValidationCode: peer.TxValidationCode_BAD_PAYLOAD,
},
},
}

for _, ic := range invalidConfigs {
_, _, err := f.CreateProcessor(ic.env)
require.Equal(t, err.Error(), ic.expectedErr.Error())
require.Equal(t, ic.expectedErr.Error(), err.Error())
}

// NOTE: common.HeaderType_CONFIG is a valid type and this should succeed when we populate ProcessorFactory (and signifies successful validation). Till then, a negative test
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/stretchr/testify/require"
)

var timeout = time.Second * time.Duration(180)
var timeout = time.Second * time.Duration(270)

func TestMain(m *testing.M) {
util.SetupTestLogging()
Expand Down
2 changes: 1 addition & 1 deletion gossip/service/gossip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
"google.golang.org/grpc"
)

const TIMEOUT = 45 * time.Second
const TIMEOUT = 90 * time.Second

func init() {
util.SetupTestLogging()
Expand Down
2 changes: 1 addition & 1 deletion internal/peer/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestGetOrdererEndpointFromConfigTx(t *testing.T) {
nil,
)
_, err := common.GetOrdererEndpointOfChain("test-channel", signer, mockEndorserClient, cryptoProvider)
require.EqualError(t, err, "error unmarshalling channel config: unexpected EOF")
require.ErrorContains(t, err, "error unmarshalling channel config")
})

t.Run("unloadable-config", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion orderer/common/channelparticipation/restapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func TestHTTPHandler_ServeHTTP_Join(t *testing.T) {
resp := httptest.NewRecorder()
req := genJoinRequestFormData(t, []byte{1, 2, 3, 4})
h.ServeHTTP(resp, req)
checkErrorResponse(t, http.StatusBadRequest, "cannot unmarshal file part config-block into a block: proto: common.Block: illegal tag 0 (wire type 1)", resp)
checkErrorResponse(t, http.StatusBadRequest, "cannot unmarshal file part config-block into a block: proto: cannot parse invalid wire-format data", resp)
})

t.Run("bad body - invalid join block", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 1df123b

Please sign in to comment.