mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 17:25:41 +00:00
substrate-test-runtime migrated to "pure" frame runtime (#13737)
* substrate-test-runtime migrated to pure-frame based * test block builder: helpers added * simple renaming * basic_authorship test adjusted * block_building storage_proof test adjusted * babe: tests: should_panic expected added * babe: tests adjusted ConsensusLog::NextEpochData is now added by pallet_babe as pallet_babe::SameAuthoritiesForever trigger is used in runtime config. * beefy: tests adjusted test-substrate-runtime is now using frame::executive to finalize the block. during finalization the digests stored during block execution are checked against header digests: https://github.com/paritytech/substrate/blob/91bb2d29ca905599098a5b35eaf24867c4fbd60a/frame/executive/src/lib.rs#L585-L591 It makes impossible to directly manipulate header's digets, w/o depositing logs into system pallet storage `Digest<T: Config>`. Instead of this dedicated extrinsic allowing to store logs items (MmrRoot / AuthoritiesChange) is used. * grandpa: tests adjusted test-substrate-runtime is now using frame::executive to finalize the block. during finalization the digest logs stored during block execution are checked against header digest logs: https://github.com/paritytech/substrate/blob/91bb2d29ca905599098a5b35eaf24867c4fbd60a/frame/executive/src/lib.rs#L585-L591 It makes impossible to directly manipulate header's digets, w/o depositing logs into system pallet storage `Digest<T: Config>`. Instead of this dedicated extrinsic allowing to store logs items (ScheduledChange / ForcedChange and DigestItem::Other) is used. * network:bitswap: test adjusted The size of unchecked extrinsic was increased. The pattern used in test will be placed at the end of scale-encoded buffer. * runtime apis versions adjusted * storage keys used in runtime adjusted * wasm vs native tests removed * rpc tests: adjusted Transfer transaction processing was slightly improved, test was adjusted. * tests: sizes adjusted Runtime extrinsic size was increased. Size of data read during block execution was also increased due to usage of new pallets in runtime. Sizes were adjusted in tests. * cargo.lock update cargo update -p substrate-test-runtime -p substrate-test-runtime-client * warnings fixed * builders cleanup: includes / std * extrinsic validation cleanup * txpool: benches performance fixed * fmt * spelling * Apply suggestions from code review Co-authored-by: Davide Galassi <davxy@datawok.net> * Apply code review suggestions * Apply code review suggestions * get rid of 1063 const * renaming: UncheckedExtrinsic -> Extrinsic * test-utils-runtime: further step to pure-frame * basic-authorship: tests OK * CheckSubstrateCall added + tests fixes * test::Transfer call removed * priority / propagate / no sudo+root-testing * fixing warnings + format * cleanup: build2/nonce + format * final tests fixes all tests are passing * logs/comments removal * should_not_accept_old_signatures test removed * make txpool benches work again * Cargo.lock reset * format * sudo hack removed * txpool benches fix+cleanup * .gitignore reverted * rebase fixing + unsigned cleanup * Cargo.toml/Cargo.lock cleanup * force-debug feature removed * mmr tests fixed * make cargo-clippy happy * network sync test uses unsigned extrinsic * cleanup * ".git/.scripts/commands/fmt/fmt.sh" * push_storage_change signed call remove * GenesisConfig cleanup * fix * fix * GenesisConfig simplified * storage_keys_works: reworked * storage_keys_works: expected keys in vec * storage keys list moved to substrate-test-runtime * substrate-test: some sanity tests + GenesisConfigBuilder rework * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * Apply suggestions from code review * Review suggestions * fix * fix * beefy: generate_blocks_and_sync block_num sync with actaul value * Apply suggestions from code review Co-authored-by: Davide Galassi <davxy@datawok.net> * Update test-utils/runtime/src/genesismap.rs Co-authored-by: Davide Galassi <davxy@datawok.net> * cargo update -p sc-rpc -p sc-transaction-pool * Review suggestions * fix * doc added * slot_duration adjusted for Babe::slot_duration * small doc fixes * array_bytes::hex used instead of hex * tiny -> medium name fix * Apply suggestions from code review Co-authored-by: Sebastian Kunert <skunert49@gmail.com> * TransferData::try_from_unchecked_extrinsic -> try_from * Update Cargo.lock --------- Co-authored-by: parity-processbot <> Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3a90728de0
commit
6a295e7c28
@@ -18,7 +18,7 @@
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use codec::Encode;
|
||||
use futures::{
|
||||
executor::block_on,
|
||||
future::{ready, Ready},
|
||||
@@ -33,7 +33,7 @@ use sp_runtime::{
|
||||
ValidTransaction,
|
||||
},
|
||||
};
|
||||
use substrate_test_runtime::{AccountId, Block, Extrinsic, Transfer, H256};
|
||||
use substrate_test_runtime::{AccountId, Block, Extrinsic, ExtrinsicBuilder, TransferData, H256};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct TestApi {
|
||||
@@ -65,8 +65,10 @@ impl ChainApi for TestApi {
|
||||
_source: TransactionSource,
|
||||
uxt: <Self::Block as BlockT>::Extrinsic,
|
||||
) -> Self::ValidationFuture {
|
||||
let nonce = uxt.transfer().nonce;
|
||||
let from = uxt.transfer().from;
|
||||
let transfer = TransferData::try_from(&uxt)
|
||||
.expect("uxt is expected to be bench_call (carrying TransferData)");
|
||||
let nonce = transfer.nonce;
|
||||
let from = transfer.from;
|
||||
|
||||
match self.block_id_to_number(at) {
|
||||
Ok(Some(num)) if num > 5 => return ready(Ok(Err(InvalidTransaction::Stale.into()))),
|
||||
@@ -131,13 +133,8 @@ impl ChainApi for TestApi {
|
||||
}
|
||||
}
|
||||
|
||||
fn uxt(transfer: Transfer) -> Extrinsic {
|
||||
Extrinsic::Transfer {
|
||||
transfer,
|
||||
signature: Decode::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
|
||||
.expect("infinite input; no dead input space; qed"),
|
||||
exhaust_resources_when_not_first: false,
|
||||
}
|
||||
fn uxt(transfer: TransferData) -> Extrinsic {
|
||||
ExtrinsicBuilder::new_bench_call(transfer).build()
|
||||
}
|
||||
|
||||
fn bench_configured(pool: Pool<TestApi>, number: u64) {
|
||||
@@ -146,7 +143,7 @@ fn bench_configured(pool: Pool<TestApi>, number: u64) {
|
||||
let mut tags = Vec::new();
|
||||
|
||||
for nonce in 1..=number {
|
||||
let xt = uxt(Transfer {
|
||||
let xt = uxt(TransferData {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
|
||||
@@ -463,7 +463,8 @@ mod tests {
|
||||
use sc_transaction_pool_api::TransactionStatus;
|
||||
use sp_runtime::transaction_validity::TransactionSource;
|
||||
use std::{collections::HashMap, time::Instant};
|
||||
use substrate_test_runtime::{AccountId, Extrinsic, Transfer, H256};
|
||||
use substrate_test_runtime::{AccountId, ExtrinsicBuilder, Transfer, H256};
|
||||
use substrate_test_runtime_client::AccountKeyring::{Alice, Bob};
|
||||
|
||||
const SOURCE: TransactionSource = TransactionSource::External;
|
||||
|
||||
@@ -477,7 +478,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -494,7 +495,7 @@ mod tests {
|
||||
// given
|
||||
let pool = pool();
|
||||
let uxt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -520,8 +521,8 @@ mod tests {
|
||||
TestApi::default().into(),
|
||||
);
|
||||
|
||||
// after validation `IncludeData` will be set to non-propagable
|
||||
let uxt = Extrinsic::IncludeData(vec![42]);
|
||||
// after validation `IncludeData` will be set to non-propagable (validate_transaction mock)
|
||||
let uxt = ExtrinsicBuilder::new_include_data(vec![42]).build();
|
||||
|
||||
// when
|
||||
let res = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, uxt));
|
||||
@@ -542,7 +543,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -553,7 +554,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
@@ -565,7 +566,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 3,
|
||||
@@ -594,7 +595,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -605,7 +606,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
@@ -616,7 +617,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 3,
|
||||
@@ -645,7 +646,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -659,27 +660,27 @@ mod tests {
|
||||
// then
|
||||
assert!(pool.validated_pool.is_banned(&hash1));
|
||||
}
|
||||
use codec::Encode;
|
||||
|
||||
#[test]
|
||||
fn should_limit_futures() {
|
||||
sp_tracing::try_init_simple();
|
||||
|
||||
let xt = uxt(Transfer {
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
});
|
||||
|
||||
// given
|
||||
let limit = Limit { count: 100, total_bytes: 200 };
|
||||
let limit = Limit { count: 100, total_bytes: xt.encoded_size() };
|
||||
|
||||
let options = Options { ready: limit.clone(), future: limit.clone(), ..Default::default() };
|
||||
|
||||
let pool = Pool::new(options, true.into(), TestApi::default().into());
|
||||
|
||||
let hash1 = block_on(pool.submit_one(
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
}),
|
||||
))
|
||||
.unwrap();
|
||||
let hash1 = block_on(pool.submit_one(&BlockId::Number(0), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().future, 1);
|
||||
|
||||
// when
|
||||
@@ -687,7 +688,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
from: Bob.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 10,
|
||||
@@ -715,7 +716,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
@@ -738,7 +739,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: INVALID_NONCE,
|
||||
@@ -763,7 +764,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -795,7 +796,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -828,7 +829,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
@@ -843,7 +844,7 @@ mod tests {
|
||||
&BlockId::Number(0),
|
||||
SOURCE,
|
||||
uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -863,7 +864,7 @@ mod tests {
|
||||
// given
|
||||
let pool = pool();
|
||||
let uxt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -887,7 +888,7 @@ mod tests {
|
||||
// given
|
||||
let pool = pool();
|
||||
let uxt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -918,7 +919,7 @@ mod tests {
|
||||
let pool = Pool::new(options, true.into(), TestApi::default().into());
|
||||
|
||||
let xt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -928,7 +929,7 @@ mod tests {
|
||||
|
||||
// when
|
||||
let xt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
from: Bob.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
amount: 4,
|
||||
nonce: 1,
|
||||
@@ -952,13 +953,17 @@ mod tests {
|
||||
|
||||
let pool = Pool::new(options, true.into(), TestApi::default().into());
|
||||
|
||||
let xt = Extrinsic::IncludeData(Vec::new());
|
||||
// after validation `IncludeData` will have priority set to 9001
|
||||
// (validate_transaction mock)
|
||||
let xt = ExtrinsicBuilder::new_include_data(Vec::new()).build();
|
||||
block_on(pool.submit_one(&BlockId::Number(0), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// then
|
||||
// after validation `Transfer` will have priority set to 4 (validate_transaction
|
||||
// mock)
|
||||
let xt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
from: Bob.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
amount: 4,
|
||||
nonce: 1,
|
||||
@@ -977,12 +982,16 @@ mod tests {
|
||||
|
||||
let pool = Pool::new(options, true.into(), TestApi::default().into());
|
||||
|
||||
let xt = Extrinsic::IncludeData(Vec::new());
|
||||
// after validation `IncludeData` will have priority set to 9001
|
||||
// (validate_transaction mock)
|
||||
let xt = ExtrinsicBuilder::new_include_data(Vec::new()).build();
|
||||
block_on(pool.submit_and_watch(&BlockId::Number(0), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
|
||||
// after validation `Transfer` will have priority set to 4 (validate_transaction
|
||||
// mock)
|
||||
let xt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
@@ -992,7 +1001,9 @@ mod tests {
|
||||
assert_eq!(pool.validated_pool().status().ready, 2);
|
||||
|
||||
// when
|
||||
let xt = Extrinsic::Store(Vec::new());
|
||||
// after validation `Store` will have priority set to 9001 (validate_transaction
|
||||
// mock)
|
||||
let xt = ExtrinsicBuilder::new_indexed_call(Vec::new()).build();
|
||||
block_on(pool.submit_one(&BlockId::Number(1), SOURCE, xt)).unwrap();
|
||||
assert_eq!(pool.validated_pool().status().ready, 2);
|
||||
|
||||
@@ -1014,7 +1025,7 @@ mod tests {
|
||||
|
||||
// when
|
||||
let xt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 1,
|
||||
@@ -1030,7 +1041,7 @@ mod tests {
|
||||
// But now before the previous one is imported we import
|
||||
// the one that it depends on.
|
||||
let xt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 4,
|
||||
nonce: 0,
|
||||
|
||||
@@ -362,6 +362,7 @@ mod tests {
|
||||
use sc_transaction_pool_api::TransactionSource;
|
||||
use sp_runtime::generic::BlockId;
|
||||
use substrate_test_runtime::{AccountId, Transfer, H256};
|
||||
use substrate_test_runtime_client::AccountKeyring::Alice;
|
||||
|
||||
#[test]
|
||||
fn revalidation_queue_works() {
|
||||
@@ -370,7 +371,7 @@ mod tests {
|
||||
let queue = Arc::new(RevalidationQueue::new(api.clone(), pool.clone()));
|
||||
|
||||
let uxt = uxt(Transfer {
|
||||
from: AccountId::from_h256(H256::from_low_u64_be(1)),
|
||||
from: Alice.into(),
|
||||
to: AccountId::from_h256(H256::from_low_u64_be(2)),
|
||||
amount: 5,
|
||||
nonce: 0,
|
||||
|
||||
@@ -31,7 +31,10 @@ use sp_runtime::{
|
||||
},
|
||||
};
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use substrate_test_runtime::{Block, Extrinsic, Hashing, Transfer, H256};
|
||||
use substrate_test_runtime::{
|
||||
substrate_test_pallet::pallet::Call as PalletCall, BalancesCall, Block, Extrinsic,
|
||||
ExtrinsicBuilder, Hashing, RuntimeCall, Transfer, TransferData, H256,
|
||||
};
|
||||
|
||||
pub(crate) const INVALID_NONCE: u64 = 254;
|
||||
|
||||
@@ -70,9 +73,11 @@ impl ChainApi for TestApi {
|
||||
let block_number = self.block_id_to_number(at).unwrap().unwrap();
|
||||
|
||||
let res = match uxt {
|
||||
Extrinsic::Transfer { transfer, .. } => {
|
||||
let nonce = transfer.nonce;
|
||||
|
||||
Extrinsic {
|
||||
function: RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }),
|
||||
..
|
||||
} => {
|
||||
let TransferData { nonce, .. } = (&uxt).try_into().unwrap();
|
||||
// This is used to control the test flow.
|
||||
if nonce > 0 {
|
||||
let opt = self.delay.lock().take();
|
||||
@@ -115,14 +120,20 @@ impl ChainApi for TestApi {
|
||||
Ok(transaction)
|
||||
}
|
||||
},
|
||||
Extrinsic::IncludeData(_) => Ok(ValidTransaction {
|
||||
Extrinsic {
|
||||
function: RuntimeCall::SubstrateTest(PalletCall::include_data { .. }),
|
||||
..
|
||||
} => Ok(ValidTransaction {
|
||||
priority: 9001,
|
||||
requires: vec![],
|
||||
provides: vec![vec![42]],
|
||||
longevity: 9001,
|
||||
propagate: false,
|
||||
}),
|
||||
Extrinsic::Store(_) => Ok(ValidTransaction {
|
||||
Extrinsic {
|
||||
function: RuntimeCall::SubstrateTest(PalletCall::indexed_call { .. }),
|
||||
..
|
||||
} => Ok(ValidTransaction {
|
||||
priority: 9001,
|
||||
requires: vec![],
|
||||
provides: vec![vec![43]],
|
||||
@@ -185,8 +196,7 @@ impl ChainApi for TestApi {
|
||||
}
|
||||
|
||||
pub(crate) fn uxt(transfer: Transfer) -> Extrinsic {
|
||||
let signature = TryFrom::try_from(&[0; 64][..]).unwrap();
|
||||
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: false }
|
||||
ExtrinsicBuilder::new_transfer(transfer).build()
|
||||
}
|
||||
|
||||
pub(crate) fn pool() -> Pool<TestApi> {
|
||||
|
||||
@@ -35,11 +35,11 @@ use sp_consensus::BlockOrigin;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::Block as _,
|
||||
transaction_validity::{InvalidTransaction, TransactionSource, ValidTransaction},
|
||||
transaction_validity::{TransactionSource, ValidTransaction},
|
||||
};
|
||||
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
|
||||
use substrate_test_runtime_client::{
|
||||
runtime::{Block, Extrinsic, Hash, Header, Index, Transfer},
|
||||
runtime::{Block, Extrinsic, ExtrinsicBuilder, Hash, Header, Index, Transfer, TransferData},
|
||||
AccountKeyring::*,
|
||||
ClientBlockImportExt,
|
||||
};
|
||||
@@ -86,7 +86,11 @@ fn submission_should_work() {
|
||||
let pool = pool();
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 209))).unwrap();
|
||||
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, vec![209]);
|
||||
}
|
||||
|
||||
@@ -96,16 +100,25 @@ fn multiple_submission_should_work() {
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 209))).unwrap();
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 210))).unwrap();
|
||||
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, vec![209, 210]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn early_nonce_should_be_culled() {
|
||||
sp_tracing::try_init_simple();
|
||||
let pool = pool();
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 208))).unwrap();
|
||||
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, Vec::<Index>::new());
|
||||
}
|
||||
|
||||
@@ -114,11 +127,19 @@ fn late_nonce_should_be_queued() {
|
||||
let pool = pool();
|
||||
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 210))).unwrap();
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, Vec::<Index>::new());
|
||||
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 209))).unwrap();
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, vec![209, 210]);
|
||||
}
|
||||
|
||||
@@ -128,14 +149,22 @@ fn prune_tags_should_work() {
|
||||
let hash209 = block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 209))).unwrap();
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 210))).unwrap();
|
||||
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, vec![209, 210]);
|
||||
|
||||
pool.validated_pool().api().push_block(1, Vec::new(), true);
|
||||
block_on(pool.prune_tags(&BlockId::number(1), vec![vec![209]], vec![hash209]))
|
||||
.expect("Prune tags");
|
||||
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, vec![210]);
|
||||
}
|
||||
|
||||
@@ -148,7 +177,11 @@ fn should_ban_invalid_transactions() {
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt.clone())).unwrap_err();
|
||||
|
||||
// when
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, Vec::<Index>::new());
|
||||
|
||||
// then
|
||||
@@ -197,7 +230,11 @@ fn should_correctly_prune_transactions_providing_more_than_one_tag() {
|
||||
block_on(pool.submit_one(&BlockId::number(2), SOURCE, xt.clone())).expect("2. Imported");
|
||||
assert_eq!(pool.validated_pool().status().ready, 1);
|
||||
assert_eq!(pool.validated_pool().status().future, 1);
|
||||
let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect();
|
||||
let pending: Vec<_> = pool
|
||||
.validated_pool()
|
||||
.ready()
|
||||
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
|
||||
.collect();
|
||||
assert_eq!(pending, vec![211]);
|
||||
|
||||
// prune it and make sure the pool is empty
|
||||
@@ -472,6 +509,7 @@ fn finalization() {
|
||||
|
||||
#[test]
|
||||
fn fork_aware_finalization() {
|
||||
sp_tracing::try_init_simple();
|
||||
let api = TestApi::empty();
|
||||
// starting block A1 (last finalized.)
|
||||
let a_header = api.push_block(1, vec![], true);
|
||||
@@ -888,48 +926,6 @@ fn ready_set_should_eventually_resolve_when_block_update_arrives() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_accept_old_signatures() {
|
||||
let client = Arc::new(substrate_test_runtime_client::new());
|
||||
let best_hash = client.info().best_hash;
|
||||
let finalized_hash = client.info().finalized_hash;
|
||||
let pool = Arc::new(
|
||||
BasicPool::new_test(
|
||||
Arc::new(FullChainApi::new(client, None, &sp_core::testing::TaskExecutor::new())),
|
||||
best_hash,
|
||||
finalized_hash,
|
||||
)
|
||||
.0,
|
||||
);
|
||||
|
||||
let transfer = Transfer { from: Alice.into(), to: Bob.into(), nonce: 0, amount: 1 };
|
||||
let _bytes: sp_core::sr25519::Signature = transfer.using_encoded(|e| Alice.sign(e)).into();
|
||||
|
||||
// generated with schnorrkel 0.1.1 from `_bytes`
|
||||
let old_singature = sp_core::sr25519::Signature::try_from(
|
||||
&array_bytes::hex2bytes(
|
||||
"c427eb672e8c441c86d31f1a81b22b43102058e9ce237cabe9897ea5099ffd426\
|
||||
cd1c6a1f4f2869c3df57901d36bedcb295657adb3a4355add86ed234eb83108",
|
||||
)
|
||||
.expect("hex invalid")[..],
|
||||
)
|
||||
.expect("signature construction failed");
|
||||
|
||||
let xt = Extrinsic::Transfer {
|
||||
transfer,
|
||||
signature: old_singature,
|
||||
exhaust_resources_when_not_first: false,
|
||||
};
|
||||
|
||||
assert_matches::assert_matches!(
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())),
|
||||
Err(error::Error::Pool(sc_transaction_pool_api::error::Error::InvalidTransaction(
|
||||
InvalidTransaction::BadProof
|
||||
))),
|
||||
"Should be invalid transaction with bad proof",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_notification_to_pool_maintain_works() {
|
||||
let mut client = Arc::new(substrate_test_runtime_client::new());
|
||||
@@ -975,7 +971,7 @@ fn import_notification_to_pool_maintain_works() {
|
||||
fn pruning_a_transaction_should_remove_it_from_best_transaction() {
|
||||
let (pool, api, _guard) = maintained_pool();
|
||||
|
||||
let xt1 = Extrinsic::IncludeData(Vec::new());
|
||||
let xt1 = ExtrinsicBuilder::new_include_data(Vec::new()).build();
|
||||
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt1.clone())).expect("1. Imported");
|
||||
assert_eq!(pool.status().ready, 1);
|
||||
@@ -1001,7 +997,7 @@ fn stale_transactions_are_pruned() {
|
||||
let (pool, api, _guard) = maintained_pool();
|
||||
|
||||
xts.into_iter().for_each(|xt| {
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.into_signed_tx()))
|
||||
block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.into_unchecked_extrinsic()))
|
||||
.expect("1. Imported");
|
||||
});
|
||||
assert_eq!(pool.status().ready, 0);
|
||||
@@ -1010,9 +1006,12 @@ fn stale_transactions_are_pruned() {
|
||||
// Almost the same as our initial transactions, but with some different `amount`s to make them
|
||||
// generate a different hash
|
||||
let xts = vec![
|
||||
Transfer { from: Alice.into(), to: Bob.into(), nonce: 1, amount: 2 }.into_signed_tx(),
|
||||
Transfer { from: Alice.into(), to: Bob.into(), nonce: 2, amount: 2 }.into_signed_tx(),
|
||||
Transfer { from: Alice.into(), to: Bob.into(), nonce: 3, amount: 2 }.into_signed_tx(),
|
||||
Transfer { from: Alice.into(), to: Bob.into(), nonce: 1, amount: 2 }
|
||||
.into_unchecked_extrinsic(),
|
||||
Transfer { from: Alice.into(), to: Bob.into(), nonce: 2, amount: 2 }
|
||||
.into_unchecked_extrinsic(),
|
||||
Transfer { from: Alice.into(), to: Bob.into(), nonce: 3, amount: 2 }
|
||||
.into_unchecked_extrinsic(),
|
||||
];
|
||||
|
||||
// Import block
|
||||
|
||||
Reference in New Issue
Block a user