mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
f61f02e59b
* 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
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
// Package spectest includes tests to ensure conformity with the eth2
|
|
// bls cryptography specification.
|
|
package spectest
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/ghodss/yaml"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestSignMessageYaml(t *testing.T) {
|
|
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/sign/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 := &SignMsgTest{}
|
|
require.NoError(t, yaml.Unmarshal(file, test))
|
|
pkBytes, err := hex.DecodeString(test.Input.Privkey[2:])
|
|
require.NoError(t, err)
|
|
sk, err := bls.SecretKeyFromBytes(pkBytes)
|
|
require.NoError(t, err)
|
|
|
|
msgBytes, err := hex.DecodeString(test.Input.Message[2:])
|
|
require.NoError(t, err)
|
|
sig := sk.Sign(msgBytes)
|
|
|
|
if !sig.Verify(sk.PublicKey(), msgBytes) {
|
|
t.Fatal("could not verify signature")
|
|
}
|
|
|
|
outputBytes, err := hex.DecodeString(test.Output[2:])
|
|
require.NoError(t, err)
|
|
|
|
if !bytes.Equal(outputBytes, sig.Marshal()) {
|
|
t.Fatalf("Test Case %d: Signature does not match the expected output. "+
|
|
"Expected %#x but received %#x", i, outputBytes, sig.Marshal())
|
|
}
|
|
t.Log("Success")
|
|
})
|
|
}
|
|
}
|