From 2776f2e6512f26c687bb62a0f12a1de0f552d62a Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 18 Oct 2023 14:55:47 +0200 Subject: [PATCH] token 2022: make `IncorrectMintAuthority` a `TokenError` --- token-metadata/example/src/processor.rs | 4 ++-- token-metadata/example/tests/initialize.rs | 7 +++---- token-metadata/interface/src/error.rs | 3 --- token/program-2022-test/tests/token_metadata_initialize.rs | 4 ++-- token/program-2022/src/error.rs | 6 ++++++ .../program-2022/src/extension/token_metadata/processor.rs | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/token-metadata/example/src/processor.rs b/token-metadata/example/src/processor.rs index 1ff45bf12e3..429c34b71bf 100644 --- a/token-metadata/example/src/processor.rs +++ b/token-metadata/example/src/processor.rs @@ -12,7 +12,7 @@ use { pubkey::Pubkey, }, spl_pod::optional_keys::OptionalNonZeroPubkey, - spl_token_2022::{extension::StateWithExtensions, state::Mint}, + spl_token_2022::{error::TokenError, extension::StateWithExtensions, state::Mint}, spl_token_metadata_interface::{ error::TokenMetadataError, instruction::{ @@ -65,7 +65,7 @@ pub fn process_initialize( return Err(ProgramError::MissingRequiredSignature); } if mint.base.mint_authority.as_ref() != COption::Some(mint_authority_info.key) { - return Err(TokenMetadataError::IncorrectMintAuthority.into()); + return Err(TokenError::IncorrectMintAuthority.into()); } } diff --git a/token-metadata/example/tests/initialize.rs b/token-metadata/example/tests/initialize.rs index ccd50373e84..b481d874a5e 100644 --- a/token-metadata/example/tests/initialize.rs +++ b/token-metadata/example/tests/initialize.rs @@ -12,9 +12,8 @@ use { system_instruction, transaction::{Transaction, TransactionError}, }, - spl_token_metadata_interface::{ - error::TokenMetadataError, instruction::initialize, state::TokenMetadata, - }, + spl_token_2022::error::TokenError, + spl_token_metadata_interface::{instruction::initialize, state::TokenMetadata}, spl_type_length_value::{ error::TlvError, state::{TlvState, TlvStateBorrowed}, @@ -265,7 +264,7 @@ async fn fail_incorrect_authority() { error, TransactionError::InstructionError( 1, - InstructionError::Custom(TokenMetadataError::IncorrectMintAuthority as u32) + InstructionError::Custom(TokenError::IncorrectMintAuthority as u32) ) ); } diff --git a/token-metadata/interface/src/error.rs b/token-metadata/interface/src/error.rs index 3f5b2437865..aa3a19e95bd 100644 --- a/token-metadata/interface/src/error.rs +++ b/token-metadata/interface/src/error.rs @@ -11,9 +11,6 @@ pub enum TokenMetadataError { /// Mint has no mint authority #[error("Mint has no mint authority")] MintHasNoMintAuthority, - /// Incorrect mint authority has signed the instruction - #[error("Incorrect mint authority has signed the instruction")] - IncorrectMintAuthority, /// Incorrect metadata update authority has signed the instruction #[error("Incorrect metadata update authority has signed the instruction")] IncorrectUpdateAuthority, diff --git a/token/program-2022-test/tests/token_metadata_initialize.rs b/token/program-2022-test/tests/token_metadata_initialize.rs index e6576d68f68..9e93650d9ea 100644 --- a/token/program-2022-test/tests/token_metadata_initialize.rs +++ b/token/program-2022-test/tests/token_metadata_initialize.rs @@ -11,7 +11,7 @@ use { }, spl_token_2022::{error::TokenError, extension::BaseStateWithExtensions, processor::Processor}, spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError}, - spl_token_metadata_interface::{error::TokenMetadataError, state::TokenMetadata}, + spl_token_metadata_interface::state::TokenMetadata, std::{convert::TryInto, sync::Arc}, }; @@ -110,7 +110,7 @@ async fn success_initialize() { TokenClientError::Client(Box::new(TransportError::TransactionError( TransactionError::InstructionError( 1, - InstructionError::Custom(TokenMetadataError::IncorrectMintAuthority as u32) + InstructionError::Custom(TokenError::IncorrectMintAuthority as u32) ) ))) ); diff --git a/token/program-2022/src/error.rs b/token/program-2022/src/error.rs index 6da2fdb2b3d..358c2a6b098 100644 --- a/token/program-2022/src/error.rs +++ b/token/program-2022/src/error.rs @@ -232,6 +232,9 @@ pub enum TokenError { /// Ciphertext arithmetic failed #[error("Ciphertext arithmetic failed")] CiphertextArithmeticFailed, + /// Incorrect mint authority has signed the instruction + #[error("Incorrect mint authority has signed the instruction")] + IncorrectMintAuthority, } impl From for ProgramError { fn from(e: TokenError) -> Self { @@ -407,6 +410,9 @@ impl PrintProgramError for TokenError { TokenError::CiphertextArithmeticFailed => { msg!("Ciphertext arithmetic failed") } + TokenError::IncorrectMintAuthority => { + msg!("Incorrect mint authority has signed the instruction") + } } } } diff --git a/token/program-2022/src/extension/token_metadata/processor.rs b/token/program-2022/src/extension/token_metadata/processor.rs index 4a19bab8fb3..3e400744e31 100644 --- a/token/program-2022/src/extension/token_metadata/processor.rs +++ b/token/program-2022/src/extension/token_metadata/processor.rs @@ -61,7 +61,7 @@ pub fn process_initialize( return Err(ProgramError::MissingRequiredSignature); } if mint.base.mint_authority.as_ref() != COption::Some(mint_authority_info.key) { - return Err(TokenMetadataError::IncorrectMintAuthority.into()); + return Err(TokenError::IncorrectMintAuthority.into()); } if mint.get_extension::().is_err() {