github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/validations_test.go (about)

     1  // Copyright (c) 2020 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package staking
     7  
     8  import (
     9  	"math"
    10  	"math/big"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/require"
    14  
    15  	"github.com/iotexproject/iotex-core/blockchain/genesis"
    16  	"github.com/iotexproject/iotex-core/test/identityset"
    17  )
    18  
    19  func initTestProtocol(t *testing.T) (*Protocol, []*Candidate) {
    20  	require := require.New(t)
    21  	p, err := NewProtocol(nil, &BuilderConfig{
    22  		Staking:                  genesis.Default.Staking,
    23  		PersistStakingPatchBlock: math.MaxUint64,
    24  	}, nil, nil, genesis.Default.GreenlandBlockHeight)
    25  	require.NoError(err)
    26  
    27  	var cans []*Candidate
    28  	cans = append(cans, &Candidate{
    29  		Owner:              identityset.Address(1),
    30  		Operator:           identityset.Address(11),
    31  		Reward:             identityset.Address(1),
    32  		Name:               "test1",
    33  		Votes:              big.NewInt(2),
    34  		SelfStakeBucketIdx: 1,
    35  		SelfStake:          big.NewInt(0),
    36  	})
    37  	cans = append(cans, &Candidate{
    38  		Owner:              identityset.Address(28),
    39  		Operator:           identityset.Address(28),
    40  		Reward:             identityset.Address(29),
    41  		Name:               "test2",
    42  		Votes:              big.NewInt(2),
    43  		SelfStakeBucketIdx: 2,
    44  		SelfStake:          big.NewInt(10),
    45  	})
    46  	cans = append(cans, &Candidate{
    47  		Owner:              identityset.Address(28),
    48  		Operator:           identityset.Address(28),
    49  		Reward:             identityset.Address(29),
    50  		Name:               "test",
    51  		Votes:              big.NewInt(2),
    52  		SelfStakeBucketIdx: 2,
    53  		SelfStake:          big.NewInt(10),
    54  	})
    55  	return p, cans
    56  }