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

Murisi/test vectors 0.30.2 rev 1 #2588

Merged
merged 11 commits into from
Feb 27, 2024
Merged
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.

49 changes: 44 additions & 5 deletions crates/governance/src/storage/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,18 +589,57 @@ pub mod testing {
}

prop_compose! {
/// Generate an arbitrary PGF target
pub fn arb_pgf_target()(
/// Generate an arbitrary PGF internal target
pub fn arb_pgf_internal_target()(
target in arb_non_internal_address(),
amount in arb_amount(),
) -> PGFTarget {
PGFTarget::Internal(PGFInternalTarget {
) -> PGFInternalTarget {
PGFInternalTarget {
target,
amount,
})
}
}
}

prop_compose! {
/// Generate an arbitrary port ID
pub fn arb_ibc_port_id()(id in "[a-zA-Z0-9_+.\\-\\[\\]#<>]{2,128}") -> PortId {
sug0 marked this conversation as resolved.
Show resolved Hide resolved
PortId::new(id).expect("generated invalid port ID")
}
}

prop_compose! {
/// Generate an arbitrary channel ID
pub fn arb_ibc_channel_id()(id: u64) -> ChannelId {
ChannelId::new(id)
}
}

prop_compose! {
/// Generate an arbitrary PGF IBC target
pub fn arb_pgf_ibc_target()(
target in "[a-zA-Z0-9_]*",
amount in arb_amount(),
port_id in arb_ibc_port_id(),
channel_id in arb_ibc_channel_id(),
) -> PGFIbcTarget {
PGFIbcTarget {
target,
amount,
port_id,
channel_id,
}
}
}

/// Generate an arbitrary PGF target
pub fn arb_pgf_target() -> impl Strategy<Value = PGFTarget> {
prop_oneof![
arb_pgf_internal_target().prop_map(PGFTarget::Internal),
arb_pgf_ibc_target().prop_map(PGFTarget::Ibc),
]
}

/// Generate an arbitrary PGF action
pub fn arb_pgf_action() -> impl Strategy<Value = PGFAction> {
prop_oneof![
Expand Down
103 changes: 96 additions & 7 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ pub mod testing {
use namada_core::types::address::MASP;
use namada_core::types::eth_bridge_pool::PendingTransfer;
use namada_core::types::hash::testing::arb_hash;
use namada_core::types::key::testing::arb_common_keypair;
use namada_core::types::storage::testing::arb_epoch;
use namada_core::types::token::testing::{
arb_denominated_amount, arb_transfer,
Expand All @@ -787,7 +788,7 @@ pub mod testing {
};
use namada_tx::data::{DecryptedTx, Fee, TxType, WrapperTx};
use proptest::prelude::{Just, Strategy};
use proptest::{option, prop_compose, prop_oneof};
use proptest::{arbitrary, collection, option, prop_compose, prop_oneof};
use prost::Message;
use ripemd::Digest as RipemdDigest;
use sha2::Digest;
Expand All @@ -803,13 +804,15 @@ pub mod testing {
arb_consensus_key_change, arb_metadata_change, arb_redelegation,
arb_withdraw,
};
use crate::tx::{Code, Commitment, Header, MaspBuilder, Section};
use crate::tx::{
Code, Commitment, Header, MaspBuilder, Section, Signature,
};
use crate::types::chain::ChainId;
use crate::types::eth_bridge_pool::testing::arb_pending_transfer;
use crate::types::key::testing::arb_common_pk;
use crate::types::time::{DateTime, DateTimeUtc, Utc};

#[derive(Debug)]
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
// To facilitate propagating debugging information
pub enum TxData {
Expand All @@ -835,15 +838,18 @@ pub mod testing {
ResignSteward(Address),
PendingTransfer(PendingTransfer),
IbcAny(Any),
Custom(Box<dyn std::fmt::Debug>),
Custom,
}

prop_compose! {
// Generate an arbitrary commitment
pub fn arb_commitment()(
hash in arb_hash(),
commitment in prop_oneof![
arb_hash().prop_map(Commitment::Hash),
arbitrary::any::<Vec<u8>>().prop_map(Commitment::Id),
murisi marked this conversation as resolved.
Show resolved Hide resolved
],
) -> Commitment {
Commitment::Hash(hash)
commitment
}
}

Expand All @@ -862,6 +868,33 @@ pub mod testing {
}
}

prop_compose! {
// Generate an arbitrary uttf8 commitment
pub fn arb_utf8_commitment()(
commitment in prop_oneof![
arb_hash().prop_map(Commitment::Hash),
"[a-zA-Z0-9_]*".prop_map(|x| Commitment::Id(x.into_bytes())),
murisi marked this conversation as resolved.
Show resolved Hide resolved
],
) -> Commitment {
commitment
}
}

prop_compose! {
// Generate an arbitrary code section
pub fn arb_utf8_code()(
salt: [u8; 8],
code in arb_utf8_commitment(),
tag in option::of("[a-zA-Z0-9_]*"),
murisi marked this conversation as resolved.
Show resolved Hide resolved
) -> Code {
Code {
salt,
code,
tag,
}
}
}

prop_compose! {
// Generate a chain ID
pub fn arb_chain_id()(id in "[a-zA-Z0-9_]*") -> ChainId {
Expand Down Expand Up @@ -987,7 +1020,7 @@ pub mod testing {
}

// Maximum number of notes to include in a transaction
const MAX_ASSETS: usize = 10;
const MAX_ASSETS: usize = 2;

// Type of MASP transaction
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1150,6 +1183,24 @@ pub mod testing {
}
}

prop_compose! {
// Generate an arbitrary transaction with maybe a memo
pub fn arb_memoed_tx()(
(mut tx, tx_data) in arb_tx(),
memo in option::of(arb_utf8_code()),
) -> (Tx, TxData) {
if let Some(memo) = memo {
let sechash = tx
.add_section(Section::ExtraData(memo))
.get_hash();
tx.set_memo_sechash(sechash);
} else {
tx.set_memo_sechash(Default::default());
}
(tx, tx_data)
}
}

prop_compose! {
// Generate an arbitrary vote proposal transaction
pub fn arb_vote_proposal_tx()(
Expand Down Expand Up @@ -1441,4 +1492,42 @@ pub mod testing {
arb_ibc_any_tx(),
]
}

prop_compose! {
// Generate an arbitrary signature section
pub fn arb_signature(targets: Vec<namada_core::types::hash::Hash>)(
targets in Just(targets),
secret_keys in collection::btree_map(
arbitrary::any::<u8>(),
arb_common_keypair(),
1..3,
),
signer in option::of(arb_non_internal_address()),
) -> Signature {
if signer.is_some() {
Signature::new(targets, secret_keys, signer)
} else {
let secret_keys = secret_keys
.into_values()
.enumerate()
.map(|(k, v)| (k as u8, v))
.collect();
Signature::new(targets, secret_keys, signer)
}
}
}

prop_compose! {
// Generate an arbitrary signed tx
pub fn arb_signed_tx()(tx in arb_memoed_tx())(
sigs in collection::vec(arb_signature(tx.0.sechashes()), 0..3),
mut tx in Just(tx),
) -> (Tx, TxData) {
for sig in sigs {
// Add all the generated signature sections
tx.0.add_section(Section::Signature(sig));
}
(tx.0, tx.1)
}
}
}
2 changes: 1 addition & 1 deletion crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2955,7 +2955,7 @@ pub mod testing {
// Maximum value for a note partition
const MAX_MONEY: u64 = 100;
// Maximum number of partitions for a note
const MAX_SPLITS: usize = 10;
const MAX_SPLITS: usize = 3;

prop_compose! {
// Arbitrarily partition the given vector of integers into sets and sum
Expand Down
Loading
Loading