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"
|
|
|
|
"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)
|
2019-09-04 18:47:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-10-04 22:46:49 +00:00
|
|
|
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
2019-09-04 18:47:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
trie, err := trieutil.GenerateTrieFromItems(
|
|
|
|
depositDataRoots,
|
|
|
|
int(params.BeaconConfig().DepositContractTreeDepth),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-10-04 22:46:49 +00:00
|
|
|
deposits, err := interop.GenerateDepositsFromData(depositDataItems, trie)
|
2019-09-04 18:47:44 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
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)),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-09-11 18:38:35 +00:00
|
|
|
want := int(numValidators)
|
2020-01-31 20:57:01 +00:00
|
|
|
if genesisState.NumValidators() != want {
|
|
|
|
t.Errorf("Wanted %d validators, received %d", want, genesisState.NumValidators())
|
2019-09-04 18:47:44 +00:00
|
|
|
}
|
2020-01-31 20:57:01 +00:00
|
|
|
if genesisState.NumValidators() != want {
|
|
|
|
t.Errorf("Wanted %d validators, received %v", want, genesisState.NumValidators())
|
2019-09-04 18:47:44 +00:00
|
|
|
}
|
2020-01-31 20:57:01 +00:00
|
|
|
if genesisState.GenesisTime() != 0 {
|
|
|
|
t.Errorf("Wanted genesis time 0, received %d", genesisState.GenesisTime())
|
2019-09-04 18:47:44 +00:00
|
|
|
}
|
|
|
|
}
|