@@ -121,3 +121,339 @@ fn test_process_set_authority_mint_multisig(
121121
122122 result
123123}
124+
125+ /// accounts[0] // Account Info - Mint Case
126+ /// accounts[1] // Authority Info
127+ /// accounts[2..13] // Signers
128+ /// instruction_data[0] // Authority Type (instruction)
129+ /// instruction_data[1] // New Authority Follows (0 -> No, 1 -> Yes)
130+ /// instruction_data[2..34] // New Authority Pubkey
131+ #[ inline( never) ]
132+ fn test_process_set_authority_mint_multisig_n1 (
133+ accounts : & [ AccountInfo ; 3 ] ,
134+ instruction_data : & [ u8 ; 34 ] ,
135+ ) -> ProgramResult {
136+ cheatcode_mint ! ( & accounts[ 0 ] ) ;
137+ cheatcode_multisig ! ( & accounts[ 1 ] ) ;
138+
139+ #[ cfg( feature = "assumptions" ) ]
140+ {
141+ let multisig = get_multisig ( & accounts[ 1 ] ) ;
142+ if multisig. m < 1 || multisig. m > MAX_SIGNERS_U8 {
143+ return Ok ( ( ) ) ;
144+ }
145+ if multisig. n != 1 {
146+ return Ok ( ( ) ) ;
147+ }
148+ }
149+
150+ let mint_old = get_mint ( & accounts[ 0 ] ) ;
151+ let mint_data_len = accounts[ 0 ] . data_len ( ) ;
152+ let old_mint_authority_is_none = mint_old. mint_authority ( ) . is_none ( ) ;
153+ let old_freeze_authority_is_none = mint_old. freeze_authority ( ) . is_none ( ) ;
154+ let old_mint_authority = mint_old. mint_authority ( ) . cloned ( ) ;
155+ let old_freeze_authority = mint_old. freeze_authority ( ) . cloned ( ) ;
156+ let maybe_multisig_is_initialised = Some ( get_multisig ( & accounts[ 1 ] ) . is_initialized ( ) ) ;
157+ let mint_is_initialised = mint_old. is_initialized ( ) ;
158+
159+ let result = call_process_set_authority ! ( accounts, instruction_data) ;
160+
161+ if instruction_data. len ( ) < 2 {
162+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
163+ return result;
164+ } else if !( 0 ..=3 ) . contains ( & instruction_data[ 0 ] ) {
165+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
166+ return result;
167+ } else if instruction_data[ 1 ] != 0 && instruction_data[ 1 ] != 1 {
168+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
169+ return result;
170+ } else if instruction_data[ 1 ] == 1 && instruction_data. len ( ) < 34 {
171+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
172+ return result;
173+ } else if accounts. len ( ) < 2 {
174+ assert_eq ! ( result, Err ( ProgramError :: NotEnoughAccountKeys ) ) ;
175+ return result;
176+ } else if mint_data_len != Account :: LEN && mint_data_len != Mint :: LEN {
177+ assert_eq ! ( result, Err ( ProgramError :: InvalidArgument ) ) ;
178+ return result;
179+ } else if mint_data_len == Mint :: LEN {
180+ let mint_new = get_mint ( & accounts[ 0 ] ) ;
181+
182+ if !mint_is_initialised. unwrap ( ) {
183+ assert_eq ! ( result, Err ( ProgramError :: UninitializedAccount ) ) ;
184+ return result;
185+ } else if instruction_data[ 0 ] != 0 && instruction_data[ 0 ] != 1 {
186+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 15 ) ) ) ;
187+ return result;
188+ } else if instruction_data[ 0 ] == 0 {
189+ if old_mint_authority_is_none {
190+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 5 ) ) ) ;
191+ return result;
192+ }
193+
194+ inner_test_validate_owner (
195+ & old_mint_authority. unwrap ( ) ,
196+ & accounts[ 1 ] ,
197+ & accounts[ 2 ..] ,
198+ maybe_multisig_is_initialised,
199+ result. clone ( ) ,
200+ ) ?;
201+
202+ if instruction_data[ 1 ] == 1 {
203+ assert_pubkey_from_slice ! ( mint_new. mint_authority( ) . unwrap( ) , & instruction_data[ 2 ..34 ] ) ;
204+ } else {
205+ assert_eq ! ( mint_new. mint_authority( ) , None ) ;
206+ }
207+ assert ! ( result. is_ok( ) )
208+ } else {
209+ assert_eq ! ( instruction_data[ 0 ] , 1 ) ;
210+ if old_freeze_authority_is_none {
211+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 16 ) ) ) ;
212+ return result;
213+ }
214+
215+ inner_test_validate_owner (
216+ & old_freeze_authority. unwrap ( ) ,
217+ & accounts[ 1 ] ,
218+ & accounts[ 2 ..] ,
219+ maybe_multisig_is_initialised,
220+ result. clone ( ) ,
221+ ) ?;
222+
223+ if instruction_data[ 1 ] == 1 {
224+ assert_pubkey_from_slice ! ( mint_new. freeze_authority( ) . unwrap( ) , & instruction_data[ 2 ..34 ] ) ;
225+ } else {
226+ assert_eq ! ( mint_new. freeze_authority( ) , None ) ;
227+ }
228+ assert ! ( result. is_ok( ) )
229+ }
230+ } else {
231+ unreachable ! ( ) ;
232+ }
233+
234+ result
235+ }
236+
237+ /// accounts[0] // Account Info - Mint Case
238+ /// accounts[1] // Authority Info
239+ /// accounts[2..13] // Signers
240+ /// instruction_data[0] // Authority Type (instruction)
241+ /// instruction_data[1] // New Authority Follows (0 -> No, 1 -> Yes)
242+ /// instruction_data[2..34] // New Authority Pubkey
243+ #[ inline( never) ]
244+ fn test_process_set_authority_mint_multisig_n2 (
245+ accounts : & [ AccountInfo ; 3 ] ,
246+ instruction_data : & [ u8 ; 34 ] ,
247+ ) -> ProgramResult {
248+ cheatcode_mint ! ( & accounts[ 0 ] ) ;
249+ cheatcode_multisig ! ( & accounts[ 1 ] ) ;
250+
251+ #[ cfg( feature = "assumptions" ) ]
252+ {
253+ let multisig = get_multisig ( & accounts[ 1 ] ) ;
254+ if multisig. m < 1 || multisig. m > MAX_SIGNERS_U8 {
255+ return Ok ( ( ) ) ;
256+ }
257+ if multisig. n != 2 {
258+ return Ok ( ( ) ) ;
259+ }
260+ }
261+
262+ let mint_old = get_mint ( & accounts[ 0 ] ) ;
263+ let mint_data_len = accounts[ 0 ] . data_len ( ) ;
264+ let old_mint_authority_is_none = mint_old. mint_authority ( ) . is_none ( ) ;
265+ let old_freeze_authority_is_none = mint_old. freeze_authority ( ) . is_none ( ) ;
266+ let old_mint_authority = mint_old. mint_authority ( ) . cloned ( ) ;
267+ let old_freeze_authority = mint_old. freeze_authority ( ) . cloned ( ) ;
268+ let maybe_multisig_is_initialised = Some ( get_multisig ( & accounts[ 1 ] ) . is_initialized ( ) ) ;
269+ let mint_is_initialised = mint_old. is_initialized ( ) ;
270+
271+ let result = call_process_set_authority ! ( accounts, instruction_data) ;
272+
273+ if instruction_data. len ( ) < 2 {
274+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
275+ return result;
276+ } else if !( 0 ..=3 ) . contains ( & instruction_data[ 0 ] ) {
277+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
278+ return result;
279+ } else if instruction_data[ 1 ] != 0 && instruction_data[ 1 ] != 1 {
280+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
281+ return result;
282+ } else if instruction_data[ 1 ] == 1 && instruction_data. len ( ) < 34 {
283+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
284+ return result;
285+ } else if accounts. len ( ) < 2 {
286+ assert_eq ! ( result, Err ( ProgramError :: NotEnoughAccountKeys ) ) ;
287+ return result;
288+ } else if mint_data_len != Account :: LEN && mint_data_len != Mint :: LEN {
289+ assert_eq ! ( result, Err ( ProgramError :: InvalidArgument ) ) ;
290+ return result;
291+ } else if mint_data_len == Mint :: LEN {
292+ let mint_new = get_mint ( & accounts[ 0 ] ) ;
293+
294+ if !mint_is_initialised. unwrap ( ) {
295+ assert_eq ! ( result, Err ( ProgramError :: UninitializedAccount ) ) ;
296+ return result;
297+ } else if instruction_data[ 0 ] != 0 && instruction_data[ 0 ] != 1 {
298+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 15 ) ) ) ;
299+ return result;
300+ } else if instruction_data[ 0 ] == 0 {
301+ if old_mint_authority_is_none {
302+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 5 ) ) ) ;
303+ return result;
304+ }
305+
306+ inner_test_validate_owner (
307+ & old_mint_authority. unwrap ( ) ,
308+ & accounts[ 1 ] ,
309+ & accounts[ 2 ..] ,
310+ maybe_multisig_is_initialised,
311+ result. clone ( ) ,
312+ ) ?;
313+
314+ if instruction_data[ 1 ] == 1 {
315+ assert_pubkey_from_slice ! ( mint_new. mint_authority( ) . unwrap( ) , & instruction_data[ 2 ..34 ] ) ;
316+ } else {
317+ assert_eq ! ( mint_new. mint_authority( ) , None ) ;
318+ }
319+ assert ! ( result. is_ok( ) )
320+ } else {
321+ assert_eq ! ( instruction_data[ 0 ] , 1 ) ;
322+ if old_freeze_authority_is_none {
323+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 16 ) ) ) ;
324+ return result;
325+ }
326+
327+ inner_test_validate_owner (
328+ & old_freeze_authority. unwrap ( ) ,
329+ & accounts[ 1 ] ,
330+ & accounts[ 2 ..] ,
331+ maybe_multisig_is_initialised,
332+ result. clone ( ) ,
333+ ) ?;
334+
335+ if instruction_data[ 1 ] == 1 {
336+ assert_pubkey_from_slice ! ( mint_new. freeze_authority( ) . unwrap( ) , & instruction_data[ 2 ..34 ] ) ;
337+ } else {
338+ assert_eq ! ( mint_new. freeze_authority( ) , None ) ;
339+ }
340+ assert ! ( result. is_ok( ) )
341+ }
342+ } else {
343+ unreachable ! ( ) ;
344+ }
345+
346+ result
347+ }
348+
349+ /// accounts[0] // Account Info - Mint Case
350+ /// accounts[1] // Authority Info
351+ /// accounts[2..13] // Signers
352+ /// instruction_data[0] // Authority Type (instruction)
353+ /// instruction_data[1] // New Authority Follows (0 -> No, 1 -> Yes)
354+ /// instruction_data[2..34] // New Authority Pubkey
355+ #[ inline( never) ]
356+ fn test_process_set_authority_mint_multisig_n3 (
357+ accounts : & [ AccountInfo ; 3 ] ,
358+ instruction_data : & [ u8 ; 34 ] ,
359+ ) -> ProgramResult {
360+ cheatcode_mint ! ( & accounts[ 0 ] ) ;
361+ cheatcode_multisig ! ( & accounts[ 1 ] ) ;
362+
363+ #[ cfg( feature = "assumptions" ) ]
364+ {
365+ let multisig = get_multisig ( & accounts[ 1 ] ) ;
366+ if multisig. m < 1 || multisig. m > MAX_SIGNERS_U8 {
367+ return Ok ( ( ) ) ;
368+ }
369+ if multisig. n != 3 {
370+ return Ok ( ( ) ) ;
371+ }
372+ }
373+
374+ let mint_old = get_mint ( & accounts[ 0 ] ) ;
375+ let mint_data_len = accounts[ 0 ] . data_len ( ) ;
376+ let old_mint_authority_is_none = mint_old. mint_authority ( ) . is_none ( ) ;
377+ let old_freeze_authority_is_none = mint_old. freeze_authority ( ) . is_none ( ) ;
378+ let old_mint_authority = mint_old. mint_authority ( ) . cloned ( ) ;
379+ let old_freeze_authority = mint_old. freeze_authority ( ) . cloned ( ) ;
380+ let maybe_multisig_is_initialised = Some ( get_multisig ( & accounts[ 1 ] ) . is_initialized ( ) ) ;
381+ let mint_is_initialised = mint_old. is_initialized ( ) ;
382+
383+ let result = call_process_set_authority ! ( accounts, instruction_data) ;
384+
385+ if instruction_data. len ( ) < 2 {
386+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
387+ return result;
388+ } else if !( 0 ..=3 ) . contains ( & instruction_data[ 0 ] ) {
389+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
390+ return result;
391+ } else if instruction_data[ 1 ] != 0 && instruction_data[ 1 ] != 1 {
392+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
393+ return result;
394+ } else if instruction_data[ 1 ] == 1 && instruction_data. len ( ) < 34 {
395+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 12 ) ) ) ;
396+ return result;
397+ } else if accounts. len ( ) < 2 {
398+ assert_eq ! ( result, Err ( ProgramError :: NotEnoughAccountKeys ) ) ;
399+ return result;
400+ } else if mint_data_len != Account :: LEN && mint_data_len != Mint :: LEN {
401+ assert_eq ! ( result, Err ( ProgramError :: InvalidArgument ) ) ;
402+ return result;
403+ } else if mint_data_len == Mint :: LEN {
404+ let mint_new = get_mint ( & accounts[ 0 ] ) ;
405+
406+ if !mint_is_initialised. unwrap ( ) {
407+ assert_eq ! ( result, Err ( ProgramError :: UninitializedAccount ) ) ;
408+ return result;
409+ } else if instruction_data[ 0 ] != 0 && instruction_data[ 0 ] != 1 {
410+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 15 ) ) ) ;
411+ return result;
412+ } else if instruction_data[ 0 ] == 0 {
413+ if old_mint_authority_is_none {
414+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 5 ) ) ) ;
415+ return result;
416+ }
417+
418+ inner_test_validate_owner (
419+ & old_mint_authority. unwrap ( ) ,
420+ & accounts[ 1 ] ,
421+ & accounts[ 2 ..] ,
422+ maybe_multisig_is_initialised,
423+ result. clone ( ) ,
424+ ) ?;
425+
426+ if instruction_data[ 1 ] == 1 {
427+ assert_pubkey_from_slice ! ( mint_new. mint_authority( ) . unwrap( ) , & instruction_data[ 2 ..34 ] ) ;
428+ } else {
429+ assert_eq ! ( mint_new. mint_authority( ) , None ) ;
430+ }
431+ assert ! ( result. is_ok( ) )
432+ } else {
433+ assert_eq ! ( instruction_data[ 0 ] , 1 ) ;
434+ if old_freeze_authority_is_none {
435+ assert_eq ! ( result, Err ( ProgramError :: Custom ( 16 ) ) ) ;
436+ return result;
437+ }
438+
439+ inner_test_validate_owner (
440+ & old_freeze_authority. unwrap ( ) ,
441+ & accounts[ 1 ] ,
442+ & accounts[ 2 ..] ,
443+ maybe_multisig_is_initialised,
444+ result. clone ( ) ,
445+ ) ?;
446+
447+ if instruction_data[ 1 ] == 1 {
448+ assert_pubkey_from_slice ! ( mint_new. freeze_authority( ) . unwrap( ) , & instruction_data[ 2 ..34 ] ) ;
449+ } else {
450+ assert_eq ! ( mint_new. freeze_authority( ) , None ) ;
451+ }
452+ assert ! ( result. is_ok( ) )
453+ }
454+ } else {
455+ unreachable ! ( ) ;
456+ }
457+
458+ result
459+ }
0 commit comments