@@ -8,6 +8,8 @@ package e2e
8
8
9
9
import (
10
10
"fmt"
11
+ "io/ioutil"
12
+ "os"
11
13
"path/filepath"
12
14
"syscall"
13
15
"time"
@@ -23,8 +25,9 @@ import (
23
25
24
26
var _ = Describe ("EndToEnd" , func () {
25
27
var (
26
- client * docker.Client
27
- w world.World
28
+ client * docker.Client
29
+ w world.World
30
+ deployment world.Deployment
28
31
)
29
32
30
33
BeforeEach (func () {
@@ -42,7 +45,7 @@ var _ = Describe("EndToEnd", func() {
42
45
43
46
// Stop the running chaincode containers
44
47
filters := map [string ][]string {}
45
- filters ["name" ] = []string {fmt .Sprintf ("%s-%s" , w . Deployment . Chaincode .Name , w . Deployment .Chaincode .Version )}
48
+ filters ["name" ] = []string {fmt .Sprintf ("%s-%s" , deployment . Chaincode .Name , deployment .Chaincode .Version )}
46
49
allContainers , _ := client .ListContainers (docker.ListContainersOptions {
47
50
Filters : filters ,
48
51
})
@@ -57,7 +60,7 @@ var _ = Describe("EndToEnd", func() {
57
60
58
61
// Remove chaincode image
59
62
filters = map [string ][]string {}
60
- filters ["label" ] = []string {fmt .Sprintf ("org.hyperledger.fabric.chaincode.id.name=%s" , w . Deployment .Chaincode .Name )}
63
+ filters ["label" ] = []string {fmt .Sprintf ("org.hyperledger.fabric.chaincode.id.name=%s" , deployment .Chaincode .Name )}
61
64
images , _ := client .ListImages (docker.ListImagesOptions {
62
65
Filters : filters ,
63
66
})
@@ -84,8 +87,21 @@ var _ = Describe("EndToEnd", func() {
84
87
It ("executes a basic solo network with 2 orgs" , func () {
85
88
w = world .GenerateBasicConfig ("solo" , 1 , 2 , testDir , components )
86
89
90
+ deployment = world.Deployment {
91
+ Channel : "testchannel" ,
92
+ Chaincode : world.Chaincode {
93
+ Name : "mycc" ,
94
+ Version : "0.0" ,
95
+ Path : filepath .Join ("github.com" , "hyperledger" , "fabric" , "integration" , "chaincode" , "simple" , "cmd" ),
96
+ ExecPath : os .Getenv ("PATH" ),
97
+ },
98
+ InitArgs : `{"Args":["init","a","100","b","200"]}` ,
99
+ Policy : `OR ('Org1MSP.member','Org2MSP.member')` ,
100
+ Orderer : "127.0.0.1:7050" ,
101
+ }
102
+
87
103
By ("generating files to bootstrap the network" )
88
- w .BootstrapNetwork ()
104
+ w .BootstrapNetwork (deployment . Channel )
89
105
Expect (filepath .Join (testDir , "configtx.yaml" )).To (BeARegularFile ())
90
106
Expect (filepath .Join (testDir , "crypto.yaml" )).To (BeARegularFile ())
91
107
Expect (filepath .Join (testDir , "crypto" , "peerOrganizations" )).To (BeADirectory ())
@@ -103,48 +119,65 @@ var _ = Describe("EndToEnd", func() {
103
119
w .BuildNetwork ()
104
120
105
121
By ("setting up the channel" )
106
- err := w .SetupChannel ()
122
+ peers := []string {
123
+ "peer0.org1.example.com" ,
124
+ "peer0.org2.example.com" ,
125
+ }
126
+ err := w .SetupChannel (deployment , peers )
107
127
Expect (err ).NotTo (HaveOccurred ())
108
128
109
129
By ("querying the chaincode" )
110
130
adminPeer := components .Peer ()
111
131
adminPeer .LogLevel = "debug"
112
- adminPeer .ConfigDir = filepath .Join (testDir , "org1.example.com_0 " )
132
+ adminPeer .ConfigDir = filepath .Join (testDir , "peer0. org1.example.com " )
113
133
adminPeer .MSPConfigPath = filepath .Join (testDir , "crypto" , "peerOrganizations" , "org1.example.com" , "users" , "Admin@org1.example.com" , "msp" )
114
- adminRunner := adminPeer .QueryChaincode (w . Deployment . Chaincode .Name , w . Deployment .Channel , `{"Args":["query","a"]}` )
134
+ adminRunner := adminPeer .QueryChaincode (deployment . Chaincode .Name , deployment .Channel , `{"Args":["query","a"]}` )
115
135
execute (adminRunner )
116
136
Eventually (adminRunner .Buffer ()).Should (gbytes .Say ("100" ))
117
137
118
138
By ("invoking the chaincode" )
119
- adminRunner = adminPeer .InvokeChaincode (w . Deployment . Chaincode .Name , w . Deployment . Channel , `{"Args":["invoke","a","b","10"]}` , w . Deployment .Orderer )
139
+ adminRunner = adminPeer .InvokeChaincode (deployment . Chaincode .Name , deployment . Channel , `{"Args":["invoke","a","b","10"]}` , deployment .Orderer )
120
140
execute (adminRunner )
121
141
Eventually (adminRunner .Err ()).Should (gbytes .Say ("Chaincode invoke successful. result: status:200" ))
122
142
123
143
By ("querying the chaincode again" )
124
- adminRunner = adminPeer .QueryChaincode (w . Deployment . Chaincode .Name , w . Deployment .Channel , `{"Args":["query","a"]}` )
144
+ adminRunner = adminPeer .QueryChaincode (deployment . Chaincode .Name , deployment .Channel , `{"Args":["query","a"]}` )
125
145
execute (adminRunner )
126
146
Eventually (adminRunner .Buffer ()).Should (gbytes .Say ("90" ))
127
147
128
148
By ("updating the channel" )
129
149
adminPeer = components .Peer ()
130
- adminPeer .ConfigDir = filepath .Join (testDir , "org1.example.com_0 " )
150
+ adminPeer .ConfigDir = filepath .Join (testDir , "peer0. org1.example.com " )
131
151
adminPeer .MSPConfigPath = filepath .Join (testDir , "crypto" , "peerOrganizations" , "org1.example.com" , "users" , "Admin@org1.example.com" , "msp" )
132
- adminRunner = adminPeer .UpdateChannel (filepath .Join (testDir , "Org1_anchors_update_tx.pb" ), w . Deployment . Channel , w . Deployment .Orderer )
152
+ adminRunner = adminPeer .UpdateChannel (filepath .Join (testDir , "Org1_anchors_update_tx.pb" ), deployment . Channel , deployment .Orderer )
133
153
execute (adminRunner )
134
154
Eventually (adminRunner .Err ()).Should (gbytes .Say ("Successfully submitted channel update" ))
135
155
})
136
156
137
157
It ("executes a basic kafka network with 2 orgs" , func () {
138
158
By ("generating files to bootstrap the network" )
139
159
w = world .GenerateBasicConfig ("kafka" , 2 , 2 , testDir , components )
140
- setupWorld (& w )
160
+ deployment = world.Deployment {
161
+ Channel : "testchannel" ,
162
+ Chaincode : world.Chaincode {
163
+ Name : "mycc" ,
164
+ Version : "0.0" ,
165
+ Path : filepath .Join ("github.com" , "hyperledger" , "fabric" , "integration" , "chaincode" , "simple" , "cmd" ),
166
+ ExecPath : os .Getenv ("PATH" ),
167
+ },
168
+ InitArgs : `{"Args":["init","a","100","b","200"]}` ,
169
+ Policy : `AND ('Org1MSP.member','Org2MSP.member')` ,
170
+ Orderer : "127.0.0.1:7050" ,
171
+ }
172
+
173
+ w .SetupWorld (deployment )
141
174
142
175
By ("querying the chaincode" )
143
176
adminPeer := components .Peer ()
144
177
adminPeer .LogLevel = "debug"
145
- adminPeer .ConfigDir = filepath .Join (testDir , "org1.example.com_0 " )
178
+ adminPeer .ConfigDir = filepath .Join (testDir , "peer0. org1.example.com " )
146
179
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"]}` )
180
+ adminRunner := adminPeer .QueryChaincode (deployment . Chaincode .Name , deployment .Channel , `{"Args":["query","a"]}` )
148
181
execute (adminRunner )
149
182
Eventually (adminRunner .Buffer ()).Should (gbytes .Say ("100" ))
150
183
@@ -157,3 +190,26 @@ func execute(r ifrit.Runner) (err error) {
157
190
Eventually (p .Wait (), 30 * time .Second ).Should (Receive (& err ))
158
191
return err
159
192
}
193
+
194
+ func copyFile (src , dest string ) {
195
+ data , err := ioutil .ReadFile (src )
196
+ Expect (err ).NotTo (HaveOccurred ())
197
+ err = ioutil .WriteFile (dest , data , 0775 )
198
+ Expect (err ).NotTo (HaveOccurred ())
199
+ }
200
+
201
+ func copyPeerConfigs (peerOrgs []world.PeerOrgConfig , rootPath string ) {
202
+ for _ , peerOrg := range peerOrgs {
203
+ for peer := 0 ; peer < peerOrg .PeerCount ; peer ++ {
204
+ peerDir := fmt .Sprintf ("peer%d.%s" , peer , peerOrg .Domain )
205
+ if _ , err := os .Stat (filepath .Join (rootPath , peerDir )); os .IsNotExist (err ) {
206
+ err := os .Mkdir (filepath .Join (rootPath , peerDir ), 0755 )
207
+ Expect (err ).NotTo (HaveOccurred ())
208
+ }
209
+ copyFile (
210
+ filepath .Join ("testdata" , fmt .Sprintf ("%s_%d-core.yaml" , peerOrg .Domain , peer )),
211
+ filepath .Join (rootPath , peerDir , "core.yaml" ),
212
+ )
213
+ }
214
+ }
215
+ }
0 commit comments