prysm-pulse/shared/bls/spectest/aggregate_verify_test.go
terence tsao f61f02e59b
First take of applying assertion funcs to shared tests (#6666)
* cmd tests
* deposit util tests
* feature config tests
* hashutil tests
* htr util tests
* interop tests
* ip util tests
* Update BLS
* Update cmd
* Update bytesutil and depositutil
* Update event
* Update keystore
* Update mathutil
* Update mputil
* Update pagination
* Update params
* Upate prome
* Update testutil
* Update trieutil
* Merge branch 'master' of github.com:prysmaticlabs/prysm into testutil-shared
* Sync with master
* Mod
* Typo
* Revert
* gazelle
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Gaz
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* fixes build error
* Merge refs/heads/master into testutil-shared
2020-08-25 10:18:29 +00:00

58 lines
1.8 KiB
Go

package spectest
import (
"encoding/hex"
"path"
"testing"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bls/iface"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestAggregateVerifyYaml(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/aggregate_verify/small")
for i, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
file, err := testutil.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
require.NoError(t, err)
test := &AggregateVerifyTest{}
require.NoError(t, yaml.Unmarshal(file, test))
pubkeys := make([]iface.PublicKey, 0, len(test.Input.Pubkeys))
msgs := make([][32]byte, 0, len(test.Input.Messages))
for _, pubKey := range test.Input.Pubkeys {
pkBytes, err := hex.DecodeString(pubKey[2:])
require.NoError(t, err)
pk, err := bls.PublicKeyFromBytes(pkBytes)
require.NoError(t, err)
pubkeys = append(pubkeys, pk)
}
for _, msg := range test.Input.Messages {
msgBytes, err := hex.DecodeString(msg[2:])
require.NoError(t, err)
require.Equal(t, 32, len(msgBytes))
msgs = append(msgs, bytesutil.ToBytes32(msgBytes))
}
sigBytes, err := hex.DecodeString(test.Input.Signature[2:])
require.NoError(t, err)
sig, err := bls.SignatureFromBytes(sigBytes)
if err != nil {
if test.Output == false {
return
}
t.Fatalf("Cannot unmarshal input to signature: %v", err)
}
verified := sig.AggregateVerify(pubkeys, msgs)
if verified != test.Output {
t.Fatalf("Signature does not match the expected verification output. "+
"Expected %#v but received %#v for test case %d", test.Output, verified, i)
}
})
}
}