prysm-pulse/beacon-chain/rpc/debug/block_test.go
Victor Farazdagi 10d3275638
Applies assertion funcs to rpc tests (#6641)
* applies assertion funcs to beacon-chain/rpc tests
* Merge branch 'master' into rpc-apply-testutils-assertions
* applies assertion funcs to beacon-chain/rpc/beacon tests
* Merge branch 'master' into rpc-apply-testutils-assertions
* applies assertion funcs to beacon-chain/rpc/debug tests
* applies assertion funcs to beacon-chain/rpc/validator tests
* Merge branch 'master' into rpc-apply-testutils-assertions
* Merge refs/heads/master into rpc-apply-testutils-assertions
2020-07-20 02:15:51 +00:00

43 lines
1.1 KiB
Go

package debug
import (
"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"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestServer_GetBlock(t *testing.T) {
db, _ := dbTest.SetupDB(t)
ctx := context.Background()
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{
Slot: 100,
}}
require.NoError(t, db.SaveBlock(ctx, b))
blockRoot, err := stateutil.BlockRoot(b.Block)
require.NoError(t, err)
bs := &Server{
BeaconDB: db,
}
res, err := bs.GetBlock(ctx, &pbrpc.BlockRequest{
BlockRoot: blockRoot[:],
})
require.NoError(t, err)
wanted, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, wanted, res.Encoded)
// Checking for nil block.
blockRoot = [32]byte{}
res, err = bs.GetBlock(ctx, &pbrpc.BlockRequest{
BlockRoot: blockRoot[:],
})
require.NoError(t, err)
assert.DeepEqual(t, []byte{}, res.Encoded)
}