Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Dec 12, 2024
1 parent b290ce7 commit 667dad7
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions zebra-rpc/src/methods/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,31 @@ async fn rpc_getblock() {
);
}

// With verbosity=2, the RPC calls getrawtransaction which queries the
// mempool, which we need to mock since we used a MockService for it. This
// function returns a future that mocks that query. This is similar to what
// we use in the getrawtransaction test, but here we don't bother checking
// if the request is correct.
let make_mempool_req = || {
let mut mempool = mempool.clone();
async move {
mempool
.expect_request_that(|_request| true)
.await
.respond(mempool::Response::Transactions(vec![]));
}
};

// Make height calls with verbosity=2 and check response
for (i, block) in blocks.iter().enumerate() {
let get_block = rpc
.get_block(i.to_string(), Some(2u8))
.await
.expect("We should have a GetBlock struct");
let get_block_req = rpc.get_block(i.to_string(), Some(2u8));

// Run both the getblock request and the mocked mempool request.
// This assumes a single mempool query, i.e. that there is a single
// transaction the block. If the test vectors changes and the block
// has more than one transaction, this will need to be adjusted.
let (response, _) = futures::join!(get_block_req, make_mempool_req());
let get_block = response.expect("We should have a GetBlock struct");

let (expected_nonce, expected_final_sapling_root) =
get_block_data(&read_state, block.clone(), i).await;
Expand All @@ -262,7 +281,11 @@ async fn rpc_getblock() {
tx: block
.transactions
.iter()
.map(|tx| GetBlockTransaction::Hash(tx.hash()))
.map(|tx| GetBlockTransaction::Object(TransactionObject {
hex: (*tx).clone().into(),
height: i.try_into().expect("valid u32"),
confirmations: (blocks.len() - i).try_into().expect("valid i64")
}))
.collect(),
trees,
size: None,
Expand All @@ -287,10 +310,10 @@ async fn rpc_getblock() {

// Make hash calls with verbosity=2 and check response
for (i, block) in blocks.iter().enumerate() {
let get_block = rpc
.get_block(blocks[i].hash().to_string(), Some(2u8))
.await
.expect("We should have a GetBlock struct");
let get_block_req = rpc.get_block(blocks[i].hash().to_string(), Some(2u8));

let (response, _) = futures::join!(get_block_req, make_mempool_req());
let get_block = response.expect("We should have a GetBlock struct");

let (expected_nonce, expected_final_sapling_root) =
get_block_data(&read_state, block.clone(), i).await;
Expand All @@ -305,7 +328,11 @@ async fn rpc_getblock() {
tx: block
.transactions
.iter()
.map(|tx| GetBlockTransaction::Hash(tx.hash()))
.map(|tx| GetBlockTransaction::Object(TransactionObject {
hex: (*tx).clone().into(),
height: i.try_into().expect("valid u32"),
confirmations: (blocks.len() - i).try_into().expect("valid i64")
}))
.collect(),
trees,
size: None,
Expand Down

0 comments on commit 667dad7

Please sign in to comment.