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