github.com/lino-network/lino@v0.6.11/test/validator/vote_test.go (about)

     1  package validator
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/lino-network/lino/test"
     9  	linotypes "github.com/lino-network/lino/types"
    10  	"github.com/tendermint/tendermint/crypto/secp256k1"
    11  
    12  	// store "github.com/lino-network/lino/x/validator/model"
    13  	valtypes "github.com/lino-network/lino/x/validator/types"
    14  	types "github.com/lino-network/lino/x/vote/types"
    15  	// abci "github.com/tendermint/tendermint/abci/types"
    16  )
    17  
    18  func TestVoteStandby(t *testing.T) {
    19  	// testName := "TestVoteStandby"
    20  
    21  	// start with 22 genesis validator
    22  	baseT := time.Unix(0, 0).Add(100 * time.Second)
    23  	baseTime := baseT.Unix()
    24  	lb := test.NewTestLinoBlockchain(t, test.DefaultNumOfVal, baseT)
    25  
    26  	// add one more validators but not oncall
    27  	for i := 0; i < 1; i++ {
    28  		newAccountResetPriv := secp256k1.GenPrivKey()
    29  		newAccountTransactionPriv := secp256k1.GenPrivKey()
    30  
    31  		newValidatorPriv := secp256k1.GenPrivKey()
    32  
    33  		newAccountName := "altval"
    34  		newAccountName += strconv.Itoa(i)
    35  
    36  		test.CreateAccount(t, newAccountName, lb, uint64(i),
    37  			newAccountResetPriv, newAccountTransactionPriv, "500000")
    38  
    39  		voteDepositMsg := types.NewStakeInMsg(newAccountName, linotypes.LNO("200000"))
    40  		test.SignCheckDeliver(t, lb, voteDepositMsg, 1, true, newAccountTransactionPriv, baseTime)
    41  
    42  		valDepositMsg := valtypes.NewValidatorRegisterMsg(newAccountName, newValidatorPriv.PubKey(), "")
    43  		test.SignCheckDeliver(t, lb, valDepositMsg, 2, true, newAccountTransactionPriv, baseTime)
    44  
    45  		test.CheckOncallValidatorList(t, newAccountName, false, lb)
    46  		test.CheckStandbyValidatorList(t, newAccountName, true, lb)
    47  
    48  	}
    49  
    50  	newAccountResetPriv := secp256k1.GenPrivKey()
    51  	newAccountTransactionPriv := secp256k1.GenPrivKey()
    52  	newAccountName := "voter"
    53  
    54  	test.CreateAccount(t, newAccountName, lb, uint64(1),
    55  		newAccountResetPriv, newAccountTransactionPriv, "500000")
    56  	voteDepositMsg := types.NewStakeInMsg(newAccountName, linotypes.LNO("100000"))
    57  	test.SignCheckDeliver(t, lb, voteDepositMsg, 1, true, newAccountTransactionPriv, baseTime)
    58  
    59  	// let voter vote altval
    60  	voteMsg := valtypes.NewVoteValidatorMsg(newAccountName, []string{"altval0"})
    61  	test.SignCheckDeliver(t, lb, voteMsg, 2, true, newAccountTransactionPriv, baseTime)
    62  
    63  	// check altval has become oncall and vote increased
    64  	test.CheckOncallValidatorList(t, "altval0", true, lb)
    65  	test.CheckStandbyValidatorList(t, "altval0", false, lb)
    66  	test.CheckReceivedVotes(t, "altval0", linotypes.NewCoinFromInt64(300000*linotypes.Decimals), lb)
    67  
    68  	// check val21 is gone
    69  	test.CheckOncallValidatorList(t, "validator21", false, lb)
    70  	test.CheckStandbyValidatorList(t, "validator21", true, lb)
    71  
    72  }