test-runtime: Return hashed call as provides in unsigned validation (#14180)

This is required to make different unsigned extrinsics resolve to different transactions in the tx
pool by having `provides` set to theh hash of the call.
This commit is contained in:
Bastian Köcher
2023-05-22 10:50:58 +02:00
committed by GitHub
parent 903d62beec
commit 86870ad0f0
2 changed files with 47 additions and 59 deletions
+38 -56
View File
@@ -995,7 +995,10 @@ mod tests {
use sp_consensus::BlockOrigin;
use sp_core::{storage::well_known_keys::HEAP_PAGES, ExecutionContext};
use sp_keyring::AccountKeyring;
use sp_runtime::{traits::SignedExtension, transaction_validity::InvalidTransaction};
use sp_runtime::{
traits::{Hash as _, SignedExtension},
transaction_validity::{InvalidTransaction, ValidTransaction},
};
use sp_state_machine::ExecutionStrategy;
use substrate_test_runtime_client::{
prelude::*, runtime::TestAPI, DefaultTestClientBuilderExt, TestClientBuilder,
@@ -1103,63 +1106,42 @@ mod tests {
fn validate_unsigned_works() {
sp_tracing::try_init_simple();
new_test_ext().execute_with(|| {
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::bench_call { transfer: Default::default() },
),
InvalidTransaction::Call.into(),
);
let failing_calls = vec![
substrate_test_pallet::Call::bench_call { transfer: Default::default() },
substrate_test_pallet::Call::include_data { data: vec![] },
substrate_test_pallet::Call::fill_block { ratio: Perbill::from_percent(50) },
];
let succeeding_calls = vec![
substrate_test_pallet::Call::deposit_log_digest_item {
log: DigestItem::Other(vec![]),
},
substrate_test_pallet::Call::storage_change { key: vec![], value: None },
substrate_test_pallet::Call::read { count: 0 },
substrate_test_pallet::Call::read_and_panic { count: 0 },
];
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::include_data { data: vec![] },
),
InvalidTransaction::Call.into(),
);
for call in failing_calls {
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call,
),
InvalidTransaction::Call.into(),
);
}
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::fill_block { ratio: Perbill::from_percent(50) },
),
InvalidTransaction::Call.into(),
);
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::deposit_log_digest_item {
log: DigestItem::Other(vec![])
},
),
Ok(Default::default()),
);
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::storage_change { key: vec![], value: None },
),
Ok(Default::default()),
);
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::read { count: 0 },
),
Ok(Default::default()),
);
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&substrate_test_pallet::Call::read_and_panic { count: 0 },
),
Ok(Default::default()),
);
for call in succeeding_calls {
assert_eq!(
<SubstrateTest as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
TransactionSource::External,
&call,
),
Ok(ValidTransaction {
provides: vec![BlakeTwo256::hash_of(&call).encode()],
..Default::default()
})
);
}
});
}