prysm-pulse/shared/keystore/deposit_input_test.go
shayzluf 59575bcac9
fuzz core/blocks package (#4907)
* fuzz core/blocks package

* gaz goimports

* fix test

* terence feedback

* terence feedback

* add error to domain. halfway through

* adding error to domain

* goimports

* added error handling to test

* error instead of continue

* terence and nishant feedback

* domain error handling

* domain error handling

* handle nil validator in ReadOnlyValidator creation

* goinmports

* [4]byte domain type

* [4]byte domain type

* [4]byte domain type fix tests

* fix tests

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-03-03 19:02:14 +05:30

47 lines
1.0 KiB
Go

package keystore_test
import (
"bytes"
"testing"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/params"
)
func TestDepositInput_GeneratesPb(t *testing.T) {
k1, err := keystore.NewKey()
if err != nil {
t.Fatal(err)
}
k2, err := keystore.NewKey()
if err != nil {
t.Fatal(err)
}
result, _, err := keystore.DepositInput(k1, k2, 0)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(result.PublicKey, k1.PublicKey.Marshal()) {
t.Errorf("Mismatched pubkeys in deposit input. Want = %x, got = %x", result.PublicKey, k1.PublicKey.Marshal())
}
sig, err := bls.SignatureFromBytes(result.Signature)
if err != nil {
t.Fatal(err)
}
sr, err := ssz.SigningRoot(result)
if err != nil {
t.Fatal(err)
}
dom := bytesutil.FromBytes4(params.BeaconConfig().DomainDeposit[:])
if !sig.Verify(sr[:], k1.PublicKey, dom) {
t.Error("Invalid proof of deposit input signature")
}
}