From 3661cf0a7f49bf9689f3ed4fa7dd3016329268e4 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Wed, 30 Oct 2024 14:11:16 -0400 Subject: [PATCH] test: start DEX actions --- ...nerate_transaction_signing_test_vectors.rs | 44 ++++++++++++++++++- 1 file changed, 43 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 b6b7ac7f38..b7de9afe13 100644 --- a/crates/core/transaction/tests/generate_transaction_signing_test_vectors.rs +++ b/crates/core/transaction/tests/generate_transaction_signing_test_vectors.rs @@ -11,9 +11,13 @@ use ibc_types::core::{ use ibc_types::timestamp::Timestamp; use penumbra_asset::asset::Id; use penumbra_dex::{ + lp::{ + position::{Position, State as PositionState}, + Reserves, TradingFunction, + }, swap::{SwapPlaintext, SwapPlan}, swap_claim::SwapClaimPlan, - BatchSwapOutputData, TradingPair, + BatchSwapOutputData, PositionOpen, TradingPair, }; use penumbra_fee::Fee; use penumbra_governance::{ @@ -441,6 +445,43 @@ fn proposal_deposit_claim_strategy() -> impl Strategy impl Strategy { + prop_oneof![Just(PositionState::Opened), Just(PositionState::Closed)] +} + +fn trading_function_strategy() -> impl Strategy { + ( + amount_strategy(), + amount_strategy(), + asset_id_strategy(), + asset_id_strategy(), + ) + .prop_map(|(p, q, asset_1, asset_2)| { + let trading_pair = TradingPair::new(asset_1, asset_2); + TradingFunction::new(trading_pair, 0u32, p, q) + }) +} + +fn position_strategy() -> impl Strategy { + ( + position_state_strategy(), + amount_strategy(), + amount_strategy(), + trading_function_strategy(), + ) + .prop_map(|(state, r1, r2, phi)| Position { + state, + reserves: Reserves { r1, r2 }, + phi, + nonce: [0u8; 32], + close_on_fill: true, + }) +} + +fn position_open_strategy() -> impl Strategy { + (position_strategy()).prop_map(|position| PositionOpen { position }) +} + fn action_plan_strategy(fvk: &FullViewingKey) -> impl Strategy { prop_oneof![ spend_plan_strategy(fvk).prop_map(ActionPlan::Spend), @@ -457,6 +498,7 @@ fn action_plan_strategy(fvk: &FullViewingKey) -> impl Strategy