migration_test.go 21.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
Copyright IBM Corp All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package e2e

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"syscall"
	"time"

	"github.com/fsouza/go-dockerclient"
	"github.com/golang/protobuf/proto"
	"github.com/hyperledger/fabric/integration/nwo"
	"github.com/hyperledger/fabric/integration/nwo/commands"
	"github.com/hyperledger/fabric/protos/common"
	protosorderer "github.com/hyperledger/fabric/protos/orderer"
	protosraft "github.com/hyperledger/fabric/protos/orderer/etcdraft"
	"github.com/hyperledger/fabric/protos/utils"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/tedsuo/ifrit"
)

var _ bool = Describe("Kafka2RaftMigration", func() {
	var (
		testDir   string
		client    *docker.Client
		network   *nwo.Network
		chaincode nwo.Chaincode

		process                           ifrit.Process
		peerProc, ordererProc, brokerProc ifrit.Process
	)

	BeforeEach(func() {
		var err error
		testDir, err = ioutil.TempDir("", "e2e")
		Expect(err).NotTo(HaveOccurred())

		client, err = docker.NewClientFromEnv()
		Expect(err).NotTo(HaveOccurred())

		chaincode = nwo.Chaincode{
			Name:    "mycc",
			Version: "0.0",
			Path:    "github.com/hyperledger/fabric/integration/chaincode/simple/cmd",
			Ctor:    `{"Args":["init","a","100","b","200"]}`,
			Policy:  `AND ('Org1MSP.member','Org2MSP.member')`,
		}
	})

	AfterEach(func() {
		if process != nil {
			process.Signal(syscall.SIGTERM)
			Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
		}

		if peerProc != nil {
			peerProc.Signal(syscall.SIGTERM)
			Eventually(peerProc.Wait(), network.EventuallyTimeout).Should(Receive())
		}

		if ordererProc != nil {
			ordererProc.Signal(syscall.SIGTERM)
			Eventually(ordererProc.Wait(), network.EventuallyTimeout).Should(Receive())
		}

		if brokerProc != nil {
			brokerProc.Signal(syscall.SIGTERM)
			Eventually(brokerProc.Wait(), network.EventuallyTimeout).Should(Receive())
		}

		if network != nil {
			network.Cleanup()
		}

		os.RemoveAll(testDir)
	})

	// These tests execute the migration config updates on Kafka based system,
	// and verify that these config update have the desired effect.
	Describe("kafka2raft migration kafka side", func() {
		BeforeEach(func() {
			conf := nwo.BasicKafka()
			conf.OrdererCap.V2_0 = true
			network = nwo.New(conf, testDir, client, BasePort(), components)
			network.GenerateConfigTree()
			network.Bootstrap()

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

		// This test executes the "green path" migration config updates on Kafka based system
		// with system channel only, and verifies that these config update have the desired effect.
		It("executes kafka2raft system channel green path", func() {
			orderer := network.Orderer("orderer")
			peer := network.Peer("Org1", "peer1")

			syschannel := network.SystemChannel.Name

			//=== No standard channels ===

			//=== Step 1: Config update on system channel, MigrationState=START ===
			By("Step 1: Config update on system channel, MigrationState=START")
			config := nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err := extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Verify initial ConsensusType value
			validateConsensusTypeValue(consensusTypeValue, "kafka", protosorderer.ConsensusType_MIG_STATE_NONE, 0)
			//Change ConsensusType value
			updateConfigWithConsensusType("kafka", []byte{}, protosorderer.ConsensusType_MIG_STATE_START, 0,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)

			By("Step 1, Verify: system channel config changed, get migration context")
			migrationContext := nwo.CurrentConfigBlockNumber(network, peer, orderer, syschannel)
			Expect(migrationContext).To(BeNumerically(">", 0))

			By("Step 1, Verify: new channels cannot be created")
			channel := "testchannel"
			network.CreateChannelFail(orderer, channel)

			//=== Step 2: Config update on system channel, MigrationState=COMMIT, type=etcdraft ===
			By("Step 2: Config update on system channel, MigrationState=COMMIT, type=etcdraft")
			config = nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())

			//Verify previous state
			validateConsensusTypeValue(consensusTypeValue, "kafka", protosorderer.ConsensusType_MIG_STATE_START, 0)

			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", []byte{}, protosorderer.ConsensusType_MIG_STATE_COMMIT, migrationContext,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)
			num := nwo.CurrentConfigBlockNumber(network, peer, orderer, syschannel)
			Expect(num).To(Equal(migrationContext + 1))

			By("Step 2, Verify: system channel config change, OSN ready to restart")
			config = nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Verify OSN ready to restart
			validateConsensusTypeValue(consensusTypeValue, "etcdraft", protosorderer.ConsensusType_MIG_STATE_COMMIT, migrationContext)

			By("Step 2, Verify: new channels cannot be created")
			network.CreateChannelFail(orderer, channel)

			By("Step 2, Verify: new config updates are not accepted")
			updateConfigWithConsensusType("kafka", []byte{}, protosorderer.ConsensusType_MIG_STATE_START, 0,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfigFail(network, orderer, syschannel, config, updatedConfig, peer, orderer)
		})

		// This test executes the "green path" migration config updates on Kafka based system
		// with a system channel and a standard channel, and verifies that these config
		// updates have the desired effect.
		It("executes kafka2raft standard channel green path", func() {
			orderer := network.Orderer("orderer")
			peer := network.Peer("Org1", "peer1")

			syschannel := network.SystemChannel.Name

			channel := "testchannel"
			network.CreateAndJoinChannel(orderer, channel)
			nwo.DeployChaincode(network, channel, orderer, chaincode)
			RunExpectQueryInvokeQuery(network, orderer, peer, channel, 100)
			RunExpectQueryInvokeQuery(network, orderer, peer, channel, 90)

			//=== Step 1: Config update on system channel, START ===
			By("Step 1: Config update on system channel, MigrationState=START")
			config := nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err := extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Verify initial status
			validateConsensusTypeValue(consensusTypeValue, "kafka", protosorderer.ConsensusType_MIG_STATE_NONE, 0)
			//Change ConsensusType value
			updateConfigWithConsensusType("kafka", []byte{}, protosorderer.ConsensusType_MIG_STATE_START, 0,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)

			By("Step 1, Verify: system channel config changed, get migration context")
			migrationContext := nwo.CurrentConfigBlockNumber(network, peer, orderer, syschannel)
			Expect(migrationContext).ToNot(Equal(0))

			config = nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			validateConsensusTypeValue(consensusTypeValue, "kafka", protosorderer.ConsensusType_MIG_STATE_START, 0)

			By("Step 1, Verify: TX's on standard channel are blocked")
			RunExpectQueryInvokeFail(network, orderer, peer, channel, 80)

			//=== Step 2: Config update on standard channel, CONTEXT ===
			By("Step 2: Config update on standard channel, MigrationState=CONTEXT")
			config = nwo.GetConfig(network, peer, orderer, channel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Verify initial status
			validateConsensusTypeValue(consensusTypeValue, "kafka", protosorderer.ConsensusType_MIG_STATE_NONE, 0)
			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", []byte{}, protosorderer.ConsensusType_MIG_STATE_CONTEXT, migrationContext,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, channel, config, updatedConfig, peer, orderer)
			//Verify standard channel changed
			By("Step 2, Verify: standard channel config changed")
			config = nwo.GetConfig(network, peer, orderer, channel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			validateConsensusTypeValue(consensusTypeValue, "etcdraft", protosorderer.ConsensusType_MIG_STATE_CONTEXT, migrationContext)

			//=== Step 3: config update on system channel, COMMIT ===
			By("Step 3: Config update on system channel, MigrationState=COMMIT")
			config = nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", []byte{}, protosorderer.ConsensusType_MIG_STATE_COMMIT, migrationContext,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)

			By("Step 3, Verify: system channel config changed")
			num := nwo.CurrentConfigBlockNumber(network, peer, orderer, syschannel)
			Expect(num).To(Equal(migrationContext + 1))
		})
	})

	// These tests execute the migration config updates on Kafka based system
	// restart the orderer onto a Raft-based system, and verifies that the newly
	// restarted orderer performs as expected.
	Describe("kafka2raft migration raft side", func() {

		// This test executes the "green path" migration config updates on Kafka based system
		// with a single orderer, and a system channel and a standard channel.
		// It then restarts the orderer onto a Raft-based system, and verifies that the
		// newly restarted orderer performs as expected.
		It("executes bootstrap to raft", func() {
			network = nwo.New(kafka2RaftMultiChannel(), testDir, client, BasePort(), components)

			orderer := network.Orderer("orderer")
			peer := network.Peer("Org1", "peer1")

			network.GenerateConfigTree()
			network.Bootstrap()

			tlsPath := "crypto/ordererOrganizations/example.com/orderers/orderer.example.com/tls/"
			Expect(filepath.Join(network.RootDir, tlsPath)).To(Equal(network.OrdererLocalTLSDir(orderer)))
			certBytes, err := ioutil.ReadFile(filepath.Join(network.RootDir, tlsPath, "server.crt"))
			Expect(err).NotTo(HaveOccurred())
261
			raft_metadata := &protosraft.ConfigMetadata{
262
263
264
265
266
267
268
269
270
				Consenters: []*protosraft.Consenter{
					{
						ClientTlsCert: certBytes,
						ServerTlsCert: certBytes,
						Host:          "127.0.0.1",
						Port:          uint32(31001),
					},
				},
				Options: &protosraft.Options{
Jay Guo's avatar
Jay Guo committed
271
272
273
274
275
					TickInterval:         "500ms",
					ElectionTick:         10,
					HeartbeatTick:        1,
					MaxInflightBlocks:    5,
					SnapshotIntervalSize: 20 * 1024 * 1024,
276
277
278
				}}

			raft_metadata_bytes := utils.MarshalOrPanic(raft_metadata)
279
			raft_metadata2 := &protosraft.ConfigMetadata{}
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
			errUnma := proto.Unmarshal(raft_metadata_bytes, raft_metadata2)
			Expect(errUnma).NotTo(HaveOccurred())

			brokerGroup := network.BrokerGroupRunner()
			brokerProc = ifrit.Invoke(brokerGroup)
			Eventually(brokerProc.Ready()).Should(BeClosed())

			ordererRunner := network.OrdererRunner(orderer)
			ordererProc = ifrit.Invoke(ordererRunner)
			Eventually(ordererProc.Ready()).Should(BeClosed())

			peerGroup := network.PeerGroupRunner()
			peerProc = ifrit.Invoke(peerGroup)
			Eventually(peerProc.Ready()).Should(BeClosed())

			syschannel := network.SystemChannel.Name

			//=== Step 0: create & join first channel, deploy and invoke chaincode ===
			By("Step 0: create & join first channel, deploy and invoke chaincode")
			channel := "testchannel1"
			network.CreateAndJoinChannel(orderer, channel)
			nwo.DeployChaincode(network, channel, orderer, chaincode)
			RunExpectQueryInvokeQuery(network, orderer, peer, channel, 100)
			RunExpectQueryInvokeQuery(network, orderer, peer, channel, 90)

			//=== Step 1: Config update on system channel, START ===
			By("Step 1: Config update on system channel, MigrationState=START")
			config := nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err := extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Change ConsensusType value
			updateConfigWithConsensusType("kafka", []byte{}, protosorderer.ConsensusType_MIG_STATE_START, 0,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)

			By("Step 1, Verify: system channel config changed, get context")
			migrationContext := nwo.CurrentConfigBlockNumber(network, peer, orderer, syschannel)
			Expect(migrationContext).ToNot(Equal(0))

			//=== Step 2: Config update on standard channel, CONTEXT ===
			By("Step 2: Config update on standard channel, MigrationState=CONTEXT")
			config = nwo.GetConfig(network, peer, orderer, channel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", raft_metadata_bytes, protosorderer.ConsensusType_MIG_STATE_CONTEXT, migrationContext,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, channel, config, updatedConfig, peer, orderer)

			//=== Step 3: config update on system channel, COMMIT ===
			By("Step 3: config update on system channel, MigrationState=COMMIT")
			config = nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", raft_metadata_bytes, protosorderer.ConsensusType_MIG_STATE_COMMIT, migrationContext,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)

			By("Step 3, Verify: system channel config changed")
			num := nwo.CurrentConfigBlockNumber(network, peer, orderer, syschannel)
			Expect(num).To(Equal(migrationContext + 1))
			num1 := nwo.CurrentConfigBlockNumber(network, peer, orderer, channel)

			//=== Step 4: kill ===
			By("Step 4: killing orderer1")
			ordererProc.Signal(syscall.SIGKILL)
			Eventually(ordererProc.Wait(), network.EventuallyTimeout).Should(Receive(MatchError("exit status 137")))

			//=== Step 5: restart ===
			By("Step 5: restarting orderer1")
			network.Consensus.Type = "etcdraft"
			ordererRunner = network.OrdererRunner(orderer)
			ordererProc = ifrit.Invoke(ordererRunner)
			Eventually(ordererProc.Ready(), network.EventuallyTimeout).Should(BeClosed())

			waitForBlockReception(orderer, peer, network, syschannel, int(num))
			waitForBlockReception(orderer, peer, network, channel, int(num1))

			By("Step 5, Verify: executing config transaction on system channel with restarted orderer")
			config = nwo.GetConfig(network, peer, orderer, syschannel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", raft_metadata_bytes, protosorderer.ConsensusType_MIG_STATE_NONE, 0,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, syschannel, config, updatedConfig, peer, orderer)

			By("Step 5, Verify: executing config transaction on standard channel with restarted orderer")
			config = nwo.GetConfig(network, peer, orderer, channel)
			updatedConfig, consensusTypeValue, err = extractOrdererConsensusType(config)
			Expect(err).NotTo(HaveOccurred())
			//Change ConsensusType value
			updateConfigWithConsensusType("etcdraft", raft_metadata_bytes, protosorderer.ConsensusType_MIG_STATE_NONE, 0,
				updatedConfig, consensusTypeValue)
			nwo.UpdateOrdererConfig(network, orderer, channel, config, updatedConfig, peer, orderer)

			By("Step 5, Verify: executing transaction on standard channel with restarted orderer")
			RunExpectQueryInvokeQuery(network, orderer, peer, channel, 80)

			By("Step 5, Verify: create new channel, executing transaction with restarted orderer")
			channel2 := "testchannel2"
			network.CreateAndJoinChannel(orderer, channel2)
			nwo.InstantiateChaincode(network, channel2, orderer, chaincode, peer, network.PeersWithChannel(channel2)...)
			RunExpectQueryRetry(network, orderer, peer, channel2, 100)
			RunExpectQueryInvokeQuery(network, orderer, peer, channel2, 100)
			RunExpectQueryInvokeQuery(network, orderer, peer, channel2, 90)
		})
	})
})

func RunExpectQueryInvokeQuery(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string, expect int) {
	By("querying the chaincode")
	sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
		ChannelID: channel,
		Name:      "mycc",
		Ctor:      `{"Args":["query","a"]}`,
	})
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
	Expect(sess).To(gbytes.Say(fmt.Sprint(expect)))

	By("invoking the chaincode")
	sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{
		ChannelID: channel,
		Orderer:   n.OrdererAddress(orderer, nwo.ListenPort),
		Name:      "mycc",
		Ctor:      `{"Args":["invoke","a","b","10"]}`,
		PeerAddresses: []string{
			n.PeerAddress(n.Peer("Org1", "peer0"), nwo.ListenPort),
			n.PeerAddress(n.Peer("Org2", "peer1"), nwo.ListenPort),
		},
		WaitForEvent: true,
	})
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
	Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200"))

	By("querying the chaincode again")
	sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
		ChannelID: channel,
		Name:      "mycc",
		Ctor:      `{"Args":["query","a"]}`,
	})
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
	Expect(sess).To(gbytes.Say(fmt.Sprint(expect - 10)))
}

func RunExpectQueryRetry(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string, expect int) {
	By("querying the chaincode with retry")

	Eventually(func() string {
		sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
			ChannelID: channel,
			Name:      "mycc",
			Ctor:      `{"Args":["query","a"]}`,
		})
		Expect(err).NotTo(HaveOccurred())
		Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit())
		if sess.ExitCode() != 0 {
			sessEC := fmt.Sprintf("exit code is %d: %s", sess.ExitCode(), string(sess.Out.Contents()))
			return sessEC
		}
		sessOut := string(sess.Out.Contents())
		expectStr := fmt.Sprintf("%d", expect)

		if strings.Contains(sessOut, expectStr) {
			return ""
		} else {
			return "waiting..."
		}
	}, n.EventuallyTimeout, time.Second).Should(BeEmpty())
}

