github.com/prysmaticlabs/prysm@v1.4.4/shared/interop/generate_genesis_state_test.go (about)

     1  package interop_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
     8  	eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
     9  	"github.com/prysmaticlabs/prysm/shared/interop"
    10  	"github.com/prysmaticlabs/prysm/shared/params"
    11  	"github.com/prysmaticlabs/prysm/shared/testutil/assert"
    12  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    13  	"github.com/prysmaticlabs/prysm/shared/trieutil"
    14  )
    15  
    16  func TestGenerateGenesisState(t *testing.T) {
    17  	numValidators := uint64(64)
    18  	privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0 /*startIndex*/, numValidators)
    19  	require.NoError(t, err)
    20  	depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
    21  	require.NoError(t, err)
    22  	trie, err := trieutil.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
    23  	require.NoError(t, err)
    24  	deposits, err := interop.GenerateDepositsFromData(depositDataItems, trie)
    25  	require.NoError(t, err)
    26  	root := trie.Root()
    27  	genesisState, err := state.GenesisBeaconState(context.Background(), deposits, 0, &eth.Eth1Data{
    28  		DepositRoot:  root[:],
    29  		DepositCount: uint64(len(deposits)),
    30  	})
    31  	require.NoError(t, err)
    32  	want := int(numValidators)
    33  	assert.Equal(t, want, genesisState.NumValidators())
    34  	assert.Equal(t, uint64(0), genesisState.GenesisTime())
    35  }