Skip to content

Commit 7192a7d

Browse files
committed
Replaced TransactionStorage run_to_block with all pallets run_to_block
1 parent 624a578 commit 7192a7d

File tree

1 file changed

+26
-18
lines changed
  • runtimes/bulletin-polkadot/tests

1 file changed

+26
-18
lines changed

runtimes/bulletin-polkadot/tests/tests.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
use bulletin_polkadot_runtime as runtime;
2-
use frame_support::assert_ok;
3-
use frame_support::traits::Hooks;
2+
use frame_support::{assert_ok, assert_noop};
3+
use frame_support::traits::{Hooks, OnIdle};
44
use pallet_transaction_storage::{Call as TxCall, AuthorizationExtent, BAD_DATA_SIZE};
5+
use frame_support::dispatch::GetDispatchInfo;
56
use sp_core::{Pair, Encode};
6-
use runtime::{RuntimeOrigin, TransactionStorage, System, Runtime, BuildStorage, RuntimeCall, UncheckedExtrinsic, TxExtension, SignedPayload, Executive, Hash};
7+
use runtime::{RuntimeOrigin, AllPalletsWithSystem, Weight, TransactionStorage, System, Runtime, BuildStorage, RuntimeCall, UncheckedExtrinsic, TxExtension, SignedPayload, Executive, Hash, Header};
78
use sp_runtime::generic::Era;
9+
use sp_runtime::traits::Header as _;
10+
use sp_runtime::traits::SaturatedConversion;
11+
use sp_runtime::traits::Dispatchable;
812
use sp_keyring::Sr25519Keyring;
913
use sp_runtime::ApplyExtrinsicResult;
1014
use sp_transaction_storage_proof::TransactionStorageProof;
1115

12-
pub fn run_to_block(n: u32, f: impl Fn() -> Option<TransactionStorageProof>) {
13-
while System::block_number() < n {
14-
if let Some(proof) = f() {
15-
TransactionStorage::check_proof(RuntimeOrigin::none(), proof).unwrap();
16-
}
17-
TransactionStorage::on_finalize(System::block_number());
18-
System::on_finalize(System::block_number());
19-
System::set_block_number(System::block_number() + 1);
20-
System::on_initialize(System::block_number());
21-
TransactionStorage::on_initialize(System::block_number());
22-
}
16+
fn run_to_block(n: u32) {
17+
System::run_to_block_with::<AllPalletsWithSystem>(
18+
n,
19+
frame_system::RunToBlockHooks::default().after_initialize(|bn| {
20+
AllPalletsWithSystem::on_idle(bn, Weight::MAX);
21+
}),
22+
);
23+
24+
let slot = runtime::Babe::current_slot();
25+
let now = slot.saturated_into::<u64>() * runtime::SLOT_DURATION;
26+
runtime::Timestamp::set(RuntimeOrigin::none(), now).unwrap();
2327
}
2428

2529
fn construct_extrinsic(
@@ -71,6 +75,10 @@ fn transaction_storage_runtime_sizes() {
7175
// Start at block 1
7276
runtime::System::set_block_number(1);
7377
runtime::TransactionStorage::on_initialize(1);
78+
// set timestamp for block 1
79+
let slot = runtime::Babe::current_slot();
80+
let now = slot.saturated_into::<u64>() * runtime::SLOT_DURATION;
81+
runtime::Timestamp::set(RuntimeOrigin::none(), now).unwrap();
7482

7583
let mut block_number: u32 = 1;
7684

@@ -79,8 +87,8 @@ fn transaction_storage_runtime_sizes() {
7987
2000, // 2 KB
8088
1 * 1024 * 1024, // 1 MB
8189
4 * 1024 * 1024, // 4 MB
82-
4 * 1024 * 1024, // another 4 MB (fails here)
83-
4 * 1024 * 1024, // another 4 MB
90+
6 * 1024 * 1024, // 6 MB
91+
8 * 1024 * 1024, // 8 MB
8492
];
8593
let total_bytes: u64 = sizes.iter().map(|s| *s as u64).sum();
8694

@@ -99,10 +107,10 @@ fn transaction_storage_runtime_sizes() {
99107
for size in sizes {
100108
let call = RuntimeCall::TransactionStorage(TxCall::<runtime::Runtime>::store { data: vec![0u8; size] });
101109
let res = construct_and_apply_extrinsic(alice_pair.clone(), call);
102-
assert!(res.is_ok(), "Failed at size={} bytes: {:?}", block_number, res);
110+
assert!(res.is_ok(), "Failed at size={} bytes: {:?}", size, res);
103111

104112
block_number += 1;
105-
run_to_block(block_number, || None);
113+
run_to_block(block_number);
106114
}
107115

108116
assert_eq!(

0 commit comments

Comments
 (0)