From 06b26f787cd75faab0c8304a75f4000b641de9f5 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Sat, 14 Sep 2024 10:01:12 -0400 Subject: [PATCH] add tests section to kitty struct --- steps/27/README.md | 12 ++++++++++++ steps/28/src/tests.rs | 2 +- steps/29/src/tests.rs | 2 +- steps/30/src/tests.rs | 2 +- steps/31/src/tests.rs | 2 +- steps/32/src/tests.rs | 2 +- steps/33/src/tests.rs | 2 +- steps/34/src/tests.rs | 2 +- steps/35/src/tests.rs | 2 +- steps/36/src/tests.rs | 2 +- steps/37/src/tests.rs | 2 +- steps/38/src/tests.rs | 2 +- steps/39/src/tests.rs | 2 +- steps/40/src/tests.rs | 2 +- steps/41/src/tests.rs | 2 +- steps/42/src/tests.rs | 2 +- steps/43/src/tests.rs | 2 +- steps/44/src/tests.rs | 2 +- steps/45/src/tests.rs | 2 +- steps/46/src/tests.rs | 2 +- steps/47/src/tests.rs | 2 +- steps/48/src/tests.rs | 2 +- steps/49/src/tests.rs | 2 +- steps/50/src/tests.rs | 2 +- steps/51/src/tests.rs | 2 +- steps/52/src/tests.rs | 2 +- steps/53/src/tests.rs | 2 +- steps/54/src/tests.rs | 2 +- 28 files changed, 39 insertions(+), 27 deletions(-) diff --git a/steps/27/README.md b/steps/27/README.md index 62f37332..9662b30f 100644 --- a/steps/27/README.md +++ b/steps/27/README.md @@ -89,3 +89,15 @@ I want to be clear, in the final compiled binary, both options for creating a ge Now that you know how to create a generic struct, create a new `Kitty` struct which is generic over ``. It should have fields for the `dna` of the kitty and the `owner` of the kitty. In our next step, we will learn how we can actually use this struct in runtime storage. + +### Tests + +We can't really "test" a struct, but we will use instances of the `Kitty` struct in other tests. + +So for this step, we simply introduce a `const DEFAULT_KITTY` to access a basic copy of the `Kitty` struct: + +```rust +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; +``` + +Remember if we update the `Kitty` struct in the future with more fields, we will also need to update this constant. diff --git a/steps/28/src/tests.rs b/steps/28/src/tests.rs index 502b9b4e..bd3a6536 100644 --- a/steps/28/src/tests.rs +++ b/steps/28/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/29/src/tests.rs b/steps/29/src/tests.rs index 502b9b4e..bd3a6536 100644 --- a/steps/29/src/tests.rs +++ b/steps/29/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/30/src/tests.rs b/steps/30/src/tests.rs index fcd51086..aa3f699c 100644 --- a/steps/30/src/tests.rs +++ b/steps/30/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/31/src/tests.rs b/steps/31/src/tests.rs index fcd51086..aa3f699c 100644 --- a/steps/31/src/tests.rs +++ b/steps/31/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/32/src/tests.rs b/steps/32/src/tests.rs index f745af1f..cae6b527 100644 --- a/steps/32/src/tests.rs +++ b/steps/32/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/33/src/tests.rs b/steps/33/src/tests.rs index f745af1f..cae6b527 100644 --- a/steps/33/src/tests.rs +++ b/steps/33/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/34/src/tests.rs b/steps/34/src/tests.rs index 61f2ec3f..d37fb7fb 100644 --- a/steps/34/src/tests.rs +++ b/steps/34/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/35/src/tests.rs b/steps/35/src/tests.rs index 61f2ec3f..d37fb7fb 100644 --- a/steps/35/src/tests.rs +++ b/steps/35/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/36/src/tests.rs b/steps/36/src/tests.rs index 20ddc3e8..6f253534 100644 --- a/steps/36/src/tests.rs +++ b/steps/36/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/37/src/tests.rs b/steps/37/src/tests.rs index 20ddc3e8..6f253534 100644 --- a/steps/37/src/tests.rs +++ b/steps/37/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/38/src/tests.rs b/steps/38/src/tests.rs index 20ddc3e8..6f253534 100644 --- a/steps/38/src/tests.rs +++ b/steps/38/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/39/src/tests.rs b/steps/39/src/tests.rs index 87b50c95..73757372 100644 --- a/steps/39/src/tests.rs +++ b/steps/39/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/40/src/tests.rs b/steps/40/src/tests.rs index 87b50c95..73757372 100644 --- a/steps/40/src/tests.rs +++ b/steps/40/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/41/src/tests.rs b/steps/41/src/tests.rs index 1668f9b2..4fd315fb 100644 --- a/steps/41/src/tests.rs +++ b/steps/41/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/42/src/tests.rs b/steps/42/src/tests.rs index 1668f9b2..4fd315fb 100644 --- a/steps/42/src/tests.rs +++ b/steps/42/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/43/src/tests.rs b/steps/43/src/tests.rs index 301b84be..a62fef25 100644 --- a/steps/43/src/tests.rs +++ b/steps/43/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/44/src/tests.rs b/steps/44/src/tests.rs index 301b84be..a62fef25 100644 --- a/steps/44/src/tests.rs +++ b/steps/44/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1 }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0 }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/45/src/tests.rs b/steps/45/src/tests.rs index 85f5ac18..1e9b3921 100644 --- a/steps/45/src/tests.rs +++ b/steps/45/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/46/src/tests.rs b/steps/46/src/tests.rs index 85f5ac18..1e9b3921 100644 --- a/steps/46/src/tests.rs +++ b/steps/46/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/47/src/tests.rs b/steps/47/src/tests.rs index ca9c1211..1d72a3c0 100644 --- a/steps/47/src/tests.rs +++ b/steps/47/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/48/src/tests.rs b/steps/48/src/tests.rs index ca9c1211..1d72a3c0 100644 --- a/steps/48/src/tests.rs +++ b/steps/48/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/49/src/tests.rs b/steps/49/src/tests.rs index 10f2397f..9cfbc71f 100644 --- a/steps/49/src/tests.rs +++ b/steps/49/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/50/src/tests.rs b/steps/50/src/tests.rs index 10f2397f..9cfbc71f 100644 --- a/steps/50/src/tests.rs +++ b/steps/50/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/51/src/tests.rs b/steps/51/src/tests.rs index 71752c83..f7e3cd32 100644 --- a/steps/51/src/tests.rs +++ b/steps/51/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/52/src/tests.rs b/steps/52/src/tests.rs index 71752c83..f7e3cd32 100644 --- a/steps/52/src/tests.rs +++ b/steps/52/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/53/src/tests.rs b/steps/53/src/tests.rs index b326c379..fd6554a4 100644 --- a/steps/53/src/tests.rs +++ b/steps/53/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. diff --git a/steps/54/src/tests.rs b/steps/54/src/tests.rs index b326c379..fd6554a4 100644 --- a/steps/54/src/tests.rs +++ b/steps/54/src/tests.rs @@ -27,7 +27,7 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; -const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 1, price: None }; +const DEFAULT_KITTY: Kitty = Kitty { dna: [0u8; 32], owner: 0, price: None }; // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime.