prysm-pulse/shared/bls/bls_test.go
Nishant Das 168cffb0dd
Check Sub Group for Herumi and Fix Edge Cases (#7823)
* check for herumi

* clean up

* fix tests

* fix
2020-11-17 04:12:23 +00:00

73 lines
2.0 KiB
Go

package bls
import (
"testing"
"github.com/prysmaticlabs/prysm/shared/bls/common"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestDisallowZeroSecretKeys(t *testing.T) {
flags := &featureconfig.Flags{}
t.Run("herumi", func(t *testing.T) {
flags := &featureconfig.Flags{}
reset := featureconfig.InitWithReset(flags)
defer reset()
_, err := SecretKeyFromBytes(common.ZeroSecretKey[:])
require.Equal(t, common.ErrZeroKey, err)
})
t.Run("blst", func(t *testing.T) {
flags.EnableBlst = true
reset := featureconfig.InitWithReset(flags)
defer reset()
// Blst does a zero check on the key during deserialization.
_, err := SecretKeyFromBytes(common.ZeroSecretKey[:])
require.Equal(t, common.ErrSecretUnmarshal, err)
})
}
func TestDisallowZeroPublicKeys(t *testing.T) {
flags := &featureconfig.Flags{}
t.Run("herumi", func(t *testing.T) {
reset := featureconfig.InitWithReset(flags)
defer reset()
_, err := PublicKeyFromBytes(common.InfinitePublicKey[:])
require.Equal(t, common.ErrInfinitePubKey, err)
})
t.Run("blst", func(t *testing.T) {
flags.EnableBlst = true
reset := featureconfig.InitWithReset(flags)
defer reset()
_, err := PublicKeyFromBytes(common.InfinitePublicKey[:])
require.Equal(t, common.ErrInfinitePubKey, err)
})
}
func TestDisallowZeroPublicKeys_AggregatePubkeys(t *testing.T) {
flags := &featureconfig.Flags{}
t.Run("herumi", func(t *testing.T) {
reset := featureconfig.InitWithReset(flags)
defer reset()
_, err := AggregatePublicKeys([][]byte{common.InfinitePublicKey[:], common.InfinitePublicKey[:]})
require.Equal(t, common.ErrInfinitePubKey, err)
})
t.Run("blst", func(t *testing.T) {
flags.EnableBlst = true
reset := featureconfig.InitWithReset(flags)
defer reset()
_, err := AggregatePublicKeys([][]byte{common.InfinitePublicKey[:], common.InfinitePublicKey[:]})
require.Equal(t, common.ErrInfinitePubKey, err)
})
}