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
|
|
|
"github.com/gogo/protobuf/proto"
|
2020-10-29 16:14:57 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-03-15 16:47:49 +00:00
|
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
2020-03-06 23:06:01 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2020-03-15 16:47:49 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2020-07-18 07:56:48 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
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-16 16:56:21 +00:00
|
|
|
db := testDB.SetupDB(t)
|
2020-03-15 16:47:49 +00:00
|
|
|
|
2020-12-16 16:56:21 +00:00
|
|
|
service := New(db)
|
2020-10-29 16:14:57 +00:00
|
|
|
b := testutil.NewBeaconBlock()
|
|
|
|
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
|
|
|
root, err := b.Block.HashTreeRoot()
|
|
|
|
require.NoError(t, err)
|
2020-03-15 16:47:49 +00:00
|
|
|
beaconState, _ := testutil.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
|
|
|
|
2020-03-27 20:28:38 +00:00
|
|
|
resumeState, err := service.Resume(ctx)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-03-15 16:47:49 +00:00
|
|
|
|
|
|
|
if !proto.Equal(beaconState.InnerStateUnsafe(), resumeState.InnerStateUnsafe()) {
|
|
|
|
t.Error("Diff saved state")
|
|
|
|
}
|
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
|
|
|
}
|