Skip to content

Commit 1c16d74

Browse files
committed
[FAB-10644] change integration/e2e to use nwo
Change-Id: I9b4f3e1f4f48a27d2940443ccfc27b5209eab9e5 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent c159910 commit 1c16d74

8 files changed

+304
-1183
lines changed

integration/e2e/acl_test.go

+212-167
Large diffs are not rendered by default.

integration/e2e/e2e_suite_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package e2e
99
import (
1010
"encoding/json"
1111

12-
"github.com/hyperledger/fabric/integration/world"
12+
"github.com/hyperledger/fabric/integration/nwo"
1313
. "github.com/onsi/ginkgo"
1414
. "github.com/onsi/gomega"
1515

@@ -21,10 +21,10 @@ func TestEndToEnd(t *testing.T) {
2121
RunSpecs(t, "EndToEnd Suite")
2222
}
2323

24-
var components *world.Components
24+
var components *nwo.Components
2525

2626
var _ = SynchronizedBeforeSuite(func() []byte {
27-
components = &world.Components{}
27+
components = &nwo.Components{}
2828
components.Build()
2929

3030
payload, err := json.Marshal(components)

integration/e2e/e2e_test.go

+89-76
Original file line numberDiff line numberDiff line change
@@ -9,126 +9,139 @@ package e2e
99
import (
1010
"io/ioutil"
1111
"os"
12-
"path/filepath"
12+
"syscall"
1313
"time"
1414

15+
docker "github.com/fsouza/go-dockerclient"
1516
. "github.com/onsi/ginkgo"
1617
. "github.com/onsi/gomega"
1718
"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"
2120
"github.com/tedsuo/ifrit"
21+
22+
"github.com/hyperledger/fabric/integration/nwo"
23+
"github.com/hyperledger/fabric/integration/nwo/commands"
2224
)
2325

2426
var _ = Describe("EndToEnd", func() {
2527
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
2933
)
3034

3135
BeforeEach(func() {
3236
var err error
3337
testDir, err = ioutil.TempDir("", "e2e")
3438
Expect(err).NotTo(HaveOccurred())
3539

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')`,
4749
}
4850
})
4951

5052
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()
5359
}
5460
os.RemoveAll(testDir)
5561
})
5662

5763
Describe("basic solo network with 2 orgs", func() {
5864
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())
6072
})
6173

6274
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")
8077

8178
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)
8383

84-
RunQueryInvokeQuery(w, deployment)
84+
By("getting the client peer by name")
85+
peer := network.Peer("Org1", "peer1")
86+
87+
RunQueryInvokeQuery(network, orderer, peer)
8588
})
8689
})
8790

8891
Describe("basic kaka network with 2 orgs", func() {
8992
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())
92100
})
93101

94102
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)
96109
})
97110
})
98111
})
99112

100-
func RunQueryInvokeQuery(w *world.World, deployment world.Deployment) {
113+
func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
101114
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"))
134147
}

integration/e2e/testdata/orderer.yaml

-77
This file was deleted.

0 commit comments

Comments
 (0)