Skip to content

Commit

Permalink
[FAB-12377] Multinode etcd/raft integration test
Browse files Browse the repository at this point in the history
This CR adds the integration test for a three node etcd/raft orderer.

Change-Id: I67f476c4f9ee3604c35f624f40734989ec88a917
Signed-off-by: Adarsh Saraf <adarshsaraf123@gmail.com>
  • Loading branch information
adarshsaraf123 committed Oct 16, 2018
1 parent 5a51534 commit 8619c8c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
14 changes: 7 additions & 7 deletions integration/e2e/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = Describe("EndToEndACL", func() {
By("setting the filtered block event ACL policy to Org1/Admins")
policyName := resources.Event_FilteredBlock
policy := "/Channel/Application/Org1/Admins"
SetACLPolicy(network, "testchannel", policyName, policy)
SetACLPolicy(network, "testchannel", policyName, policy, "orderer")

By("invoking chaincode as a permitted Org1 Admin identity")
sess, err := network.PeerAdminSession(org1Peer0, invokeChaincode)
Expand All @@ -123,7 +123,7 @@ var _ = Describe("EndToEndACL", func() {
By("setting the filtered block event ACL policy to org2/Admins")
policyName = resources.Event_FilteredBlock
policy = "/Channel/Application/org2/Admins"
SetACLPolicy(network, "testchannel", policyName, policy)
SetACLPolicy(network, "testchannel", policyName, policy, "orderer")

By("invoking chaincode as a forbidden Org1 Admin identity")
sess, err = network.PeerAdminSession(org1Peer0, invokeChaincode)
Expand All @@ -136,7 +136,7 @@ var _ = Describe("EndToEndACL", func() {
By("setting the block event ACL policy to Org1/Admins")
policyName = resources.Event_Block
policy = "/Channel/Application/Org1/Admins"
SetACLPolicy(network, "testchannel", policyName, policy)
SetACLPolicy(network, "testchannel", policyName, policy, "orderer")

By("fetching the latest block from the peer as a permitted Org1 Admin identity")
sess, err = network.PeerAdminSession(org1Peer0, fetchNewest)
Expand All @@ -159,7 +159,7 @@ var _ = Describe("EndToEndACL", func() {
By("setting the lscc/GetInstantiatedChaincodes ACL policy to Org1/Admins")
policyName = resources.Lscc_GetInstantiatedChaincodes
policy = "/Channel/Application/Org1/Admins"
SetACLPolicy(network, "testchannel", policyName, policy)
SetACLPolicy(network, "testchannel", policyName, policy, "orderer")

By("listing the instantiated chaincodes as a permitted Org1 Admin identity")
sess, err = network.PeerAdminSession(org1Peer0, commands.ChaincodeListInstantiated{
Expand Down Expand Up @@ -196,7 +196,7 @@ var _ = Describe("EndToEndACL", func() {
policyName := fmt.Sprintf("%s/%s", scc, operation)
policy := "/Channel/Application/Org1/Admins"
By("setting " + policyName + " to Org1 Admins")
SetACLPolicy(network, "testchannel", policyName, policy)
SetACLPolicy(network, "testchannel", policyName, policy, "orderer")

args = append([]string{operation}, args...)
chaincodeQuery := commands.ChaincodeQuery{
Expand Down Expand Up @@ -243,8 +243,8 @@ var _ = Describe("EndToEndACL", func() {
// previously defined ACL policies, generates the config update, signs the
// configuration with Org2's signer, and then submits the config update using
// Org1.
func SetACLPolicy(network *nwo.Network, channel, policyName, policy string) {
orderer := network.Orderer("orderer")
func SetACLPolicy(network *nwo.Network, channel, policyName, policy string, ordererName string) {
orderer := network.Orderer(ordererName)
submitter := network.Peer("Org1", "peer0")
signer := network.Peer("Org2", "peer0")

Expand Down
80 changes: 80 additions & 0 deletions integration/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ SPDX-License-Identifier: Apache-2.0
package e2e

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"syscall"
"time"

docker "github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/core/aclmgmt/resources"
"github.com/hyperledger/fabric/integration/nwo"
"github.com/hyperledger/fabric/integration/nwo/commands"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -129,6 +132,83 @@ var _ = Describe("EndToEnd", func() {
RunQueryInvokeQuery(network, orderer, peer)
})
})

Describe("three node etcdraft network with 2 orgs", func() {
BeforeEach(func() {
network = nwo.New(nwo.MultiNodeEtcdRaft(), testDir, client, 33000, components)
network.GenerateConfigTree()
network.Bootstrap()

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
Eventually(process.Ready()).Should(BeClosed())
})

// NOTE: This single test tests for all three of:
// 1. channel creation with raft orderer,
// 2. all the nodes on three-node raft cluster are in sync wrt blocks,
// 3. raft orderer processes type A config updates and delivers the
// config blocks to the peers.
It("executes an etcdraft network with 2 orgs and three orderer nodes", func() {
orderer1 := network.Orderer("orderer1")
orderer2 := network.Orderer("orderer2")
orderer3 := network.Orderer("orderer3")
peer := network.Peer("Org1", "peer1")
org1Peer0 := network.Peer("Org1", "peer0")
blockFile1 := filepath.Join(testDir, "newest_orderer1_block.pb")
blockFile2 := filepath.Join(testDir, "newest_orderer2_block.pb")
blockFile3 := filepath.Join(testDir, "newest_orderer3_block.pb")

fetchLatestBlock := func(targetOrderer *nwo.Orderer, blockFile string) {
c := commands.ChannelFetch{
ChannelID: "testchannel",
Block: "newest",
OutputFile: blockFile,
}
if targetOrderer != nil {
c.Orderer = network.OrdererAddress(targetOrderer, nwo.ListenPort)
}
sess, err := network.PeerAdminSession(org1Peer0, c)
Expect(err).NotTo(HaveOccurred())
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0))
}

By("creating a new chain and having the peers join it to test for channel creation")
network.CreateAndJoinChannel(orderer1, "testchannel")
nwo.DeployChaincode(network, "testchannel", orderer1, chaincode)
RunQueryInvokeQuery(network, orderer1, peer)

// the above can work even if the orderer nodes are not in the same Raft
// cluster; we need to verify all the three orderer nodes are in sync wrt
// blocks.
By("fetching the latest blocks from all the orderer nodes and testing them for equality")
fetchLatestBlock(orderer1, blockFile1)
fetchLatestBlock(orderer2, blockFile2)
fetchLatestBlock(orderer3, blockFile3)
b1 := nwo.UnmarshalBlockFromFile(blockFile1)
b2 := nwo.UnmarshalBlockFromFile(blockFile2)
b3 := nwo.UnmarshalBlockFromFile(blockFile3)
Expect(bytes.Equal(b1.Header.Bytes(), b2.Header.Bytes())).To(BeTrue())
Expect(bytes.Equal(b2.Header.Bytes(), b3.Header.Bytes())).To(BeTrue())

By("updating ACL policies to test for type A configuration updates")
invokeChaincode := commands.ChaincodeInvoke{
ChannelID: "testchannel",
Orderer: network.OrdererAddress(orderer1, nwo.ListenPort),
Name: chaincode.Name,
Ctor: `{"Args":["invoke","a","b","10"]}`,
WaitForEvent: true,
}
// setting the filtered block event ACL policy to org2/Admins
policyName := resources.Event_FilteredBlock
policy := "/Channel/Application/org2/Admins"
SetACLPolicy(network, "testchannel", policyName, policy, "orderer1")
// invoking chaincode as a forbidden Org1 Admin identity
sess, err := network.PeerAdminSession(org1Peer0, invokeChaincode)
Expect(err).NotTo(HaveOccurred())
Eventually(sess.Err, network.EventuallyTimeout).Should(gbytes.Say(`\Qdeliver completed with status (FORBIDDEN)\E`))
})
})
})

func RunQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer) {
Expand Down
18 changes: 18 additions & 0 deletions integration/nwo/standard_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,21 @@ func BasicEtcdRaft() *Config {
config.SystemChannel.Profile = "SampleDevModeEtcdRaft"
return config
}

func MultiNodeEtcdRaft() *Config {
config := BasicEtcdRaft()
config.Orderers = []*Orderer{
{Name: "orderer1", Organization: "OrdererOrg"},
{Name: "orderer2", Organization: "OrdererOrg"},
{Name: "orderer3", Organization: "OrdererOrg"},
}
config.Profiles = []*Profile{{
Name: "SampleDevModeEtcdRaft",
Orderers: []string{"orderer1", "orderer2", "orderer3"},
}, {
Name: "TwoOrgsChannel",
Consortium: "SampleConsortium",
Organizations: []string{"Org1", "Org2"},
}}
return config
}

0 comments on commit 8619c8c

Please sign in to comment.