Skip to content

Commit 672dcf3

Browse files
committed
move donation tests to own module
1 parent 84e2bff commit 672dcf3

File tree

2 files changed

+63
-58
lines changed

2 files changed

+63
-58
lines changed

lib/calculation/donation.ak

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use aiken/transaction.{NoDatum, Output}
2-
use aiken/transaction/credential.{Address, VerificationKeyCredential}
1+
use aiken/transaction.{Output}
32
use aiken/transaction/value.{Value, ada_policy_id, ada_asset_name}
43
use calculation/shared.{PoolState} as calc_shared
54
use shared.{SingletonValue}
6-
use sundae/multisig
7-
use types/order.{Destination, OrderDatum}
5+
use types/order.{Destination}
86

97
/// A donation describes an amount of assets to deposit into the pool, receiving nothing in return (except for the extra change on the UTXO).
108
/// 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
@@ -76,57 +74,3 @@ pub fn do_donation(
7674
has_remainder,
7775
)
7876
}
79-
80-
test donation() {
81-
let addr =
82-
Address(
83-
VerificationKeyCredential(
84-
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
85-
),
86-
None,
87-
)
88-
let ada = (#"", #"")
89-
let rberry =
90-
(#"01010101010101010101010101010101010101010101010101010101", "RBERRY")
91-
let lp = (#"99999999999999999999999999999999999999999999999999999999", "LP")
92-
let pool_state =
93-
PoolState {
94-
quantity_a: (#"", #"", 1_000_000_000),
95-
quantity_b: (rberry.1st, rberry.2nd, 1_000_000_000),
96-
quantity_lp: (lp.1st, lp.2nd, 1_000_000_000),
97-
}
98-
let input_value =
99-
value.from_lovelace(3_500_000)
100-
|> value.add(rberry.1st, rberry.2nd, 1_000_000)
101-
let assets = (
102-
(ada.1st, ada.2nd, 1_000_000),
103-
(rberry.1st, rberry.2nd, 1_000_000),
104-
)
105-
let order =
106-
OrderDatum {
107-
pool_ident: None,
108-
owner: multisig.Signature(
109-
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
110-
),
111-
max_protocol_fee: 2_500_000,
112-
destination: Destination { address: addr, datum: NoDatum },
113-
details: order.Donation {
114-
assets: assets,
115-
},
116-
extension: Void,
117-
}
118-
// There's no remainder so do_donation totally ignores this Output record
119-
let output =
120-
Output {
121-
address: addr,
122-
value: value.from_lovelace(999_999_999_999_999_999),
123-
datum: NoDatum,
124-
reference_script: None,
125-
}
126-
let (final_pool_state, has_remainder) =
127-
do_donation(pool_state, input_value, assets, order.destination, 2_500_000, output)
128-
expect !has_remainder
129-
expect final_pool_state.quantity_a.3rd == 1_001_000_000
130-
expect final_pool_state.quantity_b.3rd == 1_001_000_000
131-
True
132-
}

lib/tests/aiken/donation.ak

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use aiken/transaction.{NoDatum, Output}
2+
use aiken/transaction/credential.{Address, VerificationKeyCredential}
3+
use aiken/transaction/value
4+
use calculation/shared.{PoolState} as calc_shared
5+
use calculation/donation.{do_donation}
6+
use sundae/multisig
7+
use types/order.{Destination, OrderDatum}
8+
9+
test donation() {
10+
let addr =
11+
Address(
12+
VerificationKeyCredential(
13+
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
14+
),
15+
None,
16+
)
17+
let ada = (#"", #"")
18+
let rberry =
19+
(#"01010101010101010101010101010101010101010101010101010101", "RBERRY")
20+
let lp = (#"99999999999999999999999999999999999999999999999999999999", "LP")
21+
let pool_state =
22+
PoolState {
23+
quantity_a: (#"", #"", 1_000_000_000),
24+
quantity_b: (rberry.1st, rberry.2nd, 1_000_000_000),
25+
quantity_lp: (lp.1st, lp.2nd, 1_000_000_000),
26+
}
27+
let input_value =
28+
value.from_lovelace(3_500_000)
29+
|> value.add(rberry.1st, rberry.2nd, 1_000_000)
30+
let assets = (
31+
(ada.1st, ada.2nd, 1_000_000),
32+
(rberry.1st, rberry.2nd, 1_000_000),
33+
)
34+
let order =
35+
OrderDatum {
36+
pool_ident: None,
37+
owner: multisig.Signature(
38+
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
39+
),
40+
max_protocol_fee: 2_500_000,
41+
destination: Destination { address: addr, datum: NoDatum },
42+
details: order.Donation {
43+
assets: assets,
44+
},
45+
extension: Void,
46+
}
47+
// There's no remainder so do_donation totally ignores this Output record
48+
let output =
49+
Output {
50+
address: addr,
51+
value: value.from_lovelace(999_999_999_999_999_999),
52+
datum: NoDatum,
53+
reference_script: None,
54+
}
55+
let (final_pool_state, has_remainder) =
56+
do_donation(pool_state, input_value, assets, order.destination, 2_500_000, output)
57+
expect !has_remainder
58+
expect final_pool_state.quantity_a.3rd == 1_001_000_000
59+
expect final_pool_state.quantity_b.3rd == 1_001_000_000
60+
True
61+
}

0 commit comments

Comments
 (0)