func RunExpectQueryInvokeFail(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, channel string, expect int) {
	By("querying the chaincode")
	sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeQuery{
		ChannelID: channel,
		Name:      "mycc",
		Ctor:      `{"Args":["query","a"]}`,
	})
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
	Expect(sess).To(gbytes.Say(fmt.Sprint(expect)))

	sess, err = n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{
		ChannelID: channel,
		Orderer:   n.OrdererAddress(orderer, nwo.ListenPort),
		Name:      "mycc",
		Ctor:      `{"Args":["invoke","a","b","10"]}`,
		PeerAddresses: []string{
			n.PeerAddress(n.Peer("Org1", "peer0"), nwo.ListenPort),
			n.PeerAddress(n.Peer("Org2", "peer1"), nwo.ListenPort),
		},
		WaitForEvent: true,
	})
	Expect(err).NotTo(HaveOccurred())
	Eventually(sess, n.EventuallyTimeout).ShouldNot(gexec.Exit(0))
	Expect(sess.Err).NotTo(gbytes.Say("Chaincode invoke successful. result: status:200"))
}

func validateConsensusTypeValue(value *protosorderer.ConsensusType, cType string, state protosorderer.ConsensusType_MigrationState, context uint64) {
	Expect(value.Type).To(Equal(cType))
	Expect(value.MigrationState).To(Equal(state))
	Expect(value.MigrationContext).To(Equal(context))
}

