diff --git a/steps/19/src/tests.rs b/steps/19/src/tests.rs index 287dd333..0fb87316 100644 --- a/steps/19/src/tests.rs +++ b/steps/19/src/tests.rs @@ -102,13 +102,13 @@ fn mint_increments_count_for_kitty() { new_test_ext().execute_with(|| { // Querying storage before anything is set will return `0`. assert_eq!(CountForKitties::::get(), 0); - // Call `create_kitty` which will call `mint`. - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(1))); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); // Now the storage should be `1` assert_eq!(CountForKitties::::get(), 1); // Let's call it two more times... - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(2))); - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(3))); + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); // Now the storage should be `3` assert_eq!(CountForKitties::::get(), 3); }) diff --git a/steps/20/src/tests.rs b/steps/20/src/tests.rs index 287dd333..0fb87316 100644 --- a/steps/20/src/tests.rs +++ b/steps/20/src/tests.rs @@ -102,13 +102,13 @@ fn mint_increments_count_for_kitty() { new_test_ext().execute_with(|| { // Querying storage before anything is set will return `0`. assert_eq!(CountForKitties::::get(), 0); - // Call `create_kitty` which will call `mint`. - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(1))); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); // Now the storage should be `1` assert_eq!(CountForKitties::::get(), 1); // Let's call it two more times... - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(2))); - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(3))); + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); // Now the storage should be `3` assert_eq!(CountForKitties::::get(), 3); }) diff --git a/steps/21/src/tests.rs b/steps/21/src/tests.rs index 75e59b64..bcfff3dc 100644 --- a/steps/21/src/tests.rs +++ b/steps/21/src/tests.rs @@ -102,13 +102,13 @@ fn mint_increments_count_for_kitty() { new_test_ext().execute_with(|| { // Querying storage before anything is set will return `0`. assert_eq!(CountForKitties::::get(), 0); - // Call `create_kitty` which will call `mint`. - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(1))); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); // Now the storage should be `1` assert_eq!(CountForKitties::::get(), 1); // Let's call it two more times... - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(2))); - assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(3))); + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); // Now the storage should be `3` assert_eq!(CountForKitties::::get(), 3); }) diff --git a/steps/22/src/tests.rs b/steps/22/src/tests.rs index 401092ae..bcfff3dc 100644 --- a/steps/22/src/tests.rs +++ b/steps/22/src/tests.rs @@ -84,3 +84,55 @@ fn create_kitty_emits_event() { System::assert_last_event(Event::::Created { owner: 1 }.into()); }) } + +#[test] +fn count_for_kitties_created_correctly() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // You can `set` the value using an `u32`. + CountForKitties::::set(1337u32); + // You can `put` the value directly with a `u32`. + CountForKitties::::put(1337u32); + }) +} + +#[test] +fn mint_increments_count_for_kitty() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); + // Now the storage should be `1` + assert_eq!(CountForKitties::::get(), 1); + // Let's call it two more times... + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); + // Now the storage should be `3` + assert_eq!(CountForKitties::::get(), 3); + }) +} + +#[test] +fn mint_errors_when_overflow() { + new_test_ext().execute_with(|| { + // Set the count to the largest value possible. + CountForKitties::::set(u32::MAX); + // `create_kitty` should not succeed because of safe math. + assert_noop!( + PalletKitties::create_kitty(RuntimeOrigin::signed(1)), + Error::::TooManyKitties + ); + }) +} + +#[test] +fn kitties_map_created_correctly() { + new_test_ext().execute_with(|| { + let zero_key = [0u8; 32]; + assert_eq!(Kitties::::contains_key(zero_key), false); + Kitties::::insert(zero_key, ()); + assert_eq!(Kitties::::contains_key(zero_key), true); + }) +} diff --git a/steps/23/src/tests.rs b/steps/23/src/tests.rs index 401092ae..bc0aa673 100644 --- a/steps/23/src/tests.rs +++ b/steps/23/src/tests.rs @@ -84,3 +84,63 @@ fn create_kitty_emits_event() { System::assert_last_event(Event::::Created { owner: 1 }.into()); }) } + +#[test] +fn count_for_kitties_created_correctly() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // You can `set` the value using an `u32`. + CountForKitties::::set(1337u32); + // You can `put` the value directly with a `u32`. + CountForKitties::::put(1337u32); + }) +} + +#[test] +fn mint_increments_count_for_kitty() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); + // Now the storage should be `1` + assert_eq!(CountForKitties::::get(), 1); + // Let's call it two more times... + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); + // Now the storage should be `3` + assert_eq!(CountForKitties::::get(), 3); + }) +} + +#[test] +fn mint_errors_when_overflow() { + new_test_ext().execute_with(|| { + // Set the count to the largest value possible. + CountForKitties::::set(u32::MAX); + // `create_kitty` should not succeed because of safe math. + assert_noop!( + PalletKitties::create_kitty(RuntimeOrigin::signed(1)), + Error::::TooManyKitties + ); + }) +} + +#[test] +fn kitties_map_created_correctly() { + new_test_ext().execute_with(|| { + let zero_key = [0u8; 32]; + assert_eq!(Kitties::::contains_key(zero_key), false); + Kitties::::insert(zero_key, ()); + assert_eq!(Kitties::::contains_key(zero_key), true); + }) +} + +#[test] +fn create_kitty_adds_to_map() { + new_test_ext().execute_with(|| { + assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(1))); + assert_eq!(Kitties::::iter().count(), 1); + }) +} diff --git a/steps/24/src/tests.rs b/steps/24/src/tests.rs index 401092ae..bc0aa673 100644 --- a/steps/24/src/tests.rs +++ b/steps/24/src/tests.rs @@ -84,3 +84,63 @@ fn create_kitty_emits_event() { System::assert_last_event(Event::::Created { owner: 1 }.into()); }) } + +#[test] +fn count_for_kitties_created_correctly() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // You can `set` the value using an `u32`. + CountForKitties::::set(1337u32); + // You can `put` the value directly with a `u32`. + CountForKitties::::put(1337u32); + }) +} + +#[test] +fn mint_increments_count_for_kitty() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); + // Now the storage should be `1` + assert_eq!(CountForKitties::::get(), 1); + // Let's call it two more times... + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); + // Now the storage should be `3` + assert_eq!(CountForKitties::::get(), 3); + }) +} + +#[test] +fn mint_errors_when_overflow() { + new_test_ext().execute_with(|| { + // Set the count to the largest value possible. + CountForKitties::::set(u32::MAX); + // `create_kitty` should not succeed because of safe math. + assert_noop!( + PalletKitties::create_kitty(RuntimeOrigin::signed(1)), + Error::::TooManyKitties + ); + }) +} + +#[test] +fn kitties_map_created_correctly() { + new_test_ext().execute_with(|| { + let zero_key = [0u8; 32]; + assert_eq!(Kitties::::contains_key(zero_key), false); + Kitties::::insert(zero_key, ()); + assert_eq!(Kitties::::contains_key(zero_key), true); + }) +} + +#[test] +fn create_kitty_adds_to_map() { + new_test_ext().execute_with(|| { + assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(1))); + assert_eq!(Kitties::::iter().count(), 1); + }) +} diff --git a/steps/25/src/tests.rs b/steps/25/src/tests.rs index 401092ae..01b246d1 100644 --- a/steps/25/src/tests.rs +++ b/steps/25/src/tests.rs @@ -84,3 +84,71 @@ fn create_kitty_emits_event() { System::assert_last_event(Event::::Created { owner: 1 }.into()); }) } + +#[test] +fn count_for_kitties_created_correctly() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // You can `set` the value using an `u32`. + CountForKitties::::set(1337u32); + // You can `put` the value directly with a `u32`. + CountForKitties::::put(1337u32); + }) +} + +#[test] +fn mint_increments_count_for_kitty() { + new_test_ext().execute_with(|| { + // Querying storage before anything is set will return `0`. + assert_eq!(CountForKitties::::get(), 0); + // Call `mint` to create a new kitty. + assert_ok!(PalletKitties::mint(1, [1u8; 32])); + // Now the storage should be `1` + assert_eq!(CountForKitties::::get(), 1); + // Let's call it two more times... + assert_ok!(PalletKitties::mint(2, [2u8; 32])); + assert_ok!(PalletKitties::mint(3, [3u8; 32])); + // Now the storage should be `3` + assert_eq!(CountForKitties::::get(), 3); + }) +} + +#[test] +fn mint_errors_when_overflow() { + new_test_ext().execute_with(|| { + // Set the count to the largest value possible. + CountForKitties::::set(u32::MAX); + // `create_kitty` should not succeed because of safe math. + assert_noop!( + PalletKitties::create_kitty(RuntimeOrigin::signed(1)), + Error::::TooManyKitties + ); + }) +} + +#[test] +fn kitties_map_created_correctly() { + new_test_ext().execute_with(|| { + let zero_key = [0u8; 32]; + assert_eq!(Kitties::::contains_key(zero_key), false); + Kitties::::insert(zero_key, ()); + assert_eq!(Kitties::::contains_key(zero_key), true); + }) +} + +#[test] +fn create_kitty_adds_to_map() { + new_test_ext().execute_with(|| { + assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(1))); + assert_eq!(Kitties::::iter().count(), 1); + }) +} + +#[test] +fn cannot_mint_duplicate_kitty() { + new_test_ext().execute_with(|| { + assert_ok!(PalletKitties::mint(1, [0u8; 32])); + assert_noop!(PalletKitties::mint(2, [0u8; 32]), Error::::DuplicateKitty); + }) +}