github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/core/ppos/candidate_state_test.go (about)

     1  package pposm_test
     2  
     3  //
     4  //func newChainState() (*state.StateDB, error) {
     5  //	var (
     6  //		db      = ethdb.NewMemDatabase()
     7  //		genesis = new(core.Genesis).MustCommit(db)
     8  //	)
     9  //	fmt.Println("genesis", genesis)
    10  //	// Initialize ppos storage
    11  //
    12  //	ppos_storage.NewPPosTemp(db)
    13  //
    14  //
    15  //	// Initialize a fresh chain with only a genesis block
    16  //	blockchain, _ := core.NewBlockChain(db, nil, params.AllEthashProtocolChanges, nil, vm.Config{}, nil)
    17  //
    18  //	var state *state.StateDB
    19  //	if statedb, err := blockchain.State(); nil != err {
    20  //		return nil, errors.New("reference statedb failed" + err.Error())
    21  //	} else {
    22  //		state = statedb
    23  //	}
    24  //	return state, nil
    25  //}
    26  //
    27  //func newPool() (*pposm.CandidatePoolContext, *pposm.TicketPoolContext) {
    28  //	configs := &params.PposConfig{
    29  //		CandidateConfig: &params.CandidateConfig{
    30  //			Threshold:         "100",
    31  //			DepositLimit:      10,
    32  //			MaxChair:          1,
    33  //			MaxCount:          3,
    34  //			RefundBlockNumber: 1,
    35  //		},
    36  //		TicketConfig: &params.TicketConfig{
    37  //			TicketPrice:       "1",
    38  //			MaxCount:          10000,
    39  //			ExpireBlockNumber: 100,
    40  //		},
    41  //	}
    42  //	return pposm.NewCandidatePoolContext(configs), pposm.NewTicketPoolContext(configs)
    43  //}
    44  //
    45  //func printObject(title string, obj, logger interface{}) {
    46  //	objs, _ := json.Marshal(obj)
    47  //	switch logger.(type) {
    48  //	case *testing.T:
    49  //		t := logger.(*testing.T)
    50  //		t.Log(title, string(objs), "\n")
    51  //	case *testing.B:
    52  //		b := logger.(*testing.B)
    53  //		b.Log(title, string(objs), "\n")
    54  //	}
    55  //}
    56  //
    57  //func TestCandidatePoolAllCircle(t *testing.T) {
    58  //
    59  //	var candidatePoolContext *pposm.CandidatePoolContext
    60  //	var ticketPoolContext *pposm.TicketPoolContext
    61  //	var state *state.StateDB
    62  //	if st, err := newChainState(); nil != err {
    63  //		t.Error("Getting stateDB err", err)
    64  //	} else {
    65  //		state = st
    66  //	}
    67  //	/** test init candidatePool and ticketPool */
    68  //	candidatePoolContext, ticketPoolContext = newPool()
    69  //
    70  //	//state.Commit(false)
    71  //
    72  //	curr_blockNumber := new(big.Int).SetUint64(7)
    73  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
    74  //
    75  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
    76  //
    77  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
    78  //
    79  //	candidate := &types.Candidate{
    80  //		Deposit:     new(big.Int).SetUint64(100),
    81  //		BlockNumber: curr_blockNumber,
    82  //		CandidateId: nodeId5,
    83  //		TxIndex:     6,
    84  //		Host:        "10.0.0.1",
    85  //		Port:        "8548",
    86  //		Owner:       common.HexToAddress("0x12"),
    87  //	}
    88  //
    89  //	t.Log("Set New Candidate ...")
    90  //	/** test SetCandidate */
    91  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
    92  //		t.Error("SetCandidate err:", err)
    93  //	}
    94  //
    95  //	/** vote ticket */
    96  //	var count uint32 = 0
    97  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
    98  //
    99  //	var blockNumber = new(big.Int).SetUint64(10)
   100  //	voteNum := 10
   101  //	timeMap := make(map[uint32]int64)
   102  //	fmt.Println("VOTING START .............................................................")
   103  //	for i := 0; i < voteNum; i++ {
   104  //		startTime := time.Now().UnixNano() / 1e6
   105  //		voteOwner := ownerList[rand.Intn(2)]
   106  //		deposit := new(big.Int).SetUint64(10)
   107  //		state.SubBalance(voteOwner, deposit)
   108  //		state.AddBalance(common.TicketPoolAddr, deposit)
   109  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
   110  //		if i < 2 {
   111  //			tempBlockNumber.SetUint64(6)
   112  //			t.Logf("vote blockNumber[%v]", tempBlockNumber.Uint64())
   113  //		}
   114  //
   115  //		if i == 2 {
   116  //			fmt.Println("release ticket,start ############################################################")
   117  //			var tempBlockNumber uint64 = 6
   118  //			for i := 0; i < 4; i++ {
   119  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
   120  //				tempBlockNumber++
   121  //			}
   122  //			fmt.Println("release ticket,end ############################################################")
   123  //		}
   124  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
   125  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, candidate.CandidateId, tempBlockNumber)
   126  //		if nil != err {
   127  //			fmt.Println("vote ticket error:", err)
   128  //		}
   129  //		atomic.AddUint32(&count, 1)
   130  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
   131  //
   132  //	}
   133  //	fmt.Println("VOTING END .............................................................")
   134  //
   135  //
   136  //	/** test GetCandidate */
   137  //	t.Log("test GetCandidate ...")
   138  //	can := candidatePoolContext.GetCandidate(state, nodeId1, blockNumber)
   139  //	t.Log("GetCandidate", can)
   140  //
   141  //	/** test WithdrawCandidate */
   142  //	t.Log("test WithdrawCandidate ...")
   143  //	ok1 := candidatePoolContext.WithdrawCandidate(state, nodeId5, new(big.Int).SetUint64(uint64(99)), blockNumber)
   144  //	t.Log("error", ok1)
   145  //
   146  //	/** test WithdrawCandidate again */
   147  //	t.Log("test WithdrawCandidate again ...")
   148  //	ok2 := candidatePoolContext.WithdrawCandidate(state, nodeId5, new(big.Int).SetUint64(uint64(10)), new(big.Int).SetUint64(uint64(11)))
   149  //	t.Log("error", ok2)
   150  //
   151  //	/** test GetChosens */
   152  //	t.Log("test GetChosens ...")
   153  //	canArr := candidatePoolContext.GetChosens(state, 0, blockNumber)
   154  //	printObject("Elected candidates", canArr, t)
   155  //
   156  //	/** test GetChairpersons */
   157  //	t.Log("test GetChairpersons ...")
   158  //	canQueue := candidatePoolContext.GetChairpersons(state, blockNumber)
   159  //	printObject("Witnesses", canQueue, t)
   160  //
   161  //	/** test GetDefeat */
   162  //	t.Log("test GetDefeat ...")
   163  //	defeatArr := candidatePoolContext.GetDefeat(state, nodeId5, blockNumber)
   164  //	printObject("can be refund defeats", defeatArr, t)
   165  //
   166  //	/** test IsDefeat */
   167  //	t.Log("test IsDefeat ...")
   168  //	flag := candidatePoolContext.IsDefeat(state, nodeId5, blockNumber)
   169  //	printObject("isdefeat", flag, t)
   170  //
   171  //	/** test Election */
   172  //	t.Log("test Election ...")
   173  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
   174  //	t.Log("whether election was successful", err)
   175  //
   176  //	/** test RefundBalance */
   177  //	t.Log("test RefundBalance ...")
   178  //	err = candidatePoolContext.RefundBalance(state, nodeId5, new(big.Int).SetUint64(uint64(11)))
   179  //	t.Log("err", err)
   180  //
   181  //	/** test RefundBalance again */
   182  //	t.Log("test RefundBalance again ...")
   183  //	err = candidatePoolContext.RefundBalance(state, nodeId3, new(big.Int).SetUint64(uint64(11)))
   184  //	t.Log("err", err)
   185  //
   186  //	/** test GetOwner */
   187  //	t.Log("test GetOwner ...")
   188  //	addr := candidatePoolContext.GetOwner(state, nodeId5, blockNumber)
   189  //	t.Log("Benefit address", addr.String())
   190  //
   191  //	/**  test GetWitness */
   192  //	t.Log("test GetWitness ...")
   193  //	nodeArr, _ := candidatePoolContext.GetWitness(state, 1, blockNumber)
   194  //	printObject("nodeArr", nodeArr, t)
   195  //}
   196  //
   197  ///** Unit Test */
   198  //
   199  //// test SetCandidate
   200  //func candidate_SetCandidate(logFn func(args ...interface{}), errFn func(args ...interface{})) {
   201  //	var candidatePoolContext *pposm.CandidatePoolContext
   202  //	//var ticketPoolContext *pposm.TicketPoolContext
   203  //	var state *state.StateDB
   204  //	if st, err := newChainState(); nil != err {
   205  //		errFn("Getting stateDB err", err)
   206  //	} else {
   207  //		state = st
   208  //	}
   209  //	/** test init candidatePool and ticketPool */
   210  //	candidatePoolContext, _ = newPool()
   211  //
   212  //
   213  //	curr_blockNumber := new(big.Int).SetUint64(7)
   214  //
   215  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   216  //
   217  //
   218  //	candidate := &types.Candidate{
   219  //		Deposit:     new(big.Int).SetUint64(100),
   220  //		BlockNumber: curr_blockNumber,
   221  //		CandidateId: nodeId5,
   222  //		TxIndex:     6,
   223  //		Host:        "10.0.0.1",
   224  //		Port:        "8548",
   225  //		Owner:       common.HexToAddress("0x12"),
   226  //	}
   227  //
   228  //	logFn("Set New Candidate ...")
   229  //	/** test SetCandidate */
   230  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   231  //		errFn("SetCandidate err:", err)
   232  //	}
   233  //}
   234  //
   235  //func TestCandidatePool_SetCandidate(t *testing.T) {
   236  //	candidate_SetCandidate(t.Log, t.Error)
   237  //}
   238  //
   239  //func BenchmarkCandidatePool_SetCandidate(b *testing.B) {
   240  //	candidate_SetCandidate(b.Log, b.Error)
   241  //}
   242  //
   243  //// test GetCandidate
   244  //func candidate_GetCandidate(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   245  //	var candidatePoolContext *pposm.CandidatePoolContext
   246  //	//var ticketPoolContext *pposm.TicketPoolContext
   247  //	var state *state.StateDB
   248  //	if st, err := newChainState(); nil != err {
   249  //		errFn("Getting stateDB err", err)
   250  //	} else {
   251  //		state = st
   252  //	}
   253  //	/** test init candidatePool and ticketPool */
   254  //	candidatePoolContext, _ = newPool()
   255  //
   256  //	curr_blockNumber := new(big.Int).SetUint64(7)
   257  //
   258  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   259  //
   260  //
   261  //	candidate := &types.Candidate{
   262  //		Deposit:     new(big.Int).SetUint64(100),
   263  //		BlockNumber: curr_blockNumber,
   264  //		CandidateId: nodeId5,
   265  //		TxIndex:     6,
   266  //		Host:        "10.0.0.1",
   267  //		Port:        "8548",
   268  //		Owner:       common.HexToAddress("0x12"),
   269  //	}
   270  //
   271  //	logFn("Set New Candidate ...")
   272  //	/** test SetCandidate */
   273  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   274  //		errFn("SetCandidate err:", err)
   275  //	}
   276  //
   277  //	/** test GetCandidate */
   278  //	logFn("test GetCandidate ...")
   279  //	can := candidatePoolContext.GetCandidate(state, nodeId5, curr_blockNumber)
   280  //	printObject("GetCandidate", can, logger)
   281  //}
   282  //
   283  //func TestCandidatePool_GetCandidate(t *testing.T) {
   284  //	candidate_GetCandidate(t, t.Log, t.Error)
   285  //}
   286  //
   287  //func BenchmarkCandidatePool_GetCandidate(b *testing.B) {
   288  //	candidate_GetCandidate(b, b.Log, b.Error)
   289  //}
   290  //
   291  //// test GetCandidateArr
   292  //func candidate_GetCandidateArr(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   293  //	var candidatePoolContext *pposm.CandidatePoolContext
   294  //	//var ticketPoolContext *pposm.TicketPoolContext
   295  //	var state *state.StateDB
   296  //	if st, err := newChainState(); nil != err {
   297  //		errFn("Getting stateDB err", err)
   298  //	} else {
   299  //		state = st
   300  //	}
   301  //	/** test init candidatePool and ticketPool */
   302  //	candidatePoolContext, _ = newPool()
   303  //
   304  //	curr_blockNumber := new(big.Int).SetUint64(7)
   305  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
   306  //
   307  //
   308  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   309  //
   310  //
   311  //	candidate := &types.Candidate{
   312  //		Deposit:     new(big.Int).SetUint64(100),
   313  //		BlockNumber: curr_blockNumber,
   314  //		CandidateId: nodeId5,
   315  //		TxIndex:     6,
   316  //		Host:        "10.0.0.1",
   317  //		Port:        "8548",
   318  //		Owner:       common.HexToAddress("0x12"),
   319  //	}
   320  //
   321  //	logFn("Set New Candidate ...")
   322  //	/** test SetCandidate */
   323  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   324  //		errFn("SetCandidate err:", err)
   325  //	}
   326  //
   327  //	candidate2 := &types.Candidate{
   328  //		Deposit:     new(big.Int).SetUint64(101),
   329  //		BlockNumber: curr_blockNumber,
   330  //		CandidateId: nodeId1,
   331  //		TxIndex:     5,
   332  //		Host:        "10.0.0.1",
   333  //		Port:        "8548",
   334  //		Owner:       common.HexToAddress("0x15"),
   335  //	}
   336  //	logFn("Set New Candidate ...")
   337  //	/** test SetCandidate */
   338  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
   339  //		errFn("SetCandidate err:", err)
   340  //	}
   341  //
   342  //	/** test GetCandidate */
   343  //	logFn("test GetCandidateArr ...")
   344  //	canArr := candidatePoolContext.GetCandidateArr(state, curr_blockNumber, []discover.NodeID{candidate.CandidateId, candidate2.CandidateId}...)
   345  //	printObject("GetCandidateArr", canArr, logger)
   346  //}
   347  //
   348  //func TestCandidatePool_GetCandidateArr(t *testing.T) {
   349  //	candidate_GetCandidateArr(t, t.Log, t.Error)
   350  //}
   351  //
   352  //func BenchmarkCandidatePool_GetCandidateArr(b *testing.B) {
   353  //	candidate_GetCandidateArr(b, b.Log, b.Error)
   354  //}
   355  //
   356  //// test SetCandidateExtra
   357  //func candidate_SetCandidateExtra(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   358  //	var candidatePoolContext *pposm.CandidatePoolContext
   359  //	//var ticketPoolContext *pposm.TicketPoolContext
   360  //	var state *state.StateDB
   361  //	if st, err := newChainState(); nil != err {
   362  //		errFn("Getting stateDB err", err)
   363  //	} else {
   364  //		state = st
   365  //	}
   366  //	/** test init candidatePool and ticketPool */
   367  //	candidatePoolContext, _ = newPool()
   368  //	//state.Commit(false)
   369  //
   370  //	curr_blockNumber := new(big.Int).SetUint64(7)
   371  //
   372  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   373  //
   374  //
   375  //	candidate := &types.Candidate{
   376  //		Deposit:     new(big.Int).SetUint64(100),
   377  //		BlockNumber: curr_blockNumber,
   378  //		CandidateId: nodeId5,
   379  //		TxIndex:     6,
   380  //		Host:        "10.0.0.1",
   381  //		Port:        "8548",
   382  //		Owner:       common.HexToAddress("0x12"),
   383  //	}
   384  //
   385  //	logFn("Set New Candidate ...")
   386  //	/** test SetCandidate */
   387  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   388  //		errFn("SetCandidate err:", err)
   389  //	}
   390  //
   391  //	/** test SetCndidateExtra */
   392  //	if err := candidatePoolContext.SetCandidateExtra(state, candidate.CandidateId, "LALALALA"); nil != err {
   393  //		errFn("SetCndidateExtra err:", err)
   394  //	}
   395  //	/** test GetCandidate  */
   396  //	if can := candidatePoolContext.GetCandidate(state, candidate.CandidateId, curr_blockNumber); nil == can {
   397  //		errFn("GetCandidate err:")
   398  //	} else {
   399  //		logFn("candidate'extra:", can.Extra)
   400  //	}
   401  //}
   402  //
   403  //func TestCandidatePool_SetCandidateExtra(t *testing.T) {
   404  //	candidate_SetCandidateExtra(t, t.Log, t.Error)
   405  //}
   406  //
   407  //func BenchmarkCandidatePool_SetCandidateExtra(b *testing.B) {
   408  //	candidate_SetCandidateExtra(b, b.Log, b.Error)
   409  //}
   410  //
   411  //// test WithdrawCndidate
   412  //func candidate_WithdrawCandidate(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   413  //	var candidatePoolContext *pposm.CandidatePoolContext
   414  //	//var ticketPoolContext *pposm.TicketPoolContext
   415  //	var state *state.StateDB
   416  //	if st, err := newChainState(); nil != err {
   417  //		errFn("Getting stateDB err", err)
   418  //	} else {
   419  //		state = st
   420  //	}
   421  //	/** test init candidatePool and ticketPool */
   422  //	candidatePoolContext, _ = newPool()
   423  //
   424  //	curr_blockNumber := new(big.Int).SetUint64(7)
   425  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
   426  //
   427  //
   428  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   429  //
   430  //
   431  //	candidate := &types.Candidate{
   432  //		Deposit:     new(big.Int).SetUint64(100),
   433  //		BlockNumber: curr_blockNumber,
   434  //		CandidateId: nodeId5,
   435  //		TxIndex:     6,
   436  //		Host:        "10.0.0.1",
   437  //		Port:        "8548",
   438  //		Owner:       common.HexToAddress("0x12"),
   439  //	}
   440  //	logFn("Set New Candidate ...")
   441  //	/** test SetCandidate */
   442  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   443  //		errFn("SetCandidate err:", err)
   444  //	}
   445  //
   446  //	candidate2 := &types.Candidate{
   447  //		Deposit:     new(big.Int).SetUint64(101),
   448  //		BlockNumber: curr_blockNumber,
   449  //		CandidateId: nodeId1,
   450  //		TxIndex:     5,
   451  //		Host:        "10.0.0.1",
   452  //		Port:        "8548",
   453  //		Owner:       common.HexToAddress("0x15"),
   454  //	}
   455  //	logFn("Set New Candidate ...")
   456  //	/** test SetCandidate */
   457  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
   458  //		errFn("SetCandidate err:", err)
   459  //	}
   460  //
   461  //	/** test GetCandidate */
   462  //	logFn("test GetCandidate ...")
   463  //	can := candidatePoolContext.GetCandidate(state, nodeId5, curr_blockNumber)
   464  //	printObject("GetCandidate", can, logger)
   465  //
   466  //	/** test WithdrawCandidate */
   467  //	logFn("test WithdrawCandidate ...")
   468  //	ok1 := candidatePoolContext.WithdrawCandidate(state, nodeId5, new(big.Int).SetUint64(uint64(99)), new(big.Int).SetUint64(uint64(10)))
   469  //	logFn("error", ok1)
   470  //
   471  //	/** test GetCandidate */
   472  //	logFn("test GetCandidate ...")
   473  //	can2 := candidatePoolContext.GetCandidate(state, nodeId5, curr_blockNumber)
   474  //	printObject("GetCandidate", can2, logger)
   475  //}
   476  //
   477  //func TestCandidatePool_WithdrawCandidate(t *testing.T) {
   478  //	candidate_WithdrawCandidate(t, t.Log, t.Error)
   479  //}
   480  //
   481  //func BenchmarkCandidatePool_WithdrawCandidate(b *testing.B) {
   482  //	candidate_WithdrawCandidate(b, b.Log, b.Error)
   483  //}
   484  //
   485  //// test GetChosens
   486  //func candidate_GetChosens(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   487  //	var candidatePoolContext *pposm.CandidatePoolContext
   488  //	//var ticketPoolContext *pposm.TicketPoolContext
   489  //	var state *state.StateDB
   490  //	if st, err := newChainState(); nil != err {
   491  //		errFn("Getting stateDB err", err)
   492  //	} else {
   493  //		state = st
   494  //	}
   495  //	/** test init candidatePool and ticketPool */
   496  //	candidatePoolContext, _ = newPool()
   497  //
   498  //	curr_blockNumber := new(big.Int).SetUint64(7)
   499  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
   500  //
   501  //
   502  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   503  //
   504  //
   505  //	candidate := &types.Candidate{
   506  //		Deposit:     new(big.Int).SetUint64(100),
   507  //		BlockNumber: curr_blockNumber,
   508  //		CandidateId: nodeId5,
   509  //		TxIndex:     6,
   510  //		Host:        "10.0.0.1",
   511  //		Port:        "8548",
   512  //		Owner:       common.HexToAddress("0x12"),
   513  //	}
   514  //	logFn("Set New Candidate ...")
   515  //	/** test SetCandidate */
   516  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   517  //		errFn("SetCandidate err:", err)
   518  //	}
   519  //
   520  //	candidate2 := &types.Candidate{
   521  //		Deposit:     new(big.Int).SetUint64(101),
   522  //		BlockNumber: curr_blockNumber,
   523  //		CandidateId: nodeId1,
   524  //		TxIndex:     5,
   525  //		Host:        "10.0.0.1",
   526  //		Port:        "8548",
   527  //		Owner:       common.HexToAddress("0x15"),
   528  //	}
   529  //	logFn("Set New Candidate ...")
   530  //	/** test SetCandidate */
   531  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
   532  //		errFn("SetCandidate err:", err)
   533  //	}
   534  //
   535  //	/** test GetChosens */
   536  //	logFn("test GetChosens ...")
   537  //	canArr := candidatePoolContext.GetChosens(state, 0, curr_blockNumber)
   538  //	printObject("immediate elected candidates", canArr, logger)
   539  //}
   540  //
   541  //func TestCandidatePool_GetChosens(t *testing.T) {
   542  //	candidate_GetChosens(t, t.Log, t.Error)
   543  //}
   544  //
   545  //func BenchmarkCandidatePool_GetChosens(b *testing.B) {
   546  //	candidate_GetChosens(b, b.Log, b.Error)
   547  //}
   548  //
   549  //// test GetChairpersons
   550  //func candidate_GetChairpersons(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   551  //	var candidatePoolContext *pposm.CandidatePoolContext
   552  //	var ticketPoolContext *pposm.TicketPoolContext
   553  //	var state *state.StateDB
   554  //	if st, err := newChainState(); nil != err {
   555  //		errFn("Getting stateDB err", err)
   556  //	} else {
   557  //		state = st
   558  //	}
   559  //	/** test init candidatePool and ticketPool */
   560  //	candidatePoolContext, ticketPoolContext = newPool()
   561  //
   562  //	curr_blockNumber := new(big.Int).SetUint64(7)
   563  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
   564  //
   565  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
   566  //
   567  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
   568  //
   569  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   570  //
   571  //
   572  //	// cache
   573  //	cans := make([]*types.Candidate, 0)
   574  //
   575  //	candidate := &types.Candidate{
   576  //		Deposit:     new(big.Int).SetUint64(100),
   577  //		BlockNumber: curr_blockNumber,
   578  //		CandidateId: nodeId5,
   579  //		TxIndex:     6,
   580  //		Host:        "10.0.0.1",
   581  //		Port:        "8548",
   582  //		Owner:       common.HexToAddress("0x12"),
   583  //	}
   584  //	logFn("Set New Candidate ...")
   585  //	/** test SetCandidate */
   586  //	cans = append(cans, candidate)
   587  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   588  //		errFn("SetCandidate err:", err)
   589  //	}
   590  //
   591  //	candidate2 := &types.Candidate{
   592  //		Deposit:     new(big.Int).SetUint64(101),
   593  //		BlockNumber: curr_blockNumber,
   594  //		CandidateId: nodeId1,
   595  //		TxIndex:     5,
   596  //		Host:        "10.0.0.1",
   597  //		Port:        "8548",
   598  //		Owner:       common.HexToAddress("0x15"),
   599  //	}
   600  //	logFn("Set New Candidate ...")
   601  //	/** test SetCandidate */
   602  //	cans = append(cans, candidate2)
   603  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
   604  //		errFn("SetCandidate err:", err)
   605  //	}
   606  //
   607  //	candidate3 := &types.Candidate{
   608  //		Deposit:     new(big.Int).SetUint64(102),
   609  //		BlockNumber: curr_blockNumber,
   610  //		CandidateId: nodeId2,
   611  //		TxIndex:     5,
   612  //		Host:        "10.0.0.1",
   613  //		Port:        "8548",
   614  //		Owner:       common.HexToAddress("0x15"),
   615  //	}
   616  //	logFn("Set New Candidate ...")
   617  //	/** test SetCandidate */
   618  //	cans = append(cans, candidate3)
   619  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
   620  //		errFn("SetCandidate err:", err)
   621  //	}
   622  //
   623  //	candidate4 := &types.Candidate{
   624  //		Deposit:     new(big.Int).SetUint64(120),
   625  //		BlockNumber: curr_blockNumber,
   626  //		CandidateId: nodeId3,
   627  //		TxIndex:     4,
   628  //		Host:        "10.0.0.1",
   629  //		Port:        "8548",
   630  //		Owner:       common.HexToAddress("0x15"),
   631  //	}
   632  //	logFn("Set New Candidate ...")
   633  //	/** test SetCandidate */
   634  //	cans = append(cans, candidate4)
   635  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
   636  //		errFn("SetCandidate err:", err)
   637  //	}
   638  //
   639  //	/** vote ticket */
   640  //	var count uint32 = 0
   641  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
   642  //	var blockNumber = new(big.Int).SetUint64(10)
   643  //	voteNum := 13
   644  //	timeMap := make(map[uint32]int64)
   645  //	fmt.Println("VOTING START .............................................................")
   646  //	for i := 0; i < voteNum; i++ {
   647  //		can := cans[rand.Intn(4)]
   648  //
   649  //		startTime := time.Now().UnixNano() / 1e6
   650  //		voteOwner := ownerList[rand.Intn(2)]
   651  //		deposit := new(big.Int).SetUint64(10)
   652  //		state.SubBalance(voteOwner, deposit)
   653  //		state.AddBalance(common.TicketPoolAddr, deposit)
   654  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
   655  //		if i < 2 {
   656  //			tempBlockNumber.SetUint64(6)
   657  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
   658  //		}
   659  //
   660  //		if i == 2 {
   661  //			fmt.Println("release ticket,start ############################################################")
   662  //			var tempBlockNumber uint64 = 6
   663  //			for i := 0; i < 4; i++ {
   664  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
   665  //				tempBlockNumber++
   666  //			}
   667  //			fmt.Println("release ticket,end ############################################################")
   668  //		}
   669  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
   670  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
   671  //		if nil != err {
   672  //			fmt.Println("vote ticket error:", err)
   673  //		}
   674  //		atomic.AddUint32(&count, 1)
   675  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
   676  //
   677  //	}
   678  //	fmt.Println("VOTING END .............................................................")
   679  //
   680  //	/** test Election */
   681  //	logFn("test Election ...")
   682  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
   683  //	logFn("Whether election was successful err", err)
   684  //
   685  //	/** test switch */
   686  //	logFn("test Switch ...")
   687  //	flag := candidatePoolContext.Switch(state, blockNumber)
   688  //	logFn("Switch was success ", flag)
   689  //
   690  //	/** test GetChairpersons */
   691  //	logFn("test GetChairpersons ...")
   692  //	canArr := candidatePoolContext.GetChairpersons(state, blockNumber)
   693  //	printObject("Witnesses", canArr, logger)
   694  //}
   695  //
   696  //func TestGet_Chairpersons(t *testing.T) {
   697  //	candidate_GetChairpersons(t, t.Log, t.Error)
   698  //}
   699  //
   700  //func BenchmarkCandidatePool_GetChairpersons(b *testing.B) {
   701  //	candidate_GetChairpersons(b, b.Log, b.Error)
   702  //}
   703  //
   704  //// test GetWitness
   705  //func candidate_GetWitness(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   706  //	var candidatePoolContext *pposm.CandidatePoolContext
   707  //	var ticketPoolContext *pposm.TicketPoolContext
   708  //	var state *state.StateDB
   709  //	if st, err := newChainState(); nil != err {
   710  //		errFn("Getting stateDB err", err)
   711  //	} else {
   712  //		state = st
   713  //	}
   714  //	/** test init candidatePool and ticketPool */
   715  //	candidatePoolContext, ticketPoolContext = newPool()
   716  //
   717  //	curr_blockNumber := new(big.Int).SetUint64(7)
   718  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
   719  //
   720  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
   721  //
   722  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
   723  //
   724  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   725  //
   726  //
   727  //	// cache
   728  //	cans := make([]*types.Candidate, 0)
   729  //
   730  //	candidate := &types.Candidate{
   731  //		Deposit:     new(big.Int).SetUint64(100),
   732  //		BlockNumber: curr_blockNumber,
   733  //		CandidateId: nodeId5,
   734  //		TxIndex:     6,
   735  //		Host:        "10.0.0.1",
   736  //		Port:        "8548",
   737  //		Owner:       common.HexToAddress("0x12"),
   738  //	}
   739  //	logFn("Set New Candidate ...")
   740  //	/** test SetCandidate */
   741  //	cans = append(cans, candidate)
   742  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   743  //		errFn("SetCandidate err:", err)
   744  //	}
   745  //
   746  //	candidate2 := &types.Candidate{
   747  //		Deposit:     new(big.Int).SetUint64(101),
   748  //		BlockNumber: curr_blockNumber,
   749  //		CandidateId: nodeId1,
   750  //		TxIndex:     5,
   751  //		Host:        "10.0.0.1",
   752  //		Port:        "8548",
   753  //		Owner:       common.HexToAddress("0x15"),
   754  //	}
   755  //	logFn("Set New Candidate ...")
   756  //	/** test SetCandidate */
   757  //	cans = append(cans, candidate2)
   758  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
   759  //		errFn("SetCandidate err:", err)
   760  //	}
   761  //
   762  //	candidate3 := &types.Candidate{
   763  //		Deposit:     new(big.Int).SetUint64(102),
   764  //		BlockNumber: curr_blockNumber,
   765  //		CandidateId: nodeId2,
   766  //		TxIndex:     5,
   767  //		Host:        "10.0.0.1",
   768  //		Port:        "8548",
   769  //		Owner:       common.HexToAddress("0x15"),
   770  //	}
   771  //	logFn("Set New Candidate ...")
   772  //	/** test SetCandidate */
   773  //	cans = append(cans, candidate3)
   774  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
   775  //		errFn("SetCandidate err:", err)
   776  //	}
   777  //
   778  //	candidate4 := &types.Candidate{
   779  //		Deposit:     new(big.Int).SetUint64(120),
   780  //		BlockNumber: curr_blockNumber,
   781  //		CandidateId: nodeId3,
   782  //		TxIndex:     4,
   783  //		Host:        "10.0.0.1",
   784  //		Port:        "8548",
   785  //		Owner:       common.HexToAddress("0x15"),
   786  //	}
   787  //	logFn("Set New Candidate ...")
   788  //	/** test SetCandidate */
   789  //	cans = append(cans, candidate4)
   790  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
   791  //		errFn("SetCandidate err:", err)
   792  //	}
   793  //
   794  //	/** vote ticket */
   795  //	var count uint32 = 0
   796  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
   797  //	var blockNumber = new(big.Int).SetUint64(10)
   798  //	voteNum := 13
   799  //	timeMap := make(map[uint32]int64)
   800  //	fmt.Println("VOTING START .............................................................")
   801  //	for i := 0; i < voteNum; i++ {
   802  //		can := cans[rand.Intn(4)]
   803  //
   804  //		startTime := time.Now().UnixNano() / 1e6
   805  //		voteOwner := ownerList[rand.Intn(2)]
   806  //		deposit := new(big.Int).SetUint64(10)
   807  //		state.SubBalance(voteOwner, deposit)
   808  //		state.AddBalance(common.TicketPoolAddr, deposit)
   809  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
   810  //		if i < 2 {
   811  //			tempBlockNumber.SetUint64(6)
   812  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
   813  //		}
   814  //
   815  //		if i == 2 {
   816  //			fmt.Println("release ticket,start ############################################################")
   817  //			var tempBlockNumber uint64 = 6
   818  //			for i := 0; i < 4; i++ {
   819  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
   820  //				tempBlockNumber++
   821  //			}
   822  //			fmt.Println("release ticket,end ############################################################")
   823  //		}
   824  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
   825  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
   826  //		if nil != err {
   827  //			fmt.Println("vote ticket error:", err)
   828  //		}
   829  //		atomic.AddUint32(&count, 1)
   830  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
   831  //
   832  //	}
   833  //	fmt.Println("VOTING END .............................................................")
   834  //
   835  //	/** test Election */
   836  //	logFn("test Election ...")
   837  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
   838  //	logFn("Whether election was successful err", err)
   839  //
   840  //	/** test GetWitness */
   841  //	logFn("test GetWitness ...")
   842  //	canArr, _ := candidatePoolContext.GetWitness(state, 1, blockNumber)
   843  //	printObject("next Witnesses", canArr, logger)
   844  //
   845  //	/** test switch */
   846  //	logFn("test Switch ...")
   847  //	flag := candidatePoolContext.Switch(state, blockNumber)
   848  //	logFn("Switch was success ", flag)
   849  //
   850  //	/** test GetWitness */
   851  //	logFn("test GetWitness ...")
   852  //	canArr, _ = candidatePoolContext.GetWitness(state, 0, blockNumber)
   853  //	printObject(" current Witnesses", canArr, logger)
   854  //}
   855  //
   856  //func TestCandidatePool_GetWitness(t *testing.T) {
   857  //	candidate_GetWitness(t, t.Log, t.Error)
   858  //}
   859  //
   860  //func BenchmarkCandidatePool_GetWitness(b *testing.B) {
   861  //	candidate_GetWitness(b, b.Log, b.Error)
   862  //}
   863  //
   864  //// test GetAllWitness
   865  //func candidate_GetAllWitness(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
   866  //	var candidatePoolContext *pposm.CandidatePoolContext
   867  //	var ticketPoolContext *pposm.TicketPoolContext
   868  //	var state *state.StateDB
   869  //	if st, err := newChainState(); nil != err {
   870  //		errFn("Getting stateDB err", err)
   871  //	} else {
   872  //		state = st
   873  //	}
   874  //	/** test init candidatePool and ticketPool */
   875  //	candidatePoolContext, ticketPoolContext = newPool()
   876  //
   877  //	curr_blockNumber := new(big.Int).SetUint64(7)
   878  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
   879  //
   880  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
   881  //
   882  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
   883  //
   884  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
   885  //
   886  //
   887  //	// cache
   888  //	cans := make([]*types.Candidate, 0)
   889  //
   890  //	candidate := &types.Candidate{
   891  //		Deposit:     new(big.Int).SetUint64(100),
   892  //		BlockNumber: curr_blockNumber,
   893  //		CandidateId: nodeId5,
   894  //		TxIndex:     6,
   895  //		Host:        "10.0.0.1",
   896  //		Port:        "8548",
   897  //		Owner:       common.HexToAddress("0x12"),
   898  //	}
   899  //	logFn("Set New Candidate ...")
   900  //	/** test SetCandidate */
   901  //	cans = append(cans, candidate)
   902  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
   903  //		errFn("SetCandidate err:", err)
   904  //	}
   905  //
   906  //	candidate2 := &types.Candidate{
   907  //		Deposit:     new(big.Int).SetUint64(101),
   908  //		BlockNumber: curr_blockNumber,
   909  //		CandidateId: nodeId1,
   910  //		TxIndex:     5,
   911  //		Host:        "10.0.0.1",
   912  //		Port:        "8548",
   913  //		Owner:       common.HexToAddress("0x15"),
   914  //	}
   915  //	logFn("Set New Candidate ...")
   916  //	/** test SetCandidate */
   917  //	cans = append(cans, candidate2)
   918  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
   919  //		errFn("SetCandidate err:", err)
   920  //	}
   921  //
   922  //	candidate3 := &types.Candidate{
   923  //		Deposit:     new(big.Int).SetUint64(102),
   924  //		BlockNumber: curr_blockNumber,
   925  //		CandidateId: nodeId2,
   926  //		TxIndex:     5,
   927  //		Host:        "10.0.0.1",
   928  //		Port:        "8548",
   929  //		Owner:       common.HexToAddress("0x15"),
   930  //	}
   931  //	logFn("Set New Candidate ...")
   932  //	/** test SetCandidate */
   933  //	cans = append(cans, candidate3)
   934  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
   935  //		errFn("SetCandidate err:", err)
   936  //	}
   937  //
   938  //	candidate4 := &types.Candidate{
   939  //		Deposit:     new(big.Int).SetUint64(120),
   940  //		BlockNumber: curr_blockNumber,
   941  //		CandidateId: nodeId3,
   942  //		TxIndex:     4,
   943  //		Host:        "10.0.0.1",
   944  //		Port:        "8548",
   945  //		Owner:       common.HexToAddress("0x15"),
   946  //	}
   947  //	logFn("Set New Candidate ...")
   948  //	/** test SetCandidate */
   949  //	cans = append(cans, candidate4)
   950  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
   951  //		errFn("SetCandidate err:", err)
   952  //	}
   953  //
   954  //	/** vote ticket */
   955  //	var count uint32 = 0
   956  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
   957  //	var blockNumber = new(big.Int).SetUint64(10)
   958  //	voteNum := 13
   959  //	timeMap := make(map[uint32]int64)
   960  //	fmt.Println("VOTING START .............................................................")
   961  //	for i := 0; i < voteNum; i++ {
   962  //		can := cans[rand.Intn(4)]
   963  //
   964  //		startTime := time.Now().UnixNano() / 1e6
   965  //		voteOwner := ownerList[rand.Intn(2)]
   966  //		deposit := new(big.Int).SetUint64(10)
   967  //		state.SubBalance(voteOwner, deposit)
   968  //		state.AddBalance(common.TicketPoolAddr, deposit)
   969  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
   970  //		if i < 2 {
   971  //			tempBlockNumber.SetUint64(6)
   972  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
   973  //		}
   974  //
   975  //		if i == 2 {
   976  //			fmt.Println("release ticket,start ############################################################")
   977  //			var tempBlockNumber uint64 = 6
   978  //			for i := 0; i < 4; i++ {
   979  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
   980  //				tempBlockNumber++
   981  //			}
   982  //			fmt.Println("release ticket,end ############################################################")
   983  //		}
   984  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
   985  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
   986  //		if nil != err {
   987  //			fmt.Println("vote ticket error:", err)
   988  //		}
   989  //		atomic.AddUint32(&count, 1)
   990  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
   991  //
   992  //	}
   993  //	fmt.Println("VOTING END .............................................................")
   994  //
   995  //	/** test Election */
   996  //	logFn("test Election ...")
   997  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
   998  //	logFn("Whether election was successful err", err)
   999  //
  1000  //	/** test GetWitness */
  1001  //	logFn("test GetWitness ...")
  1002  //	canArr, _ := candidatePoolContext.GetWitness(state, 1, blockNumber)
  1003  //	printObject("next Witnesses", canArr, logger)
  1004  //
  1005  //	/** test switch */
  1006  //	logFn("test Switch ...")
  1007  //	flag := candidatePoolContext.Switch(state, blockNumber)
  1008  //	logFn("Switch was success ", flag)
  1009  //
  1010  //	/** test GetWitness */
  1011  //	logFn("test GetWitness ...")
  1012  //	canArr, _ = candidatePoolContext.GetWitness(state, 0, blockNumber)
  1013  //	printObject(" current Witnesses", canArr, logger)
  1014  //
  1015  //	/** test Election */
  1016  //	logFn("test Election again ...")
  1017  //	_, err = candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
  1018  //	logFn("Whether election again was successful err", err)
  1019  //
  1020  //	/** test GetAllWitness */
  1021  //	logFn("test GetAllWitness ...")
  1022  //	preArr, curArr, nextArr, _ := candidatePoolContext.GetAllWitness(state, blockNumber)
  1023  //	printObject("previous Witness", preArr, logger)
  1024  //	printObject(" current Witnesses", curArr, logger)
  1025  //	printObject(" next Witnesses", nextArr, logger)
  1026  //}
  1027  //
  1028  //func TestCandidatePool_GetAllWitness(t *testing.T) {
  1029  //	candidate_GetAllWitness(t, t.Log, t.Error)
  1030  //}
  1031  //
  1032  //func BenchmarkCandidatePool_GetAllWitness(b *testing.B) {
  1033  //	candidate_GetAllWitness(b, b.Log, b.Error)
  1034  //}
  1035  //
  1036  //// test GetDefeat
  1037  //func candidate_GetDefeat(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1038  //	var candidatePoolContext *pposm.CandidatePoolContext
  1039  //	var ticketPoolContext *pposm.TicketPoolContext
  1040  //	var state *state.StateDB
  1041  //	if st, err := newChainState(); nil != err {
  1042  //		errFn("Getting stateDB err", err)
  1043  //	} else {
  1044  //		state = st
  1045  //	}
  1046  //	/** test init candidatePool and ticketPool */
  1047  //	candidatePoolContext, ticketPoolContext = newPool()
  1048  //
  1049  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1050  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  1051  //
  1052  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
  1053  //
  1054  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
  1055  //
  1056  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1057  //
  1058  //
  1059  //	// cache
  1060  //	cans := make([]*types.Candidate, 0)
  1061  //
  1062  //	candidate := &types.Candidate{
  1063  //		Deposit:     new(big.Int).SetUint64(100),
  1064  //		BlockNumber: curr_blockNumber,
  1065  //		CandidateId: nodeId5,
  1066  //		TxIndex:     6,
  1067  //		Host:        "10.0.0.1",
  1068  //		Port:        "8548",
  1069  //		Owner:       common.HexToAddress("0x12"),
  1070  //	}
  1071  //	logFn("Set New Candidate ...")
  1072  //	/** test SetCandidate */
  1073  //	cans = append(cans, candidate)
  1074  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1075  //		errFn("SetCandidate err:", err)
  1076  //	}
  1077  //
  1078  //	candidate2 := &types.Candidate{
  1079  //		Deposit:     new(big.Int).SetUint64(101),
  1080  //		BlockNumber: curr_blockNumber,
  1081  //		CandidateId: nodeId1,
  1082  //		TxIndex:     5,
  1083  //		Host:        "10.0.0.1",
  1084  //		Port:        "8548",
  1085  //		Owner:       common.HexToAddress("0x15"),
  1086  //	}
  1087  //	logFn("Set New Candidate ...")
  1088  //	/** test SetCandidate */
  1089  //	cans = append(cans, candidate2)
  1090  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  1091  //		errFn("SetCandidate err:", err)
  1092  //	}
  1093  //
  1094  //	candidate3 := &types.Candidate{
  1095  //		Deposit:     new(big.Int).SetUint64(102),
  1096  //		BlockNumber: curr_blockNumber,
  1097  //		CandidateId: nodeId2,
  1098  //		TxIndex:     5,
  1099  //		Host:        "10.0.0.1",
  1100  //		Port:        "8548",
  1101  //		Owner:       common.HexToAddress("0x15"),
  1102  //	}
  1103  //	logFn("Set New Candidate ...")
  1104  //	/** test SetCandidate */
  1105  //	cans = append(cans, candidate3)
  1106  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
  1107  //		errFn("SetCandidate err:", err)
  1108  //	}
  1109  //
  1110  //	candidate4 := &types.Candidate{
  1111  //		Deposit:     new(big.Int).SetUint64(120),
  1112  //		BlockNumber: curr_blockNumber,
  1113  //		CandidateId: nodeId3,
  1114  //		TxIndex:     4,
  1115  //		Host:        "10.0.0.1",
  1116  //		Port:        "8548",
  1117  //		Owner:       common.HexToAddress("0x15"),
  1118  //	}
  1119  //	logFn("Set New Candidate ...")
  1120  //	/** test SetCandidate */
  1121  //	cans = append(cans, candidate4)
  1122  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
  1123  //		errFn("SetCandidate err:", err)
  1124  //	}
  1125  //
  1126  //	/** vote ticket */
  1127  //	var count uint32 = 0
  1128  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
  1129  //	var blockNumber = new(big.Int).SetUint64(10)
  1130  //	voteNum := 13
  1131  //	timeMap := make(map[uint32]int64)
  1132  //	fmt.Println("VOTING START .............................................................")
  1133  //	for i := 0; i < voteNum; i++ {
  1134  //		can := cans[rand.Intn(4)]
  1135  //
  1136  //		startTime := time.Now().UnixNano() / 1e6
  1137  //		voteOwner := ownerList[rand.Intn(2)]
  1138  //		deposit := new(big.Int).SetUint64(10)
  1139  //		state.SubBalance(voteOwner, deposit)
  1140  //		state.AddBalance(common.TicketPoolAddr, deposit)
  1141  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
  1142  //		if i < 2 {
  1143  //			tempBlockNumber.SetUint64(6)
  1144  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
  1145  //		}
  1146  //
  1147  //		if i == 2 {
  1148  //			fmt.Println("release ticket,start ############################################################")
  1149  //			var tempBlockNumber uint64 = 6
  1150  //			for i := 0; i < 4; i++ {
  1151  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
  1152  //				tempBlockNumber++
  1153  //			}
  1154  //			fmt.Println("release ticket,end ############################################################")
  1155  //		}
  1156  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
  1157  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
  1158  //		if nil != err {
  1159  //			fmt.Println("vote ticket error:", err)
  1160  //		}
  1161  //		atomic.AddUint32(&count, 1)
  1162  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
  1163  //
  1164  //	}
  1165  //	fmt.Println("VOTING END .............................................................")
  1166  //
  1167  //	/** test Election */
  1168  //	logFn("test Election ...")
  1169  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
  1170  //	logFn("Whether election was successful err", err)
  1171  //
  1172  //	/**  */
  1173  //	printObject("candidatePool:", *candidatePoolContext, logger)
  1174  //	/** test MaxChair */
  1175  //	logFn("test MaxChair:", candidatePoolContext.MaxChair())
  1176  //	/**test Interval*/
  1177  //	logFn("test Interval:", candidatePoolContext.GetRefundInterval(blockNumber))
  1178  //
  1179  //	/** test switch */
  1180  //	logFn("test Switch ...")
  1181  //	flag := candidatePoolContext.Switch(state, blockNumber)
  1182  //	logFn("Switch was success ", flag)
  1183  //
  1184  //	/** test GetChairpersons */
  1185  //	logFn("test GetChairpersons ...")
  1186  //	canArr := candidatePoolContext.GetChairpersons(state, blockNumber)
  1187  //	printObject("Witnesses", canArr, logger)
  1188  //
  1189  //	/** test WithdrawCandidate */
  1190  //	logFn("test WithdrawCandidate ...")
  1191  //	ok1 := candidatePoolContext.WithdrawCandidate(state, nodeId5, new(big.Int).SetUint64(uint64(99)), new(big.Int).SetUint64(uint64(10)))
  1192  //	logFn("error", ok1)
  1193  //
  1194  //	/** test GetCandidate */
  1195  //	logFn("test GetCandidate ...")
  1196  //	can2 := candidatePoolContext.GetCandidate(state, nodeId5, blockNumber)
  1197  //	printObject("GetCandidate", can2, logger)
  1198  //
  1199  //	/** test GetDefeat */
  1200  //	logFn("test GetDefeat ...")
  1201  //	defeatArr:= candidatePoolContext.GetDefeat(state, nodeId5, blockNumber)
  1202  //	printObject("can be refund defeats", defeatArr, logger)
  1203  //
  1204  //	/** test IsDefeat */
  1205  //	logFn("test IsDefeat ...")
  1206  //	flag = candidatePoolContext.IsDefeat(state, nodeId5, blockNumber)
  1207  //	logFn("isdefeat", flag)
  1208  //
  1209  //	/** test RefundBalance */
  1210  //	logFn("test RefundBalance ...")
  1211  //	err = candidatePoolContext.RefundBalance(state, nodeId5, new(big.Int).SetUint64(uint64(11)))
  1212  //	logFn("RefundBalance err", err)
  1213  //
  1214  //	/** test RefundBalance again */
  1215  //	logFn("test RefundBalance again ...")
  1216  //	err = candidatePoolContext.RefundBalance(state, nodeId5, new(big.Int).SetUint64(uint64(11)))
  1217  //	logFn("RefundBalance again err", err)
  1218  //
  1219  //	/** test GetOwner */
  1220  //	logFn("test GetOwner ...")
  1221  //	addr := candidatePoolContext.GetOwner(state, nodeId5, blockNumber)
  1222  //	logFn("Benefit address", addr.String())
  1223  //
  1224  //	/**  test GetWitness */
  1225  //	logFn("test GetWitness ...")
  1226  //	nodeArr, _ := candidatePoolContext.GetWitness(state, 0, blockNumber)
  1227  //	printObject("nodeArr", nodeArr, logger)
  1228  //}
  1229  //
  1230  //func TestGetDefeat(t *testing.T) {
  1231  //	candidate_GetDefeat(t, t.Log, t.Error)
  1232  //}
  1233  //
  1234  //func BenchmarkCandidatePool_GetDefeat(b *testing.B) {
  1235  //	candidate_GetDefeat(b, b.Log, b.Error)
  1236  //}
  1237  //
  1238  //// test GetOwner
  1239  //func candidate_GetOwner(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1240  //	var candidatePoolContext *pposm.CandidatePoolContext
  1241  //	//var ticketPoolContext *pposm.TicketPoolContext
  1242  //	var state *state.StateDB
  1243  //	if st, err := newChainState(); nil != err {
  1244  //		errFn("Getting stateDB err", err)
  1245  //	} else {
  1246  //		state = st
  1247  //	}
  1248  //	/** test init candidatePool and ticketPool */
  1249  //	candidatePoolContext, _ = newPool()
  1250  //
  1251  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1252  //
  1253  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1254  //
  1255  //
  1256  //	// cache
  1257  //	cans := make([]*types.Candidate, 0)
  1258  //
  1259  //	candidate := &types.Candidate{
  1260  //		Deposit:     new(big.Int).SetUint64(100),
  1261  //		BlockNumber: curr_blockNumber,
  1262  //		CandidateId: nodeId5,
  1263  //		TxIndex:     6,
  1264  //		Host:        "10.0.0.1",
  1265  //		Port:        "8548",
  1266  //		Owner:       common.HexToAddress("0x12"),
  1267  //	}
  1268  //	logFn("Set New Candidate ...")
  1269  //	/** test SetCandidate */
  1270  //	cans = append(cans, candidate)
  1271  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1272  //		errFn("SetCandidate err:", err)
  1273  //	}
  1274  //
  1275  //	/** test GetOwner */
  1276  //	ownerAddr := candidatePoolContext.GetOwner(state, candidate.CandidateId, curr_blockNumber)
  1277  //	logFn("Getting Onwer's Address:", ownerAddr.String())
  1278  //}
  1279  //
  1280  //func TestCandidatePool_GetOwner(t *testing.T) {
  1281  //	candidate_GetOwner(t, t.Log, t.Error)
  1282  //}
  1283  //
  1284  //func BenchmarkCandidatePool_GetOwner(b *testing.B) {
  1285  //	candidate_GetOwner(b, b.Log, b.Error)
  1286  //}
  1287  //
  1288  //// test GetRefundInterval
  1289  //func candidate_GetRefundInterval(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1290  //	var candidatePoolContext *pposm.CandidatePoolContext
  1291  //	//var ticketPoolContext *pposm.TicketPoolContext
  1292  //	var state *state.StateDB
  1293  //	if st, err := newChainState(); nil != err {
  1294  //		errFn("Getting stateDB err", err)
  1295  //	} else {
  1296  //		state = st
  1297  //	}
  1298  //	/** test init candidatePool and ticketPool */
  1299  //	candidatePoolContext, _ = newPool()
  1300  //
  1301  //	/** test  GetRefundInterval*/
  1302  //	num := candidatePoolContext.GetRefundInterval(big.NewInt(10))
  1303  //	logFn("RefundInterval:", num)
  1304  //	fmt.Println(state.Error())
  1305  //}
  1306  //
  1307  //func TestCandidatePool_GetRefundInterval(t *testing.T) {
  1308  //	candidate_GetRefundInterval(t, t.Log, t.Error)
  1309  //}
  1310  //
  1311  //func BenchmarkCandidatePool_GetRefundInterval(b *testing.B) {
  1312  //	candidate_GetRefundInterval(b, b.Log, b.Error)
  1313  //}
  1314  //
  1315  //// test MaxChair
  1316  //func candidate_MaxChair(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1317  //	var candidatePoolContext *pposm.CandidatePoolContext
  1318  //	//var ticketPoolContext *pposm.TicketPoolContext
  1319  //	var state *state.StateDB
  1320  //	if st, err := newChainState(); nil != err {
  1321  //		errFn("Getting stateDB err", err)
  1322  //	} else {
  1323  //		state = st
  1324  //	}
  1325  //	/** test init candidatePool and ticketPool */
  1326  //	candidatePoolContext, _ = newPool()
  1327  //
  1328  //	/** test  MaxChair*/
  1329  //	num := candidatePoolContext.MaxChair()
  1330  //	logFn("MaxChair:", num)
  1331  //	fmt.Println(state.Error())
  1332  //}
  1333  //
  1334  //func TestCandidatePool_MaxChair(t *testing.T) {
  1335  //	candidate_MaxChair(t, t.Log, t.Error)
  1336  //}
  1337  //
  1338  //func BenchmarkCandidatePool_MaxChair(b *testing.B) {
  1339  //	candidate_MaxChair(b, b.Log, b.Error)
  1340  //}
  1341  //
  1342  //// test IsChosens
  1343  //func candidate_IsChosens(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1344  //	var candidatePoolContext *pposm.CandidatePoolContext
  1345  //	//var ticketPoolContext *pposm.TicketPoolContext
  1346  //	var state *state.StateDB
  1347  //	if st, err := newChainState(); nil != err {
  1348  //		errFn("Getting stateDB err", err)
  1349  //	} else {
  1350  //		state = st
  1351  //	}
  1352  //	/** test init candidatePool and ticketPool */
  1353  //	candidatePoolContext, _ = newPool()
  1354  //
  1355  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1356  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  1357  //
  1358  //
  1359  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1360  //
  1361  //
  1362  //	candidate := &types.Candidate{
  1363  //		Deposit:     new(big.Int).SetUint64(100),
  1364  //		BlockNumber: curr_blockNumber,
  1365  //		CandidateId: nodeId5,
  1366  //		TxIndex:     6,
  1367  //		Host:        "10.0.0.1",
  1368  //		Port:        "8548",
  1369  //		Owner:       common.HexToAddress("0x12"),
  1370  //	}
  1371  //	logFn("Set New Candidate ...")
  1372  //	/** test SetCandidate */
  1373  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1374  //		errFn("SetCandidate err:", err)
  1375  //	}
  1376  //
  1377  //	candidate2 := &types.Candidate{
  1378  //		Deposit:     new(big.Int).SetUint64(101),
  1379  //		BlockNumber: curr_blockNumber,
  1380  //		CandidateId: nodeId1,
  1381  //		TxIndex:     5,
  1382  //		Host:        "10.0.0.1",
  1383  //		Port:        "8548",
  1384  //		Owner:       common.HexToAddress("0x15"),
  1385  //	}
  1386  //	logFn("Set New Candidate ...")
  1387  //	/** test SetCandidate */
  1388  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  1389  //		errFn("SetCandidate err:", err)
  1390  //	}
  1391  //
  1392  //	/** test GetChosens */
  1393  //	logFn("test IsChosens ...")
  1394  //	flag := candidatePoolContext.IsChosens(state, candidate2.CandidateId, curr_blockNumber)
  1395  //	logFn("IsChosens success", flag)
  1396  //}
  1397  //
  1398  //func TestCandidatePool_IsChosens(t *testing.T) {
  1399  //	candidate_IsChosens(t, t.Log, t.Error)
  1400  //}
  1401  //
  1402  //func BenchmarkCandidatePool_IsChosens(b *testing.B) {
  1403  //	candidate_IsChosens(b, b.Log, b.Error)
  1404  //}
  1405  //
  1406  //// test IsDefeat
  1407  //func candidate_IsDefeat(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1408  //	var candidatePoolContext *pposm.CandidatePoolContext
  1409  //	var ticketPoolContext *pposm.TicketPoolContext
  1410  //	var state *state.StateDB
  1411  //	if st, err := newChainState(); nil != err {
  1412  //		errFn("Getting stateDB err", err)
  1413  //	} else {
  1414  //		state = st
  1415  //	}
  1416  //	/** test init candidatePool and ticketPool */
  1417  //	candidatePoolContext, ticketPoolContext = newPool()
  1418  //
  1419  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1420  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  1421  //
  1422  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
  1423  //
  1424  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
  1425  //
  1426  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1427  //
  1428  //
  1429  //	// cache
  1430  //	cans := make([]*types.Candidate, 0)
  1431  //
  1432  //	candidate := &types.Candidate{
  1433  //		Deposit:     new(big.Int).SetUint64(100),
  1434  //		BlockNumber: curr_blockNumber,
  1435  //		CandidateId: nodeId5,
  1436  //		TxIndex:     6,
  1437  //		Host:        "10.0.0.1",
  1438  //		Port:        "8548",
  1439  //		Owner:       common.HexToAddress("0x12"),
  1440  //	}
  1441  //	logFn("Set New Candidate ...")
  1442  //	/** test SetCandidate */
  1443  //	cans = append(cans, candidate)
  1444  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1445  //		errFn("SetCandidate err:", err)
  1446  //	}
  1447  //
  1448  //	candidate2 := &types.Candidate{
  1449  //		Deposit:     new(big.Int).SetUint64(101),
  1450  //		BlockNumber: curr_blockNumber,
  1451  //		CandidateId: nodeId1,
  1452  //		TxIndex:     5,
  1453  //		Host:        "10.0.0.1",
  1454  //		Port:        "8548",
  1455  //		Owner:       common.HexToAddress("0x15"),
  1456  //	}
  1457  //	logFn("Set New Candidate ...")
  1458  //	/** test SetCandidate */
  1459  //	cans = append(cans, candidate2)
  1460  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  1461  //		errFn("SetCandidate err:", err)
  1462  //	}
  1463  //
  1464  //	candidate3 := &types.Candidate{
  1465  //		Deposit:     new(big.Int).SetUint64(102),
  1466  //		BlockNumber: curr_blockNumber,
  1467  //		CandidateId: nodeId2,
  1468  //		TxIndex:     5,
  1469  //		Host:        "10.0.0.1",
  1470  //		Port:        "8548",
  1471  //		Owner:       common.HexToAddress("0x15"),
  1472  //	}
  1473  //	logFn("Set New Candidate ...")
  1474  //	/** test SetCandidate */
  1475  //	cans = append(cans, candidate3)
  1476  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
  1477  //		errFn("SetCandidate err:", err)
  1478  //	}
  1479  //
  1480  //	candidate4 := &types.Candidate{
  1481  //		Deposit:     new(big.Int).SetUint64(120),
  1482  //		BlockNumber: curr_blockNumber,
  1483  //		CandidateId: nodeId3,
  1484  //		TxIndex:     4,
  1485  //		Host:        "10.0.0.1",
  1486  //		Port:        "8548",
  1487  //		Owner:       common.HexToAddress("0x15"),
  1488  //	}
  1489  //	logFn("Set New Candidate ...")
  1490  //	/** test SetCandidate */
  1491  //	cans = append(cans, candidate4)
  1492  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
  1493  //		errFn("SetCandidate err:", err)
  1494  //	}
  1495  //
  1496  //	/** vote ticket */
  1497  //	var count uint32 = 0
  1498  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
  1499  //	var blockNumber = new(big.Int).SetUint64(10)
  1500  //	voteNum := 13
  1501  //	timeMap := make(map[uint32]int64)
  1502  //	fmt.Println("VOTING START .............................................................")
  1503  //	for i := 0; i < voteNum; i++ {
  1504  //		can := cans[rand.Intn(4)]
  1505  //
  1506  //		startTime := time.Now().UnixNano() / 1e6
  1507  //		voteOwner := ownerList[rand.Intn(2)]
  1508  //		deposit := new(big.Int).SetUint64(10)
  1509  //		state.SubBalance(voteOwner, deposit)
  1510  //		state.AddBalance(common.TicketPoolAddr, deposit)
  1511  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
  1512  //		if i < 2 {
  1513  //			tempBlockNumber.SetUint64(6)
  1514  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
  1515  //		}
  1516  //
  1517  //		if i == 2 {
  1518  //			fmt.Println("release ticket,start ############################################################")
  1519  //			var tempBlockNumber uint64 = 6
  1520  //			for i := 0; i < 4; i++ {
  1521  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
  1522  //				tempBlockNumber++
  1523  //			}
  1524  //			fmt.Println("release ticket,end ############################################################")
  1525  //		}
  1526  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
  1527  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
  1528  //		if nil != err {
  1529  //			fmt.Println("vote ticket error:", err)
  1530  //		}
  1531  //		atomic.AddUint32(&count, 1)
  1532  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
  1533  //
  1534  //	}
  1535  //	fmt.Println("VOTING END .............................................................")
  1536  //
  1537  //	/** test Election */
  1538  //	logFn("test Election ...")
  1539  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
  1540  //	logFn("Whether election was successful err", err)
  1541  //
  1542  //	/**  */
  1543  //	printObject("candidatePool:", *candidatePoolContext, logger)
  1544  //	/** test MaxChair */
  1545  //	logFn("test MaxChair:", candidatePoolContext.MaxChair())
  1546  //	/**test Interval*/
  1547  //	logFn("test Interval:", candidatePoolContext.GetRefundInterval(blockNumber))
  1548  //
  1549  //	/** test switch */
  1550  //	logFn("test Switch ...")
  1551  //	flag := candidatePoolContext.Switch(state, blockNumber)
  1552  //	logFn("Switch was success ", flag)
  1553  //
  1554  //	/** test GetChairpersons */
  1555  //	logFn("test GetChairpersons ...")
  1556  //	canArr := candidatePoolContext.GetChairpersons(state, blockNumber)
  1557  //	printObject("Witnesses", canArr, logger)
  1558  //
  1559  //	/** test WithdrawCandidate */
  1560  //	logFn("test WithdrawCandidate ...")
  1561  //	ok1 := candidatePoolContext.WithdrawCandidate(state, nodeId5, new(big.Int).SetUint64(uint64(99)), new(big.Int).SetUint64(uint64(10)))
  1562  //	logFn("error", ok1)
  1563  //
  1564  //	/** test GetCandidate */
  1565  //	logFn("test GetCandidate ...")
  1566  //	can2 := candidatePoolContext.GetCandidate(state, nodeId5, blockNumber)
  1567  //	printObject("GetCandidate", can2, logger)
  1568  //
  1569  //	/** test GetDefeat */
  1570  //	logFn("test GetDefeat ...")
  1571  //	defeatArr := candidatePoolContext.GetDefeat(state, nodeId5, blockNumber)
  1572  //	printObject("can be refund defeats", defeatArr, logger)
  1573  //
  1574  //	/** test IsDefeat */
  1575  //	logFn("test IsDefeat ...")
  1576  //	flag = candidatePoolContext.IsDefeat(state, nodeId5, blockNumber)
  1577  //	logFn("isdefeat", flag)
  1578  //}
  1579  //
  1580  //func TestCandidatePool_IsDefeat(t *testing.T) {
  1581  //	candidate_IsDefeat(t, t.Log, t.Error)
  1582  //}
  1583  //
  1584  //func BenchmarkCandidatePool_IsDefeat(b *testing.B) {
  1585  //	candidate_IsDefeat(b, b.Log, b.Error)
  1586  //}
  1587  //
  1588  //// test RefundBalance
  1589  //func candidate_RefundBalance(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1590  //	var candidatePoolContext *pposm.CandidatePoolContext
  1591  //	var ticketPoolContext *pposm.TicketPoolContext
  1592  //	var state *state.StateDB
  1593  //	if st, err := newChainState(); nil != err {
  1594  //		errFn("Getting stateDB err", err)
  1595  //	} else {
  1596  //		state = st
  1597  //	}
  1598  //	/** test init candidatePool and ticketPool */
  1599  //	candidatePoolContext, ticketPoolContext = newPool()
  1600  //
  1601  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1602  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  1603  //
  1604  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
  1605  //
  1606  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
  1607  //
  1608  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1609  //
  1610  //
  1611  //	// cache
  1612  //	cans := make([]*types.Candidate, 0)
  1613  //
  1614  //	candidate := &types.Candidate{
  1615  //		Deposit:     new(big.Int).SetUint64(100),
  1616  //		BlockNumber: curr_blockNumber,
  1617  //		CandidateId: nodeId5,
  1618  //		TxIndex:     6,
  1619  //		Host:        "10.0.0.1",
  1620  //		Port:        "8548",
  1621  //		Owner:       common.HexToAddress("0x12"),
  1622  //	}
  1623  //	logFn("Set New Candidate ...")
  1624  //	/** test SetCandidate */
  1625  //	cans = append(cans, candidate)
  1626  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1627  //		errFn("SetCandidate err:", err)
  1628  //	}
  1629  //
  1630  //	candidate2 := &types.Candidate{
  1631  //		Deposit:     new(big.Int).SetUint64(101),
  1632  //		BlockNumber: curr_blockNumber,
  1633  //		CandidateId: nodeId1,
  1634  //		TxIndex:     5,
  1635  //		Host:        "10.0.0.1",
  1636  //		Port:        "8548",
  1637  //		Owner:       common.HexToAddress("0x15"),
  1638  //	}
  1639  //	logFn("Set New Candidate ...")
  1640  //	/** test SetCandidate */
  1641  //	cans = append(cans, candidate2)
  1642  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  1643  //		errFn("SetCandidate err:", err)
  1644  //	}
  1645  //
  1646  //	candidate3 := &types.Candidate{
  1647  //		Deposit:     new(big.Int).SetUint64(102),
  1648  //		BlockNumber: curr_blockNumber,
  1649  //		CandidateId: nodeId2,
  1650  //		TxIndex:     5,
  1651  //		Host:        "10.0.0.1",
  1652  //		Port:        "8548",
  1653  //		Owner:       common.HexToAddress("0x15"),
  1654  //	}
  1655  //	logFn("Set New Candidate ...")
  1656  //	/** test SetCandidate */
  1657  //	cans = append(cans, candidate3)
  1658  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
  1659  //		errFn("SetCandidate err:", err)
  1660  //	}
  1661  //
  1662  //	candidate4 := &types.Candidate{
  1663  //		Deposit:     new(big.Int).SetUint64(120),
  1664  //		BlockNumber: curr_blockNumber,
  1665  //		CandidateId: nodeId3,
  1666  //		TxIndex:     4,
  1667  //		Host:        "10.0.0.1",
  1668  //		Port:        "8548",
  1669  //		Owner:       common.HexToAddress("0x15"),
  1670  //	}
  1671  //	logFn("Set New Candidate ...")
  1672  //	/** test SetCandidate */
  1673  //	cans = append(cans, candidate4)
  1674  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
  1675  //		errFn("SetCandidate err:", err)
  1676  //	}
  1677  //
  1678  //	/** vote ticket */
  1679  //	var count uint32 = 0
  1680  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
  1681  //	var blockNumber = new(big.Int).SetUint64(10)
  1682  //	voteNum := 13
  1683  //	timeMap := make(map[uint32]int64)
  1684  //	fmt.Println("VOTING START .............................................................")
  1685  //	for i := 0; i < voteNum; i++ {
  1686  //		can := cans[rand.Intn(4)]
  1687  //
  1688  //		startTime := time.Now().UnixNano() / 1e6
  1689  //		voteOwner := ownerList[rand.Intn(2)]
  1690  //		deposit := new(big.Int).SetUint64(10)
  1691  //		state.SubBalance(voteOwner, deposit)
  1692  //		state.AddBalance(common.TicketPoolAddr, deposit)
  1693  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
  1694  //		if i < 2 {
  1695  //			tempBlockNumber.SetUint64(6)
  1696  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
  1697  //		}
  1698  //
  1699  //		if i == 2 {
  1700  //			fmt.Println("release ticket,start ############################################################")
  1701  //			var tempBlockNumber uint64 = 6
  1702  //			for i := 0; i < 4; i++ {
  1703  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
  1704  //				tempBlockNumber++
  1705  //			}
  1706  //			fmt.Println("release ticket,end ############################################################")
  1707  //		}
  1708  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
  1709  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
  1710  //		if nil != err {
  1711  //			fmt.Println("vote ticket error:", err)
  1712  //		}
  1713  //		atomic.AddUint32(&count, 1)
  1714  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
  1715  //
  1716  //	}
  1717  //	fmt.Println("VOTING END .............................................................")
  1718  //
  1719  //	/** test Election */
  1720  //	logFn("test Election ...")
  1721  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
  1722  //	logFn("Whether election was successful err", err)
  1723  //
  1724  //	/**  */
  1725  //	printObject("candidatePool:", *candidatePoolContext, logger)
  1726  //	/** test MaxChair */
  1727  //	logFn("test MaxChair:", candidatePoolContext.MaxChair())
  1728  //	/**test Interval*/
  1729  //	logFn("test Interval:", candidatePoolContext.GetRefundInterval(blockNumber))
  1730  //
  1731  //	/** test switch */
  1732  //	logFn("test Switch ...")
  1733  //	flag := candidatePoolContext.Switch(state, blockNumber)
  1734  //	logFn("Switch was success ", flag)
  1735  //
  1736  //	/** test GetChairpersons */
  1737  //	logFn("test GetChairpersons ...")
  1738  //	canArr := candidatePoolContext.GetChairpersons(state, blockNumber)
  1739  //	printObject("Witnesses", canArr, logger)
  1740  //
  1741  //	/** test WithdrawCandidate */
  1742  //	logFn("test WithdrawCandidate ...")
  1743  //	ok1 := candidatePoolContext.WithdrawCandidate(state, nodeId5, new(big.Int).SetUint64(uint64(99)), new(big.Int).SetUint64(uint64(10)))
  1744  //	logFn("error", ok1)
  1745  //
  1746  //	/** test GetCandidate */
  1747  //	logFn("test GetCandidate ...")
  1748  //	can2 := candidatePoolContext.GetCandidate(state, nodeId5, blockNumber)
  1749  //	printObject("GetCandidate", can2, logger)
  1750  //
  1751  //	/** test GetDefeat */
  1752  //	logFn("test GetDefeat ...")
  1753  //	defeatArr := candidatePoolContext.GetDefeat(state, nodeId5, blockNumber)
  1754  //	printObject("can be refund defeats", defeatArr, logger)
  1755  //
  1756  //	/** test IsDefeat */
  1757  //	logFn("test IsDefeat ...")
  1758  //	flag = candidatePoolContext.IsDefeat(state, nodeId5, blockNumber)
  1759  //	logFn("isdefeat", flag)
  1760  //
  1761  //	/** test RefundBalance */
  1762  //	logFn("test RefundBalance ...")
  1763  //	err = candidatePoolContext.RefundBalance(state, nodeId5, new(big.Int).SetUint64(uint64(11)))
  1764  //	logFn("RefundBalance err", err)
  1765  //
  1766  //	/** test RefundBalance again */
  1767  //	logFn("test RefundBalance again ...")
  1768  //	err = candidatePoolContext.RefundBalance(state, nodeId5, new(big.Int).SetUint64(uint64(11)))
  1769  //	logFn("RefundBalance again err", err)
  1770  //}
  1771  //
  1772  //func TestCandidatePool_RefundBalance(t *testing.T) {
  1773  //	candidate_RefundBalance(t, t.Log, t.Error)
  1774  //}
  1775  //
  1776  //func BenchmarkCandidatePool_RefundBalance(b *testing.B) {
  1777  //	candidate_RefundBalance(b, b.Log, b.Error)
  1778  //}
  1779  //
  1780  //// test UpdateElectedQueue
  1781  //func candidate_UpdateElectedQueue(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1782  //	var candidatePoolContext *pposm.CandidatePoolContext
  1783  //	var ticketPoolContext *pposm.TicketPoolContext
  1784  //	var state *state.StateDB
  1785  //	if st, err := newChainState(); nil != err {
  1786  //		errFn("Getting stateDB err", err)
  1787  //	} else {
  1788  //		state = st
  1789  //	}
  1790  //	/** test init candidatePool and ticketPool */
  1791  //	candidatePoolContext, ticketPoolContext = newPool()
  1792  //
  1793  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1794  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  1795  //
  1796  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
  1797  //
  1798  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
  1799  //
  1800  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1801  //
  1802  //
  1803  //	// cache
  1804  //	cans := make([]*types.Candidate, 0)
  1805  //
  1806  //	candidate := &types.Candidate{
  1807  //		Deposit:     new(big.Int).SetUint64(100),
  1808  //		BlockNumber: curr_blockNumber,
  1809  //		CandidateId: nodeId5,
  1810  //		TxIndex:     6,
  1811  //		Host:        "10.0.0.1",
  1812  //		Port:        "8548",
  1813  //		Owner:       common.HexToAddress("0x12"),
  1814  //	}
  1815  //	logFn("Set New Candidate ...")
  1816  //	/** test SetCandidate */
  1817  //	cans = append(cans, candidate)
  1818  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1819  //		errFn("SetCandidate err:", err)
  1820  //	}
  1821  //
  1822  //	candidate2 := &types.Candidate{
  1823  //		Deposit:     new(big.Int).SetUint64(101),
  1824  //		BlockNumber: curr_blockNumber,
  1825  //		CandidateId: nodeId1,
  1826  //		TxIndex:     5,
  1827  //		Host:        "10.0.0.1",
  1828  //		Port:        "8548",
  1829  //		Owner:       common.HexToAddress("0x15"),
  1830  //	}
  1831  //	logFn("Set New Candidate ...")
  1832  //	/** test SetCandidate */
  1833  //	cans = append(cans, candidate2)
  1834  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  1835  //		errFn("SetCandidate err:", err)
  1836  //	}
  1837  //
  1838  //	candidate3 := &types.Candidate{
  1839  //		Deposit:     new(big.Int).SetUint64(102),
  1840  //		BlockNumber: curr_blockNumber,
  1841  //		CandidateId: nodeId2,
  1842  //		TxIndex:     5,
  1843  //		Host:        "10.0.0.1",
  1844  //		Port:        "8548",
  1845  //		Owner:       common.HexToAddress("0x15"),
  1846  //	}
  1847  //	logFn("Set New Candidate ...")
  1848  //	/** test SetCandidate */
  1849  //	cans = append(cans, candidate3)
  1850  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
  1851  //		errFn("SetCandidate err:", err)
  1852  //	}
  1853  //
  1854  //	candidate4 := &types.Candidate{
  1855  //		Deposit:     new(big.Int).SetUint64(120),
  1856  //		BlockNumber: curr_blockNumber,
  1857  //		CandidateId: nodeId3,
  1858  //		TxIndex:     4,
  1859  //		Host:        "10.0.0.1",
  1860  //		Port:        "8548",
  1861  //		Owner:       common.HexToAddress("0x15"),
  1862  //	}
  1863  //	logFn("Set New Candidate ...")
  1864  //	/** test SetCandidate */
  1865  //	cans = append(cans, candidate4)
  1866  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
  1867  //		errFn("SetCandidate err:", err)
  1868  //	}
  1869  //
  1870  //	/** vote ticket */
  1871  //	var count uint32 = 0
  1872  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
  1873  //	var blockNumber = new(big.Int).SetUint64(10)
  1874  //	voteNum := 13
  1875  //	timeMap := make(map[uint32]int64)
  1876  //	fmt.Println("VOTING START .............................................................")
  1877  //	for i := 0; i < voteNum; i++ {
  1878  //		can := cans[rand.Intn(4)]
  1879  //
  1880  //		startTime := time.Now().UnixNano() / 1e6
  1881  //		voteOwner := ownerList[rand.Intn(2)]
  1882  //		deposit := new(big.Int).SetUint64(10)
  1883  //		state.SubBalance(voteOwner, deposit)
  1884  //		state.AddBalance(common.TicketPoolAddr, deposit)
  1885  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
  1886  //		if i < 2 {
  1887  //			tempBlockNumber.SetUint64(6)
  1888  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
  1889  //		}
  1890  //
  1891  //		if i == 2 {
  1892  //			fmt.Println("release ticket,start ############################################################")
  1893  //			var tempBlockNumber uint64 = 6
  1894  //			for i := 0; i < 4; i++ {
  1895  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
  1896  //				tempBlockNumber++
  1897  //			}
  1898  //			fmt.Println("release ticket,end ############################################################")
  1899  //		}
  1900  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
  1901  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
  1902  //		if nil != err {
  1903  //			fmt.Println("vote ticket error:", err)
  1904  //		}
  1905  //		atomic.AddUint32(&count, 1)
  1906  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
  1907  //
  1908  //	}
  1909  //	fmt.Println("VOTING END .............................................................")
  1910  //	/** test GetCandidate */
  1911  //	logFn("test GetCandidate ...")
  1912  //	can := candidatePoolContext.GetCandidate(state, nodeId1, blockNumber)
  1913  //	logFn("GetCandidate", can)
  1914  //
  1915  //	/** test UpdateElectedQueue */
  1916  //	logFn("test UpdateElectedQueue")
  1917  //	if err := candidatePoolContext.UpdateElectedQueue(state, big.NewInt(11), []discover.NodeID{candidate2.CandidateId, candidate3.CandidateId}...); nil != err {
  1918  //		errFn("UpdateElectedQueue err", err)
  1919  //	} else {
  1920  //		logFn("test UpdateElectedQueue success")
  1921  //	}
  1922  //}
  1923  //
  1924  //func TestCandidatePool_UpdateElectedQueue(t *testing.T) {
  1925  //	candidate_UpdateElectedQueue(t, t.Log, t.Error)
  1926  //}
  1927  //
  1928  //func BenchmarkCandidatePool_UpdateElectedQueue(b *testing.B) {
  1929  //	candidate_UpdateElectedQueue(b, b.Log, b.Error)
  1930  //}
  1931  //
  1932  //// test Election
  1933  //func candidate_Election(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  1934  //	var candidatePoolContext *pposm.CandidatePoolContext
  1935  //	var ticketPoolContext *pposm.TicketPoolContext
  1936  //	var state *state.StateDB
  1937  //	if st, err := newChainState(); nil != err {
  1938  //		errFn("Getting stateDB err", err)
  1939  //	} else {
  1940  //		state = st
  1941  //	}
  1942  //	/** test init candidatePool and ticketPool */
  1943  //	candidatePoolContext, ticketPoolContext = newPool()
  1944  //
  1945  //	curr_blockNumber := new(big.Int).SetUint64(7)
  1946  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  1947  //
  1948  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
  1949  //
  1950  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
  1951  //
  1952  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  1953  //
  1954  //
  1955  //	// cache
  1956  //	cans := make([]*types.Candidate, 0)
  1957  //
  1958  //	candidate := &types.Candidate{
  1959  //		Deposit:     new(big.Int).SetUint64(100),
  1960  //		BlockNumber: curr_blockNumber,
  1961  //		CandidateId: nodeId5,
  1962  //		TxIndex:     6,
  1963  //		Host:        "10.0.0.1",
  1964  //		Port:        "8548",
  1965  //		Owner:       common.HexToAddress("0x12"),
  1966  //	}
  1967  //	logFn("Set New Candidate ...")
  1968  //	/** test SetCandidate */
  1969  //	cans = append(cans, candidate)
  1970  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  1971  //		errFn("SetCandidate err:", err)
  1972  //	}
  1973  //
  1974  //	candidate2 := &types.Candidate{
  1975  //		Deposit:     new(big.Int).SetUint64(101),
  1976  //		BlockNumber: curr_blockNumber,
  1977  //		CandidateId: nodeId1,
  1978  //		TxIndex:     5,
  1979  //		Host:        "10.0.0.1",
  1980  //		Port:        "8548",
  1981  //		Owner:       common.HexToAddress("0x15"),
  1982  //	}
  1983  //	logFn("Set New Candidate ...")
  1984  //	/** test SetCandidate */
  1985  //	cans = append(cans, candidate2)
  1986  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  1987  //		errFn("SetCandidate err:", err)
  1988  //	}
  1989  //
  1990  //	candidate3 := &types.Candidate{
  1991  //		Deposit:     new(big.Int).SetUint64(102),
  1992  //		BlockNumber: curr_blockNumber,
  1993  //		CandidateId: nodeId2,
  1994  //		TxIndex:     5,
  1995  //		Host:        "10.0.0.1",
  1996  //		Port:        "8548",
  1997  //		Owner:       common.HexToAddress("0x15"),
  1998  //	}
  1999  //	logFn("Set New Candidate ...")
  2000  //	/** test SetCandidate */
  2001  //	cans = append(cans, candidate3)
  2002  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
  2003  //		errFn("SetCandidate err:", err)
  2004  //	}
  2005  //
  2006  //	candidate4 := &types.Candidate{
  2007  //		Deposit:     new(big.Int).SetUint64(120),
  2008  //		BlockNumber: curr_blockNumber,
  2009  //		CandidateId: nodeId3,
  2010  //		TxIndex:     4,
  2011  //		Host:        "10.0.0.1",
  2012  //		Port:        "8548",
  2013  //		Owner:       common.HexToAddress("0x15"),
  2014  //	}
  2015  //	logFn("Set New Candidate ...")
  2016  //	/** test SetCandidate */
  2017  //	cans = append(cans, candidate4)
  2018  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
  2019  //		errFn("SetCandidate err:", err)
  2020  //	}
  2021  //
  2022  //	/** vote ticket */
  2023  //	var count uint32 = 0
  2024  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
  2025  //	var blockNumber = new(big.Int).SetUint64(10)
  2026  //	voteNum := 13
  2027  //	timeMap := make(map[uint32]int64)
  2028  //	fmt.Println("VOTING START .............................................................")
  2029  //	for i := 0; i < voteNum; i++ {
  2030  //		can := cans[rand.Intn(4)]
  2031  //
  2032  //		startTime := time.Now().UnixNano() / 1e6
  2033  //		voteOwner := ownerList[rand.Intn(2)]
  2034  //		deposit := new(big.Int).SetUint64(10)
  2035  //		state.SubBalance(voteOwner, deposit)
  2036  //		state.AddBalance(common.TicketPoolAddr, deposit)
  2037  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
  2038  //		if i < 2 {
  2039  //			tempBlockNumber.SetUint64(6)
  2040  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
  2041  //		}
  2042  //
  2043  //		if i == 2 {
  2044  //			fmt.Println("release ticket,start ############################################################")
  2045  //			var tempBlockNumber uint64 = 6
  2046  //			for i := 0; i < 4; i++ {
  2047  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
  2048  //				tempBlockNumber++
  2049  //			}
  2050  //			fmt.Println("release ticket,end ############################################################")
  2051  //		}
  2052  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
  2053  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
  2054  //		if nil != err {
  2055  //			fmt.Println("vote ticket error:", err)
  2056  //		}
  2057  //		atomic.AddUint32(&count, 1)
  2058  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
  2059  //
  2060  //	}
  2061  //	fmt.Println("VOTING END .............................................................")
  2062  //
  2063  //	/** test Election */
  2064  //	logFn("test Election ...")
  2065  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
  2066  //	logFn("Whether election was successful err", err)
  2067  //
  2068  //	arr, _ := candidatePoolContext.GetWitness(state, 1, blockNumber)
  2069  //	fmt.Println(arr)
  2070  //}
  2071  //
  2072  //func TestCandidatePool_Election(t *testing.T) {
  2073  //	candidate_Election(t, t.Log, t.Error)
  2074  //}
  2075  //
  2076  //func BenchmarkCandidatePool_Election(b *testing.B) {
  2077  //	candidate_Election(b, b.Log, b.Error)
  2078  //}
  2079  //
  2080  //// test Switch
  2081  //func candidate_Switch(logger interface{}, logFn func(args ...interface{}), errFn func(args ...interface{})) {
  2082  //	var candidatePoolContext *pposm.CandidatePoolContext
  2083  //	var ticketPoolContext *pposm.TicketPoolContext
  2084  //	var state *state.StateDB
  2085  //	if st, err := newChainState(); nil != err {
  2086  //		errFn("Getting stateDB err", err)
  2087  //	} else {
  2088  //		state = st
  2089  //	}
  2090  //	/** test init candidatePool and ticketPool */
  2091  //	candidatePoolContext, ticketPoolContext = newPool()
  2092  //
  2093  //	curr_blockNumber := new(big.Int).SetUint64(7)
  2094  //	nodeId1 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341")
  2095  //
  2096  //	nodeId2 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012342")
  2097  //
  2098  //	nodeId3 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012343")
  2099  //
  2100  //	nodeId5 := discover.MustHexID("0x01234567890121345678901123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345")
  2101  //
  2102  //
  2103  //	// cache
  2104  //	cans := make([]*types.Candidate, 0)
  2105  //
  2106  //	candidate := &types.Candidate{
  2107  //		Deposit:     new(big.Int).SetUint64(100),
  2108  //		BlockNumber: curr_blockNumber,
  2109  //		CandidateId: nodeId5,
  2110  //		TxIndex:     6,
  2111  //		Host:        "10.0.0.1",
  2112  //		Port:        "8548",
  2113  //		Owner:       common.HexToAddress("0x12"),
  2114  //	}
  2115  //	logFn("Set New Candidate ...")
  2116  //	/** test SetCandidate */
  2117  //	cans = append(cans, candidate)
  2118  //	if err := candidatePoolContext.SetCandidate(state, candidate.CandidateId, candidate); nil != err {
  2119  //		errFn("SetCandidate err:", err)
  2120  //	}
  2121  //
  2122  //	candidate2 := &types.Candidate{
  2123  //		Deposit:     new(big.Int).SetUint64(101),
  2124  //		BlockNumber: curr_blockNumber,
  2125  //		CandidateId: nodeId1,
  2126  //		TxIndex:     5,
  2127  //		Host:        "10.0.0.1",
  2128  //		Port:        "8548",
  2129  //		Owner:       common.HexToAddress("0x15"),
  2130  //	}
  2131  //	logFn("Set New Candidate ...")
  2132  //	/** test SetCandidate */
  2133  //	cans = append(cans, candidate2)
  2134  //	if err := candidatePoolContext.SetCandidate(state, candidate2.CandidateId, candidate2); nil != err {
  2135  //		errFn("SetCandidate err:", err)
  2136  //	}
  2137  //
  2138  //	candidate3 := &types.Candidate{
  2139  //		Deposit:     new(big.Int).SetUint64(102),
  2140  //		BlockNumber: curr_blockNumber,
  2141  //		CandidateId: nodeId2,
  2142  //		TxIndex:     5,
  2143  //		Host:        "10.0.0.1",
  2144  //		Port:        "8548",
  2145  //		Owner:       common.HexToAddress("0x15"),
  2146  //	}
  2147  //	logFn("Set New Candidate ...")
  2148  //	/** test SetCandidate */
  2149  //	cans = append(cans, candidate3)
  2150  //	if err := candidatePoolContext.SetCandidate(state, candidate3.CandidateId, candidate3); nil != err {
  2151  //		errFn("SetCandidate err:", err)
  2152  //	}
  2153  //
  2154  //	candidate4 := &types.Candidate{
  2155  //		Deposit:     new(big.Int).SetUint64(120),
  2156  //		BlockNumber: curr_blockNumber,
  2157  //		CandidateId: nodeId3,
  2158  //		TxIndex:     4,
  2159  //		Host:        "10.0.0.1",
  2160  //		Port:        "8548",
  2161  //		Owner:       common.HexToAddress("0x15"),
  2162  //	}
  2163  //	logFn("Set New Candidate ...")
  2164  //	/** test SetCandidate */
  2165  //	cans = append(cans, candidate4)
  2166  //	if err := candidatePoolContext.SetCandidate(state, candidate4.CandidateId, candidate4); nil != err {
  2167  //		errFn("SetCandidate err:", err)
  2168  //	}
  2169  //
  2170  //	/** vote ticket */
  2171  //	var count uint32 = 0
  2172  //	ownerList := []common.Address{common.HexToAddress("0x20"), common.HexToAddress("0x21")}
  2173  //	var blockNumber = new(big.Int).SetUint64(10)
  2174  //	voteNum := 13
  2175  //	timeMap := make(map[uint32]int64)
  2176  //	fmt.Println("VOTING START .............................................................")
  2177  //	for i := 0; i < voteNum; i++ {
  2178  //		can := cans[rand.Intn(4)]
  2179  //
  2180  //		startTime := time.Now().UnixNano() / 1e6
  2181  //		voteOwner := ownerList[rand.Intn(2)]
  2182  //		deposit := new(big.Int).SetUint64(10)
  2183  //		state.SubBalance(voteOwner, deposit)
  2184  //		state.AddBalance(common.TicketPoolAddr, deposit)
  2185  //		tempBlockNumber := new(big.Int).SetUint64(blockNumber.Uint64())
  2186  //		if i < 2 {
  2187  //			tempBlockNumber.SetUint64(6)
  2188  //			logFn("vote blockNumber:", tempBlockNumber.Uint64())
  2189  //		}
  2190  //
  2191  //		if i == 2 {
  2192  //			fmt.Println("release ticket,start ############################################################")
  2193  //			var tempBlockNumber uint64 = 6
  2194  //			for i := 0; i < 4; i++ {
  2195  //				ticketPoolContext.Notify(state, new(big.Int).SetUint64(tempBlockNumber))
  2196  //				tempBlockNumber++
  2197  //			}
  2198  //			fmt.Println("release ticket,end ############################################################")
  2199  //		}
  2200  //		fmt.Println("Voting Current Candidate:", "voter is:", voteOwner.String(), " ,ticket num:", candidate.CandidateId.String(), " ,blocknumber when voted:", tempBlockNumber.String())
  2201  //		_, err := ticketPoolContext.VoteTicket(state, voteOwner, 1, deposit, can.CandidateId, tempBlockNumber)
  2202  //		if nil != err {
  2203  //			fmt.Println("vote ticket error:", err)
  2204  //		}
  2205  //		atomic.AddUint32(&count, 1)
  2206  //		timeMap[count] = (time.Now().UnixNano() / 1e6) - startTime
  2207  //
  2208  //	}
  2209  //	fmt.Println("VOTING END .............................................................")
  2210  //
  2211  //	/** test Election */
  2212  //	logFn("test Election ...")
  2213  //	_, err := candidatePoolContext.Election(state, common.Hash{}, big.NewInt(20))
  2214  //	logFn("Whether election was successful err", err)
  2215  //
  2216  //	/**  */
  2217  //	printObject("candidatePool:", *candidatePoolContext, logger)
  2218  //	/** test MaxChair */
  2219  //	logFn("test MaxChair:", candidatePoolContext.MaxChair())
  2220  //	/**test Interval*/
  2221  //	logFn("test Interval:", candidatePoolContext.GetRefundInterval(blockNumber))
  2222  //
  2223  //	next, _ := candidatePoolContext.GetWitness(state, 1, blockNumber)
  2224  //	fmt.Println("next", next)
  2225  //	/** test switch */
  2226  //	logFn("test Switch ...")
  2227  //	flag := candidatePoolContext.Switch(state, blockNumber)
  2228  //
  2229  //	logFn("Switch was success ", flag)
  2230  //
  2231  //	curr, _ := candidatePoolContext.GetWitness(state, 0,  blockNumber)
  2232  //	fmt.Println("curr", curr)
  2233  //	next, _ = candidatePoolContext.GetWitness(state, 1, blockNumber)
  2234  //	fmt.Println("next", next)
  2235  //}
  2236  //
  2237  //func TestCandidatePool_Switch(t *testing.T) {
  2238  //	candidate_Switch(t, t.Log, t.Error)
  2239  //}
  2240  //
  2241  //func BenchmarkCandidatePool_Switch(b *testing.B) {
  2242  //	candidate_Switch(b, b.Log, b.Error)
  2243  //}