@@ -31,7 +31,9 @@ import (
3131 "github.com/rollkit/rollkit/config"
3232 "github.com/rollkit/rollkit/conv"
3333 abciconv "github.com/rollkit/rollkit/conv/abci"
34+ mockda "github.com/rollkit/rollkit/da/mock"
3435 "github.com/rollkit/rollkit/mocks"
36+ "github.com/rollkit/rollkit/store"
3537 "github.com/rollkit/rollkit/types"
3638)
3739
@@ -648,60 +650,73 @@ func TestBlockchainInfo(t *testing.T) {
648650}
649651
650652func TestValidatorSetHandling (t * testing.T ) {
651- // handle multiple sequencers
652- t .Skip ()
653-
654653 assert := assert .New (t )
655654 require := require .New (t )
656- app := & mocks.Application {}
657- app .On ("InitChain" , mock .Anything ).Return (abci.ResponseInitChain {})
658- app .On ("CheckTx" , mock .Anything ).Return (abci.ResponseCheckTx {})
659- app .On ("BeginBlock" , mock .Anything ).Return (abci.ResponseBeginBlock {})
660- app .On ("Commit" , mock .Anything ).Return (abci.ResponseCommit {})
661- app .On ("GetAppHash" , mock .Anything ).Return (abci.ResponseGetAppHash {})
662- app .On ("GenerateFraudProof" , mock .Anything ).Return (abci.ResponseGenerateFraudProof {})
663655
664- key , _ , _ := crypto .GenerateEd25519Key (crand .Reader )
656+ waitCh := make (chan interface {})
657+
658+ vKeys := make ([]tmcrypto.PrivKey , 2 )
659+ apps := make ([]* mocks.Application , 2 )
660+ nodes := make ([]* FullNode , 2 )
665661
666- vKeys := make ([]tmcrypto.PrivKey , 4 )
667662 genesisValidators := make ([]tmtypes.GenesisValidator , len (vKeys ))
668663 for i := 0 ; i < len (vKeys ); i ++ {
669664 vKeys [i ] = ed25519 .GenPrivKey ()
670665 genesisValidators [i ] = tmtypes.GenesisValidator {Address : vKeys [i ].PubKey ().Address (), PubKey : vKeys [i ].PubKey (), Power : int64 (i + 100 ), Name : fmt .Sprintf ("gen #%d" , i )}
666+ apps [i ] = createApp (vKeys [0 ], waitCh , require )
671667 }
672668
673- nodeKey := & p2p.NodeKey {
674- PrivKey : vKeys [0 ],
675- }
676- signingKey , _ := conv .GetNodeKey (nodeKey )
677-
678- pbValKey , err := encoding .PubKeyToProto (vKeys [0 ].PubKey ())
679- require .NoError (err )
680-
681- waitCh := make (chan interface {})
682-
683- app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {}).Times (5 )
684- app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {ValidatorUpdates : []abci.ValidatorUpdate {{PubKey : pbValKey , Power : 0 }}}).Once ()
685- app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {}).Once ()
686- app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {ValidatorUpdates : []abci.ValidatorUpdate {{PubKey : pbValKey , Power : 100 }}}).Once ()
687- app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {}).Run (func (args mock.Arguments ) {
688- waitCh <- nil
689- })
669+ dalc := & mockda.DataAvailabilityLayerClient {}
670+ ds , err := store .NewDefaultInMemoryKVStore ()
671+ require .Nil (err )
672+ err = dalc .Init ([8 ]byte {}, nil , ds , log .TestingLogger ())
673+ require .Nil (err )
674+ err = dalc .Start ()
675+ require .Nil (err )
676+
677+ for i := 0 ; i < len (nodes ); i ++ {
678+ nodeKey := & p2p.NodeKey {
679+ PrivKey : vKeys [i ],
680+ }
681+ signingKey , err := conv .GetNodeKey (nodeKey )
682+ require .NoError (err )
683+ nodes [i ], err = newFullNode (
684+ context .Background (),
685+ config.NodeConfig {
686+ DALayer : "mock" ,
687+ Aggregator : true ,
688+ BlockManagerConfig : config.BlockManagerConfig {
689+ BlockTime : 1 * time .Second ,
690+ DABlockTime : 100 * time .Millisecond ,
691+ },
692+ },
693+ signingKey ,
694+ signingKey ,
695+ abcicli .NewLocalClient (nil , apps [i ]),
696+ & tmtypes.GenesisDoc {ChainID : "test" , Validators : genesisValidators },
697+ log .TestingLogger (),
698+ )
699+ require .NoError (err )
700+ require .NotNil (nodes [i ])
690701
691- node , err := newFullNode (context .Background (), config.NodeConfig {DALayer : "mock" , Aggregator : true , BlockManagerConfig : config.BlockManagerConfig {BlockTime : 10 * time .Millisecond }}, key , signingKey , abcicli .NewLocalClient (nil , app ), & tmtypes.GenesisDoc {ChainID : "test" , Validators : genesisValidators }, log .TestingLogger ())
692- require .NoError (err )
693- require .NotNil (node )
702+ // use same, common DALC, so nodes can share data
703+ nodes [i ].dalc = dalc
704+ nodes [i ].blockManager .SetDALC (dalc )
705+ }
694706
695- rpc := NewFullClient (node )
707+ rpc := NewFullClient (nodes [ 0 ] )
696708 require .NotNil (rpc )
697709
698- err = node .Start ()
699- require .NoError (err )
710+ for i := 0 ; i < len (nodes ); i ++ {
711+ err := nodes [i ].Start ()
712+ require .NoError (err )
713+ }
700714
715+ <- waitCh
701716 <- waitCh
702717
703718 // test first blocks
704- for h := int64 (1 ); h <= 6 ; h ++ {
719+ for h := int64 (1 ); h <= 3 ; h ++ {
705720 vals , err := rpc .Validators (context .Background (), & h , nil , nil )
706721 assert .NoError (err )
707722 assert .NotNil (vals )
@@ -710,8 +725,8 @@ func TestValidatorSetHandling(t *testing.T) {
710725 assert .EqualValues (vals .BlockHeight , h )
711726 }
712727
713- // 6th EndBlock removes first validator from the list
714- for h := int64 (7 ); h <= 8 ; h ++ {
728+ // 3rd EndBlock removes the first validator from the list
729+ for h := int64 (4 ); h <= 5 ; h ++ {
715730 vals , err := rpc .Validators (context .Background (), & h , nil , nil )
716731 assert .NoError (err )
717732 assert .NotNil (vals )
@@ -720,8 +735,9 @@ func TestValidatorSetHandling(t *testing.T) {
720735 assert .EqualValues (vals .BlockHeight , h )
721736 }
722737
723- // 8th EndBlock adds validator back
724- for h := int64 (9 ); h <= 12 ; h ++ {
738+ // 5th EndBlock adds validator back
739+ for h := int64 (6 ); h <= 9 ; h ++ {
740+ <- waitCh
725741 <- waitCh
726742 vals , err := rpc .Validators (context .Background (), & h , nil , nil )
727743 assert .NoError (err )
@@ -737,7 +753,29 @@ func TestValidatorSetHandling(t *testing.T) {
737753 assert .NotNil (vals )
738754 assert .EqualValues (len (genesisValidators ), vals .Total )
739755 assert .Len (vals .Validators , len (genesisValidators ))
740- assert .GreaterOrEqual (vals .BlockHeight , int64 (12 ))
756+ assert .GreaterOrEqual (vals .BlockHeight , int64 (9 ))
757+ }
758+
759+ func createApp (keyToRemove tmcrypto.PrivKey , waitCh chan interface {}, require * require.Assertions ) * mocks.Application {
760+ app := & mocks.Application {}
761+ app .On ("InitChain" , mock .Anything ).Return (abci.ResponseInitChain {})
762+ app .On ("CheckTx" , mock .Anything ).Return (abci.ResponseCheckTx {})
763+ app .On ("BeginBlock" , mock .Anything ).Return (abci.ResponseBeginBlock {})
764+ app .On ("Commit" , mock .Anything ).Return (abci.ResponseCommit {})
765+ app .On ("GetAppHash" , mock .Anything ).Return (abci.ResponseGetAppHash {})
766+ app .On ("GenerateFraudProof" , mock .Anything ).Return (abci.ResponseGenerateFraudProof {})
767+
768+ pbValKey , err := encoding .PubKeyToProto (keyToRemove .PubKey ())
769+ require .NoError (err )
770+
771+ app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {}).Times (2 )
772+ app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {ValidatorUpdates : []abci.ValidatorUpdate {{PubKey : pbValKey , Power : 0 }}}).Once ()
773+ app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {}).Once ()
774+ app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {ValidatorUpdates : []abci.ValidatorUpdate {{PubKey : pbValKey , Power : 100 }}}).Once ()
775+ app .On ("EndBlock" , mock .Anything ).Return (abci.ResponseEndBlock {}).Run (func (args mock.Arguments ) {
776+ waitCh <- nil
777+ })
778+ return app
741779}
742780
743781// copy-pasted from store/store_test.go
0 commit comments