v0.2.13-pre.005

This commit is contained in:
2026-08-28 05:24:26 +02:00
parent 0ee28eeb95
commit 29f27ae109
9 changed files with 529 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-interface-lib/unit_tests/program_instruction.rs
// version: 1
// version: 2
fn meta(byte: u8, writable: bool) -> crate::ProgramAccountMeta {
let pubkey = crate::Pubkey::new_from_array([byte; 32]);
@@ -105,3 +105,61 @@ fn instruction_debug_is_bounded_and_omits_accounts_and_payload_bytes() {
assert!(!rendered.contains("is_writable"));
return;
}
#[test]
fn instruction_preserves_owned_vector_allocations_without_internal_reallocation() {
let program_id = crate::Pubkey::new_from_array([0x81_u8; 32]);
let accounts = std::vec![meta(10, false), meta(11, true), meta(12, false)];
let accounts_ptr = accounts.as_ptr();
let data = std::vec![0x10_u8, 0x20, 0x30, 0x40];
let data_ptr = data.as_ptr();
let instruction = crate::ProgramInstruction::try_new(program_id, accounts, data);
assert!(instruction.is_ok());
let instruction = match instruction {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
assert_eq!(instruction.accounts().as_ptr(), accounts_ptr);
assert_eq!(instruction.data().as_ptr(), data_ptr);
return;
}
#[test]
fn instruction_limit_errors_do_not_echo_hostile_payload_or_account_material() {
let program_id = crate::Pubkey::new_from_array([0x91_u8; 32]);
let hostile_marker = b"HOSTILE_INTERFACE_PAYLOAD_SENTINEL";
let mut hostile_data = hostile_marker.to_vec();
hostile_data.resize(crate::MAX_PROGRAM_INSTRUCTION_DATA_LEN + 1, 0xA5_u8);
let data_error = crate::ProgramInstruction::try_new(program_id, std::vec::Vec::new(), hostile_data);
assert!(data_error.is_err());
let data_error = match data_error {
std::result::Result::Err(value) => value,
std::result::Result::Ok(_) => return,
};
let data_display = std::format!("{data_error}");
let data_debug = std::format!("{data_error:?}");
assert!(!data_display.contains("HOSTILE_INTERFACE_PAYLOAD_SENTINEL"));
assert!(!data_debug.contains("HOSTILE_INTERFACE_PAYLOAD_SENTINEL"));
for context in data_error.context() {
assert!(!context.value().contains("HOSTILE_INTERFACE_PAYLOAD_SENTINEL"));
}
let hostile_account = meta(0xE1, true);
let hostile_account_debug = std::format!("{hostile_account:?}");
let account_error = crate::ProgramInstruction::try_new(
program_id,
std::vec![hostile_account; crate::MAX_PROGRAM_INSTRUCTION_ACCOUNTS + 1],
std::vec::Vec::new(),
);
assert!(account_error.is_err());
let account_error = match account_error {
std::result::Result::Err(value) => value,
std::result::Result::Ok(_) => return,
};
let account_debug = std::format!("{account_error:?}");
assert!(!account_debug.contains(hostile_account_debug.as_str()));
assert_eq!(account_error.context().len(), 3);
assert_eq!(account_error.context()[0].value(), "accounts");
assert_eq!(account_error.context()[1].value(), "256");
assert_eq!(account_error.context()[2].value(), "255");
return;
}