forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocktransactor.go
56 lines (47 loc) · 1.99 KB
/
mocktransactor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
reqContex "context"
"net/http"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)
// MockTransactor provides an implementation of Transactor that exposes all its context.
type MockTransactor struct {
Ctx reqContex.Context
ChannelID string
Orderers []fab.Orderer
}
// CreateTransactionHeader creates a Transaction Header based on the current context.
func (t *MockTransactor) CreateTransactionHeader() (fab.TransactionHeader, error) {
return &MockTransactionHeader{}, nil
}
// SendTransactionProposal sends a TransactionProposal to the target peers.
func (t *MockTransactor) SendTransactionProposal(proposal *fab.TransactionProposal, targets []fab.ProposalProcessor) ([]*fab.TransactionProposalResponse, error) {
response := make([]*fab.TransactionProposalResponse, 1)
response[0] = &fab.TransactionProposalResponse{Endorser: "example.com", Status: 200,
ProposalResponse: &pb.ProposalResponse{Response: &pb.Response{Message: "success", Payload: []byte("abc"), Status: http.StatusOK},
Endorsement: &pb.Endorsement{Endorser: []byte("example.com"), Signature: []byte("signature")}},
}
return response, nil
}
// CreateTransaction create a transaction with proposal response.
func (t *MockTransactor) CreateTransaction(request fab.TransactionRequest) (*fab.Transaction, error) {
response := &fab.Transaction{
Proposal: &fab.TransactionProposal{
Proposal: &pb.Proposal{},
},
Transaction: &pb.Transaction{},
}
return response, nil
}
// SendTransaction send a transaction to the chain’s orderer service (one or more orderer endpoints) for consensus and committing to the ledger.
func (t *MockTransactor) SendTransaction(tx *fab.Transaction) (*fab.TransactionResponse, error) {
response := &fab.TransactionResponse{
Orderer: "example.com",
}
return response, nil
}