@@ -86,16 +86,16 @@ impl<'de> Deserialize<'de> for U32 {
86
86
87
87
#[ cfg( test) ]
88
88
pub ( crate ) mod tests {
89
- use std:: time:: Duration ;
89
+ use std:: { collections :: HashSet , time:: Duration } ;
90
90
91
91
use near_sdk:: { test_utils:: VMContextBuilder , testing_env, AccountId , Balance } ;
92
92
93
- use crate :: { common:: UDecimal , Contract } ;
93
+ use crate :: { common:: UDecimal , jar :: model :: Jar , product :: model :: Product , Contract } ;
94
94
95
95
pub ( crate ) struct Context {
96
96
pub contract : Contract ,
97
+ pub owner : AccountId ,
97
98
ft_contract_id : AccountId ,
98
- owner : AccountId ,
99
99
builder : VMContextBuilder ,
100
100
}
101
101
@@ -124,6 +124,33 @@ pub(crate) mod tests {
124
124
}
125
125
}
126
126
127
+ pub ( crate ) fn with_products ( mut self , products : & [ Product ] ) -> Self {
128
+ for product in products {
129
+ self . contract . products . insert ( product. id . clone ( ) , product. clone ( ) ) ;
130
+ }
131
+
132
+ self
133
+ }
134
+
135
+ pub ( crate ) fn with_jars ( mut self , jars : & [ Jar ] ) -> Self {
136
+ for jar in jars {
137
+ self . contract . jars . push ( jar. clone ( ) ) ;
138
+
139
+ let account_id = & jar. account_id ;
140
+ if !self . contract . account_jars . contains_key ( account_id) {
141
+ self . contract . account_jars . insert ( account_id. clone ( ) , HashSet :: new ( ) ) ;
142
+ }
143
+
144
+ self . contract
145
+ . account_jars
146
+ . get_mut ( account_id)
147
+ . unwrap ( )
148
+ . insert ( jar. index ) ;
149
+ }
150
+
151
+ self
152
+ }
153
+
127
154
pub ( crate ) fn set_block_timestamp_in_days ( & mut self , days : u64 ) {
128
155
self . set_block_timestamp ( Duration :: from_secs ( days * 24 * 60 * 60 ) ) ;
129
156
}
@@ -156,7 +183,7 @@ pub(crate) mod tests {
156
183
self . switch_account ( & self . ft_contract_id . clone ( ) ) ;
157
184
}
158
185
159
- pub ( crate ) fn with_deposit_yocto ( & mut self , amount : Balance , f : fn ( & mut Context ) -> ( ) ) {
186
+ pub ( crate ) fn with_deposit_yocto ( & mut self , amount : Balance , f : impl FnOnce ( & mut Context ) ) {
160
187
self . set_deposit_yocto ( amount) ;
161
188
162
189
f ( self ) ;
0 commit comments