@@ -8,15 +8,11 @@ package e2e
8
8
9
9
import (
10
10
"fmt"
11
- "io/ioutil"
12
- "os"
13
11
"path/filepath"
14
12
"syscall"
15
13
"time"
16
14
17
15
docker "github.com/fsouza/go-dockerclient"
18
- "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
19
- "github.com/hyperledger/fabric/integration/runner"
20
16
"github.com/hyperledger/fabric/integration/world"
21
17
. "github.com/onsi/ginkgo"
22
18
. "github.com/onsi/gomega"
@@ -27,161 +23,15 @@ import (
27
23
28
24
var _ = Describe ("EndToEnd" , func () {
29
25
var (
30
- client * docker.Client
31
- network * docker.Network
32
- w world.World
26
+ client * docker.Client
27
+ w world.World
33
28
)
34
29
35
30
BeforeEach (func () {
36
31
var err error
37
32
38
33
client , err = docker .NewClientFromEnv ()
39
34
Expect (err ).NotTo (HaveOccurred ())
40
-
41
- pOrg := []* localconfig.Organization {{
42
- Name : "Org1" ,
43
- ID : "Org1MSP" ,
44
- MSPDir : "crypto/peerOrganizations/org1.example.com/msp" ,
45
- AnchorPeers : []* localconfig.AnchorPeer {{
46
- Host : "0.0.0.0" ,
47
- Port : 7051 ,
48
- }},
49
- }, {
50
- Name : "Org2" ,
51
- ID : "Org2MSP" ,
52
- MSPDir : "crypto/peerOrganizations/org2.example.com/msp" ,
53
- AnchorPeers : []* localconfig.AnchorPeer {{
54
- Host : "0.0.0.0" ,
55
- Port : 14051 ,
56
- }},
57
- }}
58
-
59
- ordererOrgs := world.OrdererConfig {
60
- OrganizationName : "OrdererOrg" ,
61
- Domain : "example.com" ,
62
- OrdererNames : []string {"orderer" },
63
- BrokerCount : 2 ,
64
- ZookeeperCount : 1 ,
65
- }
66
-
67
- peerOrgs := []world.PeerOrgConfig {{
68
- OrganizationName : pOrg [0 ].Name ,
69
- Domain : "org1.example.com" ,
70
- EnableNodeOUs : false ,
71
- UserCount : 1 ,
72
- PeerCount : 1 ,
73
- }, {
74
- OrganizationName : pOrg [1 ].Name ,
75
- Domain : "org2.example.com" ,
76
- EnableNodeOUs : false ,
77
- UserCount : 1 ,
78
- PeerCount : 1 ,
79
- }}
80
-
81
- oOrg := []* localconfig.Organization {{
82
- Name : ordererOrgs .OrganizationName ,
83
- ID : "OrdererMSP" ,
84
- MSPDir : filepath .Join ("crypto" , "ordererOrganizations" , "example.com" , "orderers" , "orderer.example.com" , "msp" ),
85
- }}
86
-
87
- deployment := world.Deployment {
88
- SystemChannel : "systestchannel" ,
89
- Channel : "testchannel" ,
90
- Chaincode : world.Chaincode {
91
- Name : "mycc" ,
92
- Version : "1.0" ,
93
- Path : "github.com/hyperledger/fabric/integration/chaincode/simple/cmd" ,
94
- ExecPath : os .Getenv ("PATH" ),
95
- },
96
- InitArgs : `{"Args":["init","a","100","b","200"]}` ,
97
- Peers : []string {"peer0.org1.example.com" , "peer0.org2.example.com" },
98
- Policy : `OR ('Org1MSP.member','Org2MSP.member')` ,
99
- Orderer : "127.0.0.1:7050" ,
100
- }
101
-
102
- peerProfile := localconfig.Profile {
103
- Consortium : "SampleConsortium" ,
104
- Application : & localconfig.Application {
105
- Organizations : pOrg ,
106
- Capabilities : map [string ]bool {
107
- "V1_2" : true ,
108
- },
109
- },
110
- Capabilities : map [string ]bool {
111
- "V1_1" : true ,
112
- },
113
- }
114
-
115
- orderer := & localconfig.Orderer {
116
- BatchTimeout : 1 * time .Second ,
117
- BatchSize : localconfig.BatchSize {
118
- MaxMessageCount : 1 ,
119
- AbsoluteMaxBytes : (uint32 )(98 * 1024 * 1024 ),
120
- PreferredMaxBytes : (uint32 )(512 * 1024 ),
121
- },
122
- Kafka : localconfig.Kafka {
123
- Brokers : []string {
124
- "127.0.0.1:9092" ,
125
- "127.0.0.1:8092" ,
126
- },
127
- },
128
- Organizations : oOrg ,
129
- OrdererType : "kafka" ,
130
- Addresses : []string {"0.0.0.0:7050" },
131
- Capabilities : map [string ]bool {
132
- "V1_1" : true ,
133
- },
134
- }
135
-
136
- ordererProfile := localconfig.Profile {
137
- Application : & localconfig.Application {
138
- Organizations : oOrg ,
139
- Capabilities : map [string ]bool {
140
- "V1_2" : true ,
141
- },
142
- },
143
- Orderer : orderer ,
144
- Consortiums : map [string ]* localconfig.Consortium {
145
- "SampleConsortium" : & localconfig.Consortium {
146
- Organizations : append (oOrg , pOrg ... ),
147
- },
148
- },
149
- Capabilities : map [string ]bool {
150
- "V1_1" : true ,
151
- },
152
- }
153
-
154
- profiles := map [string ]localconfig.Profile {
155
- "TwoOrgsOrdererGenesis" : ordererProfile ,
156
- "TwoOrgsChannel" : peerProfile ,
157
- }
158
-
159
- // Create a network
160
- network , err = client .CreateNetwork (
161
- docker.CreateNetworkOptions {
162
- Name : runner .UniqueName (),
163
- Driver : "bridge" ,
164
- },
165
- )
166
- Expect (err ).NotTo (HaveOccurred ())
167
-
168
- crypto := runner.Cryptogen {
169
- Config : filepath .Join (testDir , "crypto.yaml" ),
170
- Output : filepath .Join (testDir , "crypto" ),
171
- }
172
-
173
- w = world.World {
174
- Rootpath : testDir ,
175
- Components : components ,
176
- Cryptogen : crypto ,
177
- Network : network ,
178
- Deployment : deployment ,
179
- OrdererOrgs : []world.OrdererConfig {ordererOrgs },
180
- PeerOrgs : peerOrgs ,
181
- OrdererProfileName : "TwoOrgsOrdererGenesis" ,
182
- ChannelProfileName : "TwoOrgsChannel" ,
183
- Profiles : profiles ,
184
- }
185
35
})
186
36
187
37
AfterEach (func () {
@@ -220,15 +70,20 @@ var _ = Describe("EndToEnd", func() {
220
70
// Stop the orderers and peers
221
71
for _ , localProc := range w .LocalProcess {
222
72
localProc .Signal (syscall .SIGTERM )
73
+ Eventually (localProc .Wait (), 5 * time .Second ).Should (Receive ())
74
+ localProc .Signal (syscall .SIGKILL )
75
+ Eventually (localProc .Wait (), 5 * time .Second ).Should (Receive ())
223
76
}
224
77
225
78
// Remove any started networks
226
- if network != nil {
227
- client .RemoveNetwork (network .Name )
79
+ if w . Network != nil {
80
+ client .RemoveNetwork (w . Network .Name )
228
81
}
229
82
})
230
83
231
- It ("executes a basic kafka network with 2 orgs" , func () {
84
+ It ("executes a basic solo network with 2 orgs" , func () {
85
+ w = world .GenerateBasicConfig ("solo" , 1 , 2 , testDir , components )
86
+
232
87
By ("generating files to bootstrap the network" )
233
88
w .BootstrapNetwork ()
234
89
Expect (filepath .Join (testDir , "configtx.yaml" )).To (BeARegularFile ())
@@ -278,47 +133,27 @@ var _ = Describe("EndToEnd", func() {
278
133
execute (adminRunner )
279
134
Eventually (adminRunner .Err ()).Should (gbytes .Say ("Successfully submitted channel update" ))
280
135
})
281
- })
282
136
283
- func copyFile (src , dest string ) {
284
- data , err := ioutil .ReadFile (src )
285
- Expect (err ).NotTo (HaveOccurred ())
286
- err = ioutil .WriteFile (dest , data , 0775 )
287
- Expect (err ).NotTo (HaveOccurred ())
288
- }
137
+ It ("executes a basic kafka network with 2 orgs" , func () {
138
+ By ("generating files to bootstrap the network" )
139
+ w = world .GenerateBasicConfig ("kafka" , 2 , 2 , testDir , components )
140
+ setupWorld (& w )
289
141
290
- func copyDir (src , dest string ) {
291
- os .MkdirAll (dest , 0755 )
292
- objects , err := ioutil .ReadDir (src )
293
- for _ , obj := range objects {
294
- srcfileptr := src + "/" + obj .Name ()
295
- destfileptr := dest + "/" + obj .Name ()
296
- if obj .IsDir () {
297
- copyDir (srcfileptr , destfileptr )
298
- } else {
299
- copyFile (srcfileptr , destfileptr )
300
- }
301
- }
302
- Expect (err ).NotTo (HaveOccurred ())
303
- }
142
+ By ("querying the chaincode" )
143
+ adminPeer := components .Peer ()
144
+ adminPeer .LogLevel = "debug"
145
+ adminPeer .ConfigDir = filepath .Join (testDir , "org1.example.com_0" )
146
+ adminPeer .MSPConfigPath = filepath .Join (testDir , "crypto" , "peerOrganizations" , "org1.example.com" , "users" , "Admin@org1.example.com" , "msp" )
147
+ adminRunner := adminPeer .QueryChaincode (w .Deployment .Chaincode .Name , w .Deployment .Channel , `{"Args":["query","a"]}` )
148
+ execute (adminRunner )
149
+ Eventually (adminRunner .Buffer ()).Should (gbytes .Say ("100" ))
150
+
151
+ })
152
+ })
304
153
305
154
func execute (r ifrit.Runner ) (err error ) {
306
155
p := ifrit .Invoke (r )
307
156
Eventually (p .Ready ()).Should (BeClosed ())
308
157
Eventually (p .Wait (), 30 * time .Second ).Should (Receive (& err ))
309
158
return err
310
159
}
311
-
312
- func copyPeerConfigs (peerOrgs []world.PeerOrgConfig , rootPath string ) {
313
- for _ , peerOrg := range peerOrgs {
314
- for peer := 0 ; peer < peerOrg .PeerCount ; peer ++ {
315
- peerDir := fmt .Sprintf ("%s_%d" , peerOrg .Domain , peer )
316
- if _ , err := os .Stat (filepath .Join (rootPath , peerDir )); os .IsNotExist (err ) {
317
- err := os .Mkdir (filepath .Join (rootPath , peerDir ), 0755 )
318
- Expect (err ).NotTo (HaveOccurred ())
319
- }
320
- copyFile (filepath .Join ("testdata" , fmt .Sprintf ("%s-core.yaml" , peerDir )),
321
- filepath .Join (rootPath , peerDir , "core.yaml" ))
322
- }
323
- }
324
- }
0 commit comments