mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 20:07:17 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
121 lines
3.6 KiB
Go
121 lines
3.6 KiB
Go
package sync
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain"
|
|
mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestExtractBlockDataType(t *testing.T) {
|
|
// Precompute digests
|
|
genDigest, err := signing.ComputeForkDigest(params.BeaconConfig().GenesisForkVersion, params.BeaconConfig().ZeroHash[:])
|
|
require.NoError(t, err)
|
|
altairDigest, err := signing.ComputeForkDigest(params.BeaconConfig().AltairForkVersion, params.BeaconConfig().ZeroHash[:])
|
|
require.NoError(t, err)
|
|
bellatrixDigest, err := signing.ComputeForkDigest(params.BeaconConfig().BellatrixForkVersion, params.BeaconConfig().ZeroHash[:])
|
|
require.NoError(t, err)
|
|
|
|
type args struct {
|
|
digest []byte
|
|
chain blockchain.ChainInfoFetcher
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want interfaces.SignedBeaconBlock
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no digest",
|
|
args: args{
|
|
digest: []byte{},
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
|
|
want: func() interfaces.SignedBeaconBlock {
|
|
wsb, err := blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}})
|
|
require.NoError(t, err)
|
|
return wsb
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "invalid digest",
|
|
args: args{
|
|
digest: []byte{0x00, 0x01},
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "non existent digest",
|
|
args: args{
|
|
digest: []byte{0x00, 0x01, 0x02, 0x03},
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "genesis fork version",
|
|
args: args{
|
|
digest: genDigest[:],
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: func() interfaces.SignedBeaconBlock {
|
|
wsb, err := blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}})
|
|
require.NoError(t, err)
|
|
return wsb
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "altair fork version",
|
|
args: args{
|
|
digest: altairDigest[:],
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: func() interfaces.SignedBeaconBlock {
|
|
wsb, err := blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{Body: ðpb.BeaconBlockBodyAltair{}}})
|
|
require.NoError(t, err)
|
|
return wsb
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "bellatrix fork version",
|
|
args: args{
|
|
digest: bellatrixDigest[:],
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: func() interfaces.SignedBeaconBlock {
|
|
wsb, err := blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlockBellatrix{Block: ðpb.BeaconBlockBellatrix{Body: ðpb.BeaconBlockBodyBellatrix{}}})
|
|
require.NoError(t, err)
|
|
return wsb
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := extractBlockDataType(tt.args.digest, tt.args.chain)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("extractBlockDataType() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("extractBlockDataType() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|