Skip to content

Commit

Permalink
move donation tests to own module
Browse files Browse the repository at this point in the history
  • Loading branch information
cardenaso11 committed Mar 1, 2024
1 parent 84e2bff commit 672dcf3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 58 deletions.
60 changes: 2 additions & 58 deletions lib/calculation/donation.ak
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use aiken/transaction.{NoDatum, Output}
use aiken/transaction/credential.{Address, VerificationKeyCredential}
use aiken/transaction.{Output}
use aiken/transaction/value.{Value, ada_policy_id, ada_asset_name}
use calculation/shared.{PoolState} as calc_shared
use shared.{SingletonValue}
use sundae/multisig
use types/order.{Destination, OrderDatum}
use types/order.{Destination}

/// A donation describes an amount of assets to deposit into the pool, receiving nothing in return (except for the extra change on the UTXO).
/// Because every LP token holder has an entitlement to a percentage of the assets in the pool, the donation is distributed to all LP token holders
Expand Down Expand Up @@ -76,57 +74,3 @@ pub fn do_donation(
has_remainder,
)
}

test donation() {
let addr =
Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
)
let ada = (#"", #"")
let rberry =
(#"01010101010101010101010101010101010101010101010101010101", "RBERRY")
let lp = (#"99999999999999999999999999999999999999999999999999999999", "LP")
let pool_state =
PoolState {
quantity_a: (#"", #"", 1_000_000_000),
quantity_b: (rberry.1st, rberry.2nd, 1_000_000_000),
quantity_lp: (lp.1st, lp.2nd, 1_000_000_000),
}
let input_value =
value.from_lovelace(3_500_000)
|> value.add(rberry.1st, rberry.2nd, 1_000_000)
let assets = (
(ada.1st, ada.2nd, 1_000_000),
(rberry.1st, rberry.2nd, 1_000_000),
)
let order =
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2_500_000,
destination: Destination { address: addr, datum: NoDatum },
details: order.Donation {
assets: assets,
},
extension: Void,
}
// There's no remainder so do_donation totally ignores this Output record
let output =
Output {
address: addr,
value: value.from_lovelace(999_999_999_999_999_999),
datum: NoDatum,
reference_script: None,
}
let (final_pool_state, has_remainder) =
do_donation(pool_state, input_value, assets, order.destination, 2_500_000, output)
expect !has_remainder
expect final_pool_state.quantity_a.3rd == 1_001_000_000
expect final_pool_state.quantity_b.3rd == 1_001_000_000
True
}
61 changes: 61 additions & 0 deletions lib/tests/aiken/donation.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use aiken/transaction.{NoDatum, Output}
use aiken/transaction/credential.{Address, VerificationKeyCredential}
use aiken/transaction/value
use calculation/shared.{PoolState} as calc_shared
use calculation/donation.{do_donation}
use sundae/multisig
use types/order.{Destination, OrderDatum}

test donation() {
let addr =
Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
)
let ada = (#"", #"")
let rberry =
(#"01010101010101010101010101010101010101010101010101010101", "RBERRY")
let lp = (#"99999999999999999999999999999999999999999999999999999999", "LP")
let pool_state =
PoolState {
quantity_a: (#"", #"", 1_000_000_000),
quantity_b: (rberry.1st, rberry.2nd, 1_000_000_000),
quantity_lp: (lp.1st, lp.2nd, 1_000_000_000),
}
let input_value =
value.from_lovelace(3_500_000)
|> value.add(rberry.1st, rberry.2nd, 1_000_000)
let assets = (
(ada.1st, ada.2nd, 1_000_000),
(rberry.1st, rberry.2nd, 1_000_000),
)
let order =
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2_500_000,
destination: Destination { address: addr, datum: NoDatum },
details: order.Donation {
assets: assets,
},
extension: Void,
}
// There's no remainder so do_donation totally ignores this Output record
let output =
Output {
address: addr,
value: value.from_lovelace(999_999_999_999_999_999),
datum: NoDatum,
reference_script: None,
}
let (final_pool_state, has_remainder) =
do_donation(pool_state, input_value, assets, order.destination, 2_500_000, output)
expect !has_remainder
expect final_pool_state.quantity_a.3rd == 1_001_000_000
expect final_pool_state.quantity_b.3rd == 1_001_000_000
True
}

0 comments on commit 672dcf3

Please sign in to comment.