github.com/aergoio/aergo@v1.3.1/consensus/impl/dpos/bp/cluster_test.go (about)

     1  package bp
     2  
     3  const (
     4  	BlockProducers = 32
     5  )
     6  
     7  /* TODO: BP-related paramters eliminated. Rewrite test!
     8  
     9  func TestNewClusterInvalid(t *testing.T) {
    10  	randIds := func() []string {
    11  		ids := make([]string, BlockProducers)
    12  		for i := 0; i < BlockProducers; i++ {
    13  			ids[i] = fmt.Sprintf("%v", rand.Int31())
    14  		}
    15  		return ids
    16  	}
    17  
    18  	tcs := []struct {
    19  		name string
    20  		ids  []string
    21  	}{
    22  		{"invalid size", []string{"x", "y"}},
    23  		{"invalid IDs ", randIds()},
    24  	}
    25  
    26  	for _, tc := range tcs {
    27  		bpc, err := NewCluster(newConfig(tc.ids), nil)
    28  		fmt.Println(tc.name, "--> ", err.Error())
    29  		assert.NotNil(t, err)
    30  		assert.Nil(t, bpc)
    31  	}
    32  }
    33  
    34  func TestNewCluster(t *testing.T) {
    35  	genID := func() string {
    36  		_, pubKey, err := crypto.GenerateKeyPair(crypto.Secp256k1, 256)
    37  		assert.Nil(t, err)
    38  		b, err := types.IDFromPublicKey(pubKey)
    39  		assert.Nil(t, err)
    40  		return b.Pretty()
    41  	}
    42  
    43  	genIds := func() []string {
    44  		ids := make([]string, BlockProducers)
    45  		for i := 0; i < BlockProducers; i++ {
    46  			ids[i] = genID()
    47  			fmt.Println(ids[i])
    48  		}
    49  		return ids
    50  	}
    51  
    52  	bpc, err := NewCluster(newConfig(genIds()), nil)
    53  	assert.Nil(t, err)
    54  	assert.NotNil(t, bpc, "Cluster alloc failed")
    55  }
    56  
    57  func newConfig(ids []string) *config.ConsensusConfig {
    58  	return &config.ConsensusConfig{}
    59  }
    60  */