Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regtest support to Parameter for Mobile SDKs #1054

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions zcash_client_backend/src/zip321.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ mod tests {
transaction::components::{amount::NonNegativeAmount, Amount},
};

#[cfg(feature = "local-consensus")]
use zcash_primitives::{local_consensus::LocalNetwork, BlockHeight};

use crate::address::Address;

use super::{
Expand Down Expand Up @@ -1010,6 +1013,27 @@ mod tests {
);
}

#[cfg(feature = "local-consensus")]
#[test]
fn test_zip321_spec_regtest_valid_examples() {
let params = LocalNetwork {
overwinter: Some(BlockHeight::from_u32(1)),
sapling: Some(BlockHeight::from_u32(1)),
blossom: Some(BlockHeight::from_u32(1)),
heartwood: Some(BlockHeight::from_u32(1)),
canopy: Some(BlockHeight::from_u32(1)),
nu5: Some(BlockHeight::from_u32(1)),
nu6: Some(BlockHeight::from_u32(1)),
z_future: Some(BlockHeight::from_u32(1)),
};
let valid_1 = "zcash:zregtestsapling1qqqqqqqqqqqqqqqqqqcguyvaw2vjk4sdyeg0lc970u659lvhqq7t0np6hlup5lusxle7505hlz3?amount=1&memo=VGhpcyBpcyBhIHNpbXBsZSBtZW1vLg&message=Thank%20you%20for%20your%20purchase";
let v1r = TransactionRequest::from_uri(&params, valid_1).unwrap();
assert_eq!(
v1r.payments.get(0).map(|p| p.amount),
Some(NonNegativeAmount::const_from_u64(100000000))
);
}

