v0.1.0-pre.014

This commit is contained in:
2026-07-24 17:14:02 +02:00
parent 5f6f7df509
commit 60a75c4434
140 changed files with 6217 additions and 1213 deletions

View File

@@ -1,10 +1,12 @@
// file: kb-lib/tests/external_executor_api.rs
// version: 1
// version: 2
//! Downstream-style compilation contract for externally implemented executors.
struct ExternalExecutor;
struct ExternalTypedExecutor;
impl kb_lib::ExApiInstructionExecutor for ExternalExecutor {
fn executor_name(&self) -> &'static str {
return "external_executor";
@@ -37,10 +39,57 @@ impl kb_lib::ExApiInstructionExecutor for ExternalExecutor {
}
}
impl kb_lib::ExApiTypedInstructionExecutor for ExternalTypedExecutor {
type Intent = kb_lib::MdPubkey;
fn capability(
&self,
_program_id: &kb_lib::MdProgramId,
operation_code: &str,
) -> kb_lib::ExApiExecutionCapability {
return kb_lib::ExApiExecutionCapability::unsupported("external_executor", operation_code);
}
fn build_prepared_plan(
&self,
intent: &Self::Intent,
) -> kb_core::Result<kb_lib::ExApiPreparedExecutionPlan> {
return std::result::Result::Ok(kb_lib::ExApiPreparedExecutionPlan {
executor_name: "external_typed_executor".to_string(),
executor_version: "1".to_string(),
intent_id: "external-intent".to_string(),
operation_code: "external-operation".to_string(),
fee_payer: intent.clone(),
instructions: std::vec::Vec::new(),
required_signers: std::vec::Vec::new(),
policy: kb_lib::ExApiExecutionPolicy::default(),
requested_spend_lamports: 0,
requested_compute_unit_price_micro_lamports: std::option::Option::None,
});
}
}
#[test]
fn external_executor_uses_only_the_public_kb_lib_contract() {
let executor: &dyn kb_lib::ExApiInstructionExecutor = &ExternalExecutor;
assert_eq!(executor.executor_name(), "external_executor");
assert_eq!(executor.executor_version(), "1");
assert!(executor.program_ids().is_empty());
let typed_executor = ExternalTypedExecutor;
let program_id = kb_lib::MdProgramId("external-program".to_string());
let capability = kb_lib::ExApiTypedInstructionExecutor::capability(
&typed_executor,
&program_id,
"external-operation",
);
assert!(!capability.is_supported());
let fee_payer = kb_lib::MdPubkey("external-fee-payer".to_string());
let plan =
kb_lib::ExApiTypedInstructionExecutor::build_prepared_plan(&typed_executor, &fee_payer)
.unwrap_or_else(|error| panic!("external typed executor failed: {error}"));
assert_eq!(plan.fee_payer, fee_payer);
assert!(plan.instructions.is_empty());
assert!(plan.required_signers.is_empty());
assert_eq!(plan.policy.simulation, kb_lib::ExApiExecutionSimulationPolicy::Required);
assert!(plan.policy.dry_run);
}