@@ -2,43 +2,28 @@ pub mod api;
2
2
3
3
#[ cfg( test) ]
4
4
mod tests {
5
- use near_sdk:: {
6
- json_types:: { U128 , U64 } ,
7
- test_utils:: accounts,
8
- PromiseOrValue ,
9
- } ;
5
+ use near_sdk:: { json_types:: U128 , test_utils:: accounts, PromiseOrValue } ;
10
6
11
7
use crate :: {
12
8
claim:: api:: ClaimApi ,
13
- common:: { tests:: Context , U32 } ,
14
- jar:: { api:: JarApi , model:: JarTicket } ,
15
- product:: { api:: ProductApi , tests:: get_register_product_command} ,
9
+ common:: { tests:: Context , UDecimal , U32 } ,
10
+ jar:: { api:: JarApi , model:: Jar } ,
11
+ product:: {
12
+ model:: { Apy , Product } ,
13
+ tests:: YEAR_IN_MS ,
14
+ } ,
16
15
} ;
17
16
18
17
#[ test]
19
18
fn claim_total_when_nothing_to_claim ( ) {
20
19
let alice = accounts ( 0 ) ;
21
20
let admin = accounts ( 1 ) ;
22
21
23
- let mut context = Context :: new ( admin. clone ( ) ) ;
24
-
25
- context. switch_account ( & admin) ;
26
- context. with_deposit_yocto ( 1 , |context| {
27
- context. contract . register_product ( get_register_product_command ( ) )
28
- } ) ;
22
+ let product = generate_product ( ) ;
23
+ let jar = Jar :: generate ( 0 , & alice, & product. id ) . principal ( 100_000_000 ) ;
24
+ let mut context = Context :: new ( admin) . with_products ( & [ product] ) . with_jars ( & [ jar] ) ;
29
25
30
- context. switch_account_to_owner ( ) ;
31
- context. contract . create_jar (
32
- alice. clone ( ) ,
33
- JarTicket {
34
- product_id : get_register_product_command ( ) . id ,
35
- valid_until : U64 ( 0 ) ,
36
- } ,
37
- U128 ( 100_000_000 ) ,
38
- None ,
39
- ) ;
40
-
41
- context. switch_account ( & alice. clone ( ) ) ;
26
+ context. switch_account ( & alice) ;
42
27
let result = context. contract . claim_total ( ) ;
43
28
44
29
if let PromiseOrValue :: Value ( value) = result {
@@ -53,30 +38,25 @@ mod tests {
53
38
let alice = accounts ( 0 ) ;
54
39
let admin = accounts ( 1 ) ;
55
40
56
- let mut context = Context :: new ( admin. clone ( ) ) ;
57
-
58
- context. switch_account ( & admin) ;
59
- context. with_deposit_yocto ( 1 , |context| {
60
- context. contract . register_product ( get_register_product_command ( ) )
61
- } ) ;
62
-
63
- context. switch_account_to_owner ( ) ;
64
- context. contract . create_jar (
65
- alice. clone ( ) ,
66
- JarTicket {
67
- product_id : get_register_product_command ( ) . id ,
68
- valid_until : U64 ( 0 ) ,
69
- } ,
70
- U128 ( 100_000_000_000 ) ,
71
- None ,
72
- ) ;
41
+ let product = generate_product ( ) ;
42
+ let reference_jar = Jar :: generate ( 0 , & alice, & product. id ) . principal ( 100_000_000_000 ) ;
43
+ let mut context = Context :: new ( admin)
44
+ . with_products ( & [ product] )
45
+ . with_jars ( & [ reference_jar. clone ( ) ] ) ;
73
46
74
47
context. set_block_timestamp_in_days ( 365 ) ;
75
48
76
- context. switch_account ( & alice. clone ( ) ) ;
77
- context. contract . claim_jars ( vec ! [ 0 ] , Some ( U128 ( 100 ) ) ) ;
49
+ context. switch_account ( & alice) ;
50
+ context. contract . claim_jars ( vec ! [ reference_jar . index ] , Some ( U128 ( 100 ) ) ) ;
78
51
79
- let jar = context. contract . get_jar ( U32 ( 0 ) ) ;
52
+ let jar = context. contract . get_jar ( U32 ( reference_jar . index ) ) ;
80
53
assert_eq ! ( 100 , jar. claimed_balance. 0 ) ;
81
54
}
55
+
56
+ fn generate_product ( ) -> Product {
57
+ Product :: generate ( "product" )
58
+ . enabled ( true )
59
+ . lockup_term ( YEAR_IN_MS )
60
+ . apy ( Apy :: Constant ( UDecimal :: new ( 12 , 2 ) ) )
61
+ }
82
62
}
0 commit comments