Skip to content

Commit

Permalink
[FAB-16169] clean up tests
Browse files Browse the repository at this point in the history
Change-Id: Ie3077e891fe6e3268a7f9025794fcc15103e3edf
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Nov 19, 2019
1 parent 8a70b67 commit 3107016
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 217 deletions.
86 changes: 86 additions & 0 deletions core/tx/endorser/endorsertx_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"math/rand"
"testing"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
txpkg "github.com/hyperledger/fabric/pkg/tx"
"github.com/hyperledger/fabric/protoutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -23,6 +27,88 @@ func randomLowerAlphaString(size int) string {
return string(output)
}

func genTxEnvelope(
hdrExt []byte,
payloadData []byte,
prpExt []byte,
prp []byte,
chHeader *common.ChannelHeader,
sigHeader *common.SignatureHeader,
) *txpkg.Envelope {
var hdrExtBytes []byte
if hdrExt != nil {
hdrExtBytes = hdrExt
} else {
hdrExtBytes = protoutil.MarshalOrPanic(
&peer.ChaincodeHeaderExtension{
ChaincodeId: &peer.ChaincodeID{
Name: "my-called-cc",
},
},
)
}

chHeader.Extension = hdrExtBytes

var extBytes []byte
if prpExt != nil {
extBytes = prpExt
} else {
extBytes = protoutil.MarshalOrPanic(&peer.ChaincodeAction{
Results: []byte("results"),
Response: &peer.Response{
Status: 200,
},
Events: []byte("events"),
})
}

var prpBytes []byte
if prp != nil {
prpBytes = prp
} else {
prpBytes = protoutil.MarshalOrPanic(&peer.ProposalResponsePayload{
Extension: extBytes,
ProposalHash: []byte("phash"),
})
}

ccEndAct := &peer.ChaincodeEndorsedAction{
ProposalResponsePayload: prpBytes,
Endorsements: []*peer.Endorsement{
{
Endorser: []byte("endorser"),
Signature: []byte("signature"),
},
},
}

ccActP := &peer.ChaincodeActionPayload{
Action: ccEndAct,
}

tx := &peer.Transaction{
Actions: []*peer.TransactionAction{
{
Payload: protoutil.MarshalOrPanic(ccActP),
},
},
}

var txenvPayloadDataBytes []byte
if payloadData != nil {
txenvPayloadDataBytes = payloadData
} else {
txenvPayloadDataBytes = protoutil.MarshalOrPanic(tx)
}

return &txpkg.Envelope{
ChannelHeader: chHeader,
SignatureHeader: sigHeader,
Data: txenvPayloadDataBytes,
}
}

func TestEndorserTx(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "EndorserTx Suite")
Expand Down
Loading

0 comments on commit 3107016

Please sign in to comment.