mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
78a25f99c3
* Update fastssz * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fmt * gaz * Merge refs/heads/master into update-fssz * goimports * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Fix * fix ethereumapis * fix again * kafka * fix gen file * fix compute signing root * gofmt * checkpoint progress * progress * checkpoint * progress * Fix build * checkpoint * helpers * Another test fixed * gaz * another test fix * gofmt * some fixes * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fix one test * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fill empty checkpoint roots * more padding * more padding * Fix //beacon-chain/rpc/debug:go_default_test * fix //beacon-chain/core/state:go_default_test * fix //beacon-chain/core/state:go_default_test * fix some htr errors * fix //slasher/rpc:go_default_test * Progress on //beacon-chain/core/blocks:go_default_test * Progress on //beacon-chain/core/blocks:go_default_test * Progress on //beacon-chain/core/blocks:go_default_test * fix //slasher/db/kv:go_default_test * progress * fix //beacon-chain/sync/initial-sync:go_raceon_test * gofmt and gaz * fix one more test, taking a break * Fix //beacon-chain/core/blocks:go_default_test * Complete beacon-chain/powchain * Do most of beacon-chain/rpc/beacon/ * Do most of beacon-chain/blockchain * fix //beacon-chain/operations/attestations/kv:go_default_test * Fix //beacon-chain/cache/depositcache:go_default_test * Fix //slasher/detection:go_default_test * Progress * fix //beacon-chain/rpc/validator:go_default_test * gofmt * fix //validator/client:go_default_test * fix * fix //beacon-chain/blockchain:go_raceoff_test * fix //beacon-chain/rpc/beacon:go_default_test * fix 1 of 4 shards in //beacon-chain/sync:go_default_test * Fix //beacon-chain/sync:go_default_test and gofmt * prevent panic * fix //beacon-chain/state/stategen:go_default_test * fix * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fix most tests * Self review, go mod tidy, run regen scripts * fix slasher * Update ethereumapis * disable spawn strategy override * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Remove extra line in imports * Remove extra line in imports * Gofmt * PR feedback from @nisdas
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package depositutil_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/depositutil"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestDepositInput_GeneratesPb(t *testing.T) {
|
|
k1 := bls.RandKey()
|
|
k2 := bls.RandKey()
|
|
|
|
result, _, err := depositutil.DepositInput(k1, k2, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assert.DeepEqual(t, k1.PublicKey().Marshal(), result.PublicKey)
|
|
|
|
sig, err := bls.SignatureFromBytes(result.Signature)
|
|
require.NoError(t, err)
|
|
sr, err := ssz.SigningRoot(result)
|
|
require.NoError(t, err)
|
|
domain, err := helpers.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
nil, /*forkVersion*/
|
|
nil, /*genesisValidatorsRoot*/
|
|
)
|
|
require.NoError(t, err)
|
|
root, err := (&pb.SigningData{ObjectRoot: sr[:], Domain: domain[:]}).HashTreeRoot()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, true, sig.Verify(k1.PublicKey(), root[:]))
|
|
}
|
|
|
|
func TestVerifyDepositSignature_ValidSig(t *testing.T) {
|
|
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
|
if err != nil {
|
|
t.Fatalf("Error Generating Deposits and Keys - %v", err)
|
|
}
|
|
deposit := deposits[0]
|
|
domain, err := helpers.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
params.BeaconConfig().GenesisForkVersion,
|
|
params.BeaconConfig().ZeroHash[:],
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Error Computing Domain - %v", err)
|
|
}
|
|
err = depositutil.VerifyDepositSignature(deposit.Data, domain)
|
|
if err != nil {
|
|
t.Fatal("Deposit Verification fails with a valid signature")
|
|
}
|
|
}
|
|
|
|
func TestVerifyDepositSignature_InvalidSig(t *testing.T) {
|
|
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
|
if err != nil {
|
|
t.Fatalf("Error Generating Deposits and Keys - %v", err)
|
|
}
|
|
deposit := deposits[0]
|
|
domain, err := helpers.ComputeDomain(
|
|
params.BeaconConfig().DomainDeposit,
|
|
params.BeaconConfig().GenesisForkVersion,
|
|
params.BeaconConfig().ZeroHash[:],
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Error Computing Domain - %v", err)
|
|
}
|
|
deposit.Data.Signature = deposit.Data.Signature[1:]
|
|
err = depositutil.VerifyDepositSignature(deposit.Data, domain)
|
|
if err == nil {
|
|
t.Fatal("Deposit Verification succeeds with a invalid signature")
|
|
}
|
|
}
|