@@ -107,16 +107,27 @@ fn test_initialize_token_default_values() {
107107 let encoded_parameters = cbor:: cbor_encode ( & parameters) . unwrap ( ) . into ( ) ;
108108 token_module:: initialize_token ( & mut stub, encoded_parameters) . unwrap ( ) ;
109109
110- let mut expected_state = HashMap :: with_capacity ( 3 ) ;
111- expected_state. insert ( b"\0 \0 name" . into ( ) , b"Protocol-level token" . into ( ) ) ;
112- expected_state. insert ( b"\0 \0 metadata" . into ( ) , encoded_metadata) ;
113- expected_state. insert (
114- b"\0 \0 governanceAccount" . into ( ) ,
115- stub. account_index ( & gov_account) . index . to_be_bytes ( ) . into ( ) ,
110+ // assertions directly on token state
111+ assert_eq ! (
112+ stub. get_token_state( b"\0 \0 name" . into( ) ) ,
113+ Some ( b"Protocol-level token" . into( ) )
116114 ) ;
117- assert_eq ! ( stub. state, expected_state) ;
118-
115+ assert_eq ! (
116+ stub. get_token_state( b"\0 \0 metadata" . into( ) ) ,
117+ Some ( encoded_metadata)
118+ ) ;
119+ assert_eq ! (
120+ stub. get_token_state( b"\0 \0 governanceAccount" . into( ) ) ,
121+ Some ( stub. account_index( & gov_account) . index. to_be_bytes( ) . into( ) )
122+ ) ;
123+ assert_eq ! ( stub. get_token_state( b"\0 \0 allowList" . into( ) ) , None ) ;
124+ assert_eq ! ( stub. get_token_state( b"\0 \0 denyList" . into( ) ) , None ) ;
125+ assert_eq ! ( stub. get_token_state( b"\0 \0 mintable" . into( ) ) , None ) ;
126+ assert_eq ! ( stub. get_token_state( b"\0 \0 burnable" . into( ) ) , None ) ;
127+ assert_eq ! ( stub. get_token_state( b"\0 \0 paused" . into( ) ) , None ) ;
128+ // assert governance account balance
119129 assert_eq ! ( stub. account_balance( & gov_account) , RawTokenAmount ( 0 ) ) ;
130+ // assertions using token module state query
120131 let state: TokenModuleState =
121132 cbor:: cbor_decode ( token_module:: query_token_module_state ( & stub) . unwrap ( ) ) . unwrap ( ) ;
122133 assert_eq ! ( state. name, Some ( "Protocol-level token" . to_owned( ) ) ) ;
@@ -152,19 +163,27 @@ fn test_initialize_token_no_minting() {
152163 let encoded_parameters = cbor:: cbor_encode ( & parameters) . unwrap ( ) . into ( ) ;
153164 token_module:: initialize_token ( & mut stub, encoded_parameters) . unwrap ( ) ;
154165
155- let mut expected_state = HashMap :: with_capacity ( 3 ) ;
156- expected_state. insert ( b"\0 \0 name" . into ( ) , b"Protocol-level token" . into ( ) ) ;
157- expected_state. insert ( b"\0 \0 metadata" . into ( ) , encoded_metadata) ;
158- expected_state. insert (
159- b"\0 \0 governanceAccount" . into ( ) ,
160- stub. account_index ( & gov_account) . index . to_be_bytes ( ) . into ( ) ,
166+ // assertions directly on token state
167+ assert_eq ! (
168+ stub. get_token_state( b"\0 \0 name" . into( ) ) ,
169+ Some ( b"Protocol-level token" . into( ) )
161170 ) ;
162- expected_state. insert ( b"\0 \0 allowList" . into ( ) , vec ! [ ] ) ;
163- expected_state. insert ( b"\0 \0 mintable" . into ( ) , vec ! [ ] ) ;
164- expected_state. insert ( b"\0 \0 burnable" . into ( ) , vec ! [ ] ) ;
165- assert_eq ! ( stub. state, expected_state) ;
166-
171+ assert_eq ! (
172+ stub. get_token_state( b"\0 \0 metadata" . into( ) ) ,
173+ Some ( encoded_metadata)
174+ ) ;
175+ assert_eq ! (
176+ stub. get_token_state( b"\0 \0 governanceAccount" . into( ) ) ,
177+ Some ( stub. account_index( & gov_account) . index. to_be_bytes( ) . into( ) )
178+ ) ;
179+ assert_eq ! ( stub. get_token_state( b"\0 \0 allowList" . into( ) ) , Some ( vec![ ] ) ) ;
180+ assert_eq ! ( stub. get_token_state( b"\0 \0 denyList" . into( ) ) , None ) ;
181+ assert_eq ! ( stub. get_token_state( b"\0 \0 mintable" . into( ) ) , Some ( vec![ ] ) ) ;
182+ assert_eq ! ( stub. get_token_state( b"\0 \0 burnable" . into( ) ) , Some ( vec![ ] ) ) ;
183+ assert_eq ! ( stub. get_token_state( b"\0 \0 paused" . into( ) ) , None ) ;
184+ // assert governance account balance
167185 assert_eq ! ( stub. account_balance( & gov_account) , RawTokenAmount ( 0 ) ) ;
186+ // assertions using token module state query
168187 let state: TokenModuleState =
169188 cbor:: cbor_decode ( token_module:: query_token_module_state ( & stub) . unwrap ( ) ) . unwrap ( ) ;
170189 assert_eq ! ( state. name, Some ( "Protocol-level token" . to_owned( ) ) ) ;
@@ -200,17 +219,27 @@ fn test_initialize_token_with_minting() {
200219 let encoded_parameters = cbor:: cbor_encode ( & parameters) . unwrap ( ) . into ( ) ;
201220 token_module:: initialize_token ( & mut stub, encoded_parameters) . unwrap ( ) ;
202221
203- let mut expected_state = HashMap :: with_capacity ( 3 ) ;
204- expected_state. insert ( b"\0 \0 name" . into ( ) , b"Protocol-level token" . into ( ) ) ;
205- expected_state. insert ( b"\0 \0 metadata" . into ( ) , encoded_metadata) ;
206- expected_state. insert (
207- b"\0 \0 governanceAccount" . into ( ) ,
208- stub. account_index ( & gov_account) . index . to_be_bytes ( ) . into ( ) ,
222+ // assertions directly on token state
223+ assert_eq ! (
224+ stub. get_token_state( b"\0 \0 name" . into( ) ) ,
225+ Some ( b"Protocol-level token" . into( ) )
209226 ) ;
210- expected_state. insert ( b"\0 \0 denyList" . into ( ) , vec ! [ ] ) ;
211- assert_eq ! ( stub. state, expected_state) ;
212-
227+ assert_eq ! (
228+ stub. get_token_state( b"\0 \0 metadata" . into( ) ) ,
229+ Some ( encoded_metadata)
230+ ) ;
231+ assert_eq ! (
232+ stub. get_token_state( b"\0 \0 governanceAccount" . into( ) ) ,
233+ Some ( stub. account_index( & gov_account) . index. to_be_bytes( ) . into( ) )
234+ ) ;
235+ assert_eq ! ( stub. get_token_state( b"\0 \0 allowList" . into( ) ) , None ) ;
236+ assert_eq ! ( stub. get_token_state( b"\0 \0 denyList" . into( ) ) , Some ( vec![ ] ) ) ;
237+ assert_eq ! ( stub. get_token_state( b"\0 \0 mintable" . into( ) ) , None ) ;
238+ assert_eq ! ( stub. get_token_state( b"\0 \0 burnable" . into( ) ) , None ) ;
239+ assert_eq ! ( stub. get_token_state( b"\0 \0 paused" . into( ) ) , None ) ;
240+ // assert governance account balance
213241 assert_eq ! ( stub. account_balance( & gov_account) , RawTokenAmount ( 500000 ) ) ;
242+ // assertions using token module state query
214243 let state: TokenModuleState =
215244 cbor:: cbor_decode ( token_module:: query_token_module_state ( & stub) . unwrap ( ) ) . unwrap ( ) ;
216245 assert_eq ! ( state. name, Some ( "Protocol-level token" . to_owned( ) ) ) ;
0 commit comments