v0.2.5-pre.005
This commit is contained in:
32
crates/ksp-wallet-lib/unit_tests/payload.rs
Normal file
32
crates/ksp-wallet-lib/unit_tests/payload.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
// file: crates/ksp-wallet-lib/unit_tests/payload.rs
|
||||
// version: 1
|
||||
|
||||
use base64::Engine as _;
|
||||
|
||||
#[test]
|
||||
fn metadata_payload_rejects_duplicate_note_identifiers() -> ksp_core_lib::Result<()> {
|
||||
let duplicate_id = base64::engine::general_purpose::URL_SAFE_NO_PAD.encode([7_u8; crate::KSPWALLET_V1_NOTE_ID_BYTES]);
|
||||
let payload = serde_json::json!({
|
||||
"pubkey": "11111111111111111111111111111111",
|
||||
"alias": null,
|
||||
"notes": [
|
||||
{"id": duplicate_id.clone(), "text": "first"},
|
||||
{"id": duplicate_id, "text": "second"}
|
||||
]
|
||||
});
|
||||
let encoded = match serde_json::to_vec(&payload) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return std::result::Result::Err(test_error("test metadata payload could not be serialized")),
|
||||
};
|
||||
let result = super::decode_metadata_payload(encoded.as_slice());
|
||||
let error = match result {
|
||||
std::result::Result::Ok(_) => return std::result::Result::Err(test_error("duplicate note identifiers unexpectedly parsed")),
|
||||
std::result::Result::Err(error) => error,
|
||||
};
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_FORMAT_INVALID);
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn test_error(message: &'static str) -> ksp_core_lib::Error {
|
||||
return ksp_core_lib::Error::new(crate::ERROR_CODE_FORMAT_INVALID, message);
|
||||
}
|
||||
Reference in New Issue
Block a user