Skip to content

Commit

Permalink
tests(rpc): Add grpc test for GetTaddressBalanceStream and `GetAddr…
Browse files Browse the repository at this point in the history
…essUtxosStream` (#4407)

* add test for `GetTaddressBalanceStream`

* add test for `GetAddressUtxosStream`
  • Loading branch information
oxarbitrage authored May 19, 2022
1 parent ec9b569 commit d50cf8b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zebrad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ semver = "1.0.9"
serde_json = { version = "1.0.81", features = ["preserve_order"] }
tempfile = "3.3.0"
tokio = { version = "1.18.2", features = ["full", "test-util"] }
tokio-stream = "0.1.8"

# test feature lightwalletd-grpc-tests
prost = "0.10.3"
Expand Down
71 changes: 64 additions & 7 deletions zebrad/tests/common/lightwalletd/wallet_grpc_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
//!
//! - `GetTaddressTxids`: Covered.
//! - `GetTaddressBalance`: Covered.
//! - `GetTaddressBalanceStream`: Not covered.
//! - `GetTaddressBalanceStream`: Covered.
//!
//! - `GetMempoolTx`: Not covered.
//! - `GetMempoolStream`: Not covered.
//!
//! - `GetTreeState`: Not covered, Need #3990
//!
//! - `GetAddressUtxos` -= Covered.
//! - `GetAddressUtxosStream`: Not covered.
//! - `GetAddressUtxosStream`: Covered.
//!
//! - `GetLightdInfo`: Covered.
//! - `Ping`: Not covered and it will never will, ping is only used for testing purposes.
Expand All @@ -43,9 +43,9 @@ use crate::common::{
launch::spawn_zebrad_for_rpc_without_initial_peers,
lightwalletd::{
wallet_grpc::{
connect_to_lightwalletd, spawn_lightwalletd_with_rpc_server, AddressList, BlockId,
BlockRange, ChainSpec, Empty, GetAddressUtxosArg, TransparentAddressBlockFilter,
TxFilter,
connect_to_lightwalletd, spawn_lightwalletd_with_rpc_server, Address, AddressList,
BlockId, BlockRange, ChainSpec, Empty, GetAddressUtxosArg,
TransparentAddressBlockFilter, TxFilter,
},
zebra_skip_lightwalletd_tests,
LightwalletdTestType::UpdateCachedState,
Expand Down Expand Up @@ -211,7 +211,48 @@ pub async fn run() -> Result<()> {
// because new coins are created in each block
assert!(balance.value_zat > 0);

// TODO: Create call and check for `GetTaddressBalanceStream`
// Call `GetTaddressBalanceStream` with the ZF funding stream address as a stream argument
let zf_stream_address = Address {
address: "t3dvVE3SQEi7kqNzwrfNePxZ1d4hUyztBA1".to_string(),
};

let balance_zf = rpc_client
.get_taddress_balance_stream(tokio_stream::iter(vec![zf_stream_address.clone()]))
.await?
.into_inner();

// With ZFND funding stream address, the balance will always be greater than zero,
// because new coins are created in each block
assert!(balance_zf.value_zat > 0);

// Call `GetTaddressBalanceStream` with the MG funding stream address as a stream argument
let mg_stream_address = Address {
address: "t3XyYW8yBFRuMnfvm5KLGFbEVz25kckZXym".to_string(),
};

let balance_mg = rpc_client
.get_taddress_balance_stream(tokio_stream::iter(vec![mg_stream_address.clone()]))
.await?
.into_inner();

// With Major Grants funding stream address, the balance will always be greater than zero,
// because new coins are created in each block
assert!(balance_mg.value_zat > 0);

// Call `GetTaddressBalanceStream` with both, the ZFND and the MG funding stream addresses as a stream argument
let balance_both = rpc_client
.get_taddress_balance_stream(tokio_stream::iter(vec![
zf_stream_address,
mg_stream_address,
]))
.await?
.into_inner();

// The result is the sum of the values in both addresses
assert_eq!(
balance_both.value_zat,
balance_zf.value_zat + balance_mg.value_zat
);

// TODO: Create call and checks for `GetMempoolTx` and `GetMempoolTxStream`?

Expand Down Expand Up @@ -240,7 +281,23 @@ pub async fn run() -> Result<()> {
// As we requested one entry we should get a response of length 1
assert_eq!(utxos.address_utxos.len(), 1);

// TODO: Create call and check for `GetAddressUtxosStream`
// Call `GetAddressUtxosStream` with the ZF funding stream address that will always have utxos
let mut utxos_zf = rpc_client
.get_address_utxos_stream(GetAddressUtxosArg {
addresses: vec!["t3dvVE3SQEi7kqNzwrfNePxZ1d4hUyztBA1".to_string()],
start_height: 1,
max_entries: 2,
})
.await?
.into_inner();

let mut counter = 0;
while let Some(_utxos) = utxos_zf.message().await? {
counter += 1;
}
// As we are in a "in sync" chain we know there are more than 2 utxos for this address
// but we will receive the max of 2 from the stream response because we used a limit of 2 `max_entries`.
assert_eq!(2, counter);

// Call `GetLightdInfo`
let lightd_info = rpc_client.get_lightd_info(Empty {}).await?.into_inner();
Expand Down

0 comments on commit d50cf8b

Please sign in to comment.