v0.4.8-pre.007
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// file: kb-lib/tests/external_solana_program_metadata_executor_api.rs
|
||||
// version: 1
|
||||
|
||||
//! Downstream-style compilation contract for the Solana Program Metadata executor.
|
||||
|
||||
#[test]
|
||||
fn external_consumers_build_solana_program_metadata_plans_only_through_crate_root_exports() {
|
||||
let authority = kb_lib::MdPubkey(kb_program_ids::SYSTEM_PROGRAM_ID.to_string());
|
||||
let account = kb_lib::MdPubkey(kb_program_ids::VOTE_PROGRAM_ID.to_string());
|
||||
let policy = kb_lib::ExApiExecutionPolicy {
|
||||
cost_limit: kb_lib::ExApiExecutionCostLimit {
|
||||
max_spend_lamports: std::option::Option::Some(0),
|
||||
max_fee_lamports: std::option::Option::Some(20_000),
|
||||
max_compute_unit_price_micro_lamports: std::option::Option::None,
|
||||
},
|
||||
authorized_signers: std::vec![authority.clone()],
|
||||
post_execution_validation: kb_lib::ExApiPostExecutionValidationPolicy {
|
||||
canonical_insert_required: true,
|
||||
core_extraction_required: true,
|
||||
decode_replay_required: true,
|
||||
materialization_required: true,
|
||||
},
|
||||
..kb_lib::ExApiExecutionPolicy::default()
|
||||
};
|
||||
let intent = kb_lib::ExMetadataSpmExecutionIntent {
|
||||
intent_id: "external-spm-extend".to_string(),
|
||||
fee_payer: authority.clone(),
|
||||
policy,
|
||||
allow_destructive_operation: false,
|
||||
operation: kb_lib::ExMetadataSpmOperation::Extend {
|
||||
account,
|
||||
authority,
|
||||
length: 64,
|
||||
program_context: std::option::Option::None,
|
||||
},
|
||||
};
|
||||
let executor = kb_lib::ExMetadataSolanaProgramMetadataExecutor;
|
||||
let program_id = kb_lib::MdProgramId(
|
||||
kb_program_ids::METADATA_SOLANA_PROGRAM_METADATA_PROGRAM_ID.to_string(),
|
||||
);
|
||||
let capability = kb_lib::ExApiTypedInstructionExecutor::capability(
|
||||
&executor,
|
||||
&program_id,
|
||||
kb_lib::EX_METADATA_SPM_EXTEND_OPERATION,
|
||||
);
|
||||
assert!(capability.is_supported());
|
||||
let plan = kb_lib::ExApiTypedInstructionExecutor::build_prepared_plan(&executor, &intent);
|
||||
assert!(plan.is_ok());
|
||||
let plan = match plan {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
assert_eq!(plan.operation_code, kb_lib::EX_METADATA_SPM_EXTEND_OPERATION);
|
||||
assert_eq!(plan.instructions.len(), 1);
|
||||
assert_eq!(plan.instructions[0].data, std::vec![8, 64, 0]);
|
||||
assert_eq!(plan.instructions[0].accounts.len(), 4);
|
||||
let evaluation = kb_lib::ExSafetyChecker.evaluate_prepared_plan(&plan);
|
||||
assert!(evaluation.is_ok());
|
||||
assert_eq!(
|
||||
evaluation.as_ref().map(|value| return value.decision),
|
||||
std::result::Result::Ok(kb_lib::ExSafetyDecision::Allow)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user