Skip to content

Commit 9ad2148

Browse files
committed
add oracle command tests
1 parent 1be3ba5 commit 9ad2148

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

ddk-node/src/cli_opts.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,112 @@ pub struct Connect {
115115
#[arg(help = "The public key to connect to.")]
116116
pub pubkey: String,
117117
}
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

Comments
 (0)