From 6586b01f9e3e69c6bb2427603b91ff042d669cdc Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Mon, 28 Oct 2024 17:16:04 -0400 Subject: [PATCH] test: add swaps to `EffectHash` test vector utility --- ...nerate_transaction_signing_test_vectors.rs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/core/transaction/tests/generate_transaction_signing_test_vectors.rs b/crates/core/transaction/tests/generate_transaction_signing_test_vectors.rs index ed75db1988..2c803dac25 100644 --- a/crates/core/transaction/tests/generate_transaction_signing_test_vectors.rs +++ b/crates/core/transaction/tests/generate_transaction_signing_test_vectors.rs @@ -4,6 +4,10 @@ use decaf377::{Fq, Fr}; use decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey, VerificationKeyBytes}; use ed25519_consensus::SigningKey as Ed25519SigningKey; use penumbra_asset::asset::Id; +use penumbra_dex::{ + swap::{SwapPlaintext, SwapPlan}, + TradingPair, +}; use penumbra_fee::Fee; use penumbra_keys::keys::{Bip44Path, SeedPhrase, SpendKey}; use penumbra_keys::{Address, FullViewingKey}; @@ -185,6 +189,36 @@ fn validator_definition_strategy() -> impl Strategy { }) } +fn swap_plaintext_strategy() -> impl Strategy { + ( + amount_strategy(), + amount_strategy(), + asset_id_strategy(), + asset_id_strategy(), + address_strategy(), + ) + .prop_map(|(delta_1_i, delta_2_i, asset_1, asset_2, claim_address)| { + let trading_pair = TradingPair::new(asset_1, asset_2); + SwapPlaintext::new( + &mut OsRng, + trading_pair, + delta_1_i, + delta_2_i, + Fee::from_staking_token_amount(0u64.into()), + claim_address, + ) + }) +} + +fn swap_plan_strategy() -> impl Strategy { + (swap_plaintext_strategy()).prop_map(|swap_plaintext| SwapPlan { + proof_blinding_r: Fq::rand(&mut OsRng), + proof_blinding_s: Fq::rand(&mut OsRng), + swap_plaintext, + fee_blinding: Fr::rand(&mut OsRng), + }) +} + fn action_plan_strategy(fvk: &FullViewingKey) -> impl Strategy { prop_oneof![ spend_plan_strategy(fvk).prop_map(ActionPlan::Spend), @@ -193,8 +227,8 @@ fn action_plan_strategy(fvk: &FullViewingKey) -> impl Strategy