prysm-pulse/shared/bls/spectest/aggregate_pubkeys_test.go
kilic d5e02eaa43 Change BLS Pairing Engine (#3670)
* change bls pairing engine

* fix linter warnings

* curve order

* add back spec test

* use only one dep

* fix test

* remove toBytes

* gaz

* add it back

* fix tests

* imports

* imports

* gaz

* remove hash function

* change naming

* preston's comments

* gaz

* fix test failure

* change back

* revert test changes

* gaz
2019-10-02 08:13:59 +08:00

53 lines
1.2 KiB
Go

package spectest
import (
"bytes"
"encoding/hex"
"testing"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func TestAggregatePubkeysYaml(t *testing.T) {
file, err := testutil.BazelFileBytes("tests/general/phase0/bls/aggregate_pubkeys/small/agg_pub_keys/data.yaml")
if err != nil {
t.Fatalf("Failed to read file: %v", err)
}
test := &AggregatePubkeysTest{}
if err := yaml.Unmarshal(file, test); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
pubBytes, err := hex.DecodeString(test.Input[0][2:])
if err != nil {
t.Fatalf("Cannot decode string to bytes: %v", err)
}
pk, err := bls.PublicKeyFromBytes(pubBytes)
if err != nil {
t.Fatal(err)
}
for _, pk2 := range test.Input[1:] {
pubBytes2, err := hex.DecodeString(pk2[2:])
if err != nil {
t.Fatalf("Cannot decode string to bytes: %v", err)
}
p, err := bls.PublicKeyFromBytes(pubBytes2)
if err != nil {
t.Fatal(err)
}
pk.Aggregate(p)
}
outputBytes, err := hex.DecodeString(test.Output[2:])
if err != nil {
t.Fatalf("Cannot decode string to bytes: %v", err)
}
if !bytes.Equal(outputBytes, pk.Marshal()) {
t.Fatal("Output does not equal marshaled aggregated public " +
"key bytes")
}
}