diff --git a/beacon_node/rest_api/tests/test.rs b/beacon_node/rest_api/tests/test.rs index 47cb670544..7b0add4be2 100644 --- a/beacon_node/rest_api/tests/test.rs +++ b/beacon_node/rest_api/tests/test.rs @@ -12,6 +12,7 @@ use types::{ test_utils::generate_deterministic_keypair, BeaconBlock, ChainSpec, Domain, Epoch, EthSpec, MinimalEthSpec, PublicKey, RelativeEpoch, Signature, Slot, }; +use version; type E = MinimalEthSpec; @@ -559,3 +560,18 @@ fn eth2_config() { "should match genesis time from head state" ); } + +#[test] +fn get_version() { + let mut env = build_env(); + + let node = LocalBeaconNode::production(env.core_context(), testing_client_config()); + let remote_node = node.remote_node().expect("should produce remote node"); + + let version = env + .runtime() + .block_on(remote_node.http.node().get_version()) + .expect("should fetch eth2 config from http api"); + + assert_eq!(version::version(), version, "result should be as expected"); +} diff --git a/eth2/utils/remote_beacon_node/src/lib.rs b/eth2/utils/remote_beacon_node/src/lib.rs index 180f325adb..31960d925b 100644 --- a/eth2/utils/remote_beacon_node/src/lib.rs +++ b/eth2/utils/remote_beacon_node/src/lib.rs @@ -87,6 +87,10 @@ impl HttpClient { Spec(self.clone()) } + pub fn node(&self) -> Node { + Node(self.clone()) + } + fn url(&self, path: &str) -> Result { self.url.join(path).map_err(|e| e.into()) } @@ -419,6 +423,26 @@ impl Spec { } } +/// Provides the functions on the `/node` endpoint of the node. +#[derive(Clone)] +pub struct Node(HttpClient); + +impl Node { + fn url(&self, path: &str) -> Result { + self.0 + .url("node/") + .and_then(move |url| url.join(path).map_err(Error::from)) + .map_err(Into::into) + } + + pub fn get_version(&self) -> impl Future { + let client = self.0.clone(); + self.url("version") + .into_future() + .and_then(move |url| client.json_get(url, vec![])) + } +} + #[derive(Deserialize)] #[serde(bound = "T: EthSpec")] pub struct BlockResponse {