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

Planner tests: Swap action #1838

Open
Tracked by #691
grod220 opened this issue Oct 4, 2024 · 0 comments
Open
Tracked by #691

Planner tests: Swap action #1838

grod220 opened this issue Oct 4, 2024 · 0 comments
Labels
testing Related to writing tests

Comments

@grod220
Copy link
Collaborator

grod220 commented Oct 4, 2024

Write tests for swap action:

for tpr::Swap {
value,
target_asset,
// The prepaid fee will instead be calculated directly in the rust planner logic.
//
// TODO: external consumers of prax may decide to enable manaual fees, and there may be
// additional checks required to make sure the fees satisfy to the balancing checks
// for swap claims.
fee: _,
claim_address,
} in request.swaps
{
let value: Value = value
.ok_or_else(|| anyhow!("missing value in swap"))?
.try_into()?;
let target_asset = target_asset
.ok_or_else(|| anyhow!("missing target asset in swap"))?
.try_into()?;
let claim_address = claim_address
.ok_or_else(|| anyhow!("missing claim address in swap"))?
.try_into()?;
// This is the prepaid fee for the swap claim. We don't expect much of a drift in gas
// prices in a few blocks, and the fee tier adjustments should be enough to cover it.
let estimated_claim_fee = gas_prices.fee(&swap_claim_gas_cost()).apply_tier(fee_tier);
// Determine the canonical order for the assets being swapped.
// This will determine whether the input amount is assigned to delta_1 or delta_2.
let trading_pair = TradingPair::new(value.asset_id, target_asset);
// If `trading_pair.asset_1` is the input asset, then `delta_1` is the input amount,
// and `delta_2` is 0.
//
// Otherwise, `delta_1` is 0, and `delta_2` is the input amount.
let (delta_1, delta_2) = if trading_pair.asset_1() == value.asset_id {
(value.amount, 0u64.into())
} else {
(0u64.into(), value.amount)
};
// If there is no input, then there is no swap.
if delta_1 == Amount::zero() && delta_2 == Amount::zero() {
return Err(anyhow!("No input value for swap").into());
}
// Create the `SwapPlaintext` representing the swap to be performed:
let swap_plaintext = SwapPlaintext::new(
&mut OsRng,
trading_pair,
delta_1,
delta_2,
estimated_claim_fee,
claim_address,
);
let swap = SwapPlan::new(&mut OsRng, swap_plaintext);
actions_list.push(swap);
}

@grod220 grod220 added the testing Related to writing tests label Oct 4, 2024
@github-project-automation github-project-automation bot moved this to 🗄️ Backlog in Penumbra web Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to writing tests
Projects
Status: 🗄️ Backlog
Development

No branches or pull requests

1 participant