mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
302b0f8c80
* use fast ssz anywhere applicable * use fastssz clearly * Merge branch 'master' into use-fastssz * Apply suggestions from code review * imports * Update beacon-chain/p2p/fork.go * Merge branch 'master' into use-fastssz * update go-ssz * update go-ssz * Merge refs/heads/master into use-fastssz * Merge refs/heads/master into use-fastssz
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
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) {
|
|
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 := b.MarshalSSZ()
|
|
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)
|
|
}
|
|
}
|