#[test]
fn test_zip321_spec_invalid_examples() {
// invalid; missing `address=`
Expand Down
33 changes: 30 additions & 3 deletions zcash_keys/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ mod tests {

let encoded_main = "zxviews1qqqqqqqqqqqqqq8n3zjjmvhhr854uy3qhpda3ml34haf0x388z5r7h4st4kpsf6qy3zw4wc246aw9rlfyg5ndlwvne7mwdq0qe6vxl42pqmcf8pvmmd5slmjxduqa9evgej6wa3th2505xq4nggrxdm93rxk4rpdjt5nmq2vn44e2uhm7h0hsagfvkk4n7n6nfer6u57v9cac84t7nl2zth0xpyfeg0w2p2wv2yn6jn923aaz0vdaml07l60ahapk6efchyxwysrvjsxmansf";
let encoded_test = "zxviewtestsapling1qqqqqqqqqqqqqq8n3zjjmvhhr854uy3qhpda3ml34haf0x388z5r7h4st4kpsf6qy3zw4wc246aw9rlfyg5ndlwvne7mwdq0qe6vxl42pqmcf8pvmmd5slmjxduqa9evgej6wa3th2505xq4nggrxdm93rxk4rpdjt5nmq2vn44e2uhm7h0hsagfvkk4n7n6nfer6u57v9cac84t7nl2zth0xpyfeg0w2p2wv2yn6jn923aaz0vdaml07l60ahapk6efchyxwysrvjs8evfkz";

let encoded_regtest = "zxviewregtestsapling1qqqqqqqqqqqqqq8n3zjjmvhhr854uy3qhpda3ml34haf0x388z5r7h4st4kpsf6qy3zw4wc246aw9rlfyg5ndlwvne7mwdq0qe6vxl42pqmcf8pvmmd5slmjxduqa9evgej6wa3th2505xq4nggrxdm93rxk4rpdjt5nmq2vn44e2uhm7h0hsagfvkk4n7n6nfer6u57v9cac84t7nl2zth0xpyfeg0w2p2wv2yn6jn923aaz0vdaml07l60ahapk6efchyxwysrvjskjkzax";
assert_eq!(
encode_extended_full_viewing_key(
constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
Expand All @@ -526,10 +526,19 @@ mod tests {
),
encoded_test
);

assert_eq!(
encode_extended_full_viewing_key(
constants::regtest::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
&extfvk
),
encoded_regtest
);

assert_eq!(
decode_extended_full_viewing_key(
constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
encoded_test
constants::regtest::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
encoded_regtest
)
.unwrap(),
extfvk
Expand All @@ -550,11 +559,14 @@ mod tests {
"zs1qqqqqqqqqqqqqqqqqqcguyvaw2vjk4sdyeg0lc970u659lvhqq7t0np6hlup5lusxle75c8v35z";
let encoded_test =
"ztestsapling1qqqqqqqqqqqqqqqqqqcguyvaw2vjk4sdyeg0lc970u659lvhqq7t0np6hlup5lusxle75ss7jnk";
let encoded_regtest =
"zregtestsapling1qqqqqqqqqqqqqqqqqqcguyvaw2vjk4sdyeg0lc970u659lvhqq7t0np6hlup5lusxle7505hlz3";

assert_eq!(
encode_payment_address(constants::mainnet::HRP_SAPLING_PAYMENT_ADDRESS, &addr),
encoded_main
);

assert_eq!(
decode_payment_address(
constants::mainnet::HRP_SAPLING_PAYMENT_ADDRESS,
Expand All @@ -568,6 +580,12 @@ mod tests {
encode_payment_address(constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, &addr),
encoded_test
);

assert_eq!(
encode_payment_address(constants::regtest::HRP_SAPLING_PAYMENT_ADDRESS, &addr),
encoded_regtest
);

assert_eq!(
decode_payment_address(
constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS,
Expand All @@ -576,6 +594,15 @@ mod tests {
.unwrap(),
addr
);

assert_eq!(
decode_payment_address(
constants::regtest::HRP_SAPLING_PAYMENT_ADDRESS,
encoded_regtest
)
.unwrap(),
addr
);
}

#[test]
Expand Down
11 changes: 11 additions & 0 deletions zcash_primitives/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ and this library adheres to Rust's notion of
- `impl {Clone, PartialEq, Eq} for zcash_primitives::memo::Error`
- `impl {PartialEq, Eq} for zcash_primitives::sapling::note::Rseed`
- `impl From<TxId> for [u8; 32]`
- Added feature `local-consensus` to crate `zcash_primitives`
- Adds `pub mod local_consensus`
- `zcash_primitives::local_consensus::LocalNetwork` provides a type for specifying
network upgrade activation heights for a local or specific configuration of a full
node. Developers can make use of this type when connecting to a Regtest node by
replicating the activation heights used on their node configuration.
- `impl Parameters for LocalNetwork` that use provided activation heights and
defaults to `constants::regtest::` for everything else.

### Changed
- `zcash_primitives::transaction`:
Expand Down Expand Up @@ -112,6 +120,9 @@ and this library adheres to Rust's notion of
- `zcash_primitives::zip32`:
- `ChildIndex` has been changed from an enum to an opaque struct, and no
longer supports non-hardened indices.
- `zcash_client_backend` changes related to `local-consensus` feature:
- added tests that verify `zip321` supports Payment URIs with `Local(P)`
network parameters.

### Removed
- `zcash_primitives::constants`:
Expand Down
2 changes: 2 additions & 0 deletions zcash_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ unstable-nu6 = []
## Exposes early in-development features that are not yet planned for any network upgrade.
zfuture = []

## Exposes support for working with a local consensus (e.g. regtest
Copy link
Contributor

@daira daira Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Exposes support for working with a local consensus (e.g. regtest
## Exposes support for working with a local consensus (e.g. regtest).

Non-blocking.

local-consensus = []
[lib]
bench = false

Expand Down
3 changes: 1 addition & 2 deletions zcash_primitives/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,10 @@ pub mod testing {

#[cfg(test)]
mod tests {
use std::convert::TryFrom;
pacu marked this conversation as resolved.
Show resolved Hide resolved

use super::{
BlockHeight, BranchId, NetworkUpgrade, Parameters, MAIN_NETWORK, UPGRADES_IN_ORDER,
};
use std::convert::TryFrom;

#[test]
fn nu_ordering() {
Expand Down
5 changes: 3 additions & 2 deletions zcash_primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub mod merkle_tree;
use sapling;
pub mod transaction;
pub use zip32;
pub mod zip339;

#[cfg(feature = "zfuture")]
pub mod extensions;
#[cfg(feature = "local-consensus")]
pub mod local_consensus;
pub mod zip339;