codama_nodes/
instruction_remaining_accounts_node.rs1use crate::{ArgumentValueNode, Docs, IsAccountSigner, ResolverValueNode};
2use codama_nodes_derive::{node, node_union};
3
4#[node]
5pub struct InstructionRemainingAccountsNode {
6 #[serde(default, skip_serializing_if = "crate::is_default")]
8 pub is_optional: bool,
9 #[serde(default, skip_serializing_if = "crate::is_default")]
10 pub is_signer: IsAccountSigner,
11 #[serde(default, skip_serializing_if = "crate::is_default")]
12 pub is_writable: bool,
13 #[serde(default, skip_serializing_if = "crate::is_default")]
14 pub docs: Docs,
15
16 pub value: InstructionRemainingAccountsNodeValue,
18}
19
20#[node_union]
21pub enum InstructionRemainingAccountsNodeValue {
22 Argument(ArgumentValueNode),
23 Resolver(ResolverValueNode),
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn direct_instantiation() {
32 let node = InstructionRemainingAccountsNode {
33 is_optional: false,
34 is_signer: IsAccountSigner::Either,
35 is_writable: true,
36 docs: vec!["This is a test".to_string()].into(),
37 value: ArgumentValueNode::new("myArgument").into(),
38 };
39 assert!(!node.is_optional);
40 assert_eq!(node.is_signer, IsAccountSigner::Either);
41 assert!(node.is_writable);
42 assert_eq!(node.docs, vec!["This is a test".to_string()].into());
43 assert_eq!(
44 node.value,
45 InstructionRemainingAccountsNodeValue::Argument(ArgumentValueNode::new("myArgument"))
46 );
47 }
48
49 #[test]
50 fn to_json() {
51 let node = InstructionRemainingAccountsNode {
52 is_optional: false,
53 is_signer: IsAccountSigner::Either,
54 is_writable: true,
55 docs: vec![].into(),
56 value: ArgumentValueNode::new("myArgument").into(),
57 };
58 let json = serde_json::to_string(&node).unwrap();
59 assert_eq!(
60 json,
61 r#"{"kind":"instructionRemainingAccountsNode","isSigner":"either","isWritable":true,"value":{"kind":"argumentValueNode","name":"myArgument"}}"#
62 );
63 }
64
65 #[test]
66 fn from_json() {
67 let json = r#"{"kind":"instructionRemainingAccountsNode","isSigner":"either","isWritable":true,"value":{"kind":"argumentValueNode","name":"myArgument"}}"#;
68 let node: InstructionRemainingAccountsNode = serde_json::from_str(json).unwrap();
69 assert_eq!(
70 node,
71 InstructionRemainingAccountsNode {
72 is_optional: false,
73 is_signer: IsAccountSigner::Either,
74 is_writable: true,
75 docs: vec![].into(),
76 value: ArgumentValueNode::new("myArgument").into(),
77 }
78 );
79 }
80}