mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Add a separate unit test for ComputeDomainAndSign (#8600)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
2ec3f79146
commit
feeb59de23
@ -67,6 +67,7 @@ go_test(
|
||||
shard_count = 2,
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/state/interface:go_default_library",
|
||||
"//beacon-chain/state/stateV0:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
|
@ -5,21 +5,25 @@ import (
|
||||
"testing"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"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 TestSigningRoot_ComputeOK(t *testing.T) {
|
||||
func TestSigningRoot_ComputeSigningRoot(t *testing.T) {
|
||||
emptyBlock := testutil.NewBeaconBlock()
|
||||
_, err := helpers.ComputeSigningRoot(emptyBlock, bytesutil.PadTo([]byte{'T', 'E', 'S', 'T'}, 32))
|
||||
assert.NoError(t, err, "Could not compute signing root of block")
|
||||
}
|
||||
|
||||
func TestComputeDomain_OK(t *testing.T) {
|
||||
func TestSigningRoot_ComputeDomain(t *testing.T) {
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
domainType [4]byte
|
||||
@ -40,7 +44,53 @@ func TestComputeDomain_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeForkDigest_OK(t *testing.T) {
|
||||
func TestSigningRoot_ComputeDomainAndSign(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
genState func(t *testing.T) (iface.BeaconState, []bls.SecretKey)
|
||||
genBlock func(t *testing.T, st iface.BeaconState, keys []bls.SecretKey) *eth.SignedBeaconBlock
|
||||
domainType [4]byte
|
||||
want []byte
|
||||
}{
|
||||
{
|
||||
name: "block proposer",
|
||||
genState: func(t *testing.T) (iface.BeaconState, []bls.SecretKey) {
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
|
||||
return beaconState, privKeys
|
||||
},
|
||||
genBlock: func(t *testing.T, st iface.BeaconState, keys []bls.SecretKey) *eth.SignedBeaconBlock {
|
||||
block, err := testutil.GenerateFullBlock(st, keys, nil, 1)
|
||||
require.NoError(t, err)
|
||||
return block
|
||||
},
|
||||
domainType: params.BeaconConfig().DomainBeaconProposer,
|
||||
want: []byte{
|
||||
0xad, 0xd8, 0xf0, 0xd1, 0xae, 0x82, 0xaa, 0x3, 0x9a, 0xcd, 0x8e, 0xb7, 0x84, 0x14, 0x1c, 0x21, 0x81,
|
||||
0xbc, 0x1b, 0x2, 0xb5, 0x6d, 0x4c, 0x76, 0x36, 0x5f, 0xba, 0x6e, 0x33, 0x9e, 0xda, 0xe, 0x36, 0xe1,
|
||||
0xf, 0x30, 0xae, 0x6, 0x44, 0xd4, 0x38, 0x21, 0xf0, 0x45, 0xc2, 0x54, 0x68, 0x2f, 0x12, 0xcc, 0x27,
|
||||
0x45, 0x72, 0x5, 0xaf, 0xb4, 0x85, 0x60, 0xdb, 0x7a, 0x1f, 0xe7, 0xa8, 0x62, 0xf5, 0x71, 0xac, 0x88,
|
||||
0x8c, 0xd3, 0xba, 0x4d, 0xa3, 0x3d, 0x3b, 0x87, 0x9b, 0x23, 0xae, 0xe4, 0x46, 0xc6, 0x36, 0xca, 0xa5,
|
||||
0xa1, 0x2d, 0x9e, 0x7, 0xc1, 0x40, 0xed, 0x99, 0xfd, 0xae, 0xce,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
beaconState, privKeys := tt.genState(t)
|
||||
idx, err := helpers.BeaconProposerIndex(beaconState)
|
||||
require.NoError(t, err)
|
||||
block := tt.genBlock(t, beaconState, privKeys)
|
||||
got, err := helpers.ComputeDomainAndSign(
|
||||
beaconState, helpers.CurrentEpoch(beaconState), block, tt.domainType, privKeys[idx])
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, tt.want, got, "Incorrect signature")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSigningRoot_ComputeForkDigest(t *testing.T) {
|
||||
tests := []struct {
|
||||
version []byte
|
||||
root [32]byte
|
||||
|
Loading…
Reference in New Issue
Block a user