github.com/lino-network/lino@v0.6.11/test/validator/revoke_test.go (about) 1 package validator 2 3 import ( 4 "strconv" 5 "testing" 6 "time" 7 8 "github.com/lino-network/lino/param" 9 "github.com/lino-network/lino/test" 10 linotypes "github.com/lino-network/lino/types" 11 valtypes "github.com/lino-network/lino/x/validator/types" 12 types "github.com/lino-network/lino/x/vote/types" 13 abci "github.com/tendermint/tendermint/abci/types" 14 "github.com/tendermint/tendermint/crypto/secp256k1" 15 ) 16 17 func TestRevoke(t *testing.T) { 18 // testName := "TestRegisterValidatorOneByOne" 19 20 // start with 1 genesis validator 21 baseT := time.Unix(0, 0).Add(100 * time.Second) 22 baseTime := baseT.Unix() 23 lb := test.NewTestLinoBlockchain(t, 1, baseT) 24 25 // add 1 validator 26 newAccountResetPriv := secp256k1.GenPrivKey() 27 newAccountTransactionPriv := secp256k1.GenPrivKey() 28 29 newValidatorPriv := secp256k1.GenPrivKey() 30 31 newAccountName := "validator" 32 newAccountName += strconv.Itoa(1) 33 34 test.CreateAccountWithTime(t, newAccountName, lb, uint64(0), 35 newAccountResetPriv, newAccountTransactionPriv, "500000", baseTime) 36 37 voteDepositMsg := types.NewStakeInMsg(newAccountName, strconv.Itoa(300000)) 38 test.SignCheckDeliver(t, lb, voteDepositMsg, 1, true, newAccountTransactionPriv, baseTime) 39 40 valRegisterMsg := valtypes.NewValidatorRegisterMsg(newAccountName, newValidatorPriv.PubKey(), "") 41 test.SignCheckDeliver(t, lb, valRegisterMsg, 2, true, newAccountTransactionPriv, baseTime) 42 test.CheckOncallValidatorList(t, newAccountName, true, lb) 43 44 // create a voter to vote validator1 45 newVoterResetPriv := secp256k1.GenPrivKey() 46 newVoterTransactionPriv := secp256k1.GenPrivKey() 47 newVoterName := "voter" 48 49 test.CreateAccountWithTime(t, newVoterName, lb, uint64(1), 50 newVoterResetPriv, newVoterTransactionPriv, "500000", baseTime) 51 voterDepositMsg := types.NewStakeInMsg(newVoterName, linotypes.LNO("100000")) 52 test.SignCheckDeliver(t, lb, voterDepositMsg, 1, true, newVoterTransactionPriv, baseTime) 53 54 // let voter vote validator1 55 voteMsg := valtypes.NewVoteValidatorMsg(newVoterName, []string{"validator1"}) 56 test.SignCheckDeliver(t, lb, voteMsg, 2, true, newVoterTransactionPriv, baseTime) 57 test.CheckReceivedVotes(t, "validator1", linotypes.NewCoinFromInt64(400000*linotypes.Decimals), lb) 58 59 // revoke validator1 60 valRevokeMsg := valtypes.NewValidatorRevokeMsg(newAccountName) 61 test.SignCheckDeliver(t, lb, valRevokeMsg, 3, true, newAccountTransactionPriv, baseTime) 62 test.CheckOncallValidatorList(t, newAccountName, false, lb) 63 64 // cannot revoke and register in the pending period 65 test.SignCheckDeliver(t, lb, valRegisterMsg, 4, false, newAccountTransactionPriv, baseTime) 66 test.CheckOncallValidatorList(t, newAccountName, false, lb) 67 68 test.SignCheckDeliver(t, lb, valRevokeMsg, 5, false, newAccountTransactionPriv, baseTime) 69 test.CheckOncallValidatorList(t, newAccountName, false, lb) 70 71 // after pending period, can register again 72 ctx := lb.BaseApp.NewContext(true, abci.Header{Time: baseT}) 73 ph := param.NewParamHolder(lb.CapKeyParamStore) 74 param := ph.GetValidatorParam(ctx) 75 test.SimulateOneBlock(lb, baseTime+param.ValidatorRevokePendingSec+1) 76 test.SignCheckDeliver(t, lb, valRegisterMsg, 6, true, newAccountTransactionPriv, baseTime+param.ValidatorRevokePendingSec+2) 77 test.CheckOncallValidatorList(t, newAccountName, true, lb) 78 79 // check the validator inherite the previous votes 80 test.CheckReceivedVotes(t, "validator1", linotypes.NewCoinFromInt64(400000*linotypes.Decimals), lb) 81 }