2
2
3
3
use near_sdk:: { json_types:: U128 , test_utils:: test_env:: alice, PromiseOrValue } ;
4
4
use sweat_jar_model:: {
5
- api:: { ClaimApi , JarApi , WithdrawApi } ,
5
+ api:: { ClaimApi , WithdrawApi } ,
6
6
claimed_amount_view:: ClaimedAmountView ,
7
7
MS_IN_YEAR , U32 ,
8
8
} ;
@@ -62,43 +62,6 @@ fn claim_total_detailed_when_having_tokens() {
62
62
assert_eq ! ( jar_1_expected_interest, value. detailed. get( & U32 ( jar_1. id) ) . unwrap( ) . 0 ) ;
63
63
}
64
64
65
- #[ test]
66
- fn claim_partially_detailed_when_having_tokens ( ) {
67
- let alice = alice ( ) ;
68
- let admin = admin ( ) ;
69
-
70
- let product = generate_product ( ) ;
71
- let jar_0 = Jar :: generate ( 0 , & alice, & product. id ) . principal ( 100_000_000 ) ;
72
- let jar_1 = Jar :: generate ( 1 , & alice, & product. id ) . principal ( 200_000_000 ) ;
73
- let mut context = Context :: new ( admin)
74
- . with_products ( & [ product. clone ( ) ] )
75
- . with_jars ( & [ jar_0. clone ( ) , jar_1. clone ( ) ] ) ;
76
-
77
- let product_term = product. get_lockup_term ( ) . unwrap ( ) ;
78
- let test_duration = product_term + 100 ;
79
-
80
- let jar_0_expected_interest = jar_0. get_interest ( & product, test_duration) . 0 ;
81
- let jar_1_expected_interest = jar_1. get_interest ( & product, test_duration) . 0 - 1 ;
82
-
83
- context. set_block_timestamp_in_ms ( test_duration) ;
84
-
85
- context. switch_account ( & alice) ;
86
- let result = context. contract ( ) . claim_jars (
87
- vec ! [ U32 ( jar_0. id) , U32 ( jar_1. id) ] ,
88
- Some ( U128 ( jar_0_expected_interest + jar_1_expected_interest) ) ,
89
- Some ( true ) ,
90
- ) ;
91
-
92
- let PromiseOrValue :: Value ( ClaimedAmountView :: Detailed ( value) ) = result else {
93
- panic ! ( ) ;
94
- } ;
95
-
96
- assert_eq ! ( jar_0_expected_interest + jar_1_expected_interest, value. total. 0 ) ;
97
-
98
- assert_eq ! ( jar_0_expected_interest, value. detailed. get( & U32 ( jar_0. id) ) . unwrap( ) . 0 ) ;
99
- assert_eq ! ( jar_1_expected_interest, value. detailed. get( & U32 ( jar_1. id) ) . unwrap( ) . 0 ) ;
100
- }
101
-
102
65
#[ test]
103
66
fn claim_pending_withdraw_jar ( ) {
104
67
let alice = alice ( ) ;
@@ -118,16 +81,11 @@ fn claim_pending_withdraw_jar() {
118
81
let test_duration = product_term + 100 ;
119
82
120
83
let jar_0_expected_interest = jar_0. get_interest ( & product, test_duration) ;
121
- let jar_1_expected_interest = jar_1. get_interest ( & product, test_duration) . 0 - 1 ;
122
84
123
85
context. set_block_timestamp_in_ms ( test_duration) ;
124
86
125
87
context. switch_account ( & alice) ;
126
- let result = context. contract ( ) . claim_jars (
127
- vec ! [ U32 ( jar_0. id) , U32 ( jar_1. id) ] ,
128
- Some ( U128 ( jar_0_expected_interest. 0 + jar_1_expected_interest) ) ,
129
- Some ( true ) ,
130
- ) ;
88
+ let result = context. contract ( ) . claim_total ( Some ( true ) ) ;
131
89
132
90
let PromiseOrValue :: Value ( ClaimedAmountView :: Detailed ( value) ) = result else {
133
91
panic ! ( ) ;
@@ -139,65 +97,6 @@ fn claim_pending_withdraw_jar() {
139
97
assert_eq ! ( None , value. detailed. get( & U32 ( jar_1. id) ) ) ;
140
98
}
141
99
142
- #[ test]
143
- fn claim_partially_detailed_when_having_tokens_and_request_sum_of_single_deposit ( ) {
144
- let alice = alice ( ) ;
145
- let admin = admin ( ) ;
146
-
147
- let product = generate_product ( ) ;
148
- let jar_0 = Jar :: generate ( 0 , & alice, & product. id ) . principal ( 100_000_000 ) ;
149
- let jar_1 = Jar :: generate ( 1 , & alice, & product. id ) . principal ( 200_000_000 ) ;
150
- let mut context = Context :: new ( admin)
151
- . with_products ( & [ product. clone ( ) ] )
152
- . with_jars ( & [ jar_0. clone ( ) , jar_1. clone ( ) ] ) ;
153
-
154
- let product_term = product. get_lockup_term ( ) . unwrap ( ) ;
155
- let test_duration = product_term + 100 ;
156
-
157
- let jar_0_expected_interest = jar_0. get_interest ( & product, test_duration) . 0 ;
158
-
159
- context. set_block_timestamp_in_ms ( test_duration) ;
160
-
161
- context. switch_account ( & alice) ;
162
- let result = context. contract ( ) . claim_jars (
163
- vec ! [ U32 ( jar_0. id) , U32 ( jar_1. id) ] ,
164
- Some ( U128 ( jar_0_expected_interest) ) ,
165
- Some ( true ) ,
166
- ) ;
167
-
168
- let PromiseOrValue :: Value ( ClaimedAmountView :: Detailed ( value) ) = result else {
169
- panic ! ( ) ;
170
- } ;
171
-
172
- assert_eq ! ( jar_0_expected_interest, value. total. 0 ) ;
173
-
174
- assert_eq ! ( jar_0_expected_interest, value. detailed. get( & U32 ( jar_0. id) ) . unwrap( ) . 0 ) ;
175
- assert ! ( !value. detailed. contains_key( & U32 ( jar_1. id) ) ) ;
176
- }
177
-
178
- #[ test]
179
- fn claim_partially_when_having_tokens_to_claim ( ) {
180
- let alice = alice ( ) ;
181
- let admin = admin ( ) ;
182
-
183
- let product = generate_product ( ) ;
184
- let jar = Jar :: generate ( 0 , & alice, & product. id ) . principal ( 100_000_000_000 ) ;
185
- let mut context = Context :: new ( admin) . with_products ( & [ product] ) . with_jars ( & [ jar. clone ( ) ] ) ;
186
-
187
- context. set_block_timestamp_in_days ( 365 ) ;
188
-
189
- context. switch_account ( & alice) ;
190
- let claimed = context
191
- . contract ( )
192
- . claim_jars ( vec ! [ U32 ( jar. id) ] , Some ( U128 ( 100 ) ) , None )
193
- . unwrap ( ) ;
194
-
195
- assert_eq ! ( claimed. get_total( ) . 0 , 100 ) ;
196
-
197
- let jar = context. contract ( ) . get_jar ( alice, U32 ( jar. id ) ) ;
198
- assert_eq ! ( 100 , jar. claimed_balance. 0 ) ;
199
- }
200
-
201
100
#[ test]
202
101
fn dont_delete_jar_on_all_interest_claim ( ) {
203
102
let alice = alice ( ) ;
@@ -210,9 +109,7 @@ fn dont_delete_jar_on_all_interest_claim() {
210
109
context. set_block_timestamp_in_days ( 365 ) ;
211
110
212
111
context. switch_account ( & alice) ;
213
- context
214
- . contract ( )
215
- . claim_jars ( vec ! [ U32 ( jar. id) ] , Some ( U128 ( 200_000 ) ) , None ) ;
112
+ context. contract ( ) . claim_total ( None ) ;
216
113
217
114
let jar = context. contract ( ) . get_jar_internal ( & alice, jar. id ) ;
218
115
assert_eq ! ( 200_000 , jar. claimed_balance) ;
@@ -241,10 +138,7 @@ fn claim_all_withdraw_all_and_delete_jar() {
241
138
context. set_block_timestamp_in_ms ( product. get_lockup_term ( ) . unwrap ( ) + 1 ) ;
242
139
243
140
context. switch_account ( & alice) ;
244
- let claimed = context
245
- . contract ( )
246
- . claim_jars ( vec ! [ U32 ( jar_id) ] , Some ( U128 ( 200_000 ) ) , None )
247
- . unwrap ( ) ;
141
+ let claimed = context. contract ( ) . claim_total ( None ) . unwrap ( ) ;
248
142
249
143
assert_eq ! ( 200_000 , claimed. get_total( ) . 0 ) ;
250
144
@@ -292,10 +186,7 @@ fn withdraw_all_claim_all_and_delete_jar() {
292
186
293
187
assert_eq ! ( jar. principal, 0 ) ;
294
188
295
- let claimed = context
296
- . contract ( )
297
- . claim_jars ( vec ! [ U32 ( jar_id) ] , Some ( U128 ( 200_000 ) ) , None )
298
- . unwrap ( ) ;
189
+ let claimed = context. contract ( ) . claim_total ( None ) . unwrap ( ) ;
299
190
300
191
assert_eq ! ( claimed. get_total( ) , U128 ( 200_000 ) ) ;
301
192
@@ -319,10 +210,7 @@ fn failed_future_claim() {
319
210
320
211
let jar_before_claim = context. contract ( ) . get_jar_internal ( & alice, jar. id ) . clone ( ) ;
321
212
322
- let claimed = context
323
- . contract ( )
324
- . claim_jars ( vec ! [ U32 ( jar. id) ] , Some ( U128 ( 200_000 ) ) , None )
325
- . unwrap ( ) ;
213
+ let claimed = context. contract ( ) . claim_total ( None ) . unwrap ( ) ;
326
214
327
215
assert_eq ! ( claimed. get_total( ) . 0 , 0 ) ;
328
216
0 commit comments