diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-09-19 18:58:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-19 18:58:15 +0800 |
commit | 37f117d35c6617e1944d45e001e03813a6a278ed (patch) | |
tree | 57314b479533bce05827acf0bcf64548a836e68f /crypto | |
parent | 22e70f6da486ed6796a493f25e04679b9afa1439 (diff) | |
download | dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.tar dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.tar.gz dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.tar.bz2 dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.tar.lz dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.tar.xz dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.tar.zst dexon-consensus-37f117d35c6617e1944d45e001e03813a6a278ed.zip |
core: Add dkg test (#119)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/dkg/dkg.go | 3 | ||||
-rw-r--r-- | crypto/dkg/dkg_test.go | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/crypto/dkg/dkg.go b/crypto/dkg/dkg.go index 4e21d45..df01078 100644 --- a/crypto/dkg/dkg.go +++ b/crypto/dkg/dkg.go @@ -304,6 +304,9 @@ func (prv *PrivateKey) Bytes() []byte { // VerifySignature checks that the given public key created signature over hash. func (pub PublicKey) VerifySignature( hash common.Hash, signature crypto.Signature) bool { + if len(signature) == 0 { + return false + } var sig bls.Sign if err := sig.Deserialize(signature[:]); err != nil { fmt.Println(err) diff --git a/crypto/dkg/dkg_test.go b/crypto/dkg/dkg_test.go index 8e8ce79..badb0ce 100644 --- a/crypto/dkg/dkg_test.go +++ b/crypto/dkg/dkg_test.go @@ -277,6 +277,19 @@ func (s *DKGTestSuite) TestDKGProtocol() { s.True(groupPK.VerifySignature(hash, recoverSig2)) } +func (s *DKGTestSuite) TestSignature() { + prvKey := NewPrivateKey() + pubKey := prvKey.PublicKey() + hash := crypto.Keccak256Hash([]byte("🛫")) + sig, err := prvKey.Sign(hash) + s.Require().NoError(err) + s.True(pubKey.VerifySignature(hash, sig)) + sig[0]++ + s.False(pubKey.VerifySignature(hash, sig)) + sig = crypto.Signature{} + s.False(pubKey.VerifySignature(hash, sig)) +} + func TestDKG(t *testing.T) { suite.Run(t, new(DKGTestSuite)) } |