2020-03-06 23:06:01 +00:00
|
|
|
package stategen
|
|
|
|
|
|
|
|
import (
|
2020-03-15 16:47:49 +00:00
|
|
|
"context"
|
2020-03-06 23:06:01 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
testDB "github.com/prysmaticlabs/prysm/v4/beacon-chain/db/testing"
|
|
|
|
doublylinkedtree "github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice/doubly-linked-tree"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
2020-03-06 23:06:01 +00:00
|
|
|
)
|
|
|
|
|
2020-03-15 16:47:49 +00:00
|
|
|
func TestResume(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB := testDB.SetupDB(t)
|
2020-03-15 16:47:49 +00:00
|
|
|
|
2022-09-28 20:10:27 +00:00
|
|
|
service := New(beaconDB, doublylinkedtree.New())
|
2021-09-23 18:53:46 +00:00
|
|
|
b := util.NewBeaconBlock()
|
2022-06-24 17:22:39 +00:00
|
|
|
util.SaveBlock(t, ctx, service.beaconDB, b)
|
2020-10-29 16:14:57 +00:00
|
|
|
root, err := b.Block.HashTreeRoot()
|
|
|
|
require.NoError(t, err)
|
2021-09-23 18:53:46 +00:00
|
|
|
beaconState, _ := util.DeterministicGenesisState(t, 32)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
|
|
|
require.NoError(t, service.beaconDB.SaveState(ctx, beaconState, root))
|
2020-10-29 16:14:57 +00:00
|
|
|
require.NoError(t, service.beaconDB.SaveGenesisBlockRoot(ctx, root))
|
|
|
|
require.NoError(t, service.beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Root: root[:]}))
|
2020-03-15 16:47:49 +00:00
|
|
|
|
2021-11-06 13:45:16 +00:00
|
|
|
resumeState, err := service.Resume(ctx, beaconState)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2022-10-19 14:37:45 +00:00
|
|
|
require.DeepSSZEqual(t, beaconState.ToProtoUnsafe(), resumeState.ToProtoUnsafe())
|
2020-07-18 07:56:48 +00:00
|
|
|
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
|
|
|
}
|