2021-09-29 02:27:21 +00:00
|
|
|
package simulator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
mock "github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain/testing"
|
|
|
|
dbtest "github.com/prysmaticlabs/prysm/v4/beacon-chain/db/testing"
|
|
|
|
mockstategen "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stategen/mock"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
2021-09-29 02:27:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func setupService(t *testing.T, params *Parameters) *Simulator {
|
|
|
|
slasherDB := dbtest.SetupSlasherDB(t)
|
|
|
|
beaconState, err := util.NewBeaconState()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// We setup validators in the beacon state along with their
|
|
|
|
// private keys used to generate valid signatures in generated objects.
|
|
|
|
validators := make([]*ethpb.Validator, params.NumValidators)
|
2023-01-26 14:40:12 +00:00
|
|
|
privKeys := make(map[primitives.ValidatorIndex]bls.SecretKey)
|
2021-09-29 02:27:21 +00:00
|
|
|
for valIdx := range validators {
|
|
|
|
privKey, err := bls.RandKey()
|
|
|
|
require.NoError(t, err)
|
2023-01-26 14:40:12 +00:00
|
|
|
privKeys[primitives.ValidatorIndex(valIdx)] = privKey
|
2021-09-29 02:27:21 +00:00
|
|
|
validators[valIdx] = ðpb.Validator{
|
|
|
|
PublicKey: privKey.PublicKey().Marshal(),
|
|
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = beaconState.SetValidators(validators)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-10-20 16:45:33 +00:00
|
|
|
gen := mockstategen.NewService()
|
2021-09-29 02:27:21 +00:00
|
|
|
gen.AddStateForRoot(beaconState, [32]byte{})
|
|
|
|
return &Simulator{
|
|
|
|
srvConfig: &ServiceConfig{
|
|
|
|
Params: params,
|
|
|
|
Database: slasherDB,
|
|
|
|
AttestationStateFetcher: &mock.ChainService{State: beaconState},
|
|
|
|
PrivateKeysByValidatorIndex: privKeys,
|
|
|
|
StateGen: gen,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|