drive/state_transition_action/shielded/
mod.rs1pub mod shield;
3pub mod shield_from_asset_lock;
5pub mod shielded_transfer;
7pub mod shielded_withdrawal;
9pub mod unshield;
11
12use dpp::shielded::SerializedAction;
13
14#[derive(Debug, Clone)]
16pub struct ShieldedActionNote {
17 pub nullifier: [u8; 32],
19 pub cmx: [u8; 32],
21 pub encrypted_note: Vec<u8>,
23}
24
25impl From<&SerializedAction> for ShieldedActionNote {
26 fn from(action: &SerializedAction) -> Self {
27 ShieldedActionNote {
28 nullifier: action.nullifier,
29 cmx: action.cmx,
30 encrypted_note: action.encrypted_note.clone(),
31 }
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_shielded_action_note_fields() {
41 let note = ShieldedActionNote {
42 nullifier: [0xAA; 32],
43 cmx: [0xBB; 32],
44 encrypted_note: vec![1, 2, 3, 4],
45 };
46 assert_eq!(note.nullifier, [0xAA; 32]);
47 assert_eq!(note.cmx, [0xBB; 32]);
48 assert_eq!(note.encrypted_note, vec![1, 2, 3, 4]);
49 }
50
51 #[test]
52 fn test_from_serialized_action() {
53 let action = SerializedAction {
54 nullifier: [0x11; 32],
55 rk: [0x00; 32],
56 cmx: [0x22; 32],
57 encrypted_note: vec![0xAB, 0xCD],
58 cv_net: [0x00; 32],
59 spend_auth_sig: [0x00; 64],
60 };
61 let note = ShieldedActionNote::from(&action);
62 assert_eq!(note.nullifier, [0x11; 32]);
63 assert_eq!(note.cmx, [0x22; 32]);
64 assert_eq!(note.encrypted_note, vec![0xAB, 0xCD]);
65 }
66
67 #[test]
68 fn test_from_serialized_action_empty_encrypted_note() {
69 let action = SerializedAction {
70 nullifier: [0xFF; 32],
71 rk: [0x00; 32],
72 cmx: [0x00; 32],
73 encrypted_note: vec![],
74 cv_net: [0x00; 32],
75 spend_auth_sig: [0x00; 64],
76 };
77 let note = ShieldedActionNote::from(&action);
78 assert_eq!(note.nullifier, [0xFF; 32]);
79 assert!(note.encrypted_note.is_empty());
80 }
81
82 #[test]
83 fn test_clone() {
84 let note = ShieldedActionNote {
85 nullifier: [0xAA; 32],
86 cmx: [0xBB; 32],
87 encrypted_note: vec![5, 6, 7],
88 };
89 let cloned = note.clone();
90 assert_eq!(cloned.nullifier, note.nullifier);
91 assert_eq!(cloned.cmx, note.cmx);
92 assert_eq!(cloned.encrypted_note, note.encrypted_note);
93 }
94
95 #[test]
96 fn test_debug() {
97 let note = ShieldedActionNote {
98 nullifier: [0x00; 32],
99 cmx: [0x00; 32],
100 encrypted_note: vec![],
101 };
102 let debug_str = format!("{:?}", note);
103 assert!(debug_str.contains("ShieldedActionNote"));
104 }
105}