Browse Source

Change AccoutNotProgramOwned error to AccountOwnedByWrongProgram (#1154)

man0s 3 years ago
parent
commit
561f7cdaa8

+ 4 - 0
CHANGELOG.md

@@ -20,6 +20,10 @@ incremented for features.
 * lang: Add `programdata_address: Option<Pubkey>` field to `Program` account. Will be populated if account is a program owned by the upgradable bpf loader ([#1125](https://github.com/project-serum/anchor/pull/1125))
 * lang: Add `programdata_address: Option<Pubkey>` field to `Program` account. Will be populated if account is a program owned by the upgradable bpf loader ([#1125](https://github.com/project-serum/anchor/pull/1125))
 * lang,ts,ci,cli,docs: update solana toolchain to version 1.8.5([#1133](https://github.com/project-serum/anchor/pull/1133))
 * lang,ts,ci,cli,docs: update solana toolchain to version 1.8.5([#1133](https://github.com/project-serum/anchor/pull/1133))
 
 
+### Breaking
+
+* lang, ts: Change error enum name and message for 'wrong program ownership' account validation ([#1154](https://github.com/project-serum/anchor/pull/1154)).
+
 ## [0.19.0] - 2021-12-08
 ## [0.19.0] - 2021-12-08
 
 
 ### Fixes
 ### Fixes

+ 2 - 2
lang/src/accounts/account.rs

@@ -38,7 +38,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T
             return Err(ErrorCode::AccountNotInitialized.into());
             return Err(ErrorCode::AccountNotInitialized.into());
         }
         }
         if info.owner != &T::owner() {
         if info.owner != &T::owner() {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         let mut data: &[u8] = &info.try_borrow_data()?;
         let mut data: &[u8] = &info.try_borrow_data()?;
         Ok(Account::new(info.clone(), T::try_deserialize(&mut data)?))
         Ok(Account::new(info.clone(), T::try_deserialize(&mut data)?))
@@ -53,7 +53,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Account<'a, T
             return Err(ErrorCode::AccountNotInitialized.into());
             return Err(ErrorCode::AccountNotInitialized.into());
         }
         }
         if info.owner != &T::owner() {
         if info.owner != &T::owner() {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         let mut data: &[u8] = &info.try_borrow_data()?;
         let mut data: &[u8] = &info.try_borrow_data()?;
         Ok(Account::new(
         Ok(Account::new(

+ 2 - 2
lang/src/accounts/loader.rs

@@ -59,7 +59,7 @@ impl<'info, T: ZeroCopy> Loader<'info, T> {
         acc_info: &AccountInfo<'info>,
         acc_info: &AccountInfo<'info>,
     ) -> Result<Loader<'info, T>, ProgramError> {
     ) -> Result<Loader<'info, T>, ProgramError> {
         if acc_info.owner != program_id {
         if acc_info.owner != program_id {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         let data: &[u8] = &acc_info.try_borrow_data()?;
         let data: &[u8] = &acc_info.try_borrow_data()?;
         // Discriminator must match.
         // Discriminator must match.
@@ -79,7 +79,7 @@ impl<'info, T: ZeroCopy> Loader<'info, T> {
         acc_info: &AccountInfo<'info>,
         acc_info: &AccountInfo<'info>,
     ) -> Result<Loader<'info, T>, ProgramError> {
     ) -> Result<Loader<'info, T>, ProgramError> {
         if acc_info.owner != program_id {
         if acc_info.owner != program_id {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         Ok(Loader::new(acc_info.clone()))
         Ok(Loader::new(acc_info.clone()))
     }
     }

+ 2 - 2
lang/src/accounts/loader_account.rs

@@ -55,7 +55,7 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> {
         acc_info: &AccountInfo<'info>,
         acc_info: &AccountInfo<'info>,
     ) -> Result<AccountLoader<'info, T>, ProgramError> {
     ) -> Result<AccountLoader<'info, T>, ProgramError> {
         if acc_info.owner != &T::owner() {
         if acc_info.owner != &T::owner() {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         let data: &[u8] = &acc_info.try_borrow_data()?;
         let data: &[u8] = &acc_info.try_borrow_data()?;
         // Discriminator must match.
         // Discriminator must match.
@@ -74,7 +74,7 @@ impl<'info, T: ZeroCopy + Owner> AccountLoader<'info, T> {
         acc_info: &AccountInfo<'info>,
         acc_info: &AccountInfo<'info>,
     ) -> Result<AccountLoader<'info, T>, ProgramError> {
     ) -> Result<AccountLoader<'info, T>, ProgramError> {
         if acc_info.owner != &T::owner() {
         if acc_info.owner != &T::owner() {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         Ok(AccountLoader::new(acc_info.clone()))
         Ok(AccountLoader::new(acc_info.clone()))
     }
     }

+ 2 - 2
lang/src/accounts/program_account.rs

@@ -41,7 +41,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramAccount<'a, T>
         info: &AccountInfo<'a>,
         info: &AccountInfo<'a>,
     ) -> Result<ProgramAccount<'a, T>, ProgramError> {
     ) -> Result<ProgramAccount<'a, T>, ProgramError> {
         if info.owner != program_id {
         if info.owner != program_id {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         let mut data: &[u8] = &info.try_borrow_data()?;
         let mut data: &[u8] = &info.try_borrow_data()?;
         Ok(ProgramAccount::new(
         Ok(ProgramAccount::new(
@@ -59,7 +59,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramAccount<'a, T>
         info: &AccountInfo<'a>,
         info: &AccountInfo<'a>,
     ) -> Result<ProgramAccount<'a, T>, ProgramError> {
     ) -> Result<ProgramAccount<'a, T>, ProgramError> {
         if info.owner != program_id {
         if info.owner != program_id {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         let mut data: &[u8] = &info.try_borrow_data()?;
         let mut data: &[u8] = &info.try_borrow_data()?;
         Ok(ProgramAccount::new(
         Ok(ProgramAccount::new(

+ 1 - 1
lang/src/accounts/state.rs

@@ -43,7 +43,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> ProgramState<'a, T> {
         info: &AccountInfo<'a>,
         info: &AccountInfo<'a>,
     ) -> Result<ProgramState<'a, T>, ProgramError> {
     ) -> Result<ProgramState<'a, T>, ProgramError> {
         if info.owner != program_id {
         if info.owner != program_id {
-            return Err(ErrorCode::AccountNotProgramOwned.into());
+            return Err(ErrorCode::AccountOwnedByWrongProgram.into());
         }
         }
         if info.key != &Self::address(program_id) {
         if info.key != &Self::address(program_id) {
             solana_program::msg!("Invalid state address");
             solana_program::msg!("Invalid state address");

+ 2 - 2
lang/src/error.rs

@@ -77,8 +77,8 @@ pub enum ErrorCode {
     AccountNotEnoughKeys,
     AccountNotEnoughKeys,
     #[msg("The given account is not mutable")]
     #[msg("The given account is not mutable")]
     AccountNotMutable,
     AccountNotMutable,
-    #[msg("The given account is not owned by the executing program")]
-    AccountNotProgramOwned,
+    #[msg("The given account is owned by a different program than expected")]
+    AccountOwnedByWrongProgram,
     #[msg("Program ID was not as expected")]
     #[msg("Program ID was not as expected")]
     InvalidProgramId,
     InvalidProgramId,
     #[msg("Program account is not executable")]
     #[msg("Program account is not executable")]

+ 1 - 1
tests/bpf-upgradeable-state/tests/bpf-upgradable-state.ts

@@ -122,7 +122,7 @@ describe("bpf_upgradeable_state", () => {
       assert.equal(err.code, 3007);
       assert.equal(err.code, 3007);
       assert.equal(
       assert.equal(
         err.msg,
         err.msg,
-        "The given account is not owned by the executing program"
+        "The given account is owned by a different program than expected"
       );
       );
     }
     }
   });
   });

+ 3 - 3
ts/src/error.ts

@@ -91,7 +91,7 @@ const LangErrorCode = {
   AccountDidNotSerialize: 3004,
   AccountDidNotSerialize: 3004,
   AccountNotEnoughKeys: 3005,
   AccountNotEnoughKeys: 3005,
   AccountNotMutable: 3006,
   AccountNotMutable: 3006,
-  AccountNotProgramOwned: 3007,
+  AccountOwnedByWrongProgram: 3007,
   InvalidProgramId: 3008,
   InvalidProgramId: 3008,
   InvalidProgramExecutable: 3009,
   InvalidProgramExecutable: 3009,
   AccountNotSigner: 3010,
   AccountNotSigner: 3010,
@@ -189,8 +189,8 @@ const LangErrorMessage = new Map([
   ],
   ],
   [LangErrorCode.AccountNotMutable, "The given account is not mutable"],
   [LangErrorCode.AccountNotMutable, "The given account is not mutable"],
   [
   [
-    LangErrorCode.AccountNotProgramOwned,
-    "The given account is not owned by the executing program",
+    LangErrorCode.AccountOwnedByWrongProgram,
+    "The given account is owned by a different program than expected",
   ],
   ],
   [LangErrorCode.InvalidProgramId, "Program ID was not as expected"],
   [LangErrorCode.InvalidProgramId, "Program ID was not as expected"],
   [LangErrorCode.InvalidProgramExecutable, "Program account is not executable"],
   [LangErrorCode.InvalidProgramExecutable, "Program account is not executable"],