mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
cc790ceb2e
* add changes * radek's review * kasey's review Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
97 lines
2.7 KiB
Go
97 lines
2.7 KiB
Go
package sync
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestExtractBlockDataType(t *testing.T) {
|
|
// Precompute digests
|
|
genDigest, err := helpers.ComputeForkDigest(params.BeaconConfig().GenesisForkVersion, params.BeaconConfig().ZeroHash[:])
|
|
require.NoError(t, err)
|
|
altairDigest, err := helpers.ComputeForkDigest(params.BeaconConfig().AltairForkVersion, params.BeaconConfig().ZeroHash[:])
|
|
require.NoError(t, err)
|
|
|
|
type args struct {
|
|
digest []byte
|
|
chain blockchain.ChainInfoFetcher
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want block.SignedBeaconBlock
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no digest",
|
|
args: args{
|
|
digest: []byte{},
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: wrapper.WrappedPhase0SignedBeaconBlock(ðpb.SignedBeaconBlock{}),
|
|
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: wrapper.WrappedPhase0SignedBeaconBlock(ðpb.SignedBeaconBlock{}),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "altair fork version",
|
|
args: args{
|
|
digest: altairDigest[:],
|
|
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
|
|
},
|
|
want: func() block.SignedBeaconBlock {
|
|
wsb, err := wrapper.WrappedAltairSignedBeaconBlock(ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{}})
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|