mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
ba07ccb484
* slasher/beaconclient tests * slasher/db/kv tests * Merge branch 'master' into apply-testutils-assertions-to-slasher * fix build * slasher/detection tests * rest of the tests * misc tests * tools tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * agg tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * updates aggregated_test * beacon-chain/operations/attestations/kv/* tests updated * beacon-chain/operations/attestations tests updated * beacon-chain/operations/slashings tests updated * Merge branch 'master' into apply-testutils-assertions-misc * gazelle * beacon-chain/core tests updated * fixes test * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/rpc tests updated * beacon-chain/sync/initial-sync tests * misc tests * optimizes error message parsing in testutils * Merge branch 'assertutils-optimize-processing' into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * endtoend tests * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * beacon-chain/blockchain tests updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/state/stategen tests updated * beacon-chain all left-over tests are done * Merge refs/heads/master into apply-testutils-assertions-misc * validator tests updated * slasher tests * Merge branch 'master' into apply-testutils-assertions-misc * gofmt * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * shared upd * end2end tests deps fixed * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * misc * all tests are updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc
79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package herumi_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls/herumi"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestMarshalUnmarshal(t *testing.T) {
|
|
b := herumi.RandKey().Marshal()
|
|
b32 := bytesutil.ToBytes32(b)
|
|
pk, err := herumi.SecretKeyFromBytes(b32[:])
|
|
require.NoError(t, err)
|
|
pk2, err := herumi.SecretKeyFromBytes(b32[:])
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, pk.Marshal(), pk2.Marshal())
|
|
}
|
|
|
|
func TestSecretKeyFromBytes(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input []byte
|
|
err error
|
|
}{
|
|
{
|
|
name: "Nil",
|
|
err: errors.New("secret key must be 32 bytes"),
|
|
},
|
|
{
|
|
name: "Empty",
|
|
input: []byte{},
|
|
err: errors.New("secret key must be 32 bytes"),
|
|
},
|
|
{
|
|
name: "Short",
|
|
input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
err: errors.New("secret key must be 32 bytes"),
|
|
},
|
|
{
|
|
name: "Long",
|
|
input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
err: errors.New("secret key must be 32 bytes"),
|
|
},
|
|
{
|
|
name: "Bad",
|
|
input: []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
|
err: errors.New("could not unmarshal bytes into secret key: err blsSecretKeyDeserialize ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
|
|
},
|
|
{
|
|
name: "Good",
|
|
input: []byte{0x25, 0x29, 0x5f, 0x0d, 0x1d, 0x59, 0x2a, 0x90, 0xb3, 0x33, 0xe2, 0x6e, 0x85, 0x14, 0x97, 0x08, 0x20, 0x8e, 0x9f, 0x8e, 0x8b, 0xc1, 0x8f, 0x6c, 0x77, 0xbd, 0x62, 0xf8, 0xad, 0x7a, 0x68, 0x66},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
res, err := herumi.SecretKeyFromBytes(test.input)
|
|
if test.err != nil {
|
|
assert.ErrorContains(t, test.err.Error(), err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.DeepEqual(t, test.input, res.Marshal())
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSerialize(t *testing.T) {
|
|
rk := herumi.RandKey()
|
|
b := rk.Marshal()
|
|
|
|
_, err := herumi.SecretKeyFromBytes(b)
|
|
assert.NoError(t, err)
|
|
}
|