@@ -428,113 +428,6 @@ func Test_CreateGenesisStates(t *testing.T) {
428428	}
429429}
430430
431- func  TestProtocol_ActiveCandidates (t  * testing.T ) {
432- 	require  :=  require .New (t )
433- 	ctrl  :=  gomock .NewController (t )
434- 	sm  :=  testdb .NewMockStateManagerWithoutHeightFunc (ctrl )
435- 	csIndexer  :=  NewMockContractStakingIndexerWithBucketType (ctrl )
436- 
437- 	selfStake , _  :=  new (big.Int ).SetString ("1200000000000000000000000" , 10 )
438- 	g  :=  genesis .TestDefault ()
439- 	cfg  :=  g .Staking 
440- 	cfg .BootstrapCandidates  =  []genesis.BootstrapCandidate {
441- 		{
442- 			OwnerAddress :      identityset .Address (22 ).String (),
443- 			OperatorAddress :   identityset .Address (23 ).String (),
444- 			RewardAddress :     identityset .Address (23 ).String (),
445- 			Name :              "test1" ,
446- 			SelfStakingTokens : selfStake .String (),
447- 		},
448- 	}
449- 	p , err  :=  NewProtocol (HelperCtx {
450- 		DepositGas :    nil ,
451- 		BlockInterval : getBlockInterval ,
452- 	}, & BuilderConfig {
453- 		Staking :                       cfg ,
454- 		PersistStakingPatchBlock :      math .MaxUint64 ,
455- 		SkipContractStakingViewHeight : math .MaxUint64 ,
456- 		Revise : ReviseConfig {
457- 			VoteWeight : g .Staking .VoteWeightCalConsts ,
458- 		},
459- 	}, nil , nil , csIndexer , nil )
460- 	require .NoError (err )
461- 
462- 	blkHeight  :=  g .QuebecBlockHeight  +  1 
463- 	ctx  :=  protocol .WithBlockCtx (
464- 		genesis .WithGenesisContext (context .Background (), g ),
465- 		protocol.BlockCtx {
466- 			BlockHeight : blkHeight ,
467- 		},
468- 	)
469- 	ctx  =  protocol .WithFeatureCtx (protocol .WithFeatureWithHeightCtx (ctx ))
470- 	sm .EXPECT ().Height ().DoAndReturn (func () (uint64 , error ) {
471- 		return  blkHeight , nil 
472- 	}).AnyTimes ()
473- 	// csIndexer.EXPECT().StartView(gomock.Any()).Return(nil, nil) 
474- 	csIndexer .EXPECT ().Start (gomock .Any ()).Return (nil ).AnyTimes ()
475- 	csIndexer .EXPECT ().StartHeight ().Return (uint64 (blkHeight  -  3 )).AnyTimes ()
476- 	csIndexer .EXPECT ().Height ().Return (uint64 (blkHeight ), nil ).AnyTimes ()
477- 	csIndexer .EXPECT ().LoadStakeView (gomock .Any (), gomock .Any ()).Return (nil , nil )
478- 
479- 	v , err  :=  p .Start (ctx , sm )
480- 	require .NoError (err )
481- 	require .NoError (sm .WriteView (_protocolID , v ))
482- 
483- 	err  =  p .CreateGenesisStates (ctx , sm )
484- 	require .NoError (err )
485- 
486- 	var  csIndexerHeight , csVotes  uint64 
487- 	csIndexer .EXPECT ().Height ().Return (uint64 (0 ), nil ).AnyTimes ()
488- 	csIndexer .EXPECT ().BucketsByCandidate (gomock .Any (), gomock .Any ()).DoAndReturn (func (ownerAddr  address.Address , height  uint64 ) ([]* VoteBucket , error ) {
489- 		if  height  !=  csIndexerHeight  {
490- 			return  nil , errors .Errorf ("invalid height %d" , height )
491- 		}
492- 		return  []* VoteBucket {
493- 			NewVoteBucket (identityset .Address (22 ), identityset .Address (22 ), big .NewInt (int64 (csVotes )), 1 , time .Now (), true ),
494- 		}, nil 
495- 	}).AnyTimes ()
496- 
497- 	t .Run ("contract staking indexer falls behind" , func (t  * testing.T ) {
498- 		_ , err  :=  p .ActiveCandidates (ctx , sm , 0 )
499- 		require .ErrorContains (err , "invalid height" )
500- 	})
501- 
502- 	t .Run ("contract staking votes before Redsea" , func (t  * testing.T ) {
503- 		csIndexerHeight  =  blkHeight  -  1 
504- 		csVotes  =  0 
505- 		cands , err  :=  p .ActiveCandidates (ctx , sm , 0 )
506- 		require .NoError (err )
507- 		require .Len (cands , 1 )
508- 		originCandVotes  :=  cands [0 ].Votes 
509- 		csVotes  =  100 
510- 		cands , err  =  p .ActiveCandidates (ctx , sm , 0 )
511- 		require .NoError (err )
512- 		require .Len (cands , 1 )
513- 		require .EqualValues (100 , cands [0 ].Votes .Sub (cands [0 ].Votes , originCandVotes ).Uint64 ())
514- 	})
515- 	t .Run ("contract staking votes after Redsea" , func (t  * testing.T ) {
516- 		blkHeight  =  g .RedseaBlockHeight 
517- 		ctx  :=  protocol .WithBlockCtx (
518- 			genesis .WithGenesisContext (context .Background (), g ),
519- 			protocol.BlockCtx {
520- 				BlockHeight : blkHeight ,
521- 			},
522- 		)
523- 		ctx  =  protocol .WithFeatureCtx (protocol .WithFeatureWithHeightCtx (ctx ))
524- 		csIndexerHeight  =  blkHeight  -  1 
525- 		csVotes  =  0 
526- 		cands , err  :=  p .ActiveCandidates (ctx , sm , 0 )
527- 		require .NoError (err )
528- 		require .Len (cands , 1 )
529- 		originCandVotes  :=  cands [0 ].Votes 
530- 		csVotes  =  100 
531- 		cands , err  =  p .ActiveCandidates (ctx , sm , 0 )
532- 		require .NoError (err )
533- 		require .Len (cands , 1 )
534- 		require .EqualValues (103 , cands [0 ].Votes .Sub (cands [0 ].Votes , originCandVotes ).Uint64 ())
535- 	})
536- }
537- 
538431func  TestIsSelfStakeBucket (t  * testing.T ) {
539432	r  :=  require .New (t )
540433	ctrl  :=  gomock .NewController (t )
0 commit comments