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 } ,
@@ -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 ( 616 ) ,
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 ( 616 ) ,
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_271 ) ,
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_271 ) ] ,
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_272 ) ,
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_271 ) ] ,
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_367 ) ,
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_367 ) ,
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_279 ) ] ,
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_279 ) ] ,
641642 ) ;
642643
643644 // Use this for next invoke.
@@ -748,3 +749,31 @@ 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_readonly ( ) {
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 config_account = create_config_account ( & mollusk, keys. clone ( ) ) ;
763+
764+ // Pass the exact same data (`MyConfig::default()`) to the instruction,
765+ // which we'll attempt to write into the account.
766+ let mut instruction =
767+ config_instruction:: store ( & config, true , keys. clone ( ) , & MyConfig :: default ( ) ) ;
768+
769+ // Make the config account read-only.
770+ instruction. accounts [ 0 ] . is_writable = false ;
771+
772+ mollusk. process_and_validate_instruction (
773+ & instruction,
774+ & [ ( config, config_account) ] ,
775+ & [ Check :: err ( ProgramError :: Custom (
776+ ConfigError :: ReadonlyDataModified as u32 ,
777+ ) ) ] ,
778+ ) ;
779+ }
0 commit comments