@@ -7,19 +7,19 @@ SPDX-License-Identifier: Apache-2.0
77package nwo
88
99import (
10+ "net/http"
1011 "os"
1112 "path/filepath"
12- "strings"
13-
14- "github.com/hyperledger/fabric/common/channelconfig"
15- "github.com/hyperledger/fabric/common/policies"
1613
1714 "github.com/hyperledger/fabric-protos-go-apiv2/common"
1815 "github.com/hyperledger/fabric-protos-go-apiv2/msp"
1916 protosorderer "github.com/hyperledger/fabric-protos-go-apiv2/orderer"
17+ "github.com/hyperledger/fabric/common/channelconfig"
18+ "github.com/hyperledger/fabric/common/policies"
2019 "github.com/hyperledger/fabric/integration/nwo/commands"
2120 "github.com/hyperledger/fabric/internal/configtxlator/update"
2221 "github.com/hyperledger/fabric/protoutil"
22+ . "github.com/onsi/ginkgo/v2"
2323 . "github.com/onsi/gomega"
2424 "github.com/onsi/gomega/gbytes"
2525 "github.com/onsi/gomega/gexec"
@@ -126,6 +126,13 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated
126126 Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
127127 }
128128
129+ sess , err := n .PeerAdminSession (submitter , commands.SignConfigTx {
130+ File : updateFile ,
131+ ClientAuth : n .ClientAuthRequired ,
132+ })
133+ Expect (err ).NotTo (HaveOccurred ())
134+ Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
135+
129136 var currentBlockNumber uint64
130137 // get current configuration block number
131138 if getConfigBlockFromOrderer {
@@ -134,15 +141,20 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated
134141 currentBlockNumber = CurrentConfigBlockNumber (n , submitter , nil , channel )
135142 }
136143
137- sess , err := n .PeerAdminSession (submitter , commands.ChannelUpdate {
138- ChannelID : channel ,
139- Orderer : n .OrdererAddress (orderer , ListenPort ),
140- File : updateFile ,
141- ClientAuth : n .ClientAuthRequired ,
142- })
144+ updateEnvelopeBytes , err := os .ReadFile (updateFile )
145+ Expect (err ).NotTo (HaveOccurred ())
146+
147+ updateEnvelope := & common.Envelope {}
148+ err = proto .Unmarshal (updateEnvelopeBytes , updateEnvelope )
143149 Expect (err ).NotTo (HaveOccurred ())
144- Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
145- Expect (sess .Err ).To (gbytes .Say ("Successfully submitted channel update" ))
150+
151+ ready := make (chan struct {})
152+ go func () {
153+ defer GinkgoRecover ()
154+ Update (n , orderer , channel , updateEnvelope )
155+ close (ready )
156+ }()
157+ Eventually (ready , n .EventuallyTimeout ).Should (BeClosed ())
146158
147159 if getConfigBlockFromOrderer {
148160 ccb := func () uint64 { return CurrentConfigBlockNumber (n , submitter , orderer , channel ) }
@@ -209,47 +221,57 @@ func UpdateOrdererConfig(n *Network, orderer *Orderer, channel string, current,
209221 currentBlockNumber := CurrentConfigBlockNumber (n , submitter , orderer , channel )
210222 ComputeUpdateOrdererConfig (updateFile , n , channel , current , updated , submitter , additionalSigners ... )
211223
212- Eventually (func () bool {
213- sess , err := n .OrdererAdminSession (orderer , submitter , commands.ChannelUpdate {
214- ChannelID : channel ,
215- Orderer : n .OrdererAddress (orderer , ListenPort ),
216- File : updateFile ,
217- ClientAuth : n .ClientAuthRequired ,
218- })
219- Expect (err ).NotTo (HaveOccurred ())
224+ updateEnvelopeBytes , err := os .ReadFile (updateFile )
225+ Expect (err ).NotTo (HaveOccurred ())
220226
221- sess .Wait (n .EventuallyTimeout )
222- if sess .ExitCode () != 0 {
223- return false
224- }
227+ updateEnvelope := & common.Envelope {}
228+ err = proto .Unmarshal (updateEnvelopeBytes , updateEnvelope )
229+ Expect (err ).NotTo (HaveOccurred ())
225230
226- return strings .Contains (string (sess .Err .Contents ()), "Successfully submitted channel update" )
227- }, n .EventuallyTimeout ).Should (BeTrue ())
231+ ready := make (chan struct {})
232+ go func () {
233+ defer GinkgoRecover ()
234+ Update (n , orderer , channel , updateEnvelope )
235+ close (ready )
236+ }()
237+ Eventually (ready , n .EventuallyTimeout ).Should (BeClosed ())
228238
229239 // wait for the block to be committed
230240 ccb := func () uint64 { return CurrentConfigBlockNumber (n , submitter , orderer , channel ) }
231241 Eventually (ccb , n .EventuallyTimeout ).Should (BeNumerically (">" , currentBlockNumber ))
232242}
233243
234- // UpdateOrdererConfigSession computes, signs, and submits a configuration
244+ // UpdateOrdererConfigFails computes, signs, and submits a configuration
235245// update which requires orderer signatures. The caller should wait on the
236246// returned seession retrieve the exit code.
237- func UpdateOrdererConfigSession (n * Network , orderer * Orderer , channel string , current , updated * common.Config , submitter * Peer , additionalSigners ... * Orderer ) * gexec. Session {
247+ func UpdateOrdererConfigFails (n * Network , orderer * Orderer , channel string , current , updated * common.Config , errStr string , submitter * Peer , additionalSigners ... * Orderer ) {
238248 tempDir , err := os .MkdirTemp (n .RootDir , "updateConfig" )
239249 Expect (err ).NotTo (HaveOccurred ())
240250 updateFile := filepath .Join (tempDir , "update.pb" )
241251
242252 ComputeUpdateOrdererConfig (updateFile , n , channel , current , updated , submitter , additionalSigners ... )
243253
244- // session should not return with a zero exit code nor with a success response
245- sess , err := n .OrdererAdminSession (orderer , submitter , commands.ChannelUpdate {
246- ChannelID : channel ,
247- Orderer : n .OrdererAddress (orderer , ListenPort ),
254+ sess , err := n .OrdererAdminSession (orderer , submitter , commands.SignConfigTx {
248255 File : updateFile ,
249256 ClientAuth : n .ClientAuthRequired ,
250257 })
251258 Expect (err ).NotTo (HaveOccurred ())
252- return sess
259+ Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
260+
261+ updateEnvelopeBytes , err := os .ReadFile (updateFile )
262+ Expect (err ).NotTo (HaveOccurred ())
263+
264+ updateEnvelope := & common.Envelope {}
265+ err = proto .Unmarshal (updateEnvelopeBytes , updateEnvelope )
266+ Expect (err ).NotTo (HaveOccurred ())
267+
268+ ready := make (chan struct {})
269+ go func () {
270+ defer GinkgoRecover ()
271+ UpdateWithStatus (n , orderer , channel , updateEnvelope , http .StatusBadRequest , errStr )
272+ close (ready )
273+ }()
274+ Eventually (ready , n .EventuallyTimeout ).Should (BeClosed ())
253275}
254276
255277func ComputeUpdateOrdererConfig (updateFile string , n * Network , channel string , current , updated * common.Config , submitter * Peer , additionalSigners ... * Orderer ) {
0 commit comments