// file: crates/ksp-interface-lib/tests/public_api.rs // version: 4 //! Integration canaries for the public `ksp-interface-lib` foundation. fn consume_pubkey(pubkey: ksp_interface_lib::Pubkey) -> [u8; 32] { return pubkey.to_bytes(); } #[test] fn public_pre_002_pubkey_contract_is_available_from_crate_root() { let pubkey = ksp_interface_lib::Pubkey::default(); assert_eq!(consume_pubkey(pubkey), [0_u8; 32]); return; } #[test] fn public_pre_003_account_meta_and_limit_contracts_are_available_from_crate_root() { let pubkey = ksp_interface_lib::Pubkey::new_from_array([3_u8; 32]); let readonly = ksp_interface_lib::ProgramAccountMeta::readonly(pubkey, true); let writable = ksp_interface_lib::ProgramAccountMeta::writable(pubkey, false); assert_eq!(readonly.pubkey(), &pubkey); assert!(readonly.is_signer()); assert!(!readonly.is_writable()); assert_eq!(writable.pubkey(), &pubkey); assert!(!writable.is_signer()); assert!(writable.is_writable()); assert_eq!(ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_ACCOUNTS, 255); return; } #[test] fn public_pre_003_interface_error_code_is_stable_and_core_owned() { let code: ksp_core_lib::ErrorCode = ksp_interface_lib::ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED; assert_eq!(code.domain(), "interface"); assert_eq!(code.code(), "program_instruction_limit_exceeded"); return; } #[test] fn public_pre_004_program_instruction_contract_is_available_from_crate_root() { let program_id = ksp_interface_lib::Pubkey::new_from_array([4_u8; 32]); let account = ksp_interface_lib::ProgramAccountMeta::readonly(ksp_interface_lib::Pubkey::new_from_array([5_u8; 32]), true); let instruction = ksp_interface_lib::ProgramInstruction::try_new(program_id, std::vec![account], std::vec![1_u8, 2, 3]); assert!(instruction.is_ok()); let instruction = match instruction { std::result::Result::Ok(value) => value, std::result::Result::Err(_) => return, }; assert_eq!(instruction.program_id(), &program_id); assert_eq!(instruction.accounts(), &[account]); assert_eq!(instruction.data(), &[1_u8, 2, 3]); assert_eq!(ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_DATA_LEN, 10_240); return; } #[test] fn public_pre_005_limit_error_is_observable_without_private_module_access() { let program_id = ksp_interface_lib::Pubkey::new_from_array([0xC1_u8; 32]); let rejected = ksp_interface_lib::ProgramInstruction::try_new( program_id, std::vec::Vec::new(), std::vec![0xC2_u8; ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_DATA_LEN + 1], ); assert!(rejected.is_err()); let error = match rejected { std::result::Result::Err(value) => value, std::result::Result::Ok(_) => return, }; assert_eq!(error.code(), ksp_interface_lib::ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED); assert_eq!(error.context().len(), 3); assert_eq!(error.context()[0].key(), "field"); assert_eq!(error.context()[0].value(), "data"); assert_eq!(error.context()[1].key(), "actual_len"); assert_eq!(error.context()[1].value(), "10241"); assert_eq!(error.context()[2].key(), "maximum_len"); assert_eq!(error.context()[2].value(), "10240"); return; }