Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi committed Sep 13, 2024
1 parent 44e80c5 commit d9a4c46
Show file tree
Hide file tree
Showing 54 changed files with 816 additions and 54 deletions.
17 changes: 16 additions & 1 deletion steps/1/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,13 +55,25 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}
17 changes: 16 additions & 1 deletion steps/10/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/11/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/12/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/13/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/14/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/15/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/16/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/17/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
17 changes: 16 additions & 1 deletion steps/18/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ construct_runtime! {
}
}

const ALICE: u64 = 1;
const BOB: u64 = 2;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for TestRuntime {
type Block = Block;
Expand All @@ -52,14 +55,26 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.into()
}

#[test]
fn starting_template_is_sane() {
new_test_ext().execute_with(|| {
let event = Event::<TestRuntime>::Created { owner: ALICE };
let _runtime_event: RuntimeEvent = event.into();
let _call = Call::<TestRuntime>::create_kitty {};
let result = PalletKitties::create_kitty(RuntimeOrigin::signed(BOB));
assert_ok!(result);
});
}

#[test]
fn system_and_balances_work() {
// This test will just sanity check that we can access `System` and `Balances`.
new_test_ext().execute_with(|| {
// We often need to set `System` to block 1 so that we can see events.
System::set_block_number(1);
// We often need to add some balance to a user to test features which needs tokens.
assert_ok!(Balances::mint_into(&1, 100));
assert_ok!(Balances::mint_into(&ALICE, 100));
assert_ok!(Balances::mint_into(&BOB, 100));
});
}

Expand Down
Loading

0 comments on commit d9a4c46

Please sign in to comment.