2019-10-04 22:46:49 +00:00
|
|
|
package interop_test
|
2019-09-04 18:47:44 +00:00
|
|
|
|
|
|
|
import (
|
2021-04-05 15:07:56 +00:00
|
|
|
"context"
|
2019-09-04 18:47:44 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/container/trie"
|
|
|
|
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/interop"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2019-09-04 18:47:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateGenesisState(t *testing.T) {
|
2019-09-11 18:38:35 +00:00
|
|
|
numValidators := uint64(64)
|
2019-10-04 22:46:49 +00:00
|
|
|
privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0 /*startIndex*/, numValidators)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-10-04 22:46:49 +00:00
|
|
|
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2021-09-21 18:11:16 +00:00
|
|
|
tr, err := trie.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2021-09-21 18:11:16 +00:00
|
|
|
deposits, err := interop.GenerateDepositsFromData(depositDataItems, tr)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2022-05-09 16:51:48 +00:00
|
|
|
root, err := tr.HashTreeRoot()
|
|
|
|
require.NoError(t, err)
|
2021-09-08 10:41:47 +00:00
|
|
|
genesisState, err := transition.GenesisBeaconState(context.Background(), deposits, 0, ð.Eth1Data{
|
2019-09-04 18:47:44 +00:00
|
|
|
DepositRoot: root[:],
|
|
|
|
DepositCount: uint64(len(deposits)),
|
|
|
|
})
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-11 18:38:35 +00:00
|
|
|
want := int(numValidators)
|
2020-07-19 21:08:29 +00:00
|
|
|
assert.Equal(t, want, genesisState.NumValidators())
|
|
|
|
assert.Equal(t, uint64(0), genesisState.GenesisTime())
|
2019-09-04 18:47:44 +00:00
|
|
|
}
|