2021-08-20 14:38:35 +00:00
|
|
|
package blocks_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
2021-09-27 16:19:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2021-09-23 15:23:37 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
2021-08-20 14:38:35 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-07 18:43:50 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
2021-08-20 14:38:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVerifyBlockSignatureUsingCurrentFork(t *testing.T) {
|
|
|
|
params.SetupTestConfigCleanup(t)
|
|
|
|
bCfg := params.BeaconConfig()
|
|
|
|
bCfg.AltairForkEpoch = 100
|
|
|
|
bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AltairForkVersion)] = 100
|
|
|
|
params.OverrideBeaconConfig(bCfg)
|
2021-09-23 18:53:46 +00:00
|
|
|
bState, keys := util.DeterministicGenesisState(t, 100)
|
|
|
|
altairBlk := util.NewBeaconBlockAltair()
|
2021-08-20 14:38:35 +00:00
|
|
|
altairBlk.Block.ProposerIndex = 0
|
|
|
|
altairBlk.Block.Slot = params.BeaconConfig().SlotsPerEpoch * 100
|
|
|
|
fData := ðpb.Fork{
|
|
|
|
Epoch: 100,
|
|
|
|
CurrentVersion: params.BeaconConfig().AltairForkVersion,
|
|
|
|
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
|
|
|
}
|
2021-09-27 16:19:20 +00:00
|
|
|
domain, err := signing.Domain(fData, 100, params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorRoot())
|
2021-08-20 14:38:35 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-27 16:19:20 +00:00
|
|
|
rt, err := signing.ComputeSigningRoot(altairBlk.Block, domain)
|
2021-08-20 14:38:35 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
sig := keys[0].Sign(rt[:]).Marshal()
|
|
|
|
altairBlk.Signature = sig
|
2021-09-07 18:43:50 +00:00
|
|
|
wsb, err := wrapper.WrappedAltairSignedBeaconBlock(altairBlk)
|
2021-08-20 14:38:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NoError(t, blocks.VerifyBlockSignatureUsingCurrentFork(bState, wsb))
|
|
|
|
}
|