* Add missing InstructionError::IllegalOwner conversion (#21524)
* Add missing InstructionError code
* Add test that will fail on missing conversion
* Move enum-iterator to dev-only
(cherry picked from commit 0fc1c2e1fb
)
# Conflicts:
# Cargo.lock
* Fix conflict
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5676,6 +5676,7 @@ version = "1.8.7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"bs58 0.3.1",
|
"bs58 0.3.1",
|
||||||
|
"enum-iterator",
|
||||||
"prost",
|
"prost",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
|
@ -19,6 +19,9 @@ solana-account-decoder = { path = "../account-decoder", version = "=1.8.7" }
|
|||||||
solana-sdk = { path = "../sdk", version = "=1.8.7" }
|
solana-sdk = { path = "../sdk", version = "=1.8.7" }
|
||||||
solana-transaction-status = { path = "../transaction-status", version = "=1.8.7" }
|
solana-transaction-status = { path = "../transaction-status", version = "=1.8.7" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
enum-iterator = "0.6.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["lib"]
|
crate-type = ["lib"]
|
||||||
name = "solana_storage_proto"
|
name = "solana_storage_proto"
|
||||||
|
@ -12,5 +12,13 @@ fn main() -> Result<(), std::io::Error> {
|
|||||||
.build_client(true)
|
.build_client(true)
|
||||||
.build_server(false)
|
.build_server(false)
|
||||||
.format(true)
|
.format(true)
|
||||||
|
.type_attribute(
|
||||||
|
"TransactionErrorType",
|
||||||
|
"#[cfg_attr(test, derive(enum_iterator::IntoEnumIterator))]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
"InstructionErrorType",
|
||||||
|
"#[cfg_attr(test, derive(enum_iterator::IntoEnumIterator))]",
|
||||||
|
)
|
||||||
.compile(&protos, &[proto_base_path])
|
.compile(&protos, &[proto_base_path])
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,7 @@ impl TryFrom<tx_by_addr::TransactionError> for TransactionError {
|
|||||||
46 => InstructionError::InvalidAccountOwner,
|
46 => InstructionError::InvalidAccountOwner,
|
||||||
47 => InstructionError::ArithmeticOverflow,
|
47 => InstructionError::ArithmeticOverflow,
|
||||||
48 => InstructionError::UnsupportedSysvar,
|
48 => InstructionError::UnsupportedSysvar,
|
||||||
|
49 => InstructionError::IllegalOwner,
|
||||||
_ => return Err("Invalid InstructionError"),
|
_ => return Err("Invalid InstructionError"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -848,7 +849,7 @@ impl TryFrom<tx_by_addr::TransactionByAddr> for Vec<TransactionByAddrInfo> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use {super::*, enum_iterator::IntoEnumIterator};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reward_type_encode() {
|
fn test_reward_type_encode() {
|
||||||
@ -1413,4 +1414,55 @@ mod test {
|
|||||||
tx_by_addr_transaction_error.try_into().unwrap()
|
tx_by_addr_transaction_error.try_into().unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_error_enums() {
|
||||||
|
let ix_index = 1;
|
||||||
|
let custom_error = 42;
|
||||||
|
for error in tx_by_addr::TransactionErrorType::into_enum_iter() {
|
||||||
|
if error != tx_by_addr::TransactionErrorType::InstructionError {
|
||||||
|
let tx_by_addr_error = tx_by_addr::TransactionError {
|
||||||
|
transaction_error: error as i32,
|
||||||
|
instruction_error: None,
|
||||||
|
};
|
||||||
|
let transaction_error: TransactionError = tx_by_addr_error
|
||||||
|
.clone()
|
||||||
|
.try_into()
|
||||||
|
.unwrap_or_else(|_| panic!("{:?} conversion implemented?", error));
|
||||||
|
assert_eq!(tx_by_addr_error, transaction_error.into());
|
||||||
|
} else {
|
||||||
|
for ix_error in tx_by_addr::InstructionErrorType::into_enum_iter() {
|
||||||
|
if ix_error != tx_by_addr::InstructionErrorType::Custom {
|
||||||
|
let tx_by_addr_error = tx_by_addr::TransactionError {
|
||||||
|
transaction_error: error as i32,
|
||||||
|
instruction_error: Some(tx_by_addr::InstructionError {
|
||||||
|
index: ix_index,
|
||||||
|
error: ix_error as i32,
|
||||||
|
custom: None,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
let transaction_error: TransactionError = tx_by_addr_error
|
||||||
|
.clone()
|
||||||
|
.try_into()
|
||||||
|
.unwrap_or_else(|_| panic!("{:?} conversion implemented?", ix_error));
|
||||||
|
assert_eq!(tx_by_addr_error, transaction_error.into());
|
||||||
|
} else {
|
||||||
|
let tx_by_addr_error = tx_by_addr::TransactionError {
|
||||||
|
transaction_error: error as i32,
|
||||||
|
instruction_error: Some(tx_by_addr::InstructionError {
|
||||||
|
index: ix_index,
|
||||||
|
error: ix_error as i32,
|
||||||
|
custom: Some(tx_by_addr::CustomError {
|
||||||
|
custom: custom_error,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
let transaction_error: TransactionError =
|
||||||
|
tx_by_addr_error.clone().try_into().unwrap();
|
||||||
|
assert_eq!(tx_by_addr_error, transaction_error.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user