mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 23:41:22 +00:00
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
|
package debug
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"context"
|
||
|
"testing"
|
||
|
|
||
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||
|
"github.com/prysmaticlabs/go-ssz"
|
||
|
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||
|
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||
|
)
|
||
|
|
||
|
func TestServer_GetBlock(t *testing.T) {
|
||
|
db := dbTest.SetupDB(t)
|
||
|
ctx := context.Background()
|
||
|
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{
|
||
|
Slot: 100,
|
||
|
}}
|
||
|
if err := db.SaveBlock(ctx, b); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
blockRoot, err := stateutil.BlockRoot(b.Block)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
bs := &Server{
|
||
|
BeaconDB: db,
|
||
|
}
|
||
|
res, err := bs.GetBlock(ctx, &pbrpc.BlockRequest{
|
||
|
BlockRoot: blockRoot[:],
|
||
|
})
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
wanted, err := ssz.Marshal(b)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if !bytes.Equal(wanted, res.Encoded) {
|
||
|
t.Errorf("Wanted %v, received %v", wanted, res.Encoded)
|
||
|
}
|
||
|
|
||
|
// Checking for nil block.
|
||
|
blockRoot = [32]byte{}
|
||
|
res, err = bs.GetBlock(ctx, &pbrpc.BlockRequest{
|
||
|
BlockRoot: blockRoot[:],
|
||
|
})
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if !bytes.Equal([]byte{}, res.Encoded) {
|
||
|
t.Errorf("Wanted empty, received %v", res.Encoded)
|
||
|
}
|
||
|
}
|