@@ -9,126 +9,139 @@ package e2e
9
9
import (
10
10
"io/ioutil"
11
11
"os"
12
- "path/filepath "
12
+ "syscall "
13
13
"time"
14
14
15
+ docker "github.com/fsouza/go-dockerclient"
15
16
. "github.com/onsi/ginkgo"
16
17
. "github.com/onsi/gomega"
17
18
"github.com/onsi/gomega/gbytes"
18
-
19
- "github.com/hyperledger/fabric/integration/helpers"
20
- "github.com/hyperledger/fabric/integration/world"
19
+ "github.com/onsi/gomega/gexec"
21
20
"github.com/tedsuo/ifrit"
21
+
22
+ "github.com/hyperledger/fabric/integration/nwo"
23
+ "github.com/hyperledger/fabric/integration/nwo/commands"
22
24
)
23
25
24
26
var _ = Describe ("EndToEnd" , func () {
25
27
var (
26
- testDir string
27
- w * world.World
28
- deployment world.Deployment
28
+ testDir string
29
+ client * docker.Client
30
+ network * nwo.Network
31
+ chaincode nwo.Chaincode
32
+ process ifrit.Process
29
33
)
30
34
31
35
BeforeEach (func () {
32
36
var err error
33
37
testDir , err = ioutil .TempDir ("" , "e2e" )
34
38
Expect (err ).NotTo (HaveOccurred ())
35
39
36
- deployment = world.Deployment {
37
- Channel : "testchannel" ,
38
- Chaincode : world.Chaincode {
39
- Name : "mycc" ,
40
- Version : "0.0" ,
41
- Path : "github.com/hyperledger/fabric/integration/chaincode/simple/cmd" ,
42
- ExecPath : os .Getenv ("PATH" ),
43
- },
44
- InitArgs : `{"Args":["init","a","100","b","200"]}` ,
45
- Policy : `AND ('Org1MSP.member','Org2MSP.member')` ,
46
- Orderer : "127.0.0.1:7050" ,
40
+ client , err = docker .NewClientFromEnv ()
41
+ Expect (err ).NotTo (HaveOccurred ())
42
+
43
+ chaincode = nwo.Chaincode {
44
+ Name : "mycc" ,
45
+ Version : "0.0" ,
46
+ Path : "github.com/hyperledger/fabric/integration/chaincode/simple/cmd" ,
47
+ Ctor : `{"Args":["init","a","100","b","200"]}` ,
48
+ Policy : `AND ('Org1MSP.member','Org2MSP.member')` ,
47
49
}
48
50
})
49
51
50
52
AfterEach (func () {
51
- if w != nil {
52
- w .Close (deployment )
53
+ if process != nil {
54
+ process .Signal (syscall .SIGTERM )
55
+ Eventually (process .Wait (), time .Minute ).Should (Receive ())
56
+ }
57
+ if network != nil {
58
+ network .Cleanup ()
53
59
}
54
60
os .RemoveAll (testDir )
55
61
})
56
62
57
63
Describe ("basic solo network with 2 orgs" , func () {
58
64
BeforeEach (func () {
59
- w = world .GenerateBasicConfig ("solo" , 1 , 2 , testDir , components )
65
+ network = nwo .New (nwo .BasicSolo (), testDir , client , 30000 , components )
66
+ network .GenerateConfigTree ()
67
+ network .Bootstrap ()
68
+
69
+ networkRunner := network .NetworkGroupRunner ()
70
+ process = ifrit .Invoke (networkRunner )
71
+ Eventually (process .Ready ()).Should (BeClosed ())
60
72
})
61
73
62
74
It ("executes a basic solo network with 2 orgs" , func () {
63
- By ("generating files to bootstrap the network" )
64
- w .BootstrapNetwork (deployment .Channel )
65
- Expect (filepath .Join (testDir , "configtx.yaml" )).To (BeARegularFile ())
66
- Expect (filepath .Join (testDir , "crypto.yaml" )).To (BeARegularFile ())
67
- Expect (filepath .Join (testDir , "crypto" , "peerOrganizations" )).To (BeADirectory ())
68
- Expect (filepath .Join (testDir , "crypto" , "ordererOrganizations" )).To (BeADirectory ())
69
- Expect (filepath .Join (testDir , "systestchannel_block.pb" )).To (BeARegularFile ())
70
- Expect (filepath .Join (testDir , "testchannel_tx.pb" )).To (BeARegularFile ())
71
- Expect (filepath .Join (testDir , "Org1_anchors_update_tx.pb" )).To (BeARegularFile ())
72
- Expect (filepath .Join (testDir , "Org2_anchors_update_tx.pb" )).To (BeARegularFile ())
73
-
74
- By ("setting up directories for the network" )
75
- helpers .CopyFile (filepath .Join ("testdata" , "orderer.yaml" ), filepath .Join (testDir , "orderer.yaml" ))
76
- w .CopyPeerConfigs ("testdata" )
77
-
78
- By ("building the network" )
79
- w .BuildNetwork ()
75
+ By ("getting the orderer by name" )
76
+ orderer := network .Orderer ("orderer" )
80
77
81
78
By ("setting up the channel" )
82
- w .SetupChannel (deployment , w .PeerIDs ())
79
+ network .CreateAndJoinChannel (orderer , "testchannel" )
80
+
81
+ By ("deploying the chaincode" )
82
+ nwo .DeployChaincode (network , "testchannel" , orderer , chaincode )
83
83
84
- RunQueryInvokeQuery (w , deployment )
84
+ By ("getting the client peer by name" )
85
+ peer := network .Peer ("Org1" , "peer1" )
86
+
87
+ RunQueryInvokeQuery (network , orderer , peer )
85
88
})
86
89
})
87
90
88
91
Describe ("basic kaka network with 2 orgs" , func () {
89
92
BeforeEach (func () {
90
- w = world .GenerateBasicConfig ("kafka" , 2 , 2 , testDir , components )
91
- w .SetupWorld (deployment )
93
+ network = nwo .New (nwo .BasicKafka (), testDir , client , 31000 , components )
94
+ network .GenerateConfigTree ()
95
+ network .Bootstrap ()
96
+
97
+ networkRunner := network .NetworkGroupRunner ()
98
+ process = ifrit .Invoke (networkRunner )
99
+ Eventually (process .Ready ()).Should (BeClosed ())
92
100
})
93
101
94
102
It ("executes a basic kafka network with 2 orgs" , func () {
95
- RunQueryInvokeQuery (w , deployment )
103
+ orderer := network .Orderer ("orderer" )
104
+ peer := network .Peer ("Org1" , "peer1" )
105
+
106
+ network .CreateAndJoinChannel (orderer , "testchannel" )
107
+ nwo .DeployChaincode (network , "testchannel" , orderer , chaincode )
108
+ RunQueryInvokeQuery (network , orderer , peer )
96
109
})
97
110
})
98
111
})
99
112
100
- func RunQueryInvokeQuery (w * world. World , deployment world. Deployment ) {
113
+ func RunQueryInvokeQuery (n * nwo. Network , orderer * nwo. Orderer , peer * nwo. Peer ) {
101
114
By ("querying the chaincode" )
102
- adminPeer := components . Peer ()
103
- adminPeer . LogLevel = "debug"
104
- adminPeer . ConfigDir = filepath . Join ( w . Rootpath , "peer0.org1.example.com" )
105
- adminPeer . MSPConfigPath = filepath . Join ( w . Rootpath , "crypto" , "peerOrganizations" , "org1.example.com" , "users" , "Admin@org1.example.com" , "msp" )
106
- adminRunner := adminPeer . QueryChaincode ( deployment . Chaincode . Name , deployment . Channel , `{"Args":["query","a"]}` )
107
- execute ( adminRunner )
108
- Eventually (adminRunner . Buffer ()) .Should (gbytes . Say ( "100" ))
109
-
110
- By ( "invoking the chaincode" )
111
- adminRunner = adminPeer . InvokeChaincode (
112
- deployment . Chaincode . Name ,
113
- deployment . Channel ,
114
- `{"Args":["invoke","a","b","10"]}` ,
115
- deployment . Orderer ,
116
- "--waitForEvent" ,
117
- "--peerAddresses " , "127.0.0.1:7051" ,
118
- "--peerAddresses " , "127.0.0.1:8051" ,
119
- )
120
- execute ( adminRunner )
121
- Eventually ( adminRunner . Err ()). Should ( gbytes . Say ( "Chaincode invoke successful. result: status:200" ) )
122
-
123
- By ( "querying the chaincode again" )
124
- adminRunner = adminPeer . QueryChaincode ( deployment . Chaincode . Name , deployment . Channel , `{"Args":["query","a"]}` )
125
- execute ( adminRunner )
126
- Eventually ( adminRunner . Buffer ()). Should ( gbytes . Say ( "90" ))
127
- }
128
-
129
- func execute ( r ifrit. Runner ) ( err error ) {
130
- p := ifrit . Invoke ( r )
131
- Eventually ( p . Ready ()). Should ( BeClosed ())
132
- Eventually (p . Wait (), 30 * time .Second ).Should (Receive ( & err ))
133
- return err
115
+ sess , err := n . PeerUserSession ( peer , "User1" , commands. ChaincodeQuery {
116
+ ChannelID : "testchannel" ,
117
+ Name : "mycc" ,
118
+ Ctor : `{"Args":["query","a"]}` ,
119
+ } )
120
+ Expect ( err ). NotTo ( HaveOccurred () )
121
+ Eventually (sess , time . Minute ) .Should (gexec . Exit ( 0 ))
122
+ Expect ( sess ). To ( gbytes . Say ( "100" ))
123
+
124
+ sess , err = n . PeerUserSession ( peer , "User1" , commands. ChaincodeInvoke {
125
+ ChannelID : "testchannel" ,
126
+ Orderer : n . OrdererAddress ( orderer , nwo . ListenPort ) ,
127
+ Name : "mycc" ,
128
+ Ctor : `{"Args":["invoke","a","b","10"]}` ,
129
+ PeerAddresses : [] string {
130
+ n . PeerAddress ( n . Peer ( "Org1 " , "peer0" ), nwo . ListenPort ) ,
131
+ n . PeerAddress ( n . Peer ( "Org2 " , "peer1" ), nwo . ListenPort ) ,
132
+ },
133
+ WaitForEvent : true ,
134
+ } )
135
+ Expect ( err ). NotTo ( HaveOccurred ())
136
+ Eventually ( sess , time . Minute ). Should ( gexec . Exit ( 0 ) )
137
+ Expect ( sess . Err ). To ( gbytes . Say ( " Chaincode invoke successful. result: status:200" ) )
138
+
139
+ sess , err = n . PeerUserSession ( peer , "User1" , commands. ChaincodeQuery {
140
+ ChannelID : "testchannel" ,
141
+ Name : "mycc" ,
142
+ Ctor : `{"Args":["query","a"]}` ,
143
+ } )
144
+ Expect ( err ). NotTo ( HaveOccurred ())
145
+ Eventually (sess , time .Minute ).Should (gexec . Exit ( 0 ))
146
+ Expect ( sess ). To ( gbytes . Say ( "90" ))
134
147
}
0 commit comments