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"
|
|
|
|
|
2020-03-15 16:47:49 +00:00
|
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2022-05-02 15:43:40 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
2021-07-21 21:34:07 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/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
|
|
|
|
2020-12-18 19:12:30 +00:00
|
|
|
service := New(beaconDB)
|
2021-09-23 18:53:46 +00:00
|
|
|
b := util.NewBeaconBlock()
|
2022-03-25 23:00:44 +00:00
|
|
|
wsb, err := wrapper.WrappedSignedBeaconBlock(b)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, service.beaconDB.SaveBlock(ctx, wsb))
|
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)
|
2021-02-23 22:20:11 +00:00
|
|
|
require.DeepSSZEqual(t, beaconState.InnerStateUnsafe(), resumeState.InnerStateUnsafe())
|
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
|
|
|
}
|