2022-04-05 17:13:53 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/genesis"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
2022-04-05 17:13:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSaveOrigin(t *testing.T) {
|
|
|
|
params.SetupTestConfigCleanup(t)
|
2022-05-20 07:16:53 +00:00
|
|
|
// Embedded Genesis works with Mainnet config
|
|
|
|
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
2022-04-05 17:13:53 +00:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
db := setupDB(t)
|
|
|
|
|
2022-05-06 21:42:27 +00:00
|
|
|
st, err := genesis.State(params.MainnetName)
|
2022-04-05 17:13:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
sb, err := st.MarshalSSZ()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, db.LoadGenesis(ctx, sb))
|
|
|
|
|
|
|
|
// this is necessary for mainnet, because LoadGenesis is short-circuited by the embedded state,
|
|
|
|
// so the genesis root key is never written to the db.
|
|
|
|
require.NoError(t, db.EnsureEmbeddedGenesis(ctx))
|
|
|
|
|
|
|
|
cst, err := util.NewBeaconState()
|
|
|
|
require.NoError(t, err)
|
|
|
|
csb, err := cst.MarshalSSZ()
|
|
|
|
require.NoError(t, err)
|
|
|
|
cb := util.NewBeaconBlock()
|
2022-08-02 15:30:46 +00:00
|
|
|
scb, err := blocks.NewSignedBeaconBlock(cb)
|
2022-04-05 17:13:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
cbb, err := scb.MarshalSSZ()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, db.SaveOrigin(ctx, csb, cbb))
|
2022-05-04 23:41:33 +00:00
|
|
|
|
|
|
|
broot, err := scb.Block().HashTreeRoot()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, db.IsFinalizedBlock(ctx, broot))
|
2022-04-05 17:13:53 +00:00
|
|
|
}
|