Skip to content

Commit

Permalink
Try the RPC again after waiting for transactions to verify
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 1, 2022
1 parent 02852d5 commit 4eb310b
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions zebrad/tests/common/get_block_template_rpcs/get_block_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//!
//! After finishing the sync, it will call getblocktemplate.

use std::time::Duration;

use color_eyre::eyre::{eyre, Context, Result};

use zebra_chain::parameters::Network;
Expand All @@ -16,6 +18,12 @@ use crate::common::{
test_type::TestType,
};

/// How long the test waits for the mempool to download and verify transactions.
///
/// We've seen it take anywhere from 1-45 seconds for the mempool to have some transactions in it.
pub const EXPECTED_MEMPOOL_TRANSACTION_TIME: Duration = Duration::from_secs(45);

/// Launch Zebra, wait for it to sync, and check the getblocktemplate RPC returns without errors.
pub(crate) async fn run() -> Result<()> {
let _init_guard = zebra_test::init();

Expand Down Expand Up @@ -50,15 +58,41 @@ pub(crate) async fn run() -> Result<()> {
true,
)?;

tracing::info!("calling getblocktemplate RPC method at {rpc_address}...",);
tracing::info!(
"calling getblocktemplate RPC method at {rpc_address}, \
with a mempool that is likely empty...",
);
let getblocktemplate_response = RPCRequestClient::new(rpc_address)
.call("getblocktemplate", "[]".to_string())
.await?;

let is_response_success = getblocktemplate_response.status().is_success();
let response_text = getblocktemplate_response.text().await?;

tracing::info!(response_text, "got getblocktemplate response",);
tracing::info!(
response_text,
"got getblocktemplate response, might not have transactions"
);

assert!(is_response_success);

tokio::time::sleep(EXPECTED_MEMPOOL_TRANSACTION_TIME).await;

tracing::info!(
"calling getblocktemplate RPC method at {rpc_address}, \
with a mempool that likely has transactions...",
);
let getblocktemplate_response = RPCRequestClient::new(rpc_address)
.call("getblocktemplate", "[]".to_string())
.await?;

let is_response_success = getblocktemplate_response.status().is_success();
let response_text = getblocktemplate_response.text().await?;

tracing::info!(
response_text,
"got getblocktemplate response, hopefully with transactions"
);

assert!(is_response_success);

Expand Down

0 comments on commit 4eb310b

Please sign in to comment.