github.com/koko1123/flow-go-1@v0.29.6/cmd/bootstrap/run/qc_test.go (about)

     1  package run
     2  
     3  import (
     4  	"crypto/rand"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/onflow/flow-go/crypto"
    10  	"github.com/koko1123/flow-go-1/model/bootstrap"
    11  	"github.com/koko1123/flow-go-1/model/flow"
    12  	"github.com/koko1123/flow-go-1/model/flow/order"
    13  	"github.com/koko1123/flow-go-1/module/signature"
    14  	"github.com/koko1123/flow-go-1/utils/unittest"
    15  )
    16  
    17  func TestGenerateRootQC(t *testing.T) {
    18  	participantData := createSignerData(t, 3)
    19  
    20  	block := unittest.BlockFixture()
    21  	block.Payload.Guarantees = nil
    22  	block.Payload.Seals = nil
    23  	block.Header.Height = 0
    24  	block.Header.ParentID = flow.ZeroID
    25  	block.Header.View = 3
    26  	block.Header.PayloadHash = block.Payload.Hash()
    27  
    28  	votes, err := GenerateRootBlockVotes(&block, participantData)
    29  	require.NoError(t, err)
    30  
    31  	_, err = GenerateRootQC(&block, votes, participantData, participantData.Identities())
    32  	require.NoError(t, err)
    33  }
    34  
    35  func createSignerData(t *testing.T, n int) *ParticipantData {
    36  	identities := unittest.IdentityListFixture(n).Sort(order.Canonical)
    37  
    38  	networkingKeys := unittest.NetworkingKeys(n)
    39  	stakingKeys := unittest.StakingKeys(n)
    40  
    41  	seed := make([]byte, crypto.SeedMinLenDKG)
    42  	_, err := rand.Read(seed)
    43  	require.NoError(t, err)
    44  	randomBSKs, randomBPKs, groupKey, err := crypto.BLSThresholdKeyGen(n,
    45  		signature.RandomBeaconThreshold(n), seed)
    46  	require.NoError(t, err)
    47  
    48  	participantLookup := make(map[flow.Identifier]flow.DKGParticipant)
    49  	participants := make([]Participant, n)
    50  
    51  	for i, identity := range identities {
    52  
    53  		// add to lookup
    54  		lookupParticipant := flow.DKGParticipant{
    55  			Index:    uint(i),
    56  			KeyShare: randomBPKs[i],
    57  		}
    58  		participantLookup[identity.NodeID] = lookupParticipant
    59  
    60  		// add to participant list
    61  		nodeInfo := bootstrap.NewPrivateNodeInfo(
    62  			identity.NodeID,
    63  			identity.Role,
    64  			identity.Address,
    65  			identity.Weight,
    66  			networkingKeys[i],
    67  			stakingKeys[i],
    68  		)
    69  		participants[i] = Participant{
    70  			NodeInfo:            nodeInfo,
    71  			RandomBeaconPrivKey: randomBSKs[i],
    72  		}
    73  	}
    74  
    75  	participantData := &ParticipantData{
    76  		Participants: participants,
    77  		Lookup:       participantLookup,
    78  		GroupKey:     groupKey,
    79  	}
    80  
    81  	return participantData
    82  }