Skip to content

Commit

Permalink
Merge pull request #481 from ava-labs/order-mock-validator-set
Browse files Browse the repository at this point in the history
Order mock validator set
  • Loading branch information
feuGeneA authored Sep 9, 2024
2 parents 72552b0 + 142df89 commit 170e72b
Showing 1 changed file with 44 additions and 35 deletions.
79 changes: 44 additions & 35 deletions signature-aggregator/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package aggregator

import (
"bytes"
"context"
"encoding/hex"
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -71,38 +70,51 @@ func instantiateAggregator(t *testing.T) (
return aggregator, mockNetwork
}

func makeConnectedValidators(validatorCount int) (*peers.ConnectedCanonicalValidators, []*bls.SecretKey) {
var validatorSet []*warp.Validator
var validatorSecretKeys []*bls.SecretKey
// Generate the validator values.
type validatorInfo struct {
nodeID ids.NodeID
blsSecretKey *bls.SecretKey
blsPublicKey *bls.PublicKey
blsPublicKeyBytes []byte
}

nodeValidatorIndexMap := make(map[ids.NodeID]int)
func (v validatorInfo) Compare(o validatorInfo) int {
return bytes.Compare(v.blsPublicKeyBytes, o.blsPublicKeyBytes)
}

func makeConnectedValidators(validatorCount int) (*peers.ConnectedCanonicalValidators, []*bls.SecretKey) {
validatorValues := make([]validatorInfo, validatorCount)
for i := 0; i < validatorCount; i++ {
secretKey, err := bls.NewSecretKey()
if err != nil {
panic(err)
}
validatorSecretKeys = append(validatorSecretKeys, secretKey)

pubKey := bls.PublicFromSecretKey(secretKey)

nodeID := ids.GenerateTestNodeID()
nodeValidatorIndexMap[nodeID] = i
validatorValues[i] = validatorInfo{
nodeID: nodeID,
blsSecretKey: secretKey,
blsPublicKey: pubKey,
blsPublicKeyBytes: bls.PublicKeyToUncompressedBytes(pubKey),
}
}

fmt.Printf(
"validator with pubKey %s has nodeID %s\n",
hex.EncodeToString(bls.PublicKeyToUncompressedBytes(pubKey)),
nodeID.String(),
)
// Sort the validators by public key to construct the NodeValidatorIndexMap
utils.Sort(validatorValues)

validatorSet = append(validatorSet,
&warp.Validator{
PublicKey: pubKey,
PublicKeyBytes: bls.PublicKeyToUncompressedBytes(pubKey),
Weight: 1,
NodeIDs: []ids.NodeID{nodeID},
},
)
// Placeholder for results
validatorSet := make([]*warp.Validator, validatorCount)
validatorSecretKeys := make([]*bls.SecretKey, validatorCount)
nodeValidatorIndexMap := make(map[ids.NodeID]int)
for i, validator := range validatorValues {
validatorSecretKeys[i] = validator.blsSecretKey
validatorSet[i] = &warp.Validator{
PublicKey: validator.blsPublicKey,
PublicKeyBytes: validator.blsPublicKeyBytes,
Weight: 1,
NodeIDs: []ids.NodeID{validator.nodeID},
}
nodeValidatorIndexMap[validator.nodeID] = i
}

return &peers.ConnectedCanonicalValidators{
Expand Down Expand Up @@ -325,19 +337,16 @@ func TestCreateSignedMessageSucceeds(t *testing.T) {
1,
connectedValidators,
)
require.Equal(
t,
nil,
signedMessage.Signature.Verify(
context.Background(),
msg,
networkID,
pChainState,
pChainState.currentHeight,
quorumPercentage,
100,
),
verifyErr := signedMessage.Signature.Verify(
context.Background(),
msg,
networkID,
pChainState,
pChainState.currentHeight,
quorumPercentage,
100,
)
require.NoError(t, verifyErr)
}

type pChainStateStub struct {
Expand Down

0 comments on commit 170e72b

Please sign in to comment.