Skip to content

Commit

Permalink
Add request & incomplete test for validator blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 8, 2020
1 parent 767b036 commit 510bc72
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
10 changes: 8 additions & 2 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::sync::oneshot;
use types::{
test_utils::generate_deterministic_keypairs, BeaconState, EthSpec, Hash256, MainnetEthSpec,
RelativeEpoch, Slot,
test_utils::generate_deterministic_keypairs, BeaconState, EthSpec, Hash256, Keypair,
MainnetEthSpec, RelativeEpoch, Slot,
};

type E = MainnetEthSpec;
Expand Down Expand Up @@ -45,6 +45,7 @@ struct ApiTester {
proposer_slashing: ProposerSlashing,
voluntary_exit: SignedVoluntaryExit,
_server_shutdown: oneshot::Sender<()>,
validator_keypairs: Vec<Keypair>,
network_rx: mpsc::UnboundedReceiver<NetworkMessage<E>>,
}

Expand Down Expand Up @@ -164,6 +165,7 @@ impl ApiTester {
proposer_slashing,
voluntary_exit,
_server_shutdown: shutdown_tx,
validator_keypairs: harness.validators_keypairs,
network_rx,
}
}
Expand Down Expand Up @@ -1097,6 +1099,10 @@ impl ApiTester {

self
}

pub async fn test_get_validator_block(self) -> Self {
todo!()
}
}

#[tokio::test(core_threads = 2)]
Expand Down
30 changes: 30 additions & 0 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,36 @@ impl BeaconNodeClient {

self.get(path).await
}

/// `GET validator/duties/attester/{epoch}?index`
///
/// ## Note
///
/// The `index` query parameter accepts a list of validator indices.
pub async fn get_validator_blocks<T: EthSpec>(
&self,
slot: Slot,
randao_reveal: SignatureBytes,
graffiti: Option<&Graffiti>,
) -> Result<GenericResponse<Vec<BeaconBlock<T>>>, Error> {
let mut path = self.server.clone();

path.path_segments_mut()
.expect("path is base")
.push("validator")
.push("blocks")
.push(&slot.to_string());

path.query_pairs_mut()
.append_pair("randao_reveal", &randao_reveal.to_string());

if let Some(graffiti) = graffiti {
path.query_pairs_mut()
.append_pair("graffiti", &graffiti.to_string());
}

self.get(path).await
}
}

/// Returns `Ok(response)` if the response is a `200 OK` response. Otherwise, creates an
Expand Down
12 changes: 9 additions & 3 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::str::FromStr;
use types::serde_utils;

pub use types::{
Address, Attestation, AttesterSlashing, BeaconBlockHeader, BeaconState, Checkpoint, Epoch,
EthSpec, Fork, Hash256, ProposerSlashing, PublicKeyBytes, SignatureBytes, SignedBeaconBlock,
SignedVoluntaryExit, Slot, Validator, YamlConfig, GRAFFITI_BYTES_LEN,
Address, Attestation, AttesterSlashing, BeaconBlock, BeaconBlockHeader, BeaconState,
Checkpoint, Epoch, EthSpec, Fork, Hash256, ProposerSlashing, PublicKeyBytes, SignatureBytes,
SignedBeaconBlock, SignedVoluntaryExit, Slot, Validator, YamlConfig, GRAFFITI_BYTES_LEN,
};

/// An API error serializable to JSON.
Expand Down Expand Up @@ -364,6 +364,12 @@ pub struct ValidatorDutiesData {
#[serde(transparent)]
pub struct Graffiti(#[serde(with = "serde_utils::graffiti")] pub [u8; GRAFFITI_BYTES_LEN]);

impl fmt::Display for Graffiti {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", serde_utils::hex::encode(&self.0))
}
}

impl Into<[u8; GRAFFITI_BYTES_LEN]> for Graffiti {
fn into(self) -> [u8; GRAFFITI_BYTES_LEN] {
self.0
Expand Down

0 comments on commit 510bc72

Please sign in to comment.