55 mollusk_svm:: { result:: Check , Mollusk } ,
66 serde:: { Deserialize , Serialize } ,
77 solana_config_program:: {
8+ error:: ConfigError ,
89 instruction as config_instruction,
910 state:: { ConfigKeys , ConfigState } ,
1011 } ,
1112 solana_sdk:: {
12- account:: AccountSharedData ,
13+ account:: { AccountSharedData , WritableAccount } ,
1314 instruction:: { AccountMeta , Instruction } ,
1415 program_error:: ProgramError ,
1516 pubkey:: Pubkey ,
@@ -83,7 +84,7 @@ fn test_process_create_ok() {
8384 & [ ( config, config_account) ] ,
8485 & [
8586 Check :: success ( ) ,
86- Check :: compute_units ( 612 ) ,
87+ Check :: compute_units ( 619 ) ,
8788 Check :: account ( & config)
8889 . data (
8990 & bincode:: serialize ( & ( ConfigKeys { keys : vec ! [ ] } , MyConfig :: default ( ) ) )
@@ -111,7 +112,7 @@ fn test_process_store_ok() {
111112 & [ ( config, config_account) ] ,
112113 & [
113114 Check :: success ( ) ,
114- Check :: compute_units ( 612 ) ,
115+ Check :: compute_units ( 619 ) ,
115116 Check :: account ( & config)
116117 . data ( & bincode:: serialize ( & ( ConfigKeys { keys } , my_config) ) . unwrap ( ) )
117118 . build ( ) ,
@@ -186,7 +187,7 @@ fn test_process_store_with_additional_signers() {
186187 ] ,
187188 & [
188189 Check :: success ( ) ,
189- Check :: compute_units ( 3_267 ) ,
190+ Check :: compute_units ( 3_274 ) ,
190191 Check :: account ( & config)
191192 . data ( & bincode:: serialize ( & ( ConfigKeys { keys } , my_config) ) . unwrap ( ) )
192193 . build ( ) ,
@@ -334,7 +335,7 @@ fn test_config_updates() {
334335 ( signer0, AccountSharedData :: default ( ) ) ,
335336 ( signer1, AccountSharedData :: default ( ) ) ,
336337 ] ,
337- & [ Check :: success ( ) , Check :: compute_units ( 3_267 ) ] ,
338+ & [ Check :: success ( ) , Check :: compute_units ( 3_274 ) ] ,
338339 ) ;
339340
340341 // Use this for next invoke.
@@ -352,7 +353,7 @@ fn test_config_updates() {
352353 ] ,
353354 & [
354355 Check :: success ( ) ,
355- Check :: compute_units ( 3_268 ) ,
356+ Check :: compute_units ( 3_275 ) ,
356357 Check :: account ( & config)
357358 . data ( & bincode:: serialize ( & ( ConfigKeys { keys } , new_config) ) . unwrap ( ) )
358359 . build ( ) ,
@@ -465,7 +466,7 @@ fn test_config_update_contains_duplicates_fails() {
465466 ( signer0, AccountSharedData :: default ( ) ) ,
466467 ( signer1, AccountSharedData :: default ( ) ) ,
467468 ] ,
468- & [ Check :: success ( ) , Check :: compute_units ( 3_267 ) ] ,
469+ & [ Check :: success ( ) , Check :: compute_units ( 3_274 ) ] ,
469470 ) ;
470471
471472 // Attempt update with duplicate signer inputs.
@@ -509,7 +510,7 @@ fn test_config_updates_requiring_config() {
509510 ] ,
510511 & [
511512 Check :: success ( ) ,
512- Check :: compute_units ( 3_363 ) ,
513+ Check :: compute_units ( 3_370 ) ,
513514 Check :: account ( & config)
514515 . data ( & bincode:: serialize ( & ( ConfigKeys { keys : keys. clone ( ) } , my_config) ) . unwrap ( ) )
515516 . build ( ) ,
@@ -530,7 +531,7 @@ fn test_config_updates_requiring_config() {
530531 ] ,
531532 & [
532533 Check :: success ( ) ,
533- Check :: compute_units ( 3_363 ) ,
534+ Check :: compute_units ( 3_370 ) ,
534535 Check :: account ( & config)
535536 . data ( & bincode:: serialize ( & ( ConfigKeys { keys } , new_config) ) . unwrap ( ) )
536537 . build ( ) ,
@@ -624,7 +625,7 @@ fn test_maximum_keys_input() {
624625 let result = mollusk. process_and_validate_instruction (
625626 & instruction,
626627 & [ ( config, config_account) ] ,
627- & [ Check :: success ( ) , Check :: compute_units ( 25_275 ) ] ,
628+ & [ Check :: success ( ) , Check :: compute_units ( 25_282 ) ] ,
628629 ) ;
629630
630631 // Use this for next invoke.
@@ -637,7 +638,7 @@ fn test_maximum_keys_input() {
637638 let result = mollusk. process_and_validate_instruction (
638639 & instruction,
639640 & [ ( config, updated_config_account) ] ,
640- & [ Check :: success ( ) , Check :: compute_units ( 25_275 ) ] ,
641+ & [ Check :: success ( ) , Check :: compute_units ( 25_282 ) ] ,
641642 ) ;
642643
643644 // Use this for next invoke.
@@ -748,3 +749,58 @@ fn test_safe_deserialize_from_state() {
748749 & [ Check :: err ( ProgramError :: InvalidAccountData ) ] ,
749750 ) ;
750751}
752+
753+ // Backwards compatibility test case.
754+ #[ test]
755+ fn test_write_same_data_to_executable ( ) {
756+ let mollusk = setup ( ) ;
757+
758+ let config = Pubkey :: new_unique ( ) ;
759+ let keys = vec ! [ ] ;
760+
761+ // Creates a config account with `MyConfig::default()`.
762+ let mut config_account = create_config_account ( & mollusk, keys. clone ( ) ) ;
763+
764+ // Make the config account executable.
765+ config_account. set_executable ( true ) ;
766+
767+ // Pass the exact same data (`MyConfig::default()`) to the instruction,
768+ // which we'll attempt to write into the account.
769+ let instruction = config_instruction:: store ( & config, true , keys. clone ( ) , & MyConfig :: default ( ) ) ;
770+
771+ mollusk. process_and_validate_instruction (
772+ & instruction,
773+ & [ ( config, config_account) ] ,
774+ & [ Check :: err ( ProgramError :: Custom (
775+ ConfigError :: ExecutableDataModified as u32 ,
776+ ) ) ] ,
777+ ) ;
778+ }
779+
780+ // Backwards compatibility test case.
781+ #[ test]
782+ fn test_write_same_data_to_readonly ( ) {
783+ let mollusk = setup ( ) ;
784+
785+ let config = Pubkey :: new_unique ( ) ;
786+ let keys = vec ! [ ] ;
787+
788+ // Creates a config account with `MyConfig::default()`.
789+ let config_account = create_config_account ( & mollusk, keys. clone ( ) ) ;
790+
791+ // Pass the exact same data (`MyConfig::default()`) to the instruction,
792+ // which we'll attempt to write into the account.
793+ let mut instruction =
794+ config_instruction:: store ( & config, true , keys. clone ( ) , & MyConfig :: default ( ) ) ;
795+
796+ // Make the config account read-only.
797+ instruction. accounts [ 0 ] . is_writable = false ;
798+
799+ mollusk. process_and_validate_instruction (
800+ & instruction,
801+ & [ ( config, config_account) ] ,
802+ & [ Check :: err ( ProgramError :: Custom (
803+ ConfigError :: ReadonlyDataModified as u32 ,
804+ ) ) ] ,
805+ ) ;
806+ }
0 commit comments