mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 04:51:09 +00:00
Better handling of stable-only build (#6569)
* Better handling of stable-only build * Fix node template build * Fix wasm builder node-template version mismatch * Fix load_spec error * Add , in parameter * Add descrptive panic messages in tests * Add descriptive tests in node/executor benches * Fix missing compact_code_unwrap * Add missing wasm_binary_unwrap function for executor integration test * Only define import_sp_io in no_std * Small Cargo.toml styling fix * Bump wasm-builder to 2.0.0 * Fix all `with_wasm_builder_from_crates` version in Substrate * Use `with_wasm_builder_from_crates` for node-template Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
@@ -25,7 +25,7 @@ use node_runtime::{
|
||||
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig,
|
||||
DemocracyConfig,GrandpaConfig, ImOnlineConfig, SessionConfig, SessionKeys, StakerStatus,
|
||||
StakingConfig, ElectionsConfig, IndicesConfig, SocietyConfig, SudoConfig, SystemConfig,
|
||||
TechnicalCommitteeConfig, WASM_BINARY,
|
||||
TechnicalCommitteeConfig, wasm_binary_unwrap,
|
||||
};
|
||||
use node_runtime::Block;
|
||||
use node_runtime::constants::currency::*;
|
||||
@@ -241,7 +241,7 @@ pub fn testnet_genesis(
|
||||
|
||||
GenesisConfig {
|
||||
frame_system: Some(SystemConfig {
|
||||
code: WASM_BINARY.to_vec(),
|
||||
code: wasm_binary_unwrap().to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
pallet_balances: Some(BalancesConfig {
|
||||
|
||||
@@ -36,7 +36,10 @@ criterion_group!(benches, bench_execute_block);
|
||||
criterion_main!(benches);
|
||||
|
||||
/// The wasm runtime code.
|
||||
const COMPACT_CODE: &[u8] = node_runtime::WASM_BINARY;
|
||||
pub fn compact_code_unwrap() -> &'static [u8] {
|
||||
node_runtime::WASM_BINARY.expect("Development wasm binary is not available. \
|
||||
Testing is only supported with the flag disabled.")
|
||||
}
|
||||
|
||||
const GENESIS_HASH: [u8; 32] = [69u8; 32];
|
||||
|
||||
@@ -60,7 +63,7 @@ fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
|
||||
|
||||
fn new_test_ext(genesis_config: &GenesisConfig) -> TestExternalities<BlakeTwo256> {
|
||||
let mut test_ext = TestExternalities::new_with_code(
|
||||
COMPACT_CODE,
|
||||
compact_code_unwrap(),
|
||||
genesis_config.build_storage().unwrap(),
|
||||
);
|
||||
test_ext.ext().place_storage(well_known_keys::HEAP_PAGES.to_vec(), Some(HEAP_PAGES.encode()));
|
||||
@@ -94,7 +97,7 @@ fn construct_block<E: Externalities>(
|
||||
};
|
||||
|
||||
let runtime_code = RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(COMPACT_CODE.into()),
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
||||
hash: vec![1, 2, 3],
|
||||
heap_pages: None,
|
||||
};
|
||||
@@ -168,7 +171,7 @@ fn bench_execute_block(c: &mut Criterion) {
|
||||
c.bench_function_over_inputs(
|
||||
"execute blocks",
|
||||
|b, strategy| {
|
||||
let genesis_config = node_testing::genesis::config(false, Some(COMPACT_CODE));
|
||||
let genesis_config = node_testing::genesis::config(false, Some(compact_code_unwrap()));
|
||||
let (use_native, wasm_method) = match strategy {
|
||||
ExecutionMethod::Native => (true, WasmExecutionMethod::Interpreted),
|
||||
ExecutionMethod::Wasm(wasm_method) => (false, *wasm_method),
|
||||
@@ -176,7 +179,7 @@ fn bench_execute_block(c: &mut Criterion) {
|
||||
|
||||
let executor = NativeExecutor::new(wasm_method, None, 8);
|
||||
let runtime_code = RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(COMPACT_CODE.into()),
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
||||
hash: vec![1, 2, 3],
|
||||
heap_pages: None,
|
||||
};
|
||||
|
||||
@@ -47,7 +47,10 @@ use self::common::{*, sign};
|
||||
/// The idea here is to pass it as the current runtime code to the executor so the executor will
|
||||
/// have to execute provided wasm code instead of the native equivalent. This trick is used to
|
||||
/// test code paths that differ between native and wasm versions.
|
||||
pub const BLOATY_CODE: &[u8] = node_runtime::WASM_BINARY_BLOATY;
|
||||
pub fn bloaty_code_unwrap() -> &'static [u8] {
|
||||
node_runtime::WASM_BINARY_BLOATY.expect("Development wasm binary is not available. \
|
||||
Testing is only supported with the flag disabled.")
|
||||
}
|
||||
|
||||
/// Default transfer fee. This will use the same logic that is implemented in transaction-payment module.
|
||||
///
|
||||
@@ -75,7 +78,7 @@ fn set_heap_pages<E: Externalities>(ext: &mut E, heap_pages: u64) {
|
||||
|
||||
fn changes_trie_block() -> (Vec<u8>, Hash) {
|
||||
construct_block(
|
||||
&mut new_test_ext(COMPACT_CODE, true),
|
||||
&mut new_test_ext(compact_code_unwrap(), true),
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
vec![
|
||||
@@ -95,7 +98,7 @@ fn changes_trie_block() -> (Vec<u8>, Hash) {
|
||||
/// are not guaranteed to be deterministic) and to ensure that the correct state is propagated
|
||||
/// from block1's execution to block2 to derive the correct storage_root.
|
||||
fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let block1 = construct_block(
|
||||
&mut t,
|
||||
1,
|
||||
@@ -140,7 +143,7 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
|
||||
|
||||
fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
|
||||
construct_block(
|
||||
&mut new_test_ext(COMPACT_CODE, false),
|
||||
&mut new_test_ext(compact_code_unwrap(), false),
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
vec![
|
||||
@@ -158,7 +161,7 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
|
||||
|
||||
#[test]
|
||||
fn panic_execution_with_foreign_code_gives_error() {
|
||||
let mut t = new_test_ext(BLOATY_CODE, false);
|
||||
let mut t = new_test_ext(bloaty_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(69u128, 0u8, 0u128, 0u128, 0u128).encode()
|
||||
@@ -187,7 +190,7 @@ fn panic_execution_with_foreign_code_gives_error() {
|
||||
|
||||
#[test]
|
||||
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u8, 69u128, 0u128, 0u128, 0u128).encode()
|
||||
@@ -216,7 +219,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u8, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
|
||||
@@ -259,7 +262,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_foreign_code_gives_ok() {
|
||||
let mut t = new_test_ext(BLOATY_CODE, false);
|
||||
let mut t = new_test_ext(bloaty_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u8, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
|
||||
@@ -302,7 +305,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
|
||||
|
||||
#[test]
|
||||
fn full_native_block_import_works() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
let (block1, block2) = blocks();
|
||||
|
||||
@@ -439,7 +442,7 @@ fn full_native_block_import_works() {
|
||||
|
||||
#[test]
|
||||
fn full_wasm_block_import_works() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
let (block1, block2) = blocks();
|
||||
|
||||
@@ -589,7 +592,7 @@ fn deploying_wasm_contract_should_work() {
|
||||
);
|
||||
|
||||
let b = construct_block(
|
||||
&mut new_test_ext(COMPACT_CODE, false),
|
||||
&mut new_test_ext(compact_code_unwrap(), false),
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
vec![
|
||||
@@ -628,7 +631,7 @@ fn deploying_wasm_contract_should_work() {
|
||||
]
|
||||
);
|
||||
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -652,7 +655,7 @@ fn deploying_wasm_contract_should_work() {
|
||||
|
||||
#[test]
|
||||
fn wasm_big_block_import_fails() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
set_heap_pages(&mut t.ext(), 4);
|
||||
|
||||
@@ -668,7 +671,7 @@ fn wasm_big_block_import_fails() {
|
||||
|
||||
#[test]
|
||||
fn native_big_block_import_succeeds() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -681,7 +684,7 @@ fn native_big_block_import_succeeds() {
|
||||
|
||||
#[test]
|
||||
fn native_big_block_import_fails_on_fallback() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
assert!(
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
@@ -696,7 +699,7 @@ fn native_big_block_import_fails_on_fallback() {
|
||||
|
||||
#[test]
|
||||
fn panic_execution_gives_error() {
|
||||
let mut t = new_test_ext(BLOATY_CODE, false);
|
||||
let mut t = new_test_ext(bloaty_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u8, 0 * DOLLARS, 0u128, 0u128, 0u128).encode()
|
||||
@@ -725,7 +728,7 @@ fn panic_execution_gives_error() {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_gives_ok() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u8, 111 * DOLLARS, 0u128, 0u128, 0u128).encode()
|
||||
@@ -778,7 +781,7 @@ fn full_native_block_import_works_with_changes_trie() {
|
||||
let block_data = block1.0;
|
||||
let block = Block::decode(&mut &block_data[..]).unwrap();
|
||||
|
||||
let mut t = new_test_ext(COMPACT_CODE, true);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), true);
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_execute_block",
|
||||
@@ -794,7 +797,7 @@ fn full_native_block_import_works_with_changes_trie() {
|
||||
fn full_wasm_block_import_works_with_changes_trie() {
|
||||
let block1 = changes_trie_block();
|
||||
|
||||
let mut t = new_test_ext(COMPACT_CODE, true);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), true);
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_execute_block",
|
||||
|
||||
@@ -68,7 +68,10 @@ impl AppCrypto<MultiSigner, MultiSignature> for TestAuthorityId {
|
||||
/// making the binary slimmer. There is a convention to use compact version of the runtime
|
||||
/// as canonical. This is why `native_executor_instance` also uses the compact version of the
|
||||
/// runtime.
|
||||
pub const COMPACT_CODE: &[u8] = node_runtime::WASM_BINARY;
|
||||
pub fn compact_code_unwrap() -> &'static [u8] {
|
||||
node_runtime::WASM_BINARY.expect("Development wasm binary is not available. \
|
||||
Testing is only supported with the flag disabled.")
|
||||
}
|
||||
|
||||
pub const GENESIS_HASH: [u8; 32] = [69u8; 32];
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ use self::common::{*, sign};
|
||||
|
||||
#[test]
|
||||
fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
// initial fee multiplier must be one.
|
||||
let mut prev_multiplier = Multiplier::one();
|
||||
@@ -45,7 +45,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
assert_eq!(TransactionPayment::next_fee_multiplier(), prev_multiplier);
|
||||
});
|
||||
|
||||
let mut tt = new_test_ext(COMPACT_CODE, false);
|
||||
let mut tt = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
// big one in terms of weight.
|
||||
let block1 = construct_block(
|
||||
@@ -130,7 +130,7 @@ fn transaction_fee_is_correct() {
|
||||
// - 1 MILLICENTS in substrate node.
|
||||
// - 1 milli-dot based on current polkadot runtime.
|
||||
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u8, 100 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS).encode()
|
||||
@@ -209,9 +209,9 @@ fn block_weight_capacity_report() {
|
||||
use node_primitives::Index;
|
||||
|
||||
// execution ext.
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
// setup ext.
|
||||
let mut tt = new_test_ext(COMPACT_CODE, false);
|
||||
let mut tt = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
let factor = 50;
|
||||
let mut time = 10;
|
||||
@@ -276,9 +276,9 @@ fn block_length_capacity_report() {
|
||||
use node_primitives::Index;
|
||||
|
||||
// execution ext.
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
// setup ext.
|
||||
let mut tt = new_test_ext(COMPACT_CODE, false);
|
||||
let mut tt = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
let factor = 256 * 1024;
|
||||
let mut time = 10;
|
||||
|
||||
@@ -41,7 +41,7 @@ use self::common::*;
|
||||
|
||||
#[test]
|
||||
fn should_submit_unsigned_transaction() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let (pool, state) = TestTransactionPoolExt::new();
|
||||
t.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
@@ -67,7 +67,7 @@ const PHRASE: &str = "news slush supreme milk chapter athlete soap sausage put c
|
||||
|
||||
#[test]
|
||||
fn should_submit_signed_transaction() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let (pool, state) = TestTransactionPoolExt::new();
|
||||
t.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
@@ -92,7 +92,7 @@ fn should_submit_signed_transaction() {
|
||||
|
||||
#[test]
|
||||
fn should_submit_signed_twice_from_the_same_account() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let (pool, state) = TestTransactionPoolExt::new();
|
||||
t.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
@@ -136,7 +136,7 @@ fn should_submit_signed_twice_from_the_same_account() {
|
||||
|
||||
#[test]
|
||||
fn should_submit_signed_twice_from_all_accounts() {
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let (pool, state) = TestTransactionPoolExt::new();
|
||||
t.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
@@ -195,7 +195,7 @@ fn submitted_transaction_should_be_valid() {
|
||||
use sp_runtime::transaction_validity::{ValidTransaction, TransactionSource};
|
||||
use sp_runtime::traits::StaticLookup;
|
||||
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let (pool, state) = TestTransactionPoolExt::new();
|
||||
t.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
@@ -216,7 +216,7 @@ fn submitted_transaction_should_be_valid() {
|
||||
// check that transaction is valid, but reset environment storage,
|
||||
// since CreateTransaction increments the nonce
|
||||
let tx0 = state.read().transactions[0].clone();
|
||||
let mut t = new_test_ext(COMPACT_CODE, false);
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
t.execute_with(|| {
|
||||
let source = TransactionSource::External;
|
||||
let extrinsic = UncheckedExtrinsic::decode(&mut &*tx0).unwrap();
|
||||
|
||||
@@ -20,7 +20,7 @@ use wasm_builder_runner::WasmBuilder;
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.with_current_project()
|
||||
.with_wasm_builder_from_crates_or_path("1.0.11", "../../../utils/wasm-builder")
|
||||
.with_wasm_builder_from_crates_or_path("2.0.0", "../../../utils/wasm-builder")
|
||||
.export_heap_base()
|
||||
.import_memory()
|
||||
.build()
|
||||
|
||||
@@ -88,6 +88,14 @@ use constants::{time::*, currency::*};
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
/// Wasm binary unwrapped. If built with `BUILD_DUMMY_WASM_BINARY`, the function panics.
|
||||
pub fn wasm_binary_unwrap() -> &'static [u8] {
|
||||
WASM_BINARY.expect("Development wasm binary is not available. This means the client is \
|
||||
built with `BUILD_DUMMY_WASM_BINARY` flag and it is only usable for \
|
||||
production chains. Please rebuild with the flag disabled.")
|
||||
}
|
||||
|
||||
/// Runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("node"),
|
||||
|
||||
@@ -542,7 +542,7 @@ impl BenchKeyring {
|
||||
pub fn generate_genesis(&self) -> node_runtime::GenesisConfig {
|
||||
crate::genesis::config_endowed(
|
||||
false,
|
||||
Some(node_runtime::WASM_BINARY),
|
||||
Some(node_runtime::wasm_binary_unwrap()),
|
||||
self.collect_account_ids(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::keyring::*;
|
||||
use sp_keyring::{Ed25519Keyring, Sr25519Keyring};
|
||||
use node_runtime::{
|
||||
GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, SystemConfig,
|
||||
GrandpaConfig, IndicesConfig, ContractsConfig, SocietyConfig, WASM_BINARY,
|
||||
GrandpaConfig, IndicesConfig, ContractsConfig, SocietyConfig, wasm_binary_unwrap,
|
||||
AccountId, StakerStatus,
|
||||
};
|
||||
use node_runtime::constants::currency::*;
|
||||
@@ -61,7 +61,7 @@ pub fn config_endowed(
|
||||
digest_interval: 2,
|
||||
digest_levels: 2,
|
||||
}) } else { None },
|
||||
code: code.map(|x| x.to_vec()).unwrap_or_else(|| WASM_BINARY.to_vec()),
|
||||
code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()),
|
||||
}),
|
||||
pallet_indices: Some(IndicesConfig {
|
||||
indices: vec![],
|
||||
|
||||
Reference in New Issue
Block a user