2019-10-04 22:46:49 +00:00
|
|
|
package interop_test
|
2019-09-04 18:47:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-11-27 05:08:18 +00:00
|
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2019-09-04 18:47:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
2019-10-04 22:46:49 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/interop"
|
2019-09-04 18:47:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2020-07-19 21:08:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2019-09-04 18:47:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2020-10-13 12:43:49 +00:00
|
|
|
trie, err := trieutil.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-10-04 22:46:49 +00:00
|
|
|
deposits, err := interop.GenerateDepositsFromData(depositDataItems, trie)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-04 18:47:44 +00:00
|
|
|
root := trie.Root()
|
2019-09-11 18:38:35 +00:00
|
|
|
genesisState, err := state.GenesisBeaconState(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
|
|
|
}
|