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