48 lines
2.6 KiB
Rust
48 lines
2.6 KiB
Rust
// file: crates/ksp-interface-lib/tests/external_consumer.rs
|
|
// version: 2
|
|
|
|
//! Downstream-style consumer canaries for the public Interface facade.
|
|
|
|
fn consume_instruction(instruction: ksp_interface_lib::ProgramInstruction) -> (ksp_interface_lib::Pubkey, usize, usize) {
|
|
return (*instruction.program_id(), instruction.accounts().len(), instruction.data().len());
|
|
}
|
|
|
|
fn consume_slot_lifecycle(event: ksp_interface_lib::SlotLifecycleEvent) -> (u64, ksp_interface_lib::SlotLifecycleStage) {
|
|
return (event.slot(), event.stage());
|
|
}
|
|
|
|
fn consume_transaction_execution(
|
|
event: ksp_interface_lib::TransactionExecutionEvent,
|
|
) -> (u64, ksp_interface_lib::TransactionSignature, ksp_interface_lib::TransactionExecutionOutcome) {
|
|
return (event.slot(), event.signature(), event.outcome());
|
|
}
|
|
|
|
#[test]
|
|
fn pre_005_external_consumer_uses_only_the_crate_root_facade() {
|
|
let program_id = ksp_interface_lib::Pubkey::new_from_array([0xA1_u8; 32]);
|
|
let account_id = ksp_interface_lib::Pubkey::new_from_array([0xA2_u8; 32]);
|
|
let readonly = ksp_interface_lib::ProgramAccountMeta::readonly(account_id, true);
|
|
let writable = ksp_interface_lib::ProgramAccountMeta::writable(account_id, false);
|
|
let instruction = ksp_interface_lib::ProgramInstruction::try_new(program_id, std::vec![readonly, writable, readonly], std::vec![7_u8, 8, 9]);
|
|
assert!(instruction.is_ok());
|
|
let instruction = match instruction {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(_) => return,
|
|
};
|
|
assert_eq!(consume_instruction(instruction), (program_id, 3, 3));
|
|
assert_eq!(ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_ACCOUNTS, 255);
|
|
assert_eq!(ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_DATA_LEN, 10_240);
|
|
assert_eq!(ksp_interface_lib::ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED.domain(), "interface");
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_5_pre_004_external_consumer_uses_only_crate_root_for_both_acquisition_families() {
|
|
let lifecycle = ksp_interface_lib::SlotLifecycleEvent::new(u64::MAX, ksp_interface_lib::SlotLifecycleStage::OptimisticallyConfirmed);
|
|
assert_eq!(consume_slot_lifecycle(lifecycle), (u64::MAX, ksp_interface_lib::SlotLifecycleStage::OptimisticallyConfirmed));
|
|
let signature = ksp_interface_lib::TransactionSignature::new([0xA3_u8; 64]);
|
|
let execution = ksp_interface_lib::TransactionExecutionEvent::new(u64::MAX - 1, signature, ksp_interface_lib::TransactionExecutionOutcome::Failed);
|
|
assert_eq!(consume_transaction_execution(execution), (u64::MAX - 1, signature, ksp_interface_lib::TransactionExecutionOutcome::Failed));
|
|
return;
|
|
}
|