Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Apr 12, 2022
1 parent 9fb1887 commit 981c50f
Show file tree
Hide file tree
Showing 19 changed files with 916 additions and 720 deletions.
175 changes: 110 additions & 65 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,50 +378,66 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
},
}),
event: Event::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
},
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Withdraw {
who: alice().into(),
amount: fees,
}),
event: Event::Balances(
pallet_balances::Event::Withdraw { who: alice().into(), amount: fees }.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Transfer {
from: alice().into(),
to: bob().into(),
amount: 69 * DOLLARS,
}),
event: Event::Balances(
pallet_balances::Event::Transfer {
from: alice().into(),
to: bob().into(),
amount: 69 * DOLLARS,
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}),
event: Event::Balances(
pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
event: Event::Treasury(
pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() },
}),
event: Event::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: transfer_weight,
..Default::default()
},
}
.into(),
),
topics: vec![],
},
];
Expand Down Expand Up @@ -449,87 +465,116 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
},
}),
event: Event::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
},
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Withdraw {
who: bob().into(),
amount: fees,
}),
event: Event::Balances(
pallet_balances::Event::Withdraw { who: bob().into(), amount: fees }.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Transfer {
from: bob().into(),
to: alice().into(),
amount: 5 * DOLLARS,
}),
event: Event::Balances(
pallet_balances::Event::Transfer {
from: bob().into(),
to: alice().into(),
amount: 5 * DOLLARS,
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}),
event: Event::Balances(
pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
event: Event::Treasury(
pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() },
}),
event: Event::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: transfer_weight,
..Default::default()
},
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Balances(pallet_balances::Event::Withdraw {
who: alice().into(),
amount: fees,
}),
event: Event::Balances(
pallet_balances::Event::Withdraw { who: alice().into(), amount: fees }.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Balances(pallet_balances::Event::Transfer {
from: alice().into(),
to: bob().into(),
amount: 15 * DOLLARS,
}),
event: Event::Balances(
pallet_balances::Event::Transfer {
from: alice().into(),
to: bob().into(),
amount: 15 * DOLLARS,
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Balances(pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}),
event: Event::Balances(
pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}
.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
event: Event::Treasury(
pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(),
),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() },
}),
event: Event::System(
frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: transfer_weight,
..Default::default()
},
}
.into(),
),
topics: vec![],
},
];
Expand Down
9 changes: 3 additions & 6 deletions frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,9 @@ fn transferring_less_than_one_unit_is_fine() {
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 0));
System::assert_last_event(mock::Event::Assets(crate::Event::Transferred {
asset_id: 0,
from: 1,
to: 2,
amount: 0,
}));
System::assert_last_event(
crate::Event::Transferred { asset_id: 0, from: 1, to: 2, amount: 0 }.into(),
);
});
}

Expand Down
38 changes: 19 additions & 19 deletions frame/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ macro_rules! decl_tests {
<$ext_builder>::default().monied(true).build().execute_with(|| {
assert_eq!(Balances::total_balance(&1), 10);
assert_ok!(Balances::deposit_into_existing(&1, 10).map(drop));
System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 10 }));
System::assert_last_event(crate::Event::Deposit { who: 1, amount: 10 }.into());
assert_eq!(Balances::total_balance(&1), 20);
assert_eq!(<TotalIssuance<$test>>::get(), 120);
});
Expand Down Expand Up @@ -342,7 +342,7 @@ macro_rules! decl_tests {
fn balance_works() {
<$ext_builder>::default().build().execute_with(|| {
let _ = Balances::deposit_creating(&1, 42);
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 42 }));
System::assert_has_event(crate::Event::Deposit { who: 1, amount: 42 }.into());
assert_eq!(Balances::free_balance(1), 42);
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::total_balance(&1), 42);
Expand Down Expand Up @@ -444,7 +444,7 @@ macro_rules! decl_tests {
let _ = Balances::withdraw(
&2, 11, WithdrawReasons::TRANSFER, ExistenceRequirement::KeepAlive
);
System::assert_last_event(Event::Balances(crate::Event::Withdraw { who: 2, amount: 11 }));
System::assert_last_event(crate::Event::Withdraw { who: 2, amount: 11 }.into());
assert_eq!(Balances::free_balance(2), 100);
assert_eq!(<TotalIssuance<$test>>::get(), 100);
});
Expand Down Expand Up @@ -505,7 +505,7 @@ macro_rules! decl_tests {
assert_ok!(Balances::reserve(&1, 110));
assert_ok!(Balances::repatriate_reserved(&1, &2, 41, Status::Free), 0);
System::assert_last_event(
Event::Balances(crate::Event::ReserveRepatriated { from: 1, to: 2, amount: 41, destination_status: Status::Free })
crate::Event::ReserveRepatriated { from: 1, to: 2, amount: 41, destination_status: Status::Free }.into()
);
assert_eq!(Balances::reserved_balance(1), 69);
assert_eq!(Balances::free_balance(1), 0);
Expand Down Expand Up @@ -724,18 +724,18 @@ macro_rules! decl_tests {
System::set_block_number(2);
assert_ok!(Balances::reserve(&1, 10));

System::assert_last_event(Event::Balances(crate::Event::Reserved { who: 1, amount: 10 }));
System::assert_last_event(crate::Event::Reserved { who: 1, amount: 10 }.into());

System::set_block_number(3);
assert!(Balances::unreserve(&1, 5).is_zero());

System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 }));
System::assert_last_event(crate::Event::Unreserved { who: 1, amount: 5 }.into());

System::set_block_number(4);
assert_eq!(Balances::unreserve(&1, 6), 1);

// should only unreserve 5
System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 }));
System::assert_last_event(crate::Event::Unreserved { who: 1, amount: 5 }.into());
});
}

Expand All @@ -750,9 +750,9 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::NewAccount { account: 1 }),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
system::Event::NewAccount { account: 1 }.into(),
crate::Event::Endowed { account: 1, free_balance: 100 }.into(),
crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(),
]
);

Expand All @@ -762,9 +762,9 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::KilledAccount { account: 1 }),
Event::Balances(crate::Event::DustLost { account: 1, amount: 99 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }),
system::Event::KilledAccount { account: 1 }.into(),
crate::Event::DustLost { account: 1, amount: 99 }.into(),
crate::Event::Slashed { who: 1, amount: 1 }.into(),
]
);
});
Expand All @@ -781,9 +781,9 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::NewAccount { account: 1 }),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
system::Event::NewAccount { account: 1 }.into(),
crate::Event::Endowed { account: 1, free_balance: 100 }.into(),
crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(),
]
);

Expand All @@ -793,8 +793,8 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::KilledAccount { account: 1 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 100 }),
system::Event::KilledAccount { account: 1 }.into(),
crate::Event::Slashed { who: 1, amount: 100 }.into(),
]
);
});
Expand All @@ -814,7 +814,7 @@ macro_rules! decl_tests {
assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0));
// Account is still alive
assert!(System::account_exists(&1));
System::assert_last_event(Event::Balances(crate::Event::Slashed { who: 1, amount: 900 }));
System::assert_last_event(crate::Event::Slashed { who: 1, amount: 900 }.into());

// SCENARIO: Slash will kill account because not enough balance left.
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
Expand Down
Loading

0 comments on commit 981c50f

Please sign in to comment.