@@ -82,6 +82,84 @@ describe('Cbor', () => {
8282 } ) ;
8383 } ) ;
8484
85+ describe ( 'TokenInitializationParameters' , ( ) => {
86+ test ( 'should encode and decode TokenInitializationParameters correctly' , ( ) => {
87+ const accountAddress = AccountAddress . fromBase58 ( '3XSLuJcXg6xEua6iBPnWacc3iWh93yEDMCqX8FbE3RDSbEnT9P' ) ;
88+ const tokenHolder = TokenHolder . fromAccountAddress ( accountAddress ) ;
89+ const metadataUrl = TokenMetadataUrl . fromString ( 'https://example.com/metadata.json' ) ;
90+
91+ const params = {
92+ name : 'Test Token' ,
93+ metadata : metadataUrl ,
94+ governanceAccount : tokenHolder ,
95+ allowList : true ,
96+ denyList : false ,
97+ mintable : true ,
98+ burnable : true ,
99+ customField : 'custom value' ,
100+ } ;
101+
102+ const encoded = Cbor . encode ( params ) ;
103+ const decoded = Cbor . decode ( encoded , 'TokenInitializationParameters' ) ;
104+
105+ expect ( decoded . name ) . toBe ( params . name ) ;
106+ expect ( decoded . metadata ) . toEqual ( params . metadata ) ;
107+ expect ( decoded . governanceAccount ) . toEqual ( params . governanceAccount ) ;
108+ expect ( decoded . allowList ) . toBe ( params . allowList ) ;
109+ expect ( decoded . denyList ) . toBe ( params . denyList ) ;
110+ expect ( decoded . mintable ) . toBe ( params . mintable ) ;
111+ expect ( decoded . burnable ) . toBe ( params . burnable ) ;
112+ } ) ;
113+
114+ test ( 'should throw error if TokenInitializationParameters is missing required fields' , ( ) => {
115+ // Missing governanceAccount
116+ const invalidParams1 = {
117+ name : 'Test Token' ,
118+ metadata : TokenMetadataUrl . fromString ( 'https://example.com/metadata.json' ) ,
119+ // governanceAccount is missing
120+ } ;
121+ const encoded1 = Cbor . encode ( invalidParams1 ) ;
122+ expect ( ( ) => Cbor . decode ( encoded1 , 'TokenInitializationParameters' ) ) . toThrow (
123+ / m i s s i n g o r i n v a l i d g o v e r n a n c e A c c o u n t /
124+ ) ;
125+
126+ // Missing name
127+ const accountAddress = AccountAddress . fromBase58 ( '3XSLuJcXg6xEua6iBPnWacc3iWh93yEDMCqX8FbE3RDSbEnT9P' ) ;
128+ const invalidParams2 = {
129+ // name is missing
130+ metadata : TokenMetadataUrl . fromString ( 'https://example.com/metadata.json' ) ,
131+ governanceAccount : TokenHolder . fromAccountAddress ( accountAddress ) ,
132+ } ;
133+ const encoded2 = Cbor . encode ( invalidParams2 ) ;
134+ expect ( ( ) => Cbor . decode ( encoded2 , 'TokenInitializationParameters' ) ) . toThrow ( / m i s s i n g o r i n v a l i d n a m e / ) ;
135+
136+ // Missing metadata
137+ const invalidParams3 = {
138+ name : 'Test Token' ,
139+ // metadata is missing
140+ governanceAccount : TokenHolder . fromAccountAddress ( accountAddress ) ,
141+ } ;
142+ const encoded3 = Cbor . encode ( invalidParams3 ) ;
143+ expect ( ( ) => Cbor . decode ( encoded3 , 'TokenInitializationParameters' ) ) . toThrow ( / m i s s i n g m e t a d a t a U r l / ) ;
144+ } ) ;
145+
146+ test ( 'should throw error if TokenInitializationParameters has invalid field types' , ( ) => {
147+ const accountAddress = AccountAddress . fromBase58 ( '3XSLuJcXg6xEua6iBPnWacc3iWh93yEDMCqX8FbE3RDSbEnT9P' ) ;
148+ const tokenHolder = TokenHolder . fromAccountAddress ( accountAddress ) ;
149+ const metadataUrl = TokenMetadataUrl . fromString ( 'https://example.com/metadata.json' ) ;
150+
151+ // Invalid allowList type
152+ const invalidParams = {
153+ name : 'Test Token' ,
154+ metadata : metadataUrl ,
155+ governanceAccount : tokenHolder ,
156+ allowList : 'yes' , // Should be boolean
157+ } ;
158+ const encoded = Cbor . encode ( invalidParams ) ;
159+ expect ( ( ) => Cbor . decode ( encoded , 'TokenInitializationParameters' ) ) . toThrow ( / a l l o w L i s t m u s t b e a b o o l e a n / ) ;
160+ } ) ;
161+ } ) ;
162+
85163 describe ( 'TokenModuleAccountState' , ( ) => {
86164 test ( 'should encode and decode TokenModuleAccountState correctly' , ( ) => {
87165 const state = {
0 commit comments