github.com/lino-network/lino@v0.6.11/test/vote/revoke_test.go (about) 1 package vote 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/lino-network/lino/test" 8 linotypes "github.com/lino-network/lino/types" 9 "github.com/tendermint/tendermint/crypto/secp256k1" 10 11 // val "github.com/lino-network/lino/x/validator" 12 types "github.com/lino-network/lino/x/vote/types" 13 ) 14 15 func TestVoterRevoke(t *testing.T) { 16 newAccountTransactionPriv := secp256k1.GenPrivKey() 17 newAccountName := "newuser" 18 // newValidatorPriv := secp256k1.GenPrivKey() 19 20 delegator1TransactionPriv := secp256k1.GenPrivKey() 21 delegator2TransactionPriv := secp256k1.GenPrivKey() 22 delegator1Name := "delegator1" 23 delegator2Name := "delegator2" 24 25 // to recover the coin day 26 baseT := time.Unix(0, 0).Add(7200 * time.Second) 27 baseTime := baseT.Unix() 28 lb := test.NewTestLinoBlockchain(t, test.DefaultNumOfVal, baseT) 29 30 test.CreateAccount(t, newAccountName, lb, 0, 31 secp256k1.GenPrivKey(), newAccountTransactionPriv, "500000") 32 test.CreateAccount(t, delegator1Name, lb, 1, 33 secp256k1.GenPrivKey(), delegator1TransactionPriv, "210100") 34 test.CreateAccount(t, delegator2Name, lb, 2, 35 secp256k1.GenPrivKey(), delegator2TransactionPriv, "70100") 36 37 voteDepositMsg := types.NewStakeInMsg(newAccountName, linotypes.LNO("300000")) 38 test.SignCheckDeliver(t, lb, voteDepositMsg, 1, true, newAccountTransactionPriv, baseTime) 39 40 // valDepositMsg := val.NewValidatorDepositMsg( 41 // newAccountName, linotypes.LNO("150000"), newValidatorPriv.PubKey(), "") 42 // test.SignCheckDeliver(t, lb, valDepositMsg, 1, true, newAccountTransactionPriv, baseTime) 43 44 // // let delegator delegate coins to voter 45 // delegateMsg := types.NewDelegateMsg(delegator1Name, newAccountName, linotypes.LNO("210000")) 46 // delegateMsg2 := types.NewDelegateMsg(delegator2Name, newAccountName, linotypes.LNO("70000")) 47 48 // test.SignCheckDeliver(t, lb, delegateMsg, 0, true, delegator1TransactionPriv, baseTime) 49 // test.SignCheckDeliver(t, lb, delegateMsg2, 0, true, delegator2TransactionPriv, baseTime) 50 51 // // delegator can withdraw coins 52 // delegatorWithdrawMsg := types.NewDelegatorWithdrawMsg(delegator1Name, newAccountName, 53 // linotypes.LNO("70000")) 54 // test.SignCheckDeliver(t, lb, delegatorWithdrawMsg, 1, true, delegator1TransactionPriv, baseTime) 55 56 // //all validators cannot revoke voter candidancy 57 // stakeOutMsg := types.NewStakeOutMsg(newAccountName, linotypes.LNO("300000")) 58 // test.SimulateOneBlock(lb, baseTime) 59 // test.SignCheckDeliver(t, lb, stakeOutMsg, 2, false, newAccountTransactionPriv, baseTime) 60 61 // //validators can stake out after revoking validator candidancy 62 // valRevokeMsg := val.NewValidatorRevokeMsg(newAccountName) 63 // test.SignCheckDeliver(t, lb, valRevokeMsg, 3, true, newAccountTransactionPriv, baseTime) 64 // test.SimulateOneBlock(lb, baseTime) 65 // test.SignCheckDeliver(t, lb, stakeOutMsg, 4, true, newAccountTransactionPriv, baseTime) 66 67 // // check delegator withdraw first coin return 68 // test.SimulateOneBlock(lb, baseTime+test.CoinReturnIntervalSec+1) 69 // test.CheckBalance(t, newAccountName, lb, linotypes.NewCoinFromInt64(11428471429)) 70 // test.CheckBalance(t, delegator1Name, lb, linotypes.NewCoinFromInt64(10099*linotypes.Decimals)) 71 // test.CheckBalance(t, delegator2Name, lb, linotypes.NewCoinFromInt64(99*linotypes.Decimals)) 72 73 // // check balance after freezing period 74 // for i := int64(1); i < test.CoinReturnTimes; i++ { 75 // test.SimulateOneBlock(lb, baseTime+test.CoinReturnIntervalSec*(i+1)+1) 76 // } 77 // test.CheckBalance(t, newAccountName, lb, linotypes.NewCoinFromInt64(499999*linotypes.Decimals)) 78 // test.CheckBalance(t, delegator1Name, lb, linotypes.NewCoinFromInt64(70099*linotypes.Decimals)) 79 // test.CheckBalance(t, delegator2Name, lb, linotypes.NewCoinFromInt64(99*linotypes.Decimals)) 80 }