@@ -25,8 +25,10 @@ fn test_initialize_token_parameters_decode_failure() {
2525 let res = token_module:: initialize_token ( & mut stub, vec ! [ ] . into ( ) ) ;
2626 assert_matches ! (
2727 & res,
28- Err ( TokenInitializationError :: InvalidInitializationParameters ( err) )
29- if err. contains( "Error decoding token initialization parameters" )
28+ Err ( TokenInitializationError :: CborSerialization ( err) ) => {
29+ let msg = err. to_string( ) ;
30+ assert!( msg. contains( "IO error" ) , "msg: {}" , msg) ;
31+ }
3032 ) ;
3133}
3234
@@ -88,14 +90,13 @@ fn test_initialize_token_additional_parameter() {
8890fn test_initialize_token_default_values ( ) {
8991 let mut stub = KernelStub :: new ( 0 ) ;
9092 let gov_account = stub. create_account ( ) ;
91- let governance_holder_account =
92- CborHolderAccount :: from ( stub. account_canonical_address ( & gov_account) ) ;
93+ let gov_holder_account = CborHolderAccount :: from ( stub. account_canonical_address ( & gov_account) ) ;
9394 let metadata = MetadataUrl :: from ( "https://plt.token" . to_string ( ) ) ;
9495 let encoded_metadata = cbor:: cbor_encode ( & metadata) . unwrap ( ) ;
9596 let parameters = TokenModuleInitializationParameters {
9697 name : Some ( "Protocol-level token" . to_owned ( ) ) ,
9798 metadata : Some ( metadata. clone ( ) ) ,
98- governance_account : Some ( governance_holder_account . clone ( ) ) ,
99+ governance_account : Some ( gov_holder_account . clone ( ) ) ,
99100 allow_list : None ,
100101 deny_list : None ,
101102 initial_supply : None ,
@@ -115,11 +116,12 @@ fn test_initialize_token_default_values() {
115116 ) ;
116117 assert_eq ! ( stub. state, expected_state) ;
117118
119+ assert_eq ! ( stub. account_balance( & gov_account) , RawTokenAmount ( 0 ) ) ;
118120 let state: TokenModuleState =
119121 cbor:: cbor_decode ( token_module:: query_token_module_state ( & stub) . unwrap ( ) ) . unwrap ( ) ;
120122 assert_eq ! ( state. name, Some ( "Protocol-level token" . to_owned( ) ) ) ;
121123 assert_eq ! ( state. metadata, Some ( metadata) ) ;
122- assert_eq ! ( state. governance_account, Some ( governance_holder_account ) ) ;
124+ assert_eq ! ( state. governance_account, Some ( gov_holder_account ) ) ;
123125 assert_eq ! ( state. allow_list, Some ( false ) ) ;
124126 assert_eq ! ( state. deny_list, Some ( false ) ) ;
125127 assert_eq ! ( state. mintable, Some ( false ) ) ;
@@ -128,20 +130,18 @@ fn test_initialize_token_default_values() {
128130 assert ! ( state. additional. is_empty( ) ) ;
129131}
130132
131- // todo ar write rest of testsf
132- // todo ar trim down plt model in base
133-
134133/// In this example, the parameters are valid, no minting.
135134#[ test]
136135fn test_initialize_token_no_minting ( ) {
137136 let mut stub = KernelStub :: new ( 0 ) ;
138137 let gov_account = stub. create_account ( ) ;
138+ let gov_holder_account = CborHolderAccount :: from ( stub. account_canonical_address ( & gov_account) ) ;
139139 let metadata = MetadataUrl :: from ( "https://plt.token" . to_string ( ) ) ;
140140 let encoded_metadata = cbor:: cbor_encode ( & metadata) . unwrap ( ) ;
141141 let parameters = TokenModuleInitializationParameters {
142142 name : Some ( "Protocol-level token" . to_owned ( ) ) ,
143- metadata : Some ( metadata) ,
144- governance_account : Some ( stub . account_canonical_address ( & gov_account ) . into ( ) ) ,
143+ metadata : Some ( metadata. clone ( ) ) ,
144+ governance_account : Some ( gov_holder_account . clone ( ) ) ,
145145 allow_list : Some ( true ) ,
146146 deny_list : Some ( false ) ,
147147 initial_supply : None ,
@@ -151,6 +151,7 @@ fn test_initialize_token_no_minting() {
151151 } ;
152152 let encoded_parameters = cbor:: cbor_encode ( & parameters) . unwrap ( ) . into ( ) ;
153153 token_module:: initialize_token ( & mut stub, encoded_parameters) . unwrap ( ) ;
154+
154155 let mut expected_state = HashMap :: with_capacity ( 3 ) ;
155156 expected_state. insert ( b"\0 \0 name" . into ( ) , b"Protocol-level token" . into ( ) ) ;
156157 expected_state. insert ( b"\0 \0 metadata" . into ( ) , encoded_metadata) ;
@@ -162,19 +163,33 @@ fn test_initialize_token_no_minting() {
162163 expected_state. insert ( b"\0 \0 mintable" . into ( ) , vec ! [ ] ) ;
163164 expected_state. insert ( b"\0 \0 burnable" . into ( ) , vec ! [ ] ) ;
164165 assert_eq ! ( stub. state, expected_state) ;
166+
167+ assert_eq ! ( stub. account_balance( & gov_account) , RawTokenAmount ( 0 ) ) ;
168+ let state: TokenModuleState =
169+ cbor:: cbor_decode ( token_module:: query_token_module_state ( & stub) . unwrap ( ) ) . unwrap ( ) ;
170+ assert_eq ! ( state. name, Some ( "Protocol-level token" . to_owned( ) ) ) ;
171+ assert_eq ! ( state. metadata, Some ( metadata) ) ;
172+ assert_eq ! ( state. governance_account, Some ( gov_holder_account) ) ;
173+ assert_eq ! ( state. allow_list, Some ( true ) ) ;
174+ assert_eq ! ( state. deny_list, Some ( false ) ) ;
175+ assert_eq ! ( state. mintable, Some ( true ) ) ;
176+ assert_eq ! ( state. burnable, Some ( true ) ) ;
177+ assert_eq ! ( state. paused, Some ( false ) ) ;
178+ assert ! ( state. additional. is_empty( ) ) ;
165179}
166180
167181/// In this example, the parameters are valid, with minting.
168182#[ test]
169- fn test_initialize_token_valid_2 ( ) {
183+ fn test_initialize_token_with_minting ( ) {
170184 let mut stub = KernelStub :: new ( 2 ) ;
171185 let gov_account = stub. create_account ( ) ;
172- let metadata = "https://plt.token" . to_owned ( ) . into ( ) ;
186+ let gov_holder_account = CborHolderAccount :: from ( stub. account_canonical_address ( & gov_account) ) ;
187+ let metadata = MetadataUrl :: from ( "https://plt.token" . to_string ( ) ) ;
173188 let encoded_metadata = cbor:: cbor_encode ( & metadata) . unwrap ( ) ;
174189 let parameters = TokenModuleInitializationParameters {
175190 name : Some ( "Protocol-level token" . to_owned ( ) ) ,
176- metadata : Some ( metadata) ,
177- governance_account : Some ( stub . account_canonical_address ( & gov_account ) . into ( ) ) ,
191+ metadata : Some ( metadata. clone ( ) ) ,
192+ governance_account : Some ( gov_holder_account . clone ( ) ) ,
178193 allow_list : Some ( false ) ,
179194 deny_list : Some ( true ) ,
180195 initial_supply : Some ( TokenAmount :: from_raw ( 500000 , 2 ) ) ,
@@ -184,7 +199,7 @@ fn test_initialize_token_valid_2() {
184199 } ;
185200 let encoded_parameters = cbor:: cbor_encode ( & parameters) . unwrap ( ) . into ( ) ;
186201 token_module:: initialize_token ( & mut stub, encoded_parameters) . unwrap ( ) ;
187- assert_eq ! ( stub . account_balance ( & gov_account ) , RawTokenAmount ( 500000 ) ) ;
202+
188203 let mut expected_state = HashMap :: with_capacity ( 3 ) ;
189204 expected_state. insert ( b"\0 \0 name" . into ( ) , b"Protocol-level token" . into ( ) ) ;
190205 expected_state. insert ( b"\0 \0 metadata" . into ( ) , encoded_metadata) ;
@@ -194,6 +209,19 @@ fn test_initialize_token_valid_2() {
194209 ) ;
195210 expected_state. insert ( b"\0 \0 denyList" . into ( ) , vec ! [ ] ) ;
196211 assert_eq ! ( stub. state, expected_state) ;
212+
213+ assert_eq ! ( stub. account_balance( & gov_account) , RawTokenAmount ( 500000 ) ) ;
214+ let state: TokenModuleState =
215+ cbor:: cbor_decode ( token_module:: query_token_module_state ( & stub) . unwrap ( ) ) . unwrap ( ) ;
216+ assert_eq ! ( state. name, Some ( "Protocol-level token" . to_owned( ) ) ) ;
217+ assert_eq ! ( state. metadata, Some ( metadata) ) ;
218+ assert_eq ! ( state. governance_account, Some ( gov_holder_account) ) ;
219+ assert_eq ! ( state. allow_list, Some ( false ) ) ;
220+ assert_eq ! ( state. deny_list, Some ( true ) ) ;
221+ assert_eq ! ( state. mintable, Some ( false ) ) ;
222+ assert_eq ! ( state. burnable, Some ( false ) ) ;
223+ assert_eq ! ( state. paused, Some ( false ) ) ;
224+ assert ! ( state. additional. is_empty( ) ) ;
197225}
198226
199227/// In this example, the parameters specify an initial supply with higher precision
0 commit comments