@@ -11,7 +11,7 @@ import (
1111
1212 "github.com/golang/protobuf/proto"
1313 "github.com/hyperledger/fabric/common/ledger/blockledger"
14- ramledger "github.com/hyperledger/fabric/common/ledger/blockledger/ram"
14+ "github.com/hyperledger/fabric/common/ledger/blockledger/ram"
1515 "github.com/hyperledger/fabric/common/metrics/disabled"
1616 mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config"
1717 mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
@@ -27,7 +27,6 @@ import (
2727 "github.com/hyperledger/fabric/protoutil"
2828 "github.com/pkg/errors"
2929 "github.com/stretchr/testify/assert"
30- "github.com/stretchr/testify/require"
3130)
3231
3332//go:generate counterfeiter -o mocks/signer_serializer.go --fake-name SignerSerializer . signerSerializer
@@ -202,159 +201,6 @@ func TestNewRegistrar(t *testing.T) {
202201 })
203202}
204203
205- // This test essentially brings the entire system up and is ultimately what main.go will replicate,
206- // doing it on the system and two standard channels.
207- // Then, it is testing the methods that implement the MigrationController interface,
208- // used in consensus-type migration.
209- func Test3ChanConsensusMigrationController (t * testing.T ) {
210- const (
211- testChainID1 = genesisconfig .TestChainID + "1"
212- testChainID2 = genesisconfig .TestChainID + "2"
213- )
214-
215- var genesisBlockSys * cb.Block
216- var genesisBlockStd1 * cb.Block
217- var genesisBlockStd2 * cb.Block
218-
219- //system channel
220- confSys := configtxgentest .Load (genesisconfig .SampleInsecureSoloProfile )
221- genesisBlockSys = encoder .New (confSys ).GenesisBlock ()
222- //standard channel, no Consortiums
223- confStd := configtxgentest .Load (genesisconfig .SampleInsecureSoloProfile )
224- confStd .Consortiums = nil
225- genesisBlockStd1 = encoder .New (confStd ).GenesisBlockForChannel (testChainID1 )
226- genesisBlockStd2 = encoder .New (confStd ).GenesisBlockForChannel (testChainID2 )
227-
228- t .Run ("Green path" , func (t * testing.T ) {
229- lf , rls := newRAMLedgerAndFactory3Chan (10 ,
230- genesisconfig .TestChainID , genesisBlockSys ,
231- testChainID1 , genesisBlockStd1 ,
232- testChainID2 , genesisBlockStd2 )
233-
234- consenters := make (map [string ]consensus.Consenter )
235- consenters [confSys .Orderer .OrdererType ] = & mockConsenter {}
236-
237- manager := NewRegistrar (lf , mockCrypto (), & disabled.Provider {})
238- manager .Initialize (consenters )
239-
240- chainSupport := manager .GetChain ("Fake" )
241- assert .Nilf (t , chainSupport , "Should not have found a chain that was not created" )
242-
243- chainSupport = manager .GetChain (genesisconfig .TestChainID )
244- assert .NotNilf (t , chainSupport , "Should have gotten chain which was initialized by ramledger" )
245- assert .True (t , chainSupport .IsSystemChannel ())
246- assert .True (t , ! chainSupport .MigrationStatus ().IsPending ())
247-
248- testMessageOrderAndRetrieval (confSys .Orderer .BatchSize .MaxMessageCount , genesisconfig .TestChainID , chainSupport , rls [0 ], t )
249-
250- //standard channel 1
251- chainSupport1 := manager .GetChain (testChainID1 )
252- assert .NotNilf (t , chainSupport1 , "Should have gotten chain which was initialized by ramledger" )
253- assert .True (t , ! chainSupport1 .IsSystemChannel ())
254- assert .True (t , ! chainSupport1 .MigrationStatus ().IsPending ())
255-
256- testMessageOrderAndRetrieval (confSys .Orderer .BatchSize .MaxMessageCount , testChainID1 , chainSupport1 , rls [1 ], t )
257-
258- //standard channel 2
259- chainSupport2 := manager .GetChain (testChainID2 )
260- assert .NotNilf (t , chainSupport2 , "Should have gotten chain which was initialized by ramledger" )
261- assert .True (t , ! chainSupport2 .IsSystemChannel ())
262- assert .True (t , ! chainSupport2 .MigrationStatus ().IsPending ())
263-
264- testMessageOrderAndRetrieval (confSys .Orderer .BatchSize .MaxMessageCount , testChainID2 , chainSupport2 , rls [2 ], t )
265-
266- assert .Equal (t , 3 , manager .ChannelsCount (), "Three channels" )
267-
268- // Test MigrationController methods
269- assert .True (t , ! manager .ConsensusMigrationPending ())
270- err := manager .ConsensusMigrationCommit ()
271- assert .EqualError (t , err ,
272- "cannot commit consensus-type migration because system channel (testchainid): state=MIG_STATE_NONE, context=0 (expect: state=MIG_STATE_START, context>0)" )
273-
274- ctx := uint64 (5 )
275- err = manager .ConsensusMigrationStart (ctx )
276- assert .NoError (t , err , "Migration start" )
277- assert .True (t , manager .ConsensusMigrationPending ())
278- assert .True (t , chainSupport .MigrationStatus ().IsPending ())
279- assert .True (t , chainSupport1 .MigrationStatus ().IsPending ())
280- assert .True (t , chainSupport2 .MigrationStatus ().IsPending ())
281- err = manager .ConsensusMigrationStart (ctx )
282- // Iteration order is unpredictable... can be 1 or 2
283- assert .Regexp (t , "cannot start new consensus-type migration because standard channel testchainid[12], still pending" , err .Error ())
284-
285- configTx := makeConfigTx (genesisconfig .TestChainID + "Fake" , 6 )
286- _ , _ , _ , err = manager .BroadcastChannelSupport (configTx )
287- assert .Equal (t , "cannot create channel because consensus-type migration is pending" , err .Error ())
288-
289- err = manager .ConsensusMigrationCommit ()
290- // Iteration order is unpredictable... can be 1 or 2
291- assert .Regexp (t , "cannot commit consensus-type migration because standard channel testchainid[12], still pending, state=MIG_STATE_START" , err .Error ())
292-
293- chainSupport1 .MigrationStatus ().SetStateContext (ab .ConsensusType_MIG_STATE_CONTEXT , ctx )
294- assert .True (t , chainSupport1 .MigrationStatus ().IsPending ())
295- err = manager .ConsensusMigrationCommit ()
296- assert .EqualError (t , err , "cannot commit consensus-type migration because standard channel testchainid2, still pending, state=MIG_STATE_START" )
297-
298- chainSupport2 .MigrationStatus ().SetStateContext (ab .ConsensusType_MIG_STATE_CONTEXT , ctx + 1 )
299- assert .True (t , chainSupport2 .MigrationStatus ().IsPending ())
300-
301- err = manager .ConsensusMigrationCommit ()
302- assert .EqualError (t , err , "cannot commit consensus-type migration because standard channel testchainid2, bad context=6, expected=5" )
303-
304- chainSupport2 .MigrationStatus ().SetStateContext (ab .ConsensusType_MIG_STATE_CONTEXT , ctx )
305- assert .True (t , chainSupport2 .MigrationStatus ().IsPending ())
306-
307- err = manager .ConsensusMigrationCommit ()
308- assert .NoError (t , err , "Migration can commit" )
309- })
310-
311- t .Run ("Abort path" , func (t * testing.T ) {
312- lf , rls := newRAMLedgerAndFactory3Chan (10 ,
313- genesisconfig .TestChainID , genesisBlockSys ,
314- testChainID1 , genesisBlockStd1 ,
315- testChainID2 , genesisBlockStd2 )
316-
317- consenters := make (map [string ]consensus.Consenter )
318- consenters [confSys .Orderer .OrdererType ] = & mockConsenter {}
319-
320- manager := NewRegistrar (lf , mockCrypto (), & disabled.Provider {})
321- manager .Initialize (consenters )
322-
323- chainSupport := manager .GetChain ("Fake" )
324- assert .Nilf (t , chainSupport , "Should not have found a chain that was not created" )
325-
326- chainSupport = manager .GetChain (genesisconfig .TestChainID )
327- require .NotNilf (t , chainSupport , "Should have gotten chain which was initialized by ramledger" )
328- testMessageOrderAndRetrieval (confSys .Orderer .BatchSize .MaxMessageCount , genesisconfig .TestChainID , chainSupport , rls [0 ], t )
329-
330- //standard channel 1
331- chainSupport1 := manager .GetChain (testChainID1 )
332- require .NotNilf (t , chainSupport1 , "Should have gotten chain which was initialized by ramledger" )
333- testMessageOrderAndRetrieval (confSys .Orderer .BatchSize .MaxMessageCount , testChainID1 , chainSupport1 , rls [1 ], t )
334-
335- //standard channel 2
336- chainSupport2 := manager .GetChain (testChainID2 )
337- require .NotNilf (t , chainSupport2 , "Should have gotten chain which was initialized by ramledger" )
338- testMessageOrderAndRetrieval (confSys .Orderer .BatchSize .MaxMessageCount , testChainID2 , chainSupport2 , rls [2 ], t )
339-
340- assert .Equal (t , 3 , manager .ChannelsCount (), "Three channels" )
341-
342- // Test MigrationController methods
343- ctx := uint64 (5 )
344- err := manager .ConsensusMigrationStart (ctx )
345- assert .NoError (t , err , "Migration start" )
346- assert .True (t , manager .ConsensusMigrationPending ())
347- assert .True (t , chainSupport .MigrationStatus ().IsPending ())
348- chainSupport1 .MigrationStatus ().SetStateContext (ab .ConsensusType_MIG_STATE_CONTEXT , ctx )
349- assert .True (t , chainSupport1 .MigrationStatus ().IsPending ())
350-
351- err = manager .ConsensusMigrationAbort ()
352- assert .EqualError (t , err , "Not implemented yet" )
353-
354- //TODO test abort path here, when implemented
355- })
356- }
357-
358204func TestCreateChain (t * testing.T ) {
359205 //system channel
360206 confSys := configtxgentest .Load (genesisconfig .SampleInsecureSoloProfile )
0 commit comments