Skip to content

Commit

Permalink
update instruction for new price field
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi committed Sep 14, 2024
1 parent 06b26f7 commit e1bc25e
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion steps/30/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/31/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/32/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/33/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/34/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/35/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/36/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/37/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/38/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/39/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/40/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/41/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/42/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/43/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
6 changes: 5 additions & 1 deletion steps/44/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,8 @@ Now that you know how to create and use the `BalanceOf<T>` type, add the type al

Then add a new field to the `Kitty` struct called `price`, which is an `Option<BalanceOf<T>>`.

Finally, update the `mint` function to create a new `Kitty` with the new `price` field set as `None`.
Update the `mint` function to create a new `Kitty` with the new `price` field set as `None`.

Update the `do_transfer` function to reset the `kitty.price` to `None` when the kitty gets a new owner.

Finally, update your `tests.rs` file so that `DEFAULT_KITTY` has the field and value `price: None`.
2 changes: 1 addition & 1 deletion steps/44/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/45/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
2 changes: 1 addition & 1 deletion steps/46/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down
4 changes: 2 additions & 2 deletions steps/47/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down
4 changes: 2 additions & 2 deletions steps/48/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down
4 changes: 2 additions & 2 deletions steps/49/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down
4 changes: 2 additions & 2 deletions steps/50/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down
4 changes: 2 additions & 2 deletions steps/51/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down
4 changes: 2 additions & 2 deletions steps/52/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down
7 changes: 5 additions & 2 deletions steps/53/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down Expand Up @@ -400,5 +400,8 @@ fn do_buy_kitty_logic_works() {
assert_eq!(kitty.owner, BOB);
// Price is reset to `None`.
assert_eq!(kitty.price, None);
// BOB transferred funds to ALICE.
assert_eq!(Balances::balance(&ALICE), 1337);
assert_eq!(Balances::balance(&BOB), 100_000);
})
}
7 changes: 5 additions & 2 deletions steps/54/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn kitty_struct_has_expected_traits() {
new_test_ext().execute_with(|| {
let kitty = DEFAULT_KITTY;
let bytes = kitty.encode();
let _new_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
let _decoded_kitty = Kitty::<TestRuntime>::decode(&mut &bytes[..]).unwrap();
assert!(Kitty::<TestRuntime>::max_encoded_len() > 0);
let _info = Kitty::<TestRuntime>::type_info();
})
Expand Down Expand Up @@ -319,7 +319,7 @@ fn set_price_emits_event() {
assert_ok!(PalletKitties::create_kitty(RuntimeOrigin::signed(ALICE)));
let kitty_id = Kitties::<TestRuntime>::iter_keys().collect::<Vec<_>>()[0];
assert_ok!(PalletKitties::set_price(RuntimeOrigin::signed(ALICE), kitty_id, Some(1337)));
// Assert the last event by our blockchain is the `Created` event with the correct owner.
// Assert the last event is `PriceSet` event with the correct information.
System::assert_last_event(
Event::<TestRuntime>::PriceSet { owner: ALICE, kitty_id, new_price: Some(1337) }.into(),
);
Expand Down Expand Up @@ -400,5 +400,8 @@ fn do_buy_kitty_logic_works() {
assert_eq!(kitty.owner, BOB);
// Price is reset to `None`.
assert_eq!(kitty.price, None);
// BOB transferred funds to ALICE.
assert_eq!(Balances::balance(&ALICE), 1337);
assert_eq!(Balances::balance(&BOB), 100_000);
})
}

0 comments on commit e1bc25e

Please sign in to comment.