2021-04-22 14:53:30 +00:00
|
|
|
package bls
|
2019-06-25 16:57:47 +00:00
|
|
|
|
|
|
|
import (
|
2019-09-08 19:41:52 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"path"
|
2020-06-09 22:40:48 +00:00
|
|
|
"strings"
|
2019-06-25 16:57:47 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
2021-09-15 22:55:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/crypto/bls"
|
|
|
|
"github.com/prysmaticlabs/prysm/crypto/bls/common"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2021-09-14 16:02:58 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
2019-06-25 16:57:47 +00:00
|
|
|
)
|
|
|
|
|
2021-04-22 14:53:30 +00:00
|
|
|
func TestAggregate(t *testing.T) {
|
|
|
|
t.Run("blst", testAggregate)
|
2020-09-16 13:28:28 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 14:53:30 +00:00
|
|
|
func testAggregate(t *testing.T) {
|
2021-04-22 16:34:00 +00:00
|
|
|
testFolders, testFolderPath := utils.TestFolders(t, "general", "phase0", "bls/aggregate/small")
|
2019-06-25 16:57:47 +00:00
|
|
|
|
2019-09-08 19:41:52 +00:00
|
|
|
for _, folder := range testFolders {
|
|
|
|
t.Run(folder.Name(), func(t *testing.T) {
|
2021-09-23 18:53:46 +00:00
|
|
|
file, err := util.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
|
2020-08-25 10:18:29 +00:00
|
|
|
require.NoError(t, err)
|
2020-04-14 20:27:03 +00:00
|
|
|
test := &AggregateTest{}
|
2020-08-25 10:18:29 +00:00
|
|
|
require.NoError(t, yaml.Unmarshal(file, test))
|
2020-10-30 19:06:33 +00:00
|
|
|
var sigs []common.Signature
|
2019-09-08 19:41:52 +00:00
|
|
|
for _, s := range test.Input {
|
|
|
|
sigBytes, err := hex.DecodeString(s[2:])
|
2020-08-25 10:18:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-08 19:41:52 +00:00
|
|
|
sig, err := bls.SignatureFromBytes(sigBytes)
|
2020-08-25 10:18:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-25 16:57:47 +00:00
|
|
|
sigs = append(sigs, sig)
|
|
|
|
}
|
2020-06-09 22:40:48 +00:00
|
|
|
if len(test.Input) == 0 {
|
|
|
|
if test.Output != "" {
|
|
|
|
t.Fatalf("Output Aggregate is not of zero length:Output %s", test.Output)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-06-25 16:57:47 +00:00
|
|
|
sig := bls.AggregateSignatures(sigs)
|
2020-06-09 22:40:48 +00:00
|
|
|
if strings.Contains(folder.Name(), "aggregate_na_pubkeys") {
|
|
|
|
if sig != nil {
|
|
|
|
t.Errorf("Expected nil signature, received: %v", sig)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-09-08 19:41:52 +00:00
|
|
|
outputBytes, err := hex.DecodeString(test.Output[2:])
|
2020-08-25 10:18:29 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, outputBytes, sig.Marshal())
|
2019-06-25 16:57:47 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|