Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Sep 5, 2020
1 parent 85d4593 commit cb74420
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions beacon_node/http_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ slog = "2.5.2"

[dev-dependencies]
store = { path = "../store" }
environment = { path = "../../lighthouse/environment" }
6 changes: 3 additions & 3 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct Context<T: BeaconChainTypes> {
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub enabled: bool,
pub listen_socket_addr: SocketAddr,
pub listen_addr: Ipv4Addr,
pub listen_port: u16,
}
Expand All @@ -36,9 +35,8 @@ impl Default for Config {
fn default() -> Self {
Self {
enabled: false,
listen_socket_addr: SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 5054).into(),
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
listen_port: 5054,
listen_port: 5052,
}
}
}
Expand Down Expand Up @@ -314,6 +312,7 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("beacon"))
.and(warp::path("headers"))
.and(warp::query::<api_types::HeadersQuery>())
.and(warp::path::end())
.and(chain_filter.clone())
.and_then(
|query: api_types::HeadersQuery, chain: Arc<BeaconChain<T>>| {
Expand Down Expand Up @@ -388,6 +387,7 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path("beacon"))
.and(warp::path("headers"))
.and(warp::path::param::<BlockId>())
.and(warp::path::end())
.and(chain_filter.clone())
.and_then(|block_id: BlockId, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
Expand Down
28 changes: 22 additions & 6 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use beacon_chain::{
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, HarnessType},
BeaconChain,
};
use environment::null_logger;
use eth2::{types::*, BeaconNodeClient, Url};
use http_api::Context;
use http_api::{Config, Context};
use std::net::Ipv4Addr;
use std::sync::Arc;
use store::config::StoreConfig;
use tokio::sync::oneshot;
Expand Down Expand Up @@ -78,12 +80,21 @@ impl ApiTester {
);

let context = Arc::new(Context {
config: Config {
enabled: true,
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
listen_port: 0,
},
chain: Some(chain.clone()),
listen_address: [127, 0, 0, 1],
listen_port: 0,
log: null_logger().unwrap(),
});
let ctx = context.clone();
let (listening_socket, server, server_shutdown) = http_api::serve(ctx).unwrap();
let (shutdown_tx, shutdown_rx) = oneshot::channel();
let server_shutdown = async {
// It's not really interesting why this triggered, just that it happened.
let _ = shutdown_rx.await;
};
let (listening_socket, server) = http_api::serve(ctx, server_shutdown).unwrap();

tokio::spawn(async { server.await });

Expand All @@ -100,7 +111,7 @@ impl ApiTester {
Self {
chain,
client,
_server_shutdown: server_shutdown,
_server_shutdown: shutdown_tx,
}
}

Expand Down Expand Up @@ -538,8 +549,13 @@ impl ApiTester {
let result = result.unwrap();
let block = block_opt.unwrap();
let block_root = block_root_opt.unwrap();
let canonical = self
.chain
.block_root_at_slot(block.slot())
.unwrap()
.map_or(false, |canonical| block_root == canonical);

assert!(result.canonical, "{:?}", block_id);
assert_eq!(result.canonical, canonical, "{:?}", block_id);
assert_eq!(result.root, block_root, "{:?}", block_id);
assert_eq!(
result.header.message,
Expand Down
5 changes: 1 addition & 4 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl BeaconNodeClient {

async fn get_opt<T: DeserializeOwned, U: IntoUrl>(&self, url: U) -> Result<Option<T>, Error> {
match self.client.get(url).send().await?.error_for_status() {
Ok(resp) => {
dbg!(&resp);
resp.json().await.map(Option::Some)
}
Ok(resp) => resp.json().await.map(Option::Some),
Err(err) => {
if err.status() == Some(StatusCode::NOT_FOUND) {
Ok(None)
Expand Down

0 comments on commit cb74420

Please sign in to comment.