prysm-pulse/beacon-chain/rpc/debug/block_test.go
Preston Van Loon 78a25f99c3
Update fastssz (#6760)
* Update fastssz
* Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz
* fmt
* gaz
* Merge refs/heads/master into update-fssz
* goimports
* Merge refs/heads/master into update-fssz
* Merge refs/heads/master into update-fssz
* Merge refs/heads/master into update-fssz
* Merge refs/heads/master into update-fssz
* Merge refs/heads/master into update-fssz
* Fix
* fix ethereumapis
* fix again
* kafka
* fix gen file
* fix compute signing root
* gofmt
* checkpoint progress
* progress
* checkpoint
* progress
* Fix build
* checkpoint
* helpers
* Another test fixed
* gaz
* another test fix
* gofmt
* some fixes
* Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz
* fix one test
* Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz
* fill empty checkpoint roots
* more padding
* more padding
* Fix //beacon-chain/rpc/debug:go_default_test
* fix //beacon-chain/core/state:go_default_test
* fix //beacon-chain/core/state:go_default_test
* fix some htr errors
* fix //slasher/rpc:go_default_test
* Progress on //beacon-chain/core/blocks:go_default_test
* Progress on //beacon-chain/core/blocks:go_default_test
* Progress on //beacon-chain/core/blocks:go_default_test
* fix //slasher/db/kv:go_default_test
* progress
* fix //beacon-chain/sync/initial-sync:go_raceon_test
* gofmt and gaz
* fix one more test, taking a break
* Fix //beacon-chain/core/blocks:go_default_test
* Complete beacon-chain/powchain
* Do most of beacon-chain/rpc/beacon/
* Do most of beacon-chain/blockchain
* fix //beacon-chain/operations/attestations/kv:go_default_test
* Fix //beacon-chain/cache/depositcache:go_default_test
* Fix //slasher/detection:go_default_test
* Progress
* fix //beacon-chain/rpc/validator:go_default_test
* gofmt
* fix //validator/client:go_default_test
* fix
* fix //beacon-chain/blockchain:go_raceoff_test
* fix //beacon-chain/rpc/beacon:go_default_test
* fix 1 of 4 shards in //beacon-chain/sync:go_default_test
* Fix //beacon-chain/sync:go_default_test and gofmt
* prevent panic
* fix //beacon-chain/state/stategen:go_default_test
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz
* fix most tests
* Self review, go mod tidy, run regen scripts
* fix slasher
* Update ethereumapis
* disable spawn strategy override
* Merge refs/heads/master into update-fssz
* Merge refs/heads/master into update-fssz
* Remove extra line in imports
* Remove extra line in imports
* Gofmt
* PR feedback from @nisdas
2020-08-24 01:46:17 +00:00

88 lines
2.8 KiB
Go

package debug
import (
"context"
"testing"
"time"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"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 := testutil.NewBeaconBlock()
b.Block.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)
}
func TestServer_GetAttestationInclusionSlot(t *testing.T) {
db, sc := dbTest.SetupDB(t)
ctx := context.Background()
bs := &Server{
BeaconDB: db,
StateGen: stategen.New(db, sc),
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*int64(
2*params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot)) * time.Second)},
}
s, _ := testutil.DeterministicGenesisState(t, 2048)
tr := [32]byte{'a'}
require.NoError(t, bs.StateGen.SaveState(ctx, tr, s))
c, err := helpers.BeaconCommitteeFromState(s, 1, 0)
require.NoError(t, err)
a := &ethpb.Attestation{
Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{Root: tr[:]},
Source: &ethpb.Checkpoint{Root: make([]byte, 32)},
BeaconBlockRoot: make([]byte, 32),
Slot: 1,
},
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
Signature: make([]byte, 96),
}
b := testutil.NewBeaconBlock()
b.Block.Slot = 2
b.Block.Body.Attestations = []*ethpb.Attestation{a}
require.NoError(t, bs.BeaconDB.SaveBlock(ctx, b))
res, err := bs.GetInclusionSlot(ctx, &pbrpc.InclusionSlotRequest{Slot: 1, Id: c[0]})
require.NoError(t, err)
require.Equal(t, b.Block.Slot, res.Slot)
res, err = bs.GetInclusionSlot(ctx, &pbrpc.InclusionSlotRequest{Slot: 1, Id: 9999999})
require.NoError(t, err)
require.Equal(t, params.BeaconConfig().FarFutureEpoch, res.Slot)
}