prysm-pulse/beacon-chain/state/stategen/service_test.go

38 lines
1.5 KiB
Go
Raw Normal View History

package stategen
import (
2020-03-15 16:47:49 +00:00
"context"
"testing"
2020-03-15 16:47:49 +00:00
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/params"
2020-03-15 16:47:49 +00:00
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
2020-03-15 16:47:49 +00:00
func TestResume(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
2020-03-15 16:47:49 +00:00
service := New(beaconDB)
b := testutil.NewBeaconBlock()
2021-05-26 18:33:46 +00:00
require.NoError(t, service.beaconDB.SaveBlock(ctx, interfaces.WrappedPhase0SignedBeaconBlock(b)))
root, err := b.Block.HashTreeRoot()
require.NoError(t, err)
2020-03-15 16:47:49 +00:00
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
require.NoError(t, service.beaconDB.SaveState(ctx, beaconState, root))
require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, root))
require.NoError(t, service.beaconDB.SaveFinalizedCheckpoint(ctx, &ethpb.Checkpoint{Root: root[:]}))
2020-03-15 16:47:49 +00:00
resumeState, err := service.Resume(ctx)
require.NoError(t, err)
require.DeepSSZEqual(t, beaconState.InnerStateUnsafe(), resumeState.InnerStateUnsafe())
assert.Equal(t, params.BeaconConfig().SlotsPerEpoch, service.finalizedInfo.slot, "Did not get watned slot")
assert.Equal(t, service.finalizedInfo.root, root, "Did not get wanted root")
assert.NotNil(t, service.finalizedState(), "Wanted a non nil finalized state")
2020-03-15 16:47:49 +00:00
}