Skip to content

Commit b40b1b1

Browse files
committed
Ensure time and genesis validators root match
1 parent 3c7548c commit b40b1b1

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

validator_client/http_api/src/test_utils.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,17 @@ impl ApiTester {
7171
}
7272

7373
pub async fn new_with_http_config(http_config: HttpConfig) -> Self {
74+
let slot_clock =
75+
TestingSlotClock::new(Slot::new(0), Duration::from_secs(0), Duration::from_secs(1));
76+
let genesis_validators_root = Hash256::repeat_byte(42);
7477
let spec = Arc::new(E::default_spec());
75-
Self::new_with_http_config_and_spec(http_config, spec).await
78+
Self::new_with_options(http_config, slot_clock, genesis_validators_root, spec).await
7679
}
7780

78-
pub async fn new_with_http_config_and_spec(
81+
pub async fn new_with_options(
7982
http_config: HttpConfig,
83+
slot_clock: TestingSlotClock,
84+
genesis_validators_root: Hash256,
8085
spec: Arc<ChainSpec>,
8186
) -> Self {
8287
let log = test_logger();
@@ -106,15 +111,12 @@ impl ApiTester {
106111
let slashing_db_path = validator_dir.path().join(SLASHING_PROTECTION_FILENAME);
107112
let slashing_protection = SlashingDatabase::open_or_create(&slashing_db_path).unwrap();
108113

109-
let slot_clock =
110-
TestingSlotClock::new(Slot::new(0), Duration::from_secs(0), Duration::from_secs(1));
111-
112114
let test_runtime = TestRuntime::default();
113115

114116
let validator_store = Arc::new(ValidatorStore::<_, E>::new(
115117
initialized_validators,
116118
slashing_protection,
117-
Hash256::repeat_byte(42),
119+
genesis_validators_root,
118120
spec.clone(),
119121
Some(Arc::new(DoppelgangerService::new(log.clone()))),
120122
slot_clock.clone(),

validator_client/signing_method/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub enum SigningMethod {
9696

9797
/// The additional information used to construct a signature. Mostly used for protection from replay
9898
/// attacks.
99+
#[derive(Debug)]
99100
pub struct SigningContext {
100101
pub domain: Domain,
101102
pub epoch: Epoch,

validator_manager/src/exit_validators.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,22 @@ mod test {
229229
}
230230

231231
async fn with_validators(mut self, index_of_validators_to_exit: usize) -> Self {
232-
let mut builder = ImportTestBuilder::new_with_http_config_and_spec(
232+
// Ensure genesis validators root matches the beacon node.
233+
let genesis_validators_root = self
234+
.beacon_node
235+
.harness
236+
.get_current_state()
237+
.genesis_validators_root();
238+
// And use a single slot clock for BN and VC to keep things simple.
239+
let slot_clock = self.beacon_node.harness.chain.slot_clock.clone();
240+
let vc = ApiTester::new_with_options(
233241
self.http_config.clone(),
242+
slot_clock,
243+
genesis_validators_root,
234244
self.spec.clone(),
235245
)
236246
.await;
247+
let mut builder = ImportTestBuilder::new_with_vc(vc).await;
237248

238249
println!("Validator client spec: {:?}", builder.vc.spec);
239250

validator_manager/src/import_validators.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,11 @@ pub mod tests {
385385
use std::{
386386
fs::{self, File},
387387
str::FromStr,
388-
sync::Arc,
389388
};
390389
use tempfile::{tempdir, TempDir};
391390
use types::*;
392391
use validator_http_api::{test_utils::ApiTester, Config as HttpConfig};
393392

394-
type E = MainnetEthSpec;
395-
396393
const VC_TOKEN_FILE_NAME: &str = "vc_token.json";
397394

398395
pub struct TestBuilder {
@@ -410,15 +407,12 @@ pub mod tests {
410407
}
411408

412409
pub async fn new_with_http_config(http_config: HttpConfig) -> Self {
413-
Self::new_with_http_config_and_spec(http_config, Arc::new(E::default_spec())).await
410+
let vc = ApiTester::new_with_http_config(http_config).await;
411+
Self::new_with_vc(vc).await
414412
}
415413

416-
pub async fn new_with_http_config_and_spec(
417-
http_config: HttpConfig,
418-
spec: Arc<ChainSpec>,
419-
) -> Self {
414+
pub async fn new_with_vc(vc: ApiTester) -> Self {
420415
let dir = tempdir().unwrap();
421-
let vc = ApiTester::new_with_http_config_and_spec(http_config, spec).await;
422416
let vc_token_path = dir.path().join(VC_TOKEN_FILE_NAME);
423417
fs::write(&vc_token_path, &vc.api_token).unwrap();
424418

0 commit comments

Comments
 (0)