diff --git a/runtime/src/bank/builtins/core_bpf_migration/error.rs b/runtime/src/bank/builtins/core_bpf_migration/error.rs index 60c30d86727909..2bc54a46dabb74 100644 --- a/runtime/src/bank/builtins/core_bpf_migration/error.rs +++ b/runtime/src/bank/builtins/core_bpf_migration/error.rs @@ -1,8 +1,11 @@ use {solana_sdk::pubkey::Pubkey, thiserror::Error}; /// Errors returned by a Core BPF migration. -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, Error)] pub enum CoreBpfMigrationError { + /// Bincode serialization error + #[error("Bincode serialization error: {0:?}")] + BincodeError(#[from] bincode::Error), /// Account not found #[error("Account not found: {0:?}")] AccountNotFound(Pubkey), diff --git a/runtime/src/bank/builtins/core_bpf_migration/source_upgradeable_bpf.rs b/runtime/src/bank/builtins/core_bpf_migration/source_upgradeable_bpf.rs index c22f4e42579409..ffda3db96fc289 100644 --- a/runtime/src/bank/builtins/core_bpf_migration/source_upgradeable_bpf.rs +++ b/runtime/src/bank/builtins/core_bpf_migration/source_upgradeable_bpf.rs @@ -31,12 +31,7 @@ impl SourceUpgradeableBpf { // The program account should have a pointer to its data account. if let UpgradeableLoaderState::Program { programdata_address, - } = &self - .program_account - .deserialize_data() - .map_err::(|_| { - CoreBpfMigrationError::InvalidProgramAccount(self.program_address) - })? + } = &self.program_account.deserialize_data()? { if programdata_address != &self.program_data_address { return Err(CoreBpfMigrationError::InvalidProgramAccount( @@ -66,8 +61,8 @@ impl SourceUpgradeableBpf { // Length checked in previous block. match bincode::deserialize::( &self.program_data_account.data()[..programdata_data_offset], - ) { - Ok(UpgradeableLoaderState::ProgramData { .. }) => Ok(()), + )? { + UpgradeableLoaderState::ProgramData { .. } => Ok(()), _ => Err(CoreBpfMigrationError::InvalidProgramDataAccount( self.program_data_address, )), @@ -124,6 +119,7 @@ mod tests { use { super::*, crate::bank::tests::create_simple_test_bank, + assert_matches::assert_matches, solana_sdk::{account::Account, bpf_loader_upgradeable::ID as BPF_LOADER_UPGRADEABLE_ID}, }; @@ -159,9 +155,9 @@ mod tests { let program_data_address = get_program_data_address(&program_id); // Fail if the program account does not exist - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::AccountNotFound(program_id) + CoreBpfMigrationError::AccountNotFound(..) ); // Store the proper program account @@ -178,9 +174,9 @@ mod tests { ); // Fail if the program data account does not exist - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::ProgramHasNoDataAccount(program_id) + CoreBpfMigrationError::ProgramHasNoDataAccount(..) ); // Store the proper program data account @@ -276,9 +272,9 @@ mod tests { true, &Pubkey::new_unique(), // Not the upgradeable loader ); - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::IncorrectOwner(program_id) + CoreBpfMigrationError::IncorrectOwner(..) ); // Fail if the program account's state is not `UpgradeableLoaderState::Program` @@ -290,9 +286,9 @@ mod tests { true, &BPF_LOADER_UPGRADEABLE_ID, ); - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::InvalidProgramAccount(program_id) + CoreBpfMigrationError::BincodeError(..) ); // Fail if the program account's state is `UpgradeableLoaderState::Program`, @@ -307,9 +303,9 @@ mod tests { true, &BPF_LOADER_UPGRADEABLE_ID, ); - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::InvalidProgramAccount(program_id) + CoreBpfMigrationError::InvalidProgramAccount(..) ); } @@ -344,9 +340,9 @@ mod tests { false, &Pubkey::new_unique(), // Not the upgradeable loader ); - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::IncorrectOwner(program_data_address) + CoreBpfMigrationError::IncorrectOwner(..) ); // Fail if the program data account does not have the correct state @@ -358,9 +354,9 @@ mod tests { false, &BPF_LOADER_UPGRADEABLE_ID, ); - assert_eq!( + assert_matches!( SourceUpgradeableBpf::new_checked(&bank, &program_id).unwrap_err(), - CoreBpfMigrationError::InvalidProgramDataAccount(program_data_address) + CoreBpfMigrationError::BincodeError(..) ); } } diff --git a/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs b/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs index a4533171a28bba..1b17b60bf25b55 100644 --- a/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs +++ b/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs @@ -79,6 +79,7 @@ mod tests { use { super::*, crate::bank::{tests::create_simple_test_bank, ApplyFeatureActivationsCaller}, + assert_matches::assert_matches, solana_sdk::{ account::Account, bpf_loader_upgradeable::{UpgradeableLoaderState, ID as BPF_LOADER_UPGRADEABLE_ID}, @@ -159,9 +160,9 @@ mod tests { true, &Pubkey::new_unique(), // Not the native loader ); - assert_eq!( + assert_matches!( TargetBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap_err(), - CoreBpfMigrationError::IncorrectOwner(program_address) + CoreBpfMigrationError::IncorrectOwner(..) ); // Fail if the program data account exists @@ -182,9 +183,9 @@ mod tests { false, &BPF_LOADER_UPGRADEABLE_ID, ); - assert_eq!( + assert_matches!( TargetBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap_err(), - CoreBpfMigrationError::ProgramHasDataAccount(program_address) + CoreBpfMigrationError::ProgramHasDataAccount(..) ); // Fail if the program account does not exist @@ -192,9 +193,9 @@ mod tests { &program_address, &AccountSharedData::default(), ); - assert_eq!( + assert_matches!( TargetBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap_err(), - CoreBpfMigrationError::AccountNotFound(program_address) + CoreBpfMigrationError::AccountNotFound(..) ); } @@ -226,9 +227,9 @@ mod tests { false, &BPF_LOADER_UPGRADEABLE_ID, ); - assert_eq!( + assert_matches!( TargetBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap_err(), - CoreBpfMigrationError::ProgramHasDataAccount(program_address) + CoreBpfMigrationError::ProgramHasDataAccount(..) ); // Fail if the program account exists @@ -239,9 +240,9 @@ mod tests { true, &NATIVE_LOADER_ID, ); - assert_eq!( + assert_matches!( TargetBuiltin::new_checked(&bank, &program_address, &migration_target).unwrap_err(), - CoreBpfMigrationError::AccountExists(program_address) + CoreBpfMigrationError::AccountExists(..) ); } }