82 lines
2.9 KiB
Rust
82 lines
2.9 KiB
Rust
// file: kb-lib/tests/external_solana_program_metadata_instruction_api.rs
|
|
// version: 1
|
|
|
|
//! 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 = kb_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 = kb_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: kb_lib::MdCoreInstructionReplayInput;
|
|
if let std::result::Result::Ok(value) = input_result {
|
|
input = value;
|
|
} else {
|
|
return;
|
|
}
|
|
let decoder = kb_lib::DcMetadataSolanaProgramMetadataDecoder;
|
|
let recognition = kb_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 = kb_lib::DcApiInstructionDecoder::decode(&decoder, &input);
|
|
assert_eq!(result.status, kb_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);
|
|
}
|