Skip to content

Commit feda93f

Browse files
committed
Switched to full extrinsic construction
1 parent cc18c1c commit feda93f

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

runtimes/bulletin-polkadot/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub use sp_runtime::{Perbill, Permill};
6666
mod polkadot_bridge_config;
6767
use polkadot_bridge_config::{self as bridge_config, bp_people_polkadot, bp_polkadot};
6868

69-
pub mod genesis_config_presets;
69+
mod genesis_config_presets;
7070
mod weights;
7171
mod xcm_config;
7272

runtimes/bulletin-polkadot/tests/tests.rs

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,51 @@ use bulletin_polkadot_runtime as runtime;
22
use frame_support::{assert_noop, assert_ok};
33
use frame_support::traits::Hooks;
44
use pallet_transaction_storage::{Call as TxCall, AuthorizationExtent, Error as TxError, BAD_DATA_SIZE};
5-
use sp_core::sr25519;
6-
use runtime::BuildStorage;
5+
use sp_core::{sr25519, Pair, Encode};
6+
use runtime::{Runtime, BuildStorage, RuntimeCall, UncheckedExtrinsic, TxExtension, SignedPayload, Executive, Hash};
7+
use sp_runtime::generic::Era;
8+
use sp_keyring::Sr25519Keyring;
9+
use sp_runtime::ApplyExtrinsicResult;
10+
11+
fn construct_extrinsic(
12+
sender: sp_core::sr25519::Pair,
13+
call: RuntimeCall,
14+
) -> Result<UncheckedExtrinsic, sp_runtime::transaction_validity::TransactionValidityError> {
15+
16+
let account_id = sp_runtime::AccountId32::from(sender.public());
17+
frame_system::BlockHash::<Runtime>::insert(0, Hash::default());
18+
let tx_ext: TxExtension = (
19+
frame_system::CheckNonZeroSender::<Runtime>::new(),
20+
frame_system::CheckSpecVersion::<Runtime>::new(),
21+
frame_system::CheckTxVersion::<Runtime>::new(),
22+
frame_system::CheckGenesis::<Runtime>::new(),
23+
frame_system::CheckEra::<Runtime>::from(Era::immortal()),
24+
frame_system::CheckNonce::<Runtime>::from(
25+
frame_system::Pallet::<Runtime>::account(&account_id).nonce,
26+
)
27+
.into(),
28+
frame_system::CheckWeight::<Runtime>::new(),
29+
runtime::ValidateSigned,
30+
runtime::BridgeRejectObsoleteHeadersAndMessages,
31+
)
32+
.into();
33+
let payload = SignedPayload::new(call.clone(), tx_ext.clone())?;
34+
let signature = payload.using_encoded(|e| sender.sign(e));
35+
Ok(UncheckedExtrinsic::new_signed(
36+
call,
37+
account_id.into(),
38+
runtime::Signature::Sr25519(signature),
39+
tx_ext,
40+
))
41+
}
42+
43+
fn construct_and_apply_extrinsic(
44+
account: sp_core::sr25519::Pair,
45+
call: RuntimeCall,
46+
) -> ApplyExtrinsicResult {
47+
let xt = construct_extrinsic(account, call)?;
48+
Executive::apply_extrinsic(xt)
49+
}
750

851
#[test]
952
fn transaction_storage_runtime_sizes() {
@@ -36,10 +79,10 @@ fn transaction_storage_runtime_sizes() {
3679
AuthorizationExtent { transactions: sizes.len() as u32, bytes: total_bytes },
3780
);
3881

82+
let alice_pair = Sr25519Keyring::Alice.pair();
3983
for size in sizes {
40-
let call = TxCall::<runtime::Runtime>::store { data: vec![0u8; size] };
41-
assert_ok!(runtime::TransactionStorage::pre_dispatch_signed(&who, &call));
42-
assert_ok!(runtime::TransactionStorage::store(runtime::RuntimeOrigin::none(), vec![0u8; size]));
84+
let call = RuntimeCall::TransactionStorage(TxCall::<runtime::Runtime>::store { data: vec![0u8; size] });
85+
assert_ok!(construct_and_apply_extrinsic(alice_pair.clone(), call));
4386
}
4487

4588
assert_eq!(
@@ -55,14 +98,11 @@ fn transaction_storage_runtime_sizes() {
5598
1,
5699
oversize as u64,
57100
));
58-
let too_big_call = TxCall::<runtime::Runtime>::store { data: vec![0u8; oversize] };
59-
assert_noop!(
60-
runtime::TransactionStorage::pre_dispatch_signed(&who, &too_big_call),
61-
BAD_DATA_SIZE,
62-
);
63-
assert_noop!(
64-
runtime::TransactionStorage::store(runtime::RuntimeOrigin::none(), vec![0u8; oversize]),
65-
TxError::<runtime::Runtime>::BadDataSize,
101+
let too_big_call = RuntimeCall::TransactionStorage(TxCall::<runtime::Runtime>::store { data: vec![0u8; oversize] });
102+
let res = construct_and_apply_extrinsic(alice_pair, too_big_call);
103+
assert_eq!(
104+
res,
105+
Err(BAD_DATA_SIZE.into())
66106
);
67107
});
68108
}

0 commit comments

Comments
 (0)