2020-05-21 01:36:05 +00:00
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
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) {
|
2020-06-23 20:40:55 +00:00
|
|
|
db, _ := dbTest.SetupDB(t)
|
2020-05-21 01:36:05 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-06-05 13:48:40 +00:00
|
|
|
wanted, err := b.MarshalSSZ()
|
2020-05-21 01:36:05 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|