@@ -76,7 +76,34 @@ pub enum OracleCommand {
7676 #[ arg( help = "The outcomes of the event. Separate by spaces." ) ]
7777 outcomes : Vec < String > ,
7878 } ,
79+ #[ command( about = "Create a numeric oracle event." ) ]
80+ CreateNumeric {
81+ #[ arg( help = "The maturity of the event." ) ]
82+ maturity : u32 ,
83+ #[ arg( help = "Number of digits for the numeric event." ) ]
84+ nb_digits : u32 ,
85+ } ,
86+ #[ command( about = "Sign an oracle announcement." ) ]
87+ Sign {
88+ #[ arg(
89+ long,
90+ help = "Specify if the event is enum." ,
91+ conflicts_with = "numeric"
92+ ) ]
93+ r#enum : bool ,
94+ #[ arg(
95+ long,
96+ help = "Specify if the event is numeric." ,
97+ conflicts_with = "enum"
98+ ) ]
99+ numeric : bool ,
100+ #[ arg( long, help = "The outcome to sign." ) ]
101+ outcome : String ,
102+ #[ arg( long, help = "The event id to sign." ) ]
103+ event_id : String ,
104+ } ,
79105}
106+
80107#[ derive( Parser , Clone , Debug ) ]
81108pub struct Accept {
82109 // The contract id string to accept.
@@ -88,3 +115,112 @@ pub struct Connect {
88115 #[ arg( help = "The public key to connect to." ) ]
89116 pub pubkey : String ,
90117}
118+
119+ #[ cfg( test) ]
120+ mod tests {
121+ use super :: * ;
122+
123+ #[ test]
124+ fn test_oracle_create_enum_structure ( ) {
125+ // Test creating an enum oracle command
126+ let cmd = OracleCommand :: CreateEnum {
127+ maturity : 1234567890 ,
128+ outcomes : vec ! [ "YES" . to_string( ) , "NO" . to_string( ) ] ,
129+ } ;
130+
131+ match cmd {
132+ OracleCommand :: CreateEnum { maturity, outcomes } => {
133+ assert_eq ! ( maturity, 1234567890 ) ;
134+ assert_eq ! ( outcomes, vec![ "YES" , "NO" ] ) ;
135+ }
136+ _ => panic ! ( "Wrong variant" ) ,
137+ }
138+ }
139+
140+ #[ test]
141+ fn test_oracle_create_numeric_structure ( ) {
142+ // Test creating a numeric oracle command
143+ let cmd = OracleCommand :: CreateNumeric {
144+ maturity : 1234567890 ,
145+ nb_digits : 5 ,
146+ } ;
147+
148+ match cmd {
149+ OracleCommand :: CreateNumeric {
150+ maturity,
151+ nb_digits,
152+ } => {
153+ assert_eq ! ( maturity, 1234567890 ) ;
154+ assert_eq ! ( nb_digits, 5 ) ;
155+ }
156+ _ => panic ! ( "Wrong variant" ) ,
157+ }
158+ }
159+
160+ #[ test]
161+ fn test_oracle_sign_enum_structure ( ) {
162+ // Test creating a sign command with enum flag
163+ let cmd = OracleCommand :: Sign {
164+ r#enum : true ,
165+ numeric : false ,
166+ outcome : "YES" . to_string ( ) ,
167+ event_id : "test123" . to_string ( ) ,
168+ } ;
169+
170+ match cmd {
171+ OracleCommand :: Sign {
172+ r#enum,
173+ numeric,
174+ outcome,
175+ event_id,
176+ } => {
177+ assert ! ( r#enum) ;
178+ assert ! ( !numeric) ;
179+ assert_eq ! ( outcome, "YES" ) ;
180+ assert_eq ! ( event_id, "test123" ) ;
181+ }
182+ _ => panic ! ( "Wrong variant" ) ,
183+ }
184+ }
185+
186+ #[ test]
187+ fn test_oracle_sign_numeric_structure ( ) {
188+ // Test creating a sign command with numeric flag
189+ let cmd = OracleCommand :: Sign {
190+ r#enum : false ,
191+ numeric : true ,
192+ outcome : "42" . to_string ( ) ,
193+ event_id : "test123" . to_string ( ) ,
194+ } ;
195+
196+ match cmd {
197+ OracleCommand :: Sign {
198+ r#enum,
199+ numeric,
200+ outcome,
201+ event_id,
202+ } => {
203+ assert ! ( !r#enum) ;
204+ assert ! ( numeric) ;
205+ assert_eq ! ( outcome, "42" ) ;
206+ assert_eq ! ( event_id, "test123" ) ;
207+ }
208+ _ => panic ! ( "Wrong variant" ) ,
209+ }
210+ }
211+
212+ #[ test]
213+ fn test_oracle_announcements_structure ( ) {
214+ // Test creating an announcements command
215+ let cmd = OracleCommand :: Announcements {
216+ event_id : "event123" . to_string ( ) ,
217+ } ;
218+
219+ match cmd {
220+ OracleCommand :: Announcements { event_id } => {
221+ assert_eq ! ( event_id, "event123" ) ;
222+ }
223+ _ => panic ! ( "Wrong variant" ) ,
224+ }
225+ }
226+ }
0 commit comments