Skip to content

Commit

Permalink
update snapshot test to use mock read state
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Nov 17, 2022
1 parent eec81b1 commit b15bc41
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ pub async fn test_responses<State, ReadState>(

let get_block_template_rpc = GetBlockTemplateRpcImpl::new(
network,
mining_config,
mining_config.clone(),
Buffer::new(mempool.clone(), 1),
read_state,
mock_chain_tip,
chain_verifier,
mock_chain_tip.clone(),
chain_verifier.clone(),
);

// `getblockcount`
Expand All @@ -104,6 +104,34 @@ pub async fn test_responses<State, ReadState>(

snapshot_rpc_getblockhash(get_block_hash, &settings);

// `submitblock`
let submit_block = get_block_template_rpc
.submit_block(HexData("".into()), None)
.await
.expect("unexpected error in submitblock RPC call");

snapshot_rpc_submit_block_invalid(submit_block, &settings);

// Init RPC for getblocktemplate rpc method with the mock read_state service.
let mut read_state = MockService::build().for_unit_tests();
let get_block_template_rpc = GetBlockTemplateRpcImpl::new(
network,
mining_config,
Buffer::new(mempool.clone(), 1),
read_state.clone(),
mock_chain_tip,
chain_verifier,
);

tokio::spawn(async move {
read_state
.expect_request_that(|req| {
matches!(req, zebra_state::ReadRequest::CheckContextualValidity(_))
})
.await
.respond(zebra_state::ReadResponse::Validated);
});

// `getblocktemplate`
let get_block_template = tokio::spawn(get_block_template_rpc.get_block_template());

Expand All @@ -125,14 +153,6 @@ pub async fn test_responses<State, ReadState>(
.expect("coinbase bytes are valid");

snapshot_rpc_getblocktemplate(get_block_template, coinbase_tx, &settings);

// `submitblock`
let submit_block = get_block_template_rpc
.submit_block(HexData("".into()), None)
.await
.expect("unexpected error in submitblock RPC call");

snapshot_rpc_submit_block_invalid(submit_block, &settings);
}

/// Snapshot `getblockcount` response, using `cargo insta` and JSON serialization.
Expand Down

0 comments on commit b15bc41

Please sign in to comment.