-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathdeposit_test.go
75 lines (68 loc) · 2.34 KB
/
deposit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package deposit_test
import (
"testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/contracts/deposit"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/util"
)
func TestDepositInput_GeneratesPb(t *testing.T) {
k1, err := bls.RandKey()
require.NoError(t, err)
k2, err := bls.RandKey()
require.NoError(t, err)
result, _, err := deposit.DepositInput(k1, k2, 0)
require.NoError(t, err)
assert.DeepEqual(t, k1.PublicKey().Marshal(), result.PublicKey)
sig, err := bls.SignatureFromBytes(result.Signature)
require.NoError(t, err)
testData := ðpb.DepositMessage{
PublicKey: result.PublicKey,
WithdrawalCredentials: result.WithdrawalCredentials,
Amount: result.Amount,
}
sr, err := testData.HashTreeRoot()
require.NoError(t, err)
domain, err := signing.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 := util.DeterministicDepositsAndKeys(1)
require.NoError(t, err)
dep := deposits[0]
domain, err := signing.ComputeDomain(
params.BeaconConfig().DomainDeposit,
params.BeaconConfig().GenesisForkVersion,
params.BeaconConfig().ZeroHash[:],
)
require.NoError(t, err)
err = deposit.VerifyDepositSignature(dep.Data, domain)
require.NoError(t, err)
}
func TestVerifyDepositSignature_InvalidSig(t *testing.T) {
deposits, _, err := util.DeterministicDepositsAndKeys(1)
require.NoError(t, err)
dep := deposits[0]
domain, err := signing.ComputeDomain(
params.BeaconConfig().DomainDeposit,
params.BeaconConfig().GenesisForkVersion,
params.BeaconConfig().ZeroHash[:],
)
require.NoError(t, err)
dep.Data.Signature = dep.Data.Signature[1:]
err = deposit.VerifyDepositSignature(dep.Data, domain)
if err == nil {
t.Fatal("Deposit Verification succeeds with a invalid signature")
}
}