Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposit events on genesis test #2610

Closed
wants to merge 14 commits into from
4 changes: 1 addition & 3 deletions cumulus/parachains/pallets/collective-content/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ impl WeightInfo for CCWeightInfo {
// Build test environment.
pub fn new_test_ext() -> sp_io::TestExternalities {
let t = RuntimeGenesisConfig::default().build_storage().unwrap().into();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
sp_io::TestExternalities::new(t)
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
4 changes: 0 additions & 4 deletions docs/sdk/src/guides/your_first_pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,6 @@ pub mod pallet_v2 {
#[test]
fn transfer_works() {
StateBuilder::default().build_and_execute(|| {
// skip the genesis block, as events are not deposited there and we need them for
// the final assertion.
System::set_block_number(1);

// given the the initial state, when:
assert_ok!(Pallet::<Runtime>::transfer(RuntimeOrigin::signed(1), 2, 50));

Expand Down
4 changes: 1 addition & 3 deletions substrate/frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,5 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
sp_io::TestExternalities::new(t)
}
4 changes: 1 addition & 3 deletions substrate/frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ impl ExtBuilder {
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
sp_io::TestExternalities::new(t)
}
pub fn build_and_execute_with(self, f: impl Fn()) {
let other = self.clone();
Expand Down
6 changes: 4 additions & 2 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,11 +1430,13 @@ impl<T: Config> Pallet<T> {
/// This will update storage entries that correspond to the specified topics.
/// It is expected that light-clients could subscribe to this topics.
///
/// NOTE: Events not registered at the genesis block and quietly omitted.
/// NOTE: Events not registered at the genesis block and `not(feature = "std")` and quietly
/// omitted. But, in testing (`feature = "std"`) events are deposited normally.
pub fn deposit_event_indexed(topics: &[T::Hash], event: T::RuntimeEvent) {
let block_number = Self::block_number();

// Don't populate events on genesis.
// Don't populate events on "real" genesis
#[cfg(not(feature = "std"))]
if block_number.is_zero() {
return
}
Expand Down
6 changes: 1 addition & 5 deletions substrate/frame/tx-pause/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
ext
sp_io::TestExternalities::new(t)
}

pub fn next_block() {
Expand Down
Loading