Update tests, remove transparent addresses
This commit is contained in:
parent
b0249aa7f5
commit
8405f361e9
|
|
@ -96,12 +96,6 @@ async fn test_rpc_response_data_for_network(network: &Network) {
|
||||||
// get the first transaction of the first block which is not the genesis
|
// get the first transaction of the first block which is not the genesis
|
||||||
let first_block_first_transaction = &blocks[1].transactions[0];
|
let first_block_first_transaction = &blocks[1].transactions[0];
|
||||||
|
|
||||||
// build addresses
|
|
||||||
let address = &first_block_first_transaction.outputs()[1]
|
|
||||||
.address(network)
|
|
||||||
.unwrap();
|
|
||||||
let addresses = vec![address.to_string()];
|
|
||||||
|
|
||||||
|
|
||||||
// `getblock` variants
|
// `getblock` variants
|
||||||
// A valid block height in the populated state
|
// A valid block height in the populated state
|
||||||
|
|
@ -281,52 +275,6 @@ async fn test_rpc_response_data_for_network(network: &Network) {
|
||||||
let get_raw_transaction = response.expect("We should have a GetRawTransaction struct");
|
let get_raw_transaction = response.expect("We should have a GetRawTransaction struct");
|
||||||
|
|
||||||
snapshot_rpc_getrawtransaction("verbosity_1", get_raw_transaction, &settings);
|
snapshot_rpc_getrawtransaction("verbosity_1", get_raw_transaction, &settings);
|
||||||
|
|
||||||
// `getaddresstxids`
|
|
||||||
let get_address_tx_ids = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start: 1,
|
|
||||||
end: 10,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.expect("We should have a vector of strings");
|
|
||||||
snapshot_rpc_getaddresstxids_valid("multi_block", get_address_tx_ids, &settings);
|
|
||||||
|
|
||||||
let get_address_tx_ids = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start: 2,
|
|
||||||
end: 2,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.expect("We should have a vector of strings");
|
|
||||||
snapshot_rpc_getaddresstxids_valid("single_block", get_address_tx_ids, &settings);
|
|
||||||
|
|
||||||
let get_address_tx_ids = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start: 3,
|
|
||||||
end: EXCESSIVE_BLOCK_HEIGHT,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
snapshot_rpc_getaddresstxids_invalid("excessive_end", get_address_tx_ids, &settings);
|
|
||||||
|
|
||||||
let get_address_tx_ids = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start: EXCESSIVE_BLOCK_HEIGHT,
|
|
||||||
end: EXCESSIVE_BLOCK_HEIGHT + 1,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
snapshot_rpc_getaddresstxids_invalid("excessive_start", get_address_tx_ids, &settings);
|
|
||||||
|
|
||||||
// `getaddressutxos`
|
|
||||||
let get_address_utxos = rpc
|
|
||||||
.get_address_utxos(AddressStrings { addresses })
|
|
||||||
.await
|
|
||||||
.expect("We should have a vector of strings");
|
|
||||||
snapshot_rpc_getaddressutxos(get_address_utxos, &settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test_mocked_rpc_response_data_for_network(network: &Network) {
|
async fn test_mocked_rpc_response_data_for_network(network: &Network) {
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,7 @@ pub async fn test_responses<State, ReadState>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let mock_block_verifier_router_request_handler = async move {
|
let mock_block_verifier_router_request_handler = async move {
|
||||||
mock_block_verifier_router
|
mock_block_verifier_routert2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi
|
||||||
.expect_request_that(|req| matches!(req, zebra_consensus::Request::CheckProposal(_)))
|
.expect_request_that(|req| matches!(req, zebra_consensus::Request::CheckProposal(_)))
|
||||||
.await
|
.await
|
||||||
.respond(Hash::from([0; 32]));
|
.respond(Hash::from([0; 32]));
|
||||||
|
|
@ -417,7 +417,7 @@ pub async fn test_responses<State, ReadState>(
|
||||||
|
|
||||||
// `validateaddress`
|
// `validateaddress`
|
||||||
let founder_address = if network.is_mainnet() {
|
let founder_address = if network.is_mainnet() {
|
||||||
"t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR"
|
"zs1z7rejlpsa98s2rrrfkwmaxu53e4ue0ulcrw0h4x5g8jl04tak0d3mm47vdtahatqrlkngh9sly"
|
||||||
} else {
|
} else {
|
||||||
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
|
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
|
||||||
};
|
};
|
||||||
|
|
@ -436,7 +436,7 @@ pub async fn test_responses<State, ReadState>(
|
||||||
|
|
||||||
// `z_validateaddress`
|
// `z_validateaddress`
|
||||||
let founder_address = if network.is_mainnet() {
|
let founder_address = if network.is_mainnet() {
|
||||||
"t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR"
|
"zs1z7rejlpsa98s2rrrfkwmaxu53e4ue0ulcrw0h4x5g8jl04tak0d3mm47vdtahatqrlkngh9sly"
|
||||||
} else {
|
} else {
|
||||||
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
|
"t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi"
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -593,169 +593,6 @@ async fn rpc_getrawtransaction() {
|
||||||
assert!(rpc_tx_queue_task_result.is_none());
|
assert!(rpc_tx_queue_task_result.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
|
||||||
async fn rpc_getaddresstxids_invalid_arguments() {
|
|
||||||
let _init_guard = zebra_test::init();
|
|
||||||
|
|
||||||
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
|
||||||
|
|
||||||
// Create a continuous chain of mainnet blocks from genesis
|
|
||||||
let blocks: Vec<Arc<Block>> = zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS
|
|
||||||
.iter()
|
|
||||||
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Create a populated state service
|
|
||||||
let (_state, read_state, latest_chain_tip, _chain_tip_change) =
|
|
||||||
zebra_state::populated_state(blocks.clone(), &Mainnet).await;
|
|
||||||
|
|
||||||
let (rpc, rpc_tx_queue_task_handle) = RpcImpl::new(
|
|
||||||
"RPC test",
|
|
||||||
"RPC test",
|
|
||||||
Mainnet,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
Buffer::new(mempool.clone(), 1),
|
|
||||||
Buffer::new(read_state.clone(), 1),
|
|
||||||
latest_chain_tip,
|
|
||||||
);
|
|
||||||
|
|
||||||
// call the method with an invalid address string
|
|
||||||
let address = "11111111".to_string();
|
|
||||||
let addresses = vec![address.clone()];
|
|
||||||
let start: u32 = 1;
|
|
||||||
let end: u32 = 2;
|
|
||||||
let error = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap_err();
|
|
||||||
assert_eq!(
|
|
||||||
error.message,
|
|
||||||
format!(
|
|
||||||
"invalid address \"{}\": parse error: t-addr decoding error",
|
|
||||||
address.clone()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// create a valid address
|
|
||||||
let address = "t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd".to_string();
|
|
||||||
let addresses = vec![address.clone()];
|
|
||||||
|
|
||||||
// call the method with start greater than end
|
|
||||||
let start: u32 = 2;
|
|
||||||
let end: u32 = 1;
|
|
||||||
let error = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap_err();
|
|
||||||
assert_eq!(
|
|
||||||
error.message,
|
|
||||||
"start Height(2) must be less than or equal to end Height(1)".to_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
// call the method with start equal zero
|
|
||||||
let start: u32 = 0;
|
|
||||||
let end: u32 = 1;
|
|
||||||
let error = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses: addresses.clone(),
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap_err();
|
|
||||||
assert_eq!(
|
|
||||||
error.message,
|
|
||||||
"start Height(0) and end Height(1) must both be greater than zero".to_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
// call the method outside the chain tip height
|
|
||||||
let start: u32 = 1;
|
|
||||||
let end: u32 = 11;
|
|
||||||
let error = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap_err();
|
|
||||||
assert_eq!(
|
|
||||||
error.message,
|
|
||||||
"start Height(1) and end Height(11) must both be less than or equal to the chain tip Height(10)".to_string()
|
|
||||||
);
|
|
||||||
|
|
||||||
mempool.expect_no_requests().await;
|
|
||||||
|
|
||||||
// The queue task should continue without errors or panics
|
|
||||||
let rpc_tx_queue_task_result = rpc_tx_queue_task_handle.now_or_never();
|
|
||||||
assert!(rpc_tx_queue_task_result.is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
|
||||||
async fn rpc_getaddresstxids_response() {
|
|
||||||
let _init_guard = zebra_test::init();
|
|
||||||
|
|
||||||
for network in Network::iter() {
|
|
||||||
let blocks: Vec<Arc<Block>> = network
|
|
||||||
.blockchain_map()
|
|
||||||
.iter()
|
|
||||||
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
|
|
||||||
.collect();
|
|
||||||
// The first few blocks after genesis send funds to the same founders reward address,
|
|
||||||
// in one output per coinbase transaction.
|
|
||||||
//
|
|
||||||
// Get the coinbase transaction of the first block
|
|
||||||
// (the genesis block coinbase transaction is ignored by the consensus rules).
|
|
||||||
let first_block_first_transaction = &blocks[1].transactions[0];
|
|
||||||
|
|
||||||
// Get the address.
|
|
||||||
let address = first_block_first_transaction.outputs()[1]
|
|
||||||
.address(&network)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Create a populated state service
|
|
||||||
let (_state, read_state, latest_chain_tip, _chain_tip_change) =
|
|
||||||
zebra_state::populated_state(blocks.to_owned(), &network).await;
|
|
||||||
|
|
||||||
if network == Mainnet {
|
|
||||||
// Exhaustively test possible block ranges for mainnet.
|
|
||||||
//
|
|
||||||
// TODO: if it takes too long on slower machines, turn this into a proptest with 10-20 cases
|
|
||||||
for start in 1..=10 {
|
|
||||||
for end in start..=10 {
|
|
||||||
rpc_getaddresstxids_response_with(
|
|
||||||
&network,
|
|
||||||
start..=end,
|
|
||||||
&address,
|
|
||||||
&read_state,
|
|
||||||
&latest_chain_tip,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Just test the full range for testnet.
|
|
||||||
rpc_getaddresstxids_response_with(
|
|
||||||
&network,
|
|
||||||
1..=10,
|
|
||||||
&address,
|
|
||||||
&read_state,
|
|
||||||
&latest_chain_tip,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn rpc_getaddresstxids_response_with(
|
async fn rpc_getaddresstxids_response_with(
|
||||||
network: &Network,
|
network: &Network,
|
||||||
range: RangeInclusive<u32>,
|
range: RangeInclusive<u32>,
|
||||||
|
|
@ -776,22 +613,6 @@ async fn rpc_getaddresstxids_response_with(
|
||||||
latest_chain_tip.clone(),
|
latest_chain_tip.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// call the method with valid arguments
|
|
||||||
let addresses = vec![address.to_string()];
|
|
||||||
let response = rpc
|
|
||||||
.get_address_tx_ids(GetAddressTxIdsRequest {
|
|
||||||
addresses,
|
|
||||||
start: *range.start(),
|
|
||||||
end: *range.end(),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.expect("arguments are valid so no error can happen here");
|
|
||||||
|
|
||||||
// One founders reward output per coinbase transactions, no other transactions.
|
|
||||||
assert_eq!(response.len(), range.count());
|
|
||||||
|
|
||||||
mempool.expect_no_requests().await;
|
|
||||||
|
|
||||||
// Shut down the queue task, to close the state's file descriptors.
|
// Shut down the queue task, to close the state's file descriptors.
|
||||||
// (If we don't, opening ~100 simultaneous states causes process file descriptor limit errors.)
|
// (If we don't, opening ~100 simultaneous states causes process file descriptor limit errors.)
|
||||||
//
|
//
|
||||||
|
|
@ -810,87 +631,6 @@ async fn rpc_getaddresstxids_response_with(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
|
||||||
async fn rpc_getaddressutxos_invalid_arguments() {
|
|
||||||
let _init_guard = zebra_test::init();
|
|
||||||
|
|
||||||
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
|
||||||
let mut state: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
|
||||||
|
|
||||||
let rpc = RpcImpl::new(
|
|
||||||
"RPC test",
|
|
||||||
"RPC test",
|
|
||||||
Mainnet,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
Buffer::new(mempool.clone(), 1),
|
|
||||||
Buffer::new(state.clone(), 1),
|
|
||||||
NoChainTip,
|
|
||||||
);
|
|
||||||
|
|
||||||
// call the method with an invalid address string
|
|
||||||
let address = "11111111".to_string();
|
|
||||||
let addresses = vec![address.clone()];
|
|
||||||
let error = rpc
|
|
||||||
.0
|
|
||||||
.get_address_utxos(AddressStrings::new(addresses))
|
|
||||||
.await
|
|
||||||
.unwrap_err();
|
|
||||||
assert_eq!(
|
|
||||||
error.message,
|
|
||||||
format!("invalid address \"{address}\": parse error: t-addr decoding error")
|
|
||||||
);
|
|
||||||
|
|
||||||
mempool.expect_no_requests().await;
|
|
||||||
state.expect_no_requests().await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
|
||||||
async fn rpc_getaddressutxos_response() {
|
|
||||||
let _init_guard = zebra_test::init();
|
|
||||||
|
|
||||||
let blocks: Vec<Arc<Block>> = zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS
|
|
||||||
.iter()
|
|
||||||
.map(|(_height, block_bytes)| block_bytes.zcash_deserialize_into().unwrap())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// get the first transaction of the first block
|
|
||||||
let first_block_first_transaction = &blocks[1].transactions[0];
|
|
||||||
// get the address, this is always `t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd`
|
|
||||||
let address = &first_block_first_transaction.outputs()[1]
|
|
||||||
.address(&Mainnet)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
|
||||||
// Create a populated state service
|
|
||||||
let (_state, read_state, latest_chain_tip, _chain_tip_change) =
|
|
||||||
zebra_state::populated_state(blocks.clone(), &Mainnet).await;
|
|
||||||
|
|
||||||
let rpc = RpcImpl::new(
|
|
||||||
"RPC test",
|
|
||||||
"RPC test",
|
|
||||||
Mainnet,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
Buffer::new(mempool.clone(), 1),
|
|
||||||
Buffer::new(read_state.clone(), 1),
|
|
||||||
latest_chain_tip,
|
|
||||||
);
|
|
||||||
|
|
||||||
// call the method with a valid address
|
|
||||||
let addresses = vec![address.to_string()];
|
|
||||||
let response = rpc
|
|
||||||
.0
|
|
||||||
.get_address_utxos(AddressStrings::new(addresses))
|
|
||||||
.await
|
|
||||||
.expect("address is valid so no error can happen here");
|
|
||||||
|
|
||||||
// there are 10 outputs for provided address
|
|
||||||
assert_eq!(response.len(), 10);
|
|
||||||
|
|
||||||
mempool.expect_no_requests().await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
||||||
async fn rpc_getblockcount() {
|
async fn rpc_getblockcount() {
|
||||||
|
|
@ -1636,7 +1376,7 @@ async fn rpc_validateaddress() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let validate_address = get_block_template_rpc
|
let validate_address = get_block_template_rpc
|
||||||
.validate_address("t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR".to_string())
|
.validate_address("zs1z7rejlpsa98s2rrrfkwmaxu53e4ue0ulcrw0h4x5g8jl04tak0d3mm47vdtahatqrlkngh9sly".to_string())
|
||||||
.await
|
.await
|
||||||
.expect("we should have a validate_address::Response");
|
.expect("we should have a validate_address::Response");
|
||||||
|
|
||||||
|
|
@ -1646,7 +1386,7 @@ async fn rpc_validateaddress() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let validate_address = get_block_template_rpc
|
let validate_address = get_block_template_rpc
|
||||||
.validate_address("t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi".to_string())
|
.validate_address("zs1z7rejlpsa98s2rrrfkwmaxu53e4ue0ulcrw0h4x5g8jl04tak0d3mm47vdtahatqrlkngh9sly".to_string())
|
||||||
.await
|
.await
|
||||||
.expect("We should have a validate_address::Response");
|
.expect("We should have a validate_address::Response");
|
||||||
|
|
||||||
|
|
@ -1681,7 +1421,7 @@ async fn rpc_z_validateaddress() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let z_validate_address = get_block_template_rpc
|
let z_validate_address = get_block_template_rpc
|
||||||
.z_validate_address("t3fqvkzrrNaMcamkQMwAyHRjfDdM2xQvDTR".to_string())
|
.z_validate_address("zs1z7rejlpsa98s2rrrfkwmaxu53e4ue0ulcrw0h4x5g8jl04tak0d3mm47vdtahatqrlkngh9sly".to_string())
|
||||||
.await
|
.await
|
||||||
.expect("we should have a z_validate_address::Response");
|
.expect("we should have a z_validate_address::Response");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue