This repository has been archived by the owner on Nov 29, 2019. It is now read-only.
/
utils.go
160 lines (140 loc) · 3.62 KB
/
utils.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package helpers
import (
"fmt"
"net"
"github.com/hyperledger/fabric/integration/nwo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/hyperledger/fabric-chaincode-evm/fab3/types"
)
type JsonRPCRequest struct {
JsonRPC string `json:"jsonrpc"`
ID int `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
type JsonRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data"`
}
type JsonRPCResponse struct {
JsonRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result string `json:"result,omitempty"`
Error JsonRPCError `json:"error,omitempty"`
}
type JsonRPCArrayResponse struct {
JsonRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result []string `json:"result,omitempty"`
Error JsonRPCError `json:"error,omitempty"`
}
type JsonRPCLogArrayResponse struct {
JsonRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result []types.Log `json:"result,omitempty"`
Error JsonRPCError `json:"error,omitempty"`
}
type JsonRPCTxReceipt struct {
JsonRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result types.TxReceipt `json:"result"`
Error JsonRPCError `json:"error,omitempty"`
}
type MessageParams struct {
To string `json:"to"`
From string `json:"from,omitempty"`
Data string `json:"data,omitempty"`
}
type ChaincodeQueryWithHex struct {
ChannelID string
Name string
Ctor string
}
func (c ChaincodeQueryWithHex) SessionName() string {
return "peer-chaincode-query"
}
func (c ChaincodeQueryWithHex) Args() []string {
return []string{
"chaincode", "query",
"--channelID", c.ChannelID,
"--name", c.Name,
"--ctor", c.Ctor,
"--hex",
}
}
func Build() *nwo.Components {
components := &nwo.Components{}
components.Build()
proxyBinPath, err := gexec.Build("github.com/hyperledger/fabric-chaincode-evm/fab3/cmd")
Expect(err).ToNot(HaveOccurred())
components.Paths["fab3"] = proxyBinPath
return components
}
func SimpleSoloNetwork() *nwo.Config {
return &nwo.Config{
Organizations: []*nwo.Organization{{
Name: "OrdererOrg",
MSPID: "OrdererMSP",
Domain: "example.com",
EnableNodeOUs: false,
Users: 0,
CA: &nwo.CA{Hostname: "ca"},
}, {
Name: "Org1",
MSPID: "Org1MSP",
Domain: "org1.example.com",
EnableNodeOUs: true,
Users: 2,
CA: &nwo.CA{Hostname: "ca"},
}},
Consortiums: []*nwo.Consortium{{
Name: "SampleConsortium",
Organizations: []string{
"Org1",
},
}},
Consensus: &nwo.Consensus{
Type: "solo",
},
SystemChannel: &nwo.SystemChannel{
Name: "systemchannel",
Profile: "OneOrgOrdererGenesis",
},
Orderers: []*nwo.Orderer{
{Name: "orderer", Organization: "OrdererOrg"},
},
Channels: []*nwo.Channel{
{Name: "testchannel", Profile: "OneOrgChannel"},
},
Peers: []*nwo.Peer{{
Name: "peer0",
Organization: "Org1",
Channels: []*nwo.PeerChannel{
{Name: "testchannel", Anchor: true},
},
}},
Profiles: []*nwo.Profile{{
Name: "OneOrgOrdererGenesis",
Orderers: []string{"orderer"},
}, {
Name: "OneOrgChannel",
Consortium: "SampleConsortium",
Organizations: []string{"Org1"},
}},
}
}
func WaitForFab3(port uint16) {
Eventually(func() error {
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
if err == nil {
defer conn.Close()
}
return err
}).Should(Succeed())
}