Files
khadhroony-bot3/ks-lib/tests/external_solana_program_metadata_instruction_api.rs
2026-08-09 19:34:08 +02:00

82 lines
2.9 KiB
Rust

// file: ks-lib/tests/external_solana_program_metadata_instruction_api.rs
// version: 2
//! Downstream-style compilation contract for the Solana Program Metadata instruction decoder.
#[test]
fn external_consumers_decode_instructions_only_through_crate_root_exports() {
let account = solana_pubkey::Pubkey::new_from_array([31_u8; 32]).to_string();
let authority = solana_pubkey::Pubkey::new_from_array([32_u8; 32]).to_string();
let placeholder = ks_program_ids::METADATA_SOLANA_PROGRAM_METADATA_PROGRAM_ID;
let account_keys = serde_json::json!([
{
"accountIndex": 0,
"accountKey": account,
"source": "static",
"signer": false,
"writable": true
},
{
"accountIndex": 1,
"accountKey": authority,
"source": "static",
"signer": true,
"writable": false
},
{
"accountIndex": 2,
"accountKey": placeholder,
"source": "static",
"signer": false,
"writable": false
},
{
"accountIndex": 3,
"accountKey": placeholder,
"source": "static",
"signer": false,
"writable": false
}
]);
let instruction_accounts = serde_json::json!([
{"accountIndex": 0, "accountKey": account},
{"accountIndex": 1, "accountKey": authority},
{"accountIndex": 2, "accountKey": placeholder},
{"accountIndex": 3, "accountKey": placeholder}
]);
let input_result = ks_lib::MdCoreInstructionReplayInput::new(
"spm:external:extend",
"signature",
42,
"0",
placeholder,
false,
std::option::Option::None,
account_keys,
instruction_accounts,
std::option::Option::Some(serde_json::json!({"dataBase64": "CAEA"})),
std::option::Option::None,
serde_json::json!([]),
serde_json::json!([]),
serde_json::json!([]),
serde_json::json!([]),
);
assert!(input_result.is_ok());
let input: ks_lib::MdCoreInstructionReplayInput;
if let std::result::Result::Ok(value) = input_result {
input = value;
} else {
return;
}
let decoder = ks_lib::DcMetadataSolanaProgramMetadataDecoder;
let recognition = ks_lib::DcApiInstructionDecoder::recognize(&decoder, &input);
assert!(recognition.compatible);
assert!(recognition.exact);
assert_eq!(recognition.entry_code.as_deref(), std::option::Option::Some("extend"));
let result = ks_lib::DcApiInstructionDecoder::decode(&decoder, &input);
assert_eq!(result.status, ks_lib::DcApiDecoderOutcomeStatus::Decoded);
assert_eq!(result.recognized_entry_code.as_deref(), std::option::Option::Some("extend"));
assert_eq!(result.observations.len(), 1);
assert_eq!(result.observations[0].payload_json["parameters"]["length"], 1);
}