func extractOrdererConsensusType(config *common.Config) (updatedConfig *common.Config, consensusTypeValue *protosorderer.ConsensusType, err error) {
	updatedConfig = proto.Clone(config).(*common.Config)
	consensusTypeConfigValue := updatedConfig.ChannelGroup.Groups["Orderer"].Values["ConsensusType"]
	consensusTypeValue = new(protosorderer.ConsensusType)
	err = proto.Unmarshal(consensusTypeConfigValue.Value, consensusTypeValue)
	return
}

func updateConfigWithConsensusType(consensusType string, consensusMetadata []byte, migState protosorderer.ConsensusType_MigrationState, migContext uint64,
	updatedConfig *common.Config, consensusTypeValue *protosorderer.ConsensusType) {
	consensusTypeValue.Type = consensusType
	consensusTypeValue.Metadata = consensusMetadata
	consensusTypeValue.MigrationState = migState
	consensusTypeValue.MigrationContext = migContext
	updatedConfig.ChannelGroup.Groups["Orderer"].Values["ConsensusType"] = &common.ConfigValue{
		ModPolicy: "Admins",
		Value:     utils.MarshalOrPanic(consensusTypeValue),
	}
}

func kafka2RaftMultiChannel() *nwo.Config {
	config := nwo.BasicKafka()
	config.OrdererCap.V2_0 = true

	config.Channels = []*nwo.Channel{
		{Name: "testchannel1", Profile: "TwoOrgsChannel"},
		{Name: "testchannel2", Profile: "TwoOrgsChannel"}}

	for _, peer := range config.Peers {
		peer.Channels = []*nwo.PeerChannel{
			{Name: "testchannel1", Anchor: true},
			{Name: "testchannel2", Anchor: true},
		}
	}
	return config
}