Skip to content
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 42 additions & 24 deletions testing/web3signer_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod tests {
use eth2_keystore::KeystoreBuilder;
use eth2_network_config::Eth2NetworkConfig;
use fixed_bytes::FixedBytesExtended;
use futures::StreamExt;
use initialized_validators::{
InitializedValidators, load_pem_certificate, load_pkcs12_identity,
};
Expand All @@ -50,7 +51,7 @@ mod tests {
use types::{attestation::AttestationBase, *};
use url::Url;
use validator_store::{
Error as ValidatorStoreError, SignedBlock, UnsignedBlock, ValidatorStore,
AttestationToSign, Error as ValidatorStoreError, SignedBlock, UnsignedBlock, ValidatorStore,
};

/// If the we are unable to reach the Web3Signer HTTP API within this time out then we will
Expand Down Expand Up @@ -654,13 +655,14 @@ mod tests {
.await
.assert_signatures_match("attestation", |pubkey, validator_store| async move {
let attestation = get_attestation();
validator_store
.sign_attestations(vec![(0, pubkey, 0, attestation)])
.await
.unwrap()
.pop()
.unwrap()
.1
let stream = validator_store.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey,
validator_committee_index: 0,
attestation,
}]);
tokio::pin!(stream);
stream.next().await.unwrap().unwrap().pop().unwrap().1
})
.await
.assert_signatures_match("signed_aggregate", |pubkey, validator_store| async move {
Expand Down Expand Up @@ -879,22 +881,28 @@ mod tests {
.await
.assert_signatures_match("first_attestation", |pubkey, validator_store| async move {
let attestation = first_attestation();
validator_store
.sign_attestations(vec![(0, pubkey, 0, attestation)])
.await
.unwrap()
.pop()
.unwrap()
.1
let stream = validator_store.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey,
validator_committee_index: 0,
attestation,
}]);
tokio::pin!(stream);
stream.next().await.unwrap().unwrap().pop().unwrap().1
})
.await
.assert_slashable_attestation_should_sign(
"double_vote_attestation",
move |pubkey, validator_store| async move {
let attestation = double_vote_attestation();
validator_store
.sign_attestations(vec![(0, pubkey, 0, attestation)])
.await
let stream = validator_store.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey,
validator_committee_index: 0,
attestation,
}]);
tokio::pin!(stream);
stream.next().await.unwrap()
},
slashable_message_should_sign,
)
Expand All @@ -903,9 +911,14 @@ mod tests {
"surrounding_attestation",
move |pubkey, validator_store| async move {
let attestation = surrounding_attestation();
validator_store
.sign_attestations(vec![(0, pubkey, 0, attestation)])
.await
let stream = validator_store.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey,
validator_committee_index: 0,
attestation,
}]);
tokio::pin!(stream);
stream.next().await.unwrap()
},
slashable_message_should_sign,
)
Expand All @@ -914,9 +927,14 @@ mod tests {
"surrounded_attestation",
move |pubkey, validator_store| async move {
let attestation = surrounded_attestation();
validator_store
.sign_attestations(vec![(0, pubkey, 0, attestation)])
.await
let stream = validator_store.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey,
validator_committee_index: 0,
attestation,
}]);
tokio::pin!(stream);
stream.next().await.unwrap()
},
slashable_message_should_sign,
)
Expand Down
43 changes: 28 additions & 15 deletions validator_client/http_api/src/tests/keystores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use eth2::lighthouse_vc::{
types::Web3SignerValidatorRequest,
};
use fixed_bytes::FixedBytesExtended;
use futures::StreamExt;
use itertools::Itertools;
use lighthouse_validator_store::DEFAULT_GAS_LIMIT;
use rand::rngs::StdRng;
Expand All @@ -19,6 +20,7 @@ use std::{collections::HashMap, path::Path};
use tokio::runtime::Handle;
use typenum::Unsigned;
use types::{Address, attestation::AttestationBase};
use validator_store::AttestationToSign;
use validator_store::ValidatorStore;
use zeroize::Zeroizing;

Expand Down Expand Up @@ -1101,11 +1103,16 @@ async fn generic_migration_test(
// Sign attestations on VC1.
for (validator_index, attestation) in first_vc_attestations {
let public_key = keystore_pubkey(&keystores[validator_index]);
let safe_attestations = tester1
let stream = tester1
.validator_store
.sign_attestations(vec![(0, public_key, 0, attestation.clone())])
.await
.unwrap();
.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey: public_key,
validator_committee_index: 0,
attestation: attestation.clone(),
}]);
tokio::pin!(stream);
let safe_attestations = stream.next().await.unwrap().unwrap();
assert_eq!(safe_attestations.len(), 1);
// Compare data only, ignoring signatures which are added during signing.
assert_eq!(safe_attestations[0].1.data(), attestation.data());
Expand Down Expand Up @@ -1184,10 +1191,16 @@ async fn generic_migration_test(
// Sign attestations on the second VC.
for (validator_index, attestation, should_succeed) in second_vc_attestations {
let public_key = keystore_pubkey(&keystores[validator_index]);
let result = tester2
let stream = tester2
.validator_store
.sign_attestations(vec![(0, public_key, 0, attestation.clone())])
.await;
.sign_attestations(vec![AttestationToSign {
validator_index: 0,
pubkey: public_key,
validator_committee_index: 0,
attestation: attestation.clone(),
}]);
tokio::pin!(stream);
let result = stream.next().await.unwrap();
match result {
Ok(safe_attestations) => {
if should_succeed {
Expand Down Expand Up @@ -1331,14 +1344,14 @@ async fn delete_concurrent_with_signing() {
for j in 0..num_attestations {
let att = make_attestation(j, j + 1);
for (validator_index, public_key) in thread_pubkeys.iter().enumerate() {
let _ = validator_store
.sign_attestations(vec![(
validator_index as u64,
*public_key,
0,
att.clone(),
)])
.await;
let stream = validator_store.sign_attestations(vec![AttestationToSign {
validator_index: validator_index as u64,
pubkey: *public_key,
validator_committee_index: 0,
attestation: att.clone(),
}]);
tokio::pin!(stream);
let _ = stream.next().await;
}
}
});
Expand Down
Loading
Loading