Skip to content

Commit 82bb263

Browse files
committed
fix(cardano-blockchain-types): key registration decoding test
Signed-off-by: bkioshn <[email protected]>
1 parent 8693044 commit 82bb263

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

rust/cardano-blockchain-types/src/cip36/key_registration.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,64 @@ fn decode_nonce(d: &mut Decoder) -> Result<u64, decode::Error> {
305305
fn decode_purpose(d: &mut Decoder) -> Result<u64, decode::Error> {
306306
decode_helper(d, "CIP36 Key Registration purpose", &mut ())
307307
}
308+
309+
#[cfg(test)]
310+
mod tests {
311+
312+
use super::*;
313+
314+
#[test]
315+
fn test_decode_payment_address() {
316+
let hex_data = hex::decode(
317+
// 0x004777561e7d9ec112ec307572faec1aff61ff0cfed68df4cd5c847f1872b617657881e30ad17c46e4010c9cb3ebb2440653a34d32219c83e9
318+
"5839004777561E7D9EC112EC307572FAEC1AFF61FF0CFED68DF4CD5C847F1872B617657881E30AD17C46E4010C9CB3EBB2440653A34D32219C83E9"
319+
).expect("cannot decode hex");
320+
let mut decoder = Decoder::new(&hex_data);
321+
let address = decode_payment_addr(&mut decoder);
322+
assert_eq!(address.unwrap().to_vec().len(), 57);
323+
}
324+
325+
#[test]
326+
fn test_decode_stake_pk() {
327+
let hex_data = hex::decode(
328+
// 0xe3cd2404c84de65f96918f18d5b445bcb933a7cda18eeded7945dd191e432369
329+
"5820E3CD2404C84DE65F96918F18D5B445BCB933A7CDA18EEDED7945DD191E432369",
330+
)
331+
.expect("cannot decode hex");
332+
let mut decoder = Decoder::new(&hex_data);
333+
let stake_pk = decode_stake_pk(&mut decoder);
334+
assert!(stake_pk.is_ok());
335+
}
336+
337+
#[test]
338+
// cip-36 version
339+
fn test_decode_voting_key_cip36() {
340+
let hex_data = hex::decode(
341+
// [["0x0036ef3e1f0d3f5989e2d155ea54bdb2a72c4c456ccb959af4c94868f473f5a0", 1]]
342+
"818258200036EF3E1F0D3F5989E2D155EA54BDB2A72C4C456CCB959AF4C94868F473F5A001",
343+
)
344+
.expect("cannot decode hex");
345+
let mut decoder = Decoder::new(&hex_data);
346+
347+
let (is_cip36, voting_pk) = decode_voting_key(&mut decoder).expect("Failed to decode");
348+
349+
assert!(is_cip36);
350+
assert_eq!(voting_pk.len(), 1);
351+
}
352+
353+
#[test]
354+
// cip-15 version
355+
fn test_decode_voting_key_2() {
356+
let hex_data = hex::decode(
357+
// 0x0036ef3e1f0d3f5989e2d155ea54bdb2a72c4c456ccb959af4c94868f473f5a0
358+
"58200036EF3E1F0D3F5989E2D155EA54BDB2A72C4C456CCB959AF4C94868F473F5A0",
359+
)
360+
.expect("cannot decode hex");
361+
let mut decoder = Decoder::new(&hex_data);
362+
363+
let (is_cip36, voting_pk) = decode_voting_key(&mut decoder).expect("Failed to decode");
364+
365+
assert!(!is_cip36);
366+
assert_eq!(voting_pk.len(), 1);
367+
}
368+
}

0 commit comments

Comments
 (0)