fix(test): Avoid spurious rpc_getblocktemplate test failure (#5909)
* moves mock service request handling to main thread * removes unnecessary block
This commit is contained in:
parent
53e836efdc
commit
bc783a7745
|
|
@ -901,8 +901,6 @@ async fn rpc_getblocktemplate() {
|
||||||
|
|
||||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
||||||
async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
||||||
use std::panic;
|
|
||||||
|
|
||||||
use zebra_chain::{
|
use zebra_chain::{
|
||||||
amount::NonNegative,
|
amount::NonNegative,
|
||||||
block::{Hash, MAX_BLOCK_BYTES, ZCASH_BLOCK_VERSION},
|
block::{Hash, MAX_BLOCK_BYTES, ZCASH_BLOCK_VERSION},
|
||||||
|
|
@ -931,7 +929,7 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
||||||
|
|
||||||
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
||||||
|
|
||||||
let read_state = MockService::build().for_unit_tests();
|
let mut read_state = MockService::build().for_unit_tests();
|
||||||
let chain_verifier = MockService::build().for_unit_tests();
|
let chain_verifier = MockService::build().for_unit_tests();
|
||||||
|
|
||||||
let mut mock_sync_status = MockSyncStatus::default();
|
let mut mock_sync_status = MockSyncStatus::default();
|
||||||
|
|
@ -973,9 +971,8 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fake the ChainInfo response
|
// Fake the ChainInfo response
|
||||||
tokio::spawn(async move {
|
let mock_read_state_request_handler = async move {
|
||||||
read_state
|
read_state
|
||||||
.clone()
|
|
||||||
.expect_request_that(|req| matches!(req, ReadRequest::ChainInfo))
|
.expect_request_that(|req| matches!(req, ReadRequest::ChainInfo))
|
||||||
.await
|
.await
|
||||||
.respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo {
|
.respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo {
|
||||||
|
|
@ -987,24 +984,28 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
||||||
max_time: fake_max_time,
|
max_time: fake_max_time,
|
||||||
history_tree: fake_history_tree(Mainnet),
|
history_tree: fake_history_tree(Mainnet),
|
||||||
}));
|
}));
|
||||||
});
|
};
|
||||||
|
|
||||||
let get_block_template = tokio::spawn(get_block_template_rpc.get_block_template(None));
|
let mock_mempool_request_handler = {
|
||||||
|
let mut mempool = mempool.clone();
|
||||||
|
async move {
|
||||||
|
mempool
|
||||||
|
.expect_request(mempool::Request::FullTransactions)
|
||||||
|
.await
|
||||||
|
.respond(mempool::Response::FullTransactions(vec![]));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
mempool
|
let get_block_template_fut = get_block_template_rpc.get_block_template(None);
|
||||||
.expect_request(mempool::Request::FullTransactions)
|
|
||||||
.await
|
|
||||||
.respond(mempool::Response::FullTransactions(vec![]));
|
|
||||||
|
|
||||||
let get_block_template = get_block_template
|
let (get_block_template, ..) = tokio::join!(
|
||||||
.await
|
get_block_template_fut,
|
||||||
.unwrap_or_else(|error| match error.try_into_panic() {
|
mock_mempool_request_handler,
|
||||||
Ok(panic_object) => panic::resume_unwind(panic_object),
|
mock_read_state_request_handler,
|
||||||
Err(cancelled_error) => {
|
);
|
||||||
panic!("getblocktemplate task was unexpectedly cancelled: {cancelled_error:?}")
|
|
||||||
}
|
let get_block_template =
|
||||||
})
|
get_block_template.expect("unexpected error in getblocktemplate RPC call");
|
||||||
.expect("unexpected error in getblocktemplate RPC call");
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_block_template.capabilities,
|
get_block_template.capabilities,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue