Skip to content

Commit

Permalink
[FAB-14491] relocate mocks nearer to consumer
Browse files Browse the repository at this point in the history
- move core/mocks/endorser to core/endorser/mocks
- move core/mocks/ccprovider to core/endorser/mocks

Change-Id: I61275d49cc9d1baf51da31fc7b664dc6b61d9059
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Jul 15, 2019
1 parent 17674cc commit a2edfb9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 45 deletions.
80 changes: 39 additions & 41 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"github.com/hyperledger/fabric/core/endorser/mocks"
"github.com/hyperledger/fabric/core/handlers/endorsement/builtin"
"github.com/hyperledger/fabric/core/ledger"
mockccprovider "github.com/hyperledger/fabric/core/mocks/ccprovider"
em "github.com/hyperledger/fabric/core/mocks/endorser"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/msp/mgmt"
msptesttools "github.com/hyperledger/fabric/msp/mgmt/testtools"
Expand Down Expand Up @@ -73,8 +71,8 @@ func getSignedPropWithCHIdAndArgs(chid, ccid, ccver string, ccargs [][]byte, t *
return &pb.SignedProposal{ProposalBytes: propBytes, Signature: signature}
}

func newMockTxSim() *mockccprovider.MockTxSim {
return &mockccprovider.MockTxSim{
func newMockTxSim() *mocks.MockTxSim {
return &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand Down Expand Up @@ -133,13 +131,13 @@ func testEndorsementCompletedMetric(t *testing.T, fakeMetrics *fakeEndorserMetri
}

func TestEndorserNilProp(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -161,7 +159,7 @@ func TestEndorserNilProp(t *testing.T) {
}

func TestEndorserUninvokableSysCC(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
Expand All @@ -177,13 +175,13 @@ func TestEndorserUninvokableSysCC(t *testing.T) {
}

func TestEndorserCCInvocationFailed(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 1000, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}}), Message: "achoo"},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -199,13 +197,13 @@ func TestEndorserCCInvocationFailed(t *testing.T) {
}

func TestEndorserNoCCDef(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionError: errors.New("gesundheit"),
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -221,14 +219,14 @@ func TestEndorserNoCCDef(t *testing.T) {
}

func TestEndorserBadInstPolicy(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
CheckInstantiationPolicyError: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -247,7 +245,7 @@ func TestEndorserSysCC(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand All @@ -267,13 +265,13 @@ func TestEndorserSysCC(t *testing.T) {
}

func TestEndorserCCInvocationError(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ExecuteError: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -288,13 +286,13 @@ func TestEndorserCCInvocationError(t *testing.T) {
}

func TestEndorserLSCCBadType(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -318,12 +316,12 @@ func TestEndorserLSCCBadType(t *testing.T) {
}

func TestEndorserDupTXId(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -348,14 +346,14 @@ func TestEndorserDupTXId(t *testing.T) {
}

func TestEndorserBadACL(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
CheckACLErr: errors.New(""),
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -379,13 +377,13 @@ func TestEndorserBadACL(t *testing.T) {
}

func TestEndorserGoodPathEmptyChannel(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -405,13 +403,13 @@ func TestEndorserGoodPathEmptyChannel(t *testing.T) {
}

func TestEndorserLSCCInitFails(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand Down Expand Up @@ -450,13 +448,13 @@ func TestEndorserLSCCDeploySysCC(t *testing.T) {
SysCCMap := make(map[string]struct{})
deployedCCName := "barf"
SysCCMap[deployedCCName] = struct{}{}
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand Down Expand Up @@ -485,7 +483,7 @@ func TestEndorserGoodPathWEvents(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand All @@ -505,13 +503,13 @@ func TestEndorserGoodPathWEvents(t *testing.T) {
}

func TestEndorserBadChannel(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand All @@ -531,7 +529,7 @@ func TestEndorserGoodPath(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand Down Expand Up @@ -564,7 +562,7 @@ func TestEndorserChaincodeCallLogging(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand All @@ -591,7 +589,7 @@ func TestEndorserLSCC(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand All @@ -617,7 +615,7 @@ func TestEndorserLSCC(t *testing.T) {
assert.EqualValues(t, 200, pResp.Response.Status)
}

func attachPluginEndorser(support *em.MockSupport, signerReturnErr error) {
func attachPluginEndorser(support *mocks.MockSupport, signerReturnErr error) {
csr := &mocks.ChannelStateRetriever{}
queryCreator := &mocks.QueryCreator{}
csr.On("NewQueryCreator", mock.Anything).Return(queryCreator, nil)
Expand All @@ -638,7 +636,7 @@ func TestEndorseWithPlugin(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand All @@ -664,7 +662,7 @@ func TestEndorseEndorsementFailure(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand Down Expand Up @@ -701,7 +699,7 @@ func TestEndorseEndorsementFailureDueToCCError(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand Down Expand Up @@ -733,13 +731,13 @@ func TestEndorseEndorsementFailureDueToCCError(t *testing.T) {
}

func TestSimulateProposal(t *testing.T) {
es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
GetTransactionByIDErr: errors.New(""),
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
GetTxSimulatorRv: &mockccprovider.MockTxSim{
GetTxSimulatorRv: &mocks.MockTxSim{
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
PubSimulationResults: &rwset.TxReadWriteSet{},
},
Expand Down Expand Up @@ -771,7 +769,7 @@ func TestEndorserAcquireTxSimulator(t *testing.T) {
m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)
m.On("Serialize").Return([]byte{1, 1, 1}, nil)
m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)
support := &em.MockSupport{
support := &mocks.MockSupport{
Mock: m,
GetApplicationConfigBoolRv: true,
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package endorser
package mocks

import (
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/endorser"
"github.com/hyperledger/fabric/core/ledger"
mc "github.com/hyperledger/fabric/core/mocks/ccprovider"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/mock"
Expand All @@ -30,7 +29,7 @@ type MockSupport struct {
ExecuteError error
ChaincodeDefinitionRv ccprovider.ChaincodeDefinition
ChaincodeDefinitionError error
GetTxSimulatorRv *mc.MockTxSim
GetTxSimulatorRv *MockTxSim
GetTxSimulatorErr error
CheckInstantiationPolicyError error
GetTransactionByIDErr error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright IBM Corp. 2018 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package ccprovider
package mocks

import (
commonledger "github.com/hyperledger/fabric/common/ledger"
Expand Down

0 comments on commit a2edfb9

Please sign in to comment.