github.com/anjalikarhana/fabric@v2.1.1+incompatible/integration/raft/raft_suite_test.go (about) 1 /* 2 Copyright IBM Corp All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package raft 8 9 import ( 10 "encoding/json" 11 "fmt" 12 "testing" 13 14 "github.com/hyperledger/fabric/integration" 15 "github.com/hyperledger/fabric/integration/nwo" 16 "github.com/hyperledger/fabric/integration/nwo/commands" 17 . "github.com/onsi/ginkgo" 18 . "github.com/onsi/gomega" 19 "github.com/onsi/gomega/gbytes" 20 "github.com/onsi/gomega/gexec" 21 ) 22 23 func TestRaft(t *testing.T) { 24 RegisterFailHandler(Fail) 25 RunSpecs(t, "Raft-based Ordering Service Suite") 26 } 27 28 var ( 29 buildServer *nwo.BuildServer 30 components *nwo.Components 31 ) 32 33 var _ = SynchronizedBeforeSuite(func() []byte { 34 buildServer = nwo.NewBuildServer() 35 buildServer.Serve() 36 37 components = buildServer.Components() 38 payload, err := json.Marshal(components) 39 Expect(err).NotTo(HaveOccurred()) 40 41 return payload 42 }, func(payload []byte) { 43 err := json.Unmarshal(payload, &components) 44 Expect(err).NotTo(HaveOccurred()) 45 }) 46 47 var _ = SynchronizedAfterSuite(func() { 48 }, func() { 49 buildServer.Shutdown() 50 }) 51 52 func StartPort() int { 53 return integration.RaftBasePort.StartPortForNode() 54 } 55 56 func RunInvoke(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string) { 57 By("Querying chaincode") 58 sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ 59 ChannelID: channel, 60 Orderer: n.OrdererAddress(orderer, nwo.ListenPort), 61 Name: "mycc", 62 Ctor: `{"Args":["invoke","a","b","10"]}`, 63 PeerAddresses: []string{ 64 n.PeerAddress(n.Peer("Org1", "peer0"), nwo.ListenPort), 65 n.PeerAddress(n.Peer("Org2", "peer0"), nwo.ListenPort), 66 }, 67 WaitForEvent: true, 68 }) 69 Expect(err).NotTo(HaveOccurred()) 70 Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) 71 Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) 72 } 73 74 func RunQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string) int { 75 By("Invoking chaincode") 76 sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{ 77 ChannelID: channel, 78 Name: "mycc", 79 Ctor: `{"Args":["query","a"]}`, 80 }) 81 Expect(err).NotTo(HaveOccurred()) 82 Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) 83 84 var result int 85 i, err := fmt.Sscanf(string(sess.Out.Contents()), "%d", &result) 86 Expect(err).NotTo(HaveOccurred()) 87 Expect(i).To(Equal(1)) 88 return int(result) 89 }