Skip to content

Commit 95c4fc9

Browse files
ale-linuxyacovm
authored andcommitted
[FAB-6891] use mocks to test the endorser
This change set uses a mock support for the endorsement in testing instead of using the real implementation. This way, the endorser may be tested without any dependency on other packages/components. Change-Id: Ic3eee5908f221be8bedcb2b643dcba6800ab62aa Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
1 parent b1d94d6 commit 95c4fc9

File tree

6 files changed

+501
-1294
lines changed

6 files changed

+501
-1294
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package resourceconfig
8+
9+
type MockChaincodeDefinition struct {
10+
NameRv string
11+
VersionRv string
12+
EndorsementStr string
13+
ValidationStr string
14+
ValidationBytes []byte
15+
HashRv []byte
16+
}
17+
18+
func (m *MockChaincodeDefinition) CCName() string {
19+
return m.NameRv
20+
}
21+
22+
func (m *MockChaincodeDefinition) Hash() []byte {
23+
return m.HashRv
24+
}
25+
26+
func (m *MockChaincodeDefinition) CCVersion() string {
27+
return m.VersionRv
28+
}
29+
30+
func (m *MockChaincodeDefinition) Validation() (string, []byte) {
31+
return m.ValidationStr, m.ValidationBytes
32+
}
33+
34+
func (m *MockChaincodeDefinition) Endorsement() string {
35+
return m.EndorsementStr
36+
}

core/endorser/endorser.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ package endorser
99
import (
1010
"fmt"
1111

12-
"github.com/golang/protobuf/proto"
1312
"github.com/hyperledger/fabric/common/flogging"
1413
"github.com/hyperledger/fabric/common/resourcesconfig"
1514
"github.com/hyperledger/fabric/common/util"
1615
"github.com/hyperledger/fabric/core/chaincode"
1716
"github.com/hyperledger/fabric/core/chaincode/shim"
1817
"github.com/hyperledger/fabric/core/common/validation"
1918
"github.com/hyperledger/fabric/core/ledger"
20-
"github.com/hyperledger/fabric/core/peer"
21-
"github.com/hyperledger/fabric/msp"
2219
"github.com/hyperledger/fabric/protos/common"
2320
"github.com/hyperledger/fabric/protos/ledger/rwset"
2421
pb "github.com/hyperledger/fabric/protos/peer"
@@ -513,33 +510,3 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
513510

514511
return pResp, nil
515512
}
516-
517-
// Only exposed for testing purposes - commit the tx simulation so that
518-
// a deploy transaction is persisted and that chaincode can be invoked.
519-
// This makes the endorser test self-sufficient
520-
func (e *Endorser) commitTxSimulation(proposal *pb.Proposal, chainID string, signer msp.SigningIdentity, pResp *pb.ProposalResponse, blockNumber uint64) error {
521-
tx, err := putils.CreateSignedTx(proposal, signer, pResp)
522-
if err != nil {
523-
return err
524-
}
525-
526-
lgr := peer.GetLedger(chainID)
527-
if lgr == nil {
528-
return errors.Errorf("failed to look up the ledger for channel %s", chainID)
529-
}
530-
531-
txBytes, err := proto.Marshal(tx)
532-
if err != nil {
533-
return err
534-
}
535-
block := common.NewBlock(blockNumber, []byte{})
536-
block.Data.Data = [][]byte{txBytes}
537-
block.Header.DataHash = block.Data.Hash()
538-
if err = lgr.CommitWithPvtData(&ledger.BlockAndPvtData{
539-
Block: block,
540-
}); err != nil {
541-
return err
542-
}
543-
544-
return nil
545-
}

0 commit comments

Comments
 (0)