Skip to content

Commit b56755d

Browse files
committed
feat: add solution for ex00
1 parent 95926b1 commit b56755d

File tree

1 file changed

+20
-6
lines changed
  • exercises/ex00-writing-tests/flipper/src/tests

1 file changed

+20
-6
lines changed
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::mock::*;
2-
use crate::{pallet, Error};
2+
use crate::Error;
33
use frame_support::{assert_noop, assert_ok};
44

55
#[test]
@@ -12,17 +12,31 @@ fn set_value_ok() {
1212

1313
#[test]
1414
fn set_value_err_already_set() {
15-
new_test_ext().execute_with(|| todo!("Verify if the function returns the expected error."));
15+
new_test_ext().execute_with(|| {
16+
assert_ok!(Flipper::set_value(Origin::signed(1), true));
17+
assert_noop!(
18+
Flipper::set_value(Origin::signed(1), true),
19+
Error::<TestRuntime>::AlreadySet
20+
);
21+
});
1622
}
1723

1824
#[test]
1925
fn flip_value_ok() {
20-
new_test_ext()
21-
.execute_with(|| todo!("Ensure the good behaviour of the flip_value() function."));
26+
new_test_ext().execute_with(|| {
27+
assert_ok!(Flipper::set_value(Origin::signed(1), true));
28+
assert_eq!(Flipper::value(), Some(true));
29+
assert_ok!(Flipper::flip_value(Origin::signed(1)));
30+
assert_eq!(Flipper::value(), Some(false));
31+
});
2232
}
2333

2434
#[test]
2535
fn flip_value_ko() {
26-
new_test_ext()
27-
.execute_with(|| todo!("write a scenario that triggers an error in flip_value()"));
36+
new_test_ext().execute_with(|| {
37+
assert_noop!(
38+
Flipper::flip_value(Origin::signed(1)),
39+
Error::<TestRuntime>::NoneValue
40+
);
41+
});
2842
}

0 commit comments

Comments
 (0)