Skip to content

Commit

Permalink
[FAB-6767] mock utils for SDK go
Browse files Browse the repository at this point in the history
- Added mock util in mockdata for
create mock block with CCEvent and TxStatus

Change-Id: Ibbf7f4bbb456cb980dd6ca7e32b05cf5cb99ec00
Signed-off-by: Sudesh Shetty <[email protected]>
  • Loading branch information
sudeshrshetty committed Oct 31, 2017
1 parent e3ec402 commit 25ef379
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/fabric-client/mocks/mockdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ func marshalOrPanic(pb proto.Message) []byte {
// CreateBlockWithCCEvent creates a mock block
func CreateBlockWithCCEvent(events *pp.ChaincodeEvent, txID string,
channelID string) (*common.Block, error) {
return CreateBlockWithCCEventAndTxStatus(events, txID, channelID, pp.TxValidationCode_VALID)
}

// CreateBlockWithCCEventAndTxStatus creates a mock block with the given CC event and TX validation code
func CreateBlockWithCCEventAndTxStatus(events *pp.ChaincodeEvent, txID string,
channelID string, txValidationCode pp.TxValidationCode) (*common.Block, error) {
chdr := &common.ChannelHeader{
Type: int32(common.HeaderType_ENDORSER_TRANSACTION),
Version: 1,
Expand Down Expand Up @@ -522,6 +528,9 @@ func CreateBlockWithCCEvent(events *pp.ChaincodeEvent, txID string,
block.Header.DataHash = cutil.ComputeSHA256(blockbytes)

txsfltr := ledger_util.NewTxValidationFlags(len(block.Data.Data))
for i := 0; i < len(block.Data.Data); i++ {
txsfltr[i] = uint8(txValidationCode)
}

block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER] = txsfltr

Expand Down

0 comments on commit 25ef379

Please sign in to comment.