Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

substrate-test-runtime migrated to "pure" frame runtime #13737

Merged
merged 87 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
79c54bc
substrate-test-runtime migrated to pure-frame based
michalkucharczyk Mar 28, 2023
bde190c
test block builder: helpers added
michalkucharczyk Mar 28, 2023
bca82c1
simple renaming
michalkucharczyk Mar 28, 2023
b02b857
basic_authorship test adjusted
michalkucharczyk Mar 28, 2023
6ad4794
block_building storage_proof test adjusted
michalkucharczyk Mar 28, 2023
fb9ccd9
babe: tests: should_panic expected added
michalkucharczyk Mar 28, 2023
46b0c0d
babe: tests adjusted
michalkucharczyk Mar 28, 2023
1f092be
beefy: tests adjusted
michalkucharczyk Mar 28, 2023
8779211
grandpa: tests adjusted
michalkucharczyk Mar 28, 2023
4ea7a7d
network:bitswap: test adjusted
michalkucharczyk Mar 28, 2023
b64afdb
runtime apis versions adjusted
michalkucharczyk Mar 28, 2023
8772c8a
storage keys used in runtime adjusted
michalkucharczyk Mar 28, 2023
95eac77
wasm vs native tests removed
michalkucharczyk Mar 28, 2023
7d0c0eb
rpc tests: adjusted
michalkucharczyk Mar 28, 2023
cacd226
tests: sizes adjusted
michalkucharczyk Mar 28, 2023
bd43792
cargo.lock update
michalkucharczyk Mar 28, 2023
6fa4ac2
warnings fixed
michalkucharczyk Mar 28, 2023
2125300
builders cleanup: includes / std
michalkucharczyk Mar 28, 2023
3603ab9
extrinsic validation cleanup
michalkucharczyk Mar 29, 2023
76e4792
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
Mar 29, 2023
89000e3
txpool: benches performance fixed
michalkucharczyk Mar 29, 2023
4513a70
fmt
michalkucharczyk Mar 29, 2023
53d37b0
spelling
michalkucharczyk Mar 30, 2023
c43a9dc
Apply suggestions from code review
michalkucharczyk Mar 30, 2023
2b536fc
Apply code review suggestions
michalkucharczyk Mar 30, 2023
14ac282
Apply code review suggestions
michalkucharczyk Mar 30, 2023
4990127
get rid of 1063 const
michalkucharczyk Mar 30, 2023
906f646
renaming: UncheckedExtrinsic -> Extrinsic
michalkucharczyk Mar 31, 2023
63cdbb2
test-utils-runtime: further step to pure-frame
michalkucharczyk Apr 4, 2023
b94002b
basic-authorship: tests OK
michalkucharczyk Apr 4, 2023
c17fac1
CheckSubstrateCall added + tests fixes
michalkucharczyk Apr 5, 2023
e8e73c3
test::Transfer call removed
michalkucharczyk Apr 12, 2023
18abfaf
priority / propagate / no sudo+root-testing
michalkucharczyk Apr 12, 2023
b7f9423
fixing warnings + format
michalkucharczyk Apr 12, 2023
f5fd0d9
cleanup: build2/nonce + format
michalkucharczyk Apr 13, 2023
05701e4
final tests fixes
michalkucharczyk Apr 13, 2023
4a05623
logs/comments removal
michalkucharczyk Apr 13, 2023
44c073d
should_not_accept_old_signatures test removed
michalkucharczyk Apr 13, 2023
cf1a8b5
make txpool benches work again
michalkucharczyk Apr 13, 2023
b25d035
Cargo.lock reset
michalkucharczyk Apr 13, 2023
7061723
format
michalkucharczyk Apr 13, 2023
d9b8cd7
sudo hack removed
michalkucharczyk Apr 13, 2023
2200471
txpool benches fix+cleanup
michalkucharczyk Apr 14, 2023
1ec59d2
.gitignore reverted
michalkucharczyk Apr 14, 2023
25fb0cf
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
michalkucharczyk Apr 14, 2023
e1549f7
rebase fixing + unsigned cleanup
michalkucharczyk Apr 14, 2023
1042f26
Cargo.toml/Cargo.lock cleanup
michalkucharczyk Apr 14, 2023
18c0d16
force-debug feature removed
michalkucharczyk Apr 14, 2023
abf87b5
mmr tests fixed
michalkucharczyk Apr 14, 2023
04784ad
make cargo-clippy happy
michalkucharczyk Apr 14, 2023
98a736e
network sync test uses unsigned extrinsic
michalkucharczyk Apr 14, 2023
ecd4f9c
cleanup
michalkucharczyk Apr 14, 2023
6efc711
".git/.scripts/commands/fmt/fmt.sh"
Apr 14, 2023
c5a8bd8
push_storage_change signed call remove
michalkucharczyk Apr 17, 2023
2b47289
GenesisConfig cleanup
michalkucharczyk Apr 17, 2023
63866f0
fix
michalkucharczyk Apr 17, 2023
31f3d80
fix
michalkucharczyk Apr 17, 2023
88683c8
GenesisConfig simplified
michalkucharczyk Apr 18, 2023
c956f06
storage_keys_works: reworked
michalkucharczyk Apr 18, 2023
f6aefcd
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
michalkucharczyk Apr 18, 2023
bc2b6be
storage_keys_works: expected keys in vec
michalkucharczyk Apr 19, 2023
a115071
storage keys list moved to substrate-test-runtime
michalkucharczyk Apr 19, 2023
b71a5b3
substrate-test: some sanity tests + GenesisConfigBuilder rework
michalkucharczyk Apr 19, 2023
8004fe9
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
Apr 25, 2023
ae1997a
Apply suggestions from code review
michalkucharczyk Apr 26, 2023
259f871
Apply suggestions from code review
michalkucharczyk Apr 26, 2023
22069a0
Review suggestions
michalkucharczyk Apr 26, 2023
042f2e4
fix
michalkucharczyk Apr 26, 2023
6b64277
fix
michalkucharczyk Apr 26, 2023
6443a9d
beefy: generate_blocks_and_sync block_num sync with actaul value
michalkucharczyk Apr 26, 2023
734ddfd
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
May 2, 2023
65e03c8
Apply suggestions from code review
michalkucharczyk May 3, 2023
123b023
Update test-utils/runtime/src/genesismap.rs
michalkucharczyk May 3, 2023
5c58b38
cargo update -p sc-rpc -p sc-transaction-pool
michalkucharczyk May 3, 2023
f31082b
Review suggestions
michalkucharczyk May 3, 2023
ab177b0
fix
michalkucharczyk May 3, 2023
c5970e8
doc added
michalkucharczyk May 3, 2023
1a7325e
slot_duration adjusted for Babe::slot_duration
michalkucharczyk May 3, 2023
ff0a322
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
May 3, 2023
9656ae9
small doc fixes
michalkucharczyk May 3, 2023
c83d009
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
May 3, 2023
3c4c413
array_bytes::hex used instead of hex
michalkucharczyk May 3, 2023
2bff606
tiny -> medium name fix
michalkucharczyk May 4, 2023
194b1df
Apply suggestions from code review
michalkucharczyk May 4, 2023
9597261
TransferData::try_from_unchecked_extrinsic -> try_from
michalkucharczyk May 4, 2023
ddf3ce1
Merge remote-tracking branch 'origin/master' into mku-refactor-substr…
michalkucharczyk May 4, 2023
7a01bb6
Update Cargo.lock
michalkucharczyk May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

180 changes: 111 additions & 69 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,37 +547,29 @@ mod tests {
use sp_api::Core;
use sp_blockchain::HeaderBackend;
use sp_consensus::{BlockOrigin, Environment, Proposer};
use sp_core::Pair;
use sp_runtime::{generic::BlockId, traits::NumberFor};
use sp_runtime::{generic::BlockId, traits::NumberFor, Perbill};
use substrate_test_runtime_client::{
prelude::*,
runtime::{Extrinsic, Transfer},
runtime::{Block as TestBlock, Extrinsic, ExtrinsicBuilder, Transfer},
TestClientBuilder, TestClientBuilderExt,
};

const SOURCE: TransactionSource = TransactionSource::External;

fn extrinsic(nonce: u64) -> Extrinsic {
Transfer {
amount: Default::default(),
nonce,
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
}
.into_signed_tx()
}
// Note:
// Maximum normal extrinsic size for substrate_test_runtime is ~65% of max_block (refer to
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
// substrate_test_runtime::RuntimeBlockWeights for details).
// This extrinsic sizing allows for:
// - one huge xts + a lot of tiny dust
// - one huge, no medium,
// - two medium xts
// This is widely exploited in following tests.
const HUGE: u32 = 649000000;
const MEDIUM: u32 = 250000000;
const TINY: u32 = 1000;
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved

fn exhausts_resources_extrinsic_from(who: usize) -> Extrinsic {
let pair = AccountKeyring::numeric(who);
let transfer = Transfer {
// increase the amount to bump priority
amount: 1,
nonce: 0,
from: pair.public(),
to: AccountKeyring::Bob.into(),
};
let signature = pair.sign(&transfer.encode()).into();
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: true }
fn extrinsic(nonce: u64) -> Extrinsic {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(TINY)).nonce(nonce).build()
}

fn chain_event<B: BlockT>(header: B::Header) -> ChainEvent<B>
Expand Down Expand Up @@ -738,7 +730,7 @@ mod tests {
#[test]
fn should_not_remove_invalid_transactions_from_the_same_sender_after_one_was_invalid() {
// given
let mut client = Arc::new(substrate_test_runtime_client::new());
let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full(
Default::default(),
Expand All @@ -748,38 +740,29 @@ mod tests {
client.clone(),
);

let tiny = |nonce| {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(MEDIUM))
.nonce(nonce)
.build()
};
let huge = |nonce| {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(HUGE)).nonce(nonce).build()
};

block_on(txpool.submit_at(
&BlockId::number(0),
SOURCE,
vec![
extrinsic(0),
extrinsic(1),
Transfer {
amount: Default::default(),
nonce: 2,
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
}.into_resources_exhausting_tx(),
extrinsic(3),
Transfer {
amount: Default::default(),
nonce: 4,
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
}.into_resources_exhausting_tx(),
extrinsic(5),
extrinsic(6),
],
vec![tiny(0), tiny(1), huge(2), tiny(3), huge(4), tiny(5), tiny(6)],
))
.unwrap();

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), None, None);
let mut propose_block = |client: &TestClient,
number,
parent_number,
expected_block_extrinsics,
expected_pool_transactions| {
let hash = client.expect_block_hash_from_id(&BlockId::Number(number)).unwrap();
let hash = client.expect_block_hash_from_id(&BlockId::Number(parent_number)).unwrap();
let proposer = proposer_factory.init_with_now(
&client.expect_header(hash).unwrap(),
Box::new(move || time::Instant::now()),
Expand All @@ -794,12 +777,30 @@ mod tests {

// then
// block should have some extrinsics although we have some more in the pool.
assert_eq!(txpool.ready().count(), expected_pool_transactions);
assert_eq!(block.extrinsics().len(), expected_block_extrinsics);
assert_eq!(
txpool.ready().count(),
expected_pool_transactions,
"at block: {}",
block.header.number
);
assert_eq!(
block.extrinsics().len(),
expected_block_extrinsics,
"at block: {}",
block.header.number
);

block
};

let import_and_maintain = |mut client: Arc<TestClient>, block: TestBlock| {
let hash = block.hash();
block_on(client.import(BlockOrigin::Own, block)).unwrap();
block_on(txpool.maintain(chain_event(
client.expect_header(hash).expect("there should be header"),
)));
};

block_on(
txpool.maintain(chain_event(
client
Expand All @@ -811,19 +812,28 @@ mod tests {

// let's create one block and import it
let block = propose_block(&client, 0, 2, 7);
skunert marked this conversation as resolved.
Show resolved Hide resolved
let hashof1 = block.hash();
block_on(client.import(BlockOrigin::Own, block)).unwrap();

block_on(
txpool.maintain(chain_event(
client.expect_header(hashof1).expect("there should be header"),
)),
);
import_and_maintain(client.clone(), block);
assert_eq!(txpool.ready().count(), 5);

// now let's make sure that we can still make some progress
let block = propose_block(&client, 1, 2, 5);
block_on(client.import(BlockOrigin::Own, block)).unwrap();
let block = propose_block(&client, 1, 1, 5);
import_and_maintain(client.clone(), block);
assert_eq!(txpool.ready().count(), 4);

// again let's make sure that we can still make some progress
let block = propose_block(&client, 2, 1, 4);
import_and_maintain(client.clone(), block);
assert_eq!(txpool.ready().count(), 3);

// again let's make sure that we can still make some progress
let block = propose_block(&client, 3, 1, 3);
import_and_maintain(client.clone(), block);
assert_eq!(txpool.ready().count(), 2);

// again let's make sure that we can still make some progress
let block = propose_block(&client, 4, 2, 2);
import_and_maintain(client.clone(), block);
assert_eq!(txpool.ready().count(), 0);
}

#[test]
Expand All @@ -849,9 +859,9 @@ mod tests {
amount: 100,
nonce: 0,
}
.into_signed_tx(),
.into_unchecked_extrinsic(),
)
.chain((0..extrinsics_num - 1).map(|v| Extrinsic::IncludeData(vec![v as u8; 10])))
.chain((0..extrinsics_num - 1).map(|v| extrinsic(v as u64 + 1)))
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
.collect::<Vec<_>>();

let block_limit = genesis_header.encoded_size() +
Expand All @@ -862,7 +872,7 @@ mod tests {
.sum::<usize>() +
Vec::<Extrinsic>::new().encoded_size();

block_on(txpool.submit_at(&BlockId::number(0), SOURCE, extrinsics)).unwrap();
block_on(txpool.submit_at(&BlockId::number(0), SOURCE, extrinsics.clone())).unwrap();

block_on(txpool.maintain(chain_event(genesis_header.clone())));

Expand Down Expand Up @@ -905,7 +915,13 @@ mod tests {

let proposer = block_on(proposer_factory.init(&genesis_header)).unwrap();

// Give it enough time
// Exact block_limit, which includes:
// 99 (header_size) + 718 (proof@initialize_block) + 246 (one Transfer extrinsic)
let block_limit = {
let builder =
client.new_block_at(genesis_header.hash(), Default::default(), true).unwrap();
builder.estimate_block_size(true) + extrinsics[0].encoded_size()
};
let block = block_on(proposer.propose(
Default::default(),
Default::default(),
Expand All @@ -915,7 +931,7 @@ mod tests {
.map(|r| r.block)
.unwrap();

// The block limit didn't changed, but we now include the proof in the estimation of the
// The block limit was increased, but we now include the proof in the estimation of the
// block size and thus, only the `Transfer` will fit into the block. It reads more data
// than we have reserved in the block limit.
assert_eq!(block.extrinsics().len(), 1);
Expand All @@ -934,16 +950,25 @@ mod tests {
client.clone(),
);

let tiny = |nonce| {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(TINY)).nonce(nonce).build()
};
let huge = |who| {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(HUGE))
.signer(AccountKeyring::numeric(who))
.build()
};

block_on(
txpool.submit_at(
&BlockId::number(0),
SOURCE,
// add 2 * MAX_SKIPPED_TRANSACTIONS that exhaust resources
(0..MAX_SKIPPED_TRANSACTIONS * 2)
.into_iter()
.map(|i| exhausts_resources_extrinsic_from(i))
.map(huge)
// and some transactions that are okay.
.chain((0..MAX_SKIPPED_TRANSACTIONS).into_iter().map(|i| extrinsic(i as _)))
.chain((0..MAX_SKIPPED_TRANSACTIONS as u64).into_iter().map(tiny))
.collect(),
),
)
Expand Down Expand Up @@ -997,15 +1022,27 @@ mod tests {
client.clone(),
);

let tiny = |who| {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(TINY))
.signer(AccountKeyring::numeric(who))
.nonce(1)
.build()
};
let huge = |who| {
ExtrinsicBuilder::new_fill_block(Perbill::from_parts(HUGE))
.signer(AccountKeyring::numeric(who))
.build()
};

block_on(
txpool.submit_at(
&BlockId::number(0),
SOURCE,
(0..MAX_SKIPPED_TRANSACTIONS + 2)
.into_iter()
.map(|i| exhausts_resources_extrinsic_from(i))
.map(huge)
// and some transactions that are okay.
.chain((0..MAX_SKIPPED_TRANSACTIONS).into_iter().map(|i| extrinsic(i as _)))
.chain((0..MAX_SKIPPED_TRANSACTIONS + 2).into_iter().map(tiny))
.collect(),
),
)
Expand All @@ -1018,7 +1055,7 @@ mod tests {
.expect("there should be header"),
)),
);
assert_eq!(txpool.ready().count(), MAX_SKIPPED_TRANSACTIONS * 2 + 2);
assert_eq!(txpool.ready().count(), MAX_SKIPPED_TRANSACTIONS * 2 + 4);

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), None, None);
Expand Down Expand Up @@ -1049,8 +1086,13 @@ mod tests {
.map(|r| r.block)
.unwrap();

// then the block should have no transactions despite some in the pool
assert_eq!(block.extrinsics().len(), 1);
// then the block should have one or two transactions. This maybe random as they are
// processed in parallel. The same signer and consecutive nonces for huge and tiny
// transactions guarantees that max two transactions will get to the block.
assert!(
(1..3).contains(&block.extrinsics().len()),
"Block shall contain one or two extrinsics."
);
assert!(
cell2.lock().0 > MAX_SKIPPED_TRANSACTIONS,
"Not enough calls to current time, which indicates the test might have ended because of deadline, not soft deadline"
Expand Down
2 changes: 1 addition & 1 deletion client/basic-authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! # use sp_runtime::generic::BlockId;
//! # use std::{sync::Arc, time::Duration};
//! # use substrate_test_runtime_client::{
//! # runtime::{Extrinsic, Transfer}, AccountKeyring,
//! # runtime::Transfer, AccountKeyring,
//! # DefaultTestClientBuilderExt, TestClientBuilderExt,
//! # };
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
Expand Down
Loading