mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -16,29 +16,33 @@
|
||||
// limitations under the License.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||
use frame_support::Hashable;
|
||||
use node_executor::Executor;
|
||||
use node_primitives::{BlockNumber, Hash};
|
||||
use node_runtime::{
|
||||
Block, BuildStorage, Call, CheckedExtrinsic, GenesisConfig, Header, UncheckedExtrinsic,
|
||||
constants::currency::*, Block, BuildStorage, Call, CheckedExtrinsic, GenesisConfig, Header,
|
||||
UncheckedExtrinsic,
|
||||
};
|
||||
use node_runtime::constants::currency::*;
|
||||
use node_testing::keyring::*;
|
||||
use sp_core::{NativeOrEncoded, NeverNativeValue};
|
||||
use sp_core::storage::well_known_keys;
|
||||
use sp_core::traits::{CodeExecutor, RuntimeCode};
|
||||
use frame_support::Hashable;
|
||||
use sp_state_machine::TestExternalities as CoreTestExternalities;
|
||||
use sc_executor::{NativeExecutor, RuntimeInfo, WasmExecutionMethod, Externalities};
|
||||
use sc_executor::{Externalities, NativeExecutor, RuntimeInfo, WasmExecutionMethod};
|
||||
use sp_core::{
|
||||
storage::well_known_keys,
|
||||
traits::{CodeExecutor, RuntimeCode},
|
||||
NativeOrEncoded, NeverNativeValue,
|
||||
};
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_state_machine::TestExternalities as CoreTestExternalities;
|
||||
|
||||
criterion_group!(benches, bench_execute_block);
|
||||
criterion_main!(benches);
|
||||
|
||||
/// The wasm runtime code.
|
||||
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.")
|
||||
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];
|
||||
@@ -66,7 +70,9 @@ fn new_test_ext(genesis_config: &GenesisConfig) -> TestExternalities<BlakeTwo256
|
||||
compact_code_unwrap(),
|
||||
genesis_config.build_storage().unwrap(),
|
||||
);
|
||||
test_ext.ext().place_storage(well_known_keys::HEAP_PAGES.to_vec(), Some(HEAP_PAGES.encode()));
|
||||
test_ext
|
||||
.ext()
|
||||
.place_storage(well_known_keys::HEAP_PAGES.to_vec(), Some(HEAP_PAGES.encode()));
|
||||
test_ext
|
||||
}
|
||||
|
||||
@@ -77,16 +83,16 @@ fn construct_block<E: Externalities>(
|
||||
parent_hash: Hash,
|
||||
extrinsics: Vec<CheckedExtrinsic>,
|
||||
) -> (Vec<u8>, Hash) {
|
||||
use sp_trie::{TrieConfiguration, trie_types::Layout};
|
||||
use sp_trie::{trie_types::Layout, TrieConfiguration};
|
||||
|
||||
// sign extrinsics.
|
||||
let extrinsics = extrinsics.into_iter().map(sign).collect::<Vec<_>>();
|
||||
|
||||
// calculate the header fields that we can.
|
||||
let extrinsics_root = Layout::<BlakeTwo256>::ordered_trie_root(
|
||||
extrinsics.iter().map(Encode::encode)
|
||||
).to_fixed_bytes()
|
||||
.into();
|
||||
let extrinsics_root =
|
||||
Layout::<BlakeTwo256>::ordered_trie_root(extrinsics.iter().map(Encode::encode))
|
||||
.to_fixed_bytes()
|
||||
.into();
|
||||
|
||||
let header = Header {
|
||||
parent_hash,
|
||||
@@ -103,34 +109,44 @@ fn construct_block<E: Externalities>(
|
||||
};
|
||||
|
||||
// execute the block to get the real header.
|
||||
executor.call::<NeverNativeValue, fn() -> _>(
|
||||
ext,
|
||||
&runtime_code,
|
||||
"Core_initialize_block",
|
||||
&header.encode(),
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
|
||||
for i in extrinsics.iter() {
|
||||
executor.call::<NeverNativeValue, fn() -> _>(
|
||||
executor
|
||||
.call::<NeverNativeValue, fn() -> _>(
|
||||
ext,
|
||||
&runtime_code,
|
||||
"BlockBuilder_apply_extrinsic",
|
||||
&i.encode(),
|
||||
"Core_initialize_block",
|
||||
&header.encode(),
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
for i in extrinsics.iter() {
|
||||
executor
|
||||
.call::<NeverNativeValue, fn() -> _>(
|
||||
ext,
|
||||
&runtime_code,
|
||||
"BlockBuilder_apply_extrinsic",
|
||||
&i.encode(),
|
||||
true,
|
||||
None,
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let header = match executor.call::<NeverNativeValue, fn() -> _>(
|
||||
ext,
|
||||
&runtime_code,
|
||||
"BlockBuilder_finalize_block",
|
||||
&[0u8;0],
|
||||
true,
|
||||
None,
|
||||
).0.unwrap() {
|
||||
let header = match executor
|
||||
.call::<NeverNativeValue, fn() -> _>(
|
||||
ext,
|
||||
&runtime_code,
|
||||
"BlockBuilder_finalize_block",
|
||||
&[0u8; 0],
|
||||
true,
|
||||
None,
|
||||
)
|
||||
.0
|
||||
.unwrap()
|
||||
{
|
||||
NativeOrEncoded::Native(_) => unreachable!(),
|
||||
NativeOrEncoded::Encoded(h) => Header::decode(&mut &h[..]).unwrap(),
|
||||
};
|
||||
@@ -139,29 +155,21 @@ fn construct_block<E: Externalities>(
|
||||
(Block { header, extrinsics }.encode(), hash.into())
|
||||
}
|
||||
|
||||
fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor<Executor>)
|
||||
-> Vec<(Vec<u8>, Hash)>
|
||||
{
|
||||
fn test_blocks(
|
||||
genesis_config: &GenesisConfig,
|
||||
executor: &NativeExecutor<Executor>,
|
||||
) -> Vec<(Vec<u8>, Hash)> {
|
||||
let mut test_ext = new_test_ext(genesis_config);
|
||||
let mut block1_extrinsics = vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set(0)),
|
||||
},
|
||||
];
|
||||
block1_extrinsics.extend((0..20).map(|i| {
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(i, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 1 * DOLLARS)),
|
||||
}
|
||||
let mut block1_extrinsics = vec![CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set(0)),
|
||||
}];
|
||||
block1_extrinsics.extend((0..20).map(|i| CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(i, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 1 * DOLLARS)),
|
||||
}));
|
||||
let block1 = construct_block(
|
||||
executor,
|
||||
&mut test_ext.ext(),
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
block1_extrinsics,
|
||||
);
|
||||
let block1 =
|
||||
construct_block(executor, &mut test_ext.ext(), 1, GENESIS_HASH.into(), block1_extrinsics);
|
||||
|
||||
vec![block1]
|
||||
}
|
||||
@@ -176,47 +184,47 @@ fn bench_execute_block(c: &mut Criterion) {
|
||||
];
|
||||
|
||||
for strategy in execution_methods {
|
||||
group.bench_function(
|
||||
format!("{:?}", strategy),
|
||||
|b| {
|
||||
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),
|
||||
};
|
||||
group.bench_function(format!("{:?}", strategy), |b| {
|
||||
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),
|
||||
};
|
||||
|
||||
let executor = NativeExecutor::new(wasm_method, None, 8);
|
||||
let runtime_code = RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
||||
hash: vec![1, 2, 3],
|
||||
heap_pages: None,
|
||||
};
|
||||
let executor = NativeExecutor::new(wasm_method, None, 8);
|
||||
let runtime_code = RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
||||
hash: vec![1, 2, 3],
|
||||
heap_pages: None,
|
||||
};
|
||||
|
||||
// Get the runtime version to initialize the runtimes cache.
|
||||
{
|
||||
let mut test_ext = new_test_ext(&genesis_config);
|
||||
executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap();
|
||||
}
|
||||
// Get the runtime version to initialize the runtimes cache.
|
||||
{
|
||||
let mut test_ext = new_test_ext(&genesis_config);
|
||||
executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap();
|
||||
}
|
||||
|
||||
let blocks = test_blocks(&genesis_config, &executor);
|
||||
let blocks = test_blocks(&genesis_config, &executor);
|
||||
|
||||
b.iter_batched_ref(
|
||||
|| new_test_ext(&genesis_config),
|
||||
|test_ext| {
|
||||
for block in blocks.iter() {
|
||||
executor.call::<NeverNativeValue, fn() -> _>(
|
||||
b.iter_batched_ref(
|
||||
|| new_test_ext(&genesis_config),
|
||||
|test_ext| {
|
||||
for block in blocks.iter() {
|
||||
executor
|
||||
.call::<NeverNativeValue, fn() -> _>(
|
||||
&mut test_ext.ext(),
|
||||
&runtime_code,
|
||||
"Core_execute_block",
|
||||
&block.0,
|
||||
use_native,
|
||||
None,
|
||||
).0.unwrap();
|
||||
}
|
||||
},
|
||||
BatchSize::LargeInput,
|
||||
);
|
||||
},
|
||||
);
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
}
|
||||
},
|
||||
BatchSize::LargeInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
//! A `CodeExecutor` specialization which uses natively compiled runtime when the wasm to be
|
||||
//! executed is equivalent to the natively compiled code.
|
||||
|
||||
pub use sc_executor::NativeExecutor;
|
||||
use sc_executor::native_executor_instance;
|
||||
pub use sc_executor::NativeExecutor;
|
||||
|
||||
// Declare an instance of the native executor named `Executor`. Include the wasm binary as the
|
||||
// equivalent wasm code.
|
||||
|
||||
@@ -15,30 +15,28 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use codec::{Encode, Decode, Joiner};
|
||||
use codec::{Decode, Encode, Joiner};
|
||||
use frame_support::{
|
||||
traits::Currency,
|
||||
weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
|
||||
weights::{DispatchClass, DispatchInfo, GetDispatchInfo},
|
||||
};
|
||||
use sp_core::{NeverNativeValue, traits::Externalities, storage::well_known_keys};
|
||||
use frame_system::{self, AccountInfo, EventRecord, Phase};
|
||||
use sp_core::{storage::well_known_keys, traits::Externalities, NeverNativeValue};
|
||||
use sp_runtime::{
|
||||
ApplyExtrinsicResult,
|
||||
traits::Hash as HashT,
|
||||
transaction_validity::InvalidTransaction,
|
||||
traits::Hash as HashT, transaction_validity::InvalidTransaction, ApplyExtrinsicResult,
|
||||
};
|
||||
use frame_system::{self, EventRecord, Phase, AccountInfo};
|
||||
|
||||
use node_runtime::{
|
||||
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
|
||||
System, TransactionPayment, Event,
|
||||
constants::{time::SLOT_DURATION, currency::*},
|
||||
};
|
||||
use node_primitives::{Balance, Hash};
|
||||
use wat;
|
||||
use node_runtime::{
|
||||
constants::{currency::*, time::SLOT_DURATION},
|
||||
Balances, Block, Call, CheckedExtrinsic, Event, Header, Runtime, System, TransactionPayment,
|
||||
UncheckedExtrinsic,
|
||||
};
|
||||
use node_testing::keyring::*;
|
||||
use wat;
|
||||
|
||||
pub mod common;
|
||||
use self::common::{*, sign};
|
||||
use self::common::{sign, *};
|
||||
|
||||
/// The wasm runtime binary which hasn't undergone the compacting process.
|
||||
///
|
||||
@@ -46,8 +44,10 @@ use self::common::{*, sign};
|
||||
/// 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 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.")
|
||||
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.
|
||||
@@ -87,7 +87,10 @@ fn changes_trie_block() -> (Vec<u8>, Hash) {
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(0, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 69 * DOLLARS)),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(
|
||||
bob().into(),
|
||||
69 * DOLLARS,
|
||||
)),
|
||||
},
|
||||
],
|
||||
(time / SLOT_DURATION).into(),
|
||||
@@ -111,7 +114,10 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(0, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 69 * DOLLARS)),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(
|
||||
bob().into(),
|
||||
69 * DOLLARS,
|
||||
)),
|
||||
},
|
||||
],
|
||||
(time1 / SLOT_DURATION).into(),
|
||||
@@ -128,12 +134,18 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((bob(), signed_extra(0, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(alice().into(), 5 * DOLLARS)),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(
|
||||
alice().into(),
|
||||
5 * DOLLARS,
|
||||
)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(1, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 15 * DOLLARS)),
|
||||
}
|
||||
function: Call::Balances(pallet_balances::Call::transfer(
|
||||
bob().into(),
|
||||
15 * DOLLARS,
|
||||
)),
|
||||
},
|
||||
],
|
||||
(time2 / SLOT_DURATION).into(),
|
||||
);
|
||||
@@ -158,7 +170,7 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(nonce, 0))),
|
||||
function: Call::System(frame_system::Call::remark(vec![0; size])),
|
||||
}
|
||||
},
|
||||
],
|
||||
(time * 1000 / SLOT_DURATION).into(),
|
||||
)
|
||||
@@ -169,7 +181,7 @@ fn panic_execution_with_foreign_code_gives_error() {
|
||||
let mut t = new_test_ext(bloaty_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(69u128, 0u32, 0u128, 0u128, 0u128).encode()
|
||||
(69u128, 0u32, 0u128, 0u128, 0u128).encode(),
|
||||
);
|
||||
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 69_u128.encode());
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
@@ -180,7 +192,8 @@ fn panic_execution_with_foreign_code_gives_error() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
let v = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -188,7 +201,9 @@ fn panic_execution_with_foreign_code_gives_error() {
|
||||
&vec![].and(&xt()),
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
let r = ApplyExtrinsicResult::decode(&mut &v.as_encoded()[..]).unwrap();
|
||||
assert_eq!(r, Err(InvalidTransaction::Payment.into()));
|
||||
}
|
||||
@@ -198,7 +213,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
(0u32, 0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode()
|
||||
(0u32, 0u32, 0u32, 69u128, 0u128, 0u128, 0u128).encode(),
|
||||
);
|
||||
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 69_u128.encode());
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
@@ -209,7 +224,8 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
let v = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -217,7 +233,9 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
&vec![].and(&xt()),
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
let r = ApplyExtrinsicResult::decode(&mut &v.as_encoded()[..]).unwrap();
|
||||
assert_eq!(r, Err(InvalidTransaction::Payment.into()));
|
||||
}
|
||||
@@ -229,19 +247,21 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (111 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (0 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(
|
||||
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
|
||||
(111 * DOLLARS).encode()
|
||||
(111 * DOLLARS).encode(),
|
||||
);
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
|
||||
@@ -251,7 +271,8 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
|
||||
let fees = t.execute_with(|| transfer_fee(&xt()));
|
||||
@@ -262,7 +283,8 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
&vec![].and(&xt()),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
|
||||
t.execute_with(|| {
|
||||
@@ -278,19 +300,21 @@ fn successful_execution_with_foreign_code_gives_ok() {
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (111 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (0 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(
|
||||
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
|
||||
(111 * DOLLARS).encode()
|
||||
(111 * DOLLARS).encode(),
|
||||
);
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
|
||||
@@ -300,7 +324,8 @@ fn successful_execution_with_foreign_code_gives_ok() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
|
||||
let fees = t.execute_with(|| transfer_fee(&xt()));
|
||||
@@ -311,7 +336,8 @@ fn successful_execution_with_foreign_code_gives_ok() {
|
||||
&vec![].and(&xt()),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
|
||||
t.execute_with(|| {
|
||||
@@ -330,7 +356,9 @@ fn full_native_block_import_works() {
|
||||
let mut fees = t.execute_with(|| transfer_fee(&xt()));
|
||||
|
||||
let transfer_weight = default_transfer_call().get_dispatch_info().weight;
|
||||
let timestamp_weight = pallet_timestamp::Call::set::<Runtime>(Default::default()).get_dispatch_info().weight;
|
||||
let timestamp_weight = pallet_timestamp::Call::set::<Runtime>(Default::default())
|
||||
.get_dispatch_info()
|
||||
.weight;
|
||||
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -338,7 +366,9 @@ fn full_native_block_import_works() {
|
||||
&block1.0,
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
t.execute_with(|| {
|
||||
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
|
||||
@@ -347,9 +377,11 @@ fn full_native_block_import_works() {
|
||||
let events = vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(
|
||||
DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() }
|
||||
)),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
|
||||
weight: timestamp_weight,
|
||||
class: DispatchClass::Mandatory,
|
||||
..Default::default()
|
||||
})),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -368,9 +400,10 @@ fn full_native_block_import_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(
|
||||
DispatchInfo { weight: transfer_weight, ..Default::default() }
|
||||
)),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
|
||||
weight: transfer_weight,
|
||||
..Default::default()
|
||||
})),
|
||||
topics: vec![],
|
||||
},
|
||||
];
|
||||
@@ -385,34 +418,33 @@ fn full_native_block_import_works() {
|
||||
&block2.0,
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
t.execute_with(|| {
|
||||
assert_eq!(
|
||||
Balances::total_balance(&alice()),
|
||||
alice_last_known_balance - 10 * DOLLARS - fees,
|
||||
);
|
||||
assert_eq!(
|
||||
Balances::total_balance(&bob()),
|
||||
179 * DOLLARS - fees,
|
||||
);
|
||||
assert_eq!(Balances::total_balance(&bob()), 179 * DOLLARS - fees,);
|
||||
let events = vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(
|
||||
DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() }
|
||||
)),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
|
||||
weight: timestamp_weight,
|
||||
class: DispatchClass::Mandatory,
|
||||
..Default::default()
|
||||
})),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::Balances(
|
||||
pallet_balances::Event::Transfer(
|
||||
bob().into(),
|
||||
alice().into(),
|
||||
5 * DOLLARS,
|
||||
)
|
||||
),
|
||||
event: Event::Balances(pallet_balances::Event::Transfer(
|
||||
bob().into(),
|
||||
alice().into(),
|
||||
5 * DOLLARS,
|
||||
)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -422,20 +454,19 @@ fn full_native_block_import_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(
|
||||
DispatchInfo { weight: transfer_weight, ..Default::default() }
|
||||
)),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
|
||||
weight: transfer_weight,
|
||||
..Default::default()
|
||||
})),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(2),
|
||||
event: Event::Balances(
|
||||
pallet_balances::Event::Transfer(
|
||||
alice().into(),
|
||||
bob().into(),
|
||||
15 * DOLLARS,
|
||||
)
|
||||
),
|
||||
event: Event::Balances(pallet_balances::Event::Transfer(
|
||||
alice().into(),
|
||||
bob().into(),
|
||||
15 * DOLLARS,
|
||||
)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -445,9 +476,10 @@ fn full_native_block_import_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(2),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(
|
||||
DispatchInfo { weight: transfer_weight, ..Default::default() }
|
||||
)),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
|
||||
weight: transfer_weight,
|
||||
..Default::default()
|
||||
})),
|
||||
topics: vec![],
|
||||
},
|
||||
];
|
||||
@@ -470,7 +502,9 @@ fn full_wasm_block_import_works() {
|
||||
&block1.0,
|
||||
false,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
t.execute_with(|| {
|
||||
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - fees);
|
||||
@@ -486,17 +520,16 @@ fn full_wasm_block_import_works() {
|
||||
&block2.0,
|
||||
false,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
t.execute_with(|| {
|
||||
assert_eq!(
|
||||
Balances::total_balance(&alice()),
|
||||
alice_last_known_balance - 10 * DOLLARS - fees,
|
||||
);
|
||||
assert_eq!(
|
||||
Balances::total_balance(&bob()),
|
||||
179 * DOLLARS - 1 * fees,
|
||||
);
|
||||
assert_eq!(Balances::total_balance(&bob()), 179 * DOLLARS - 1 * fees,);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -600,11 +633,7 @@ fn deploying_wasm_contract_should_work() {
|
||||
let transfer_code = wat::parse_str(CODE_TRANSFER).unwrap();
|
||||
let transfer_ch = <Runtime as frame_system::Config>::Hashing::hash(&transfer_code);
|
||||
|
||||
let addr = pallet_contracts::Pallet::<Runtime>::contract_address(
|
||||
&charlie(),
|
||||
&transfer_ch,
|
||||
&[],
|
||||
);
|
||||
let addr = pallet_contracts::Pallet::<Runtime>::contract_address(&charlie(), &transfer_ch, &[]);
|
||||
|
||||
let subsistence = pallet_contracts::Pallet::<Runtime>::subsistence_threshold();
|
||||
|
||||
@@ -627,19 +656,17 @@ fn deploying_wasm_contract_should_work() {
|
||||
transfer_code,
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
)
|
||||
),
|
||||
),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(1, 0))),
|
||||
function: Call::Contracts(
|
||||
pallet_contracts::Call::call::<Runtime>(
|
||||
sp_runtime::MultiAddress::Id(addr.clone()),
|
||||
10,
|
||||
500_000_000,
|
||||
vec![0x00, 0x01, 0x02, 0x03]
|
||||
)
|
||||
),
|
||||
function: Call::Contracts(pallet_contracts::Call::call::<Runtime>(
|
||||
sp_runtime::MultiAddress::Id(addr.clone()),
|
||||
10,
|
||||
500_000_000,
|
||||
vec![0x00, 0x01, 0x02, 0x03],
|
||||
)),
|
||||
},
|
||||
],
|
||||
(time / SLOT_DURATION).into(),
|
||||
@@ -647,20 +674,14 @@ fn deploying_wasm_contract_should_work() {
|
||||
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_execute_block",
|
||||
&b.0,
|
||||
false,
|
||||
None,
|
||||
).0.unwrap();
|
||||
executor_call::<NeverNativeValue, fn() -> _>(&mut t, "Core_execute_block", &b.0, false, None)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
t.execute_with(|| {
|
||||
// Verify that the contract does exist by querying some of its storage items
|
||||
// It does not matter that the storage item itself does not exist.
|
||||
assert!(
|
||||
&pallet_contracts::Pallet::<Runtime>::get_storage(addr, Default::default()).is_ok()
|
||||
);
|
||||
assert!(&pallet_contracts::Pallet::<Runtime>::get_storage(addr, Default::default()).is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -676,7 +697,8 @@ fn wasm_big_block_import_fails() {
|
||||
&block_with_size(42, 0, 120_000).0,
|
||||
false,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(result.is_err()); // Err(Wasmi(Trap(Trap { kind: Host(AllocatorOutOfSpace) })))
|
||||
}
|
||||
|
||||
@@ -690,7 +712,9 @@ fn native_big_block_import_succeeds() {
|
||||
&block_with_size(42, 0, 120_000).0,
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -700,15 +724,15 @@ fn native_big_block_import_fails_on_fallback() {
|
||||
// We set the heap pages to 8 because we know that should give an OOM in WASM with the given block.
|
||||
set_heap_pages(&mut t.ext(), 8);
|
||||
|
||||
assert!(
|
||||
executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_execute_block",
|
||||
&block_with_size(42, 0, 120_000).0,
|
||||
false,
|
||||
None,
|
||||
).0.is_err()
|
||||
);
|
||||
assert!(executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_execute_block",
|
||||
&block_with_size(42, 0, 120_000).0,
|
||||
false,
|
||||
None,
|
||||
)
|
||||
.0
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -718,8 +742,9 @@ fn panic_execution_gives_error() {
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (0 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(), 0_u128.encode());
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
@@ -730,7 +755,8 @@ fn panic_execution_gives_error() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
false,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -738,7 +764,10 @@ fn panic_execution_gives_error() {
|
||||
&vec![].and(&xt()),
|
||||
false,
|
||||
None,
|
||||
).0.unwrap().into_encoded();
|
||||
)
|
||||
.0
|
||||
.unwrap()
|
||||
.into_encoded();
|
||||
let r = ApplyExtrinsicResult::decode(&mut &r[..]).unwrap();
|
||||
assert_eq!(r, Err(InvalidTransaction::Payment.into()));
|
||||
}
|
||||
@@ -750,19 +779,21 @@ fn successful_execution_gives_ok() {
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (111 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(
|
||||
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
|
||||
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
|
||||
data: (0 * DOLLARS, 0u128, 0u128, 0u128),
|
||||
.. Default::default()
|
||||
}.encode(),
|
||||
..Default::default()
|
||||
}
|
||||
.encode(),
|
||||
);
|
||||
t.insert(
|
||||
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
|
||||
(111 * DOLLARS).encode()
|
||||
(111 * DOLLARS).encode(),
|
||||
);
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
|
||||
@@ -772,7 +803,8 @@ fn successful_execution_gives_ok() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
false,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
t.execute_with(|| {
|
||||
assert_eq!(Balances::total_balance(&alice()), 111 * DOLLARS);
|
||||
@@ -786,7 +818,10 @@ fn successful_execution_gives_ok() {
|
||||
&vec![].and(&xt()),
|
||||
false,
|
||||
None,
|
||||
).0.unwrap().into_encoded();
|
||||
)
|
||||
.0
|
||||
.unwrap()
|
||||
.into_encoded();
|
||||
ApplyExtrinsicResult::decode(&mut &r[..])
|
||||
.unwrap()
|
||||
.expect("Extrinsic could not be applied")
|
||||
@@ -811,7 +846,9 @@ fn full_native_block_import_works_with_changes_trie() {
|
||||
&block.encode(),
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
assert!(t.ext().storage_changes_root(&GENESIS_HASH).unwrap().is_some());
|
||||
}
|
||||
@@ -827,7 +864,9 @@ fn full_wasm_block_import_works_with_changes_trie() {
|
||||
&block1.0,
|
||||
false,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
assert!(t.ext().storage_changes_root(&GENESIS_HASH).unwrap().is_some());
|
||||
}
|
||||
@@ -835,8 +874,7 @@ fn full_wasm_block_import_works_with_changes_trie() {
|
||||
#[test]
|
||||
fn should_import_block_with_test_client() {
|
||||
use node_testing::client::{
|
||||
ClientBlockImportExt, TestClientBuilderExt, TestClientBuilder,
|
||||
sp_consensus::BlockOrigin,
|
||||
sp_consensus::BlockOrigin, ClientBlockImportExt, TestClientBuilder, TestClientBuilderExt,
|
||||
};
|
||||
|
||||
let mut client = TestClientBuilder::new().build();
|
||||
|
||||
@@ -15,34 +15,32 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use frame_system::offchain::AppCrypto;
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::Hashable;
|
||||
use sp_state_machine::TestExternalities as CoreTestExternalities;
|
||||
use sp_consensus_babe::{BABE_ENGINE_ID, Slot, digests::{PreDigest, SecondaryPlainPreDigest}};
|
||||
use frame_system::offchain::AppCrypto;
|
||||
use sc_executor::{error::Result, NativeExecutor, WasmExecutionMethod};
|
||||
use sp_consensus_babe::{
|
||||
digests::{PreDigest, SecondaryPlainPreDigest},
|
||||
Slot, BABE_ENGINE_ID,
|
||||
};
|
||||
use sp_core::{
|
||||
NeverNativeValue, NativeOrEncoded,
|
||||
crypto::KeyTypeId,
|
||||
sr25519::Signature,
|
||||
traits::{CodeExecutor, RuntimeCode},
|
||||
NativeOrEncoded, NeverNativeValue,
|
||||
};
|
||||
use sp_runtime::{
|
||||
ApplyExtrinsicResult,
|
||||
MultiSigner,
|
||||
MultiSignature,
|
||||
Digest,
|
||||
DigestItem,
|
||||
traits::{Header as HeaderT, BlakeTwo256},
|
||||
traits::{BlakeTwo256, Header as HeaderT},
|
||||
ApplyExtrinsicResult, Digest, DigestItem, MultiSignature, MultiSigner,
|
||||
};
|
||||
use sc_executor::{NativeExecutor, WasmExecutionMethod};
|
||||
use sc_executor::error::Result;
|
||||
use sp_state_machine::TestExternalities as CoreTestExternalities;
|
||||
|
||||
use node_executor::Executor;
|
||||
use node_primitives::{BlockNumber, Hash};
|
||||
use node_runtime::{
|
||||
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Runtime, BuildStorage,
|
||||
constants::currency::*,
|
||||
constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, Runtime,
|
||||
UncheckedExtrinsic,
|
||||
};
|
||||
use node_primitives::{Hash, BlockNumber};
|
||||
use node_testing::keyring::*;
|
||||
use sp_externalities::Externalities;
|
||||
|
||||
@@ -50,8 +48,8 @@ pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test");
|
||||
|
||||
pub mod sr25519 {
|
||||
mod app_sr25519 {
|
||||
use sp_application_crypto::{app_crypto, sr25519};
|
||||
use super::super::TEST_KEY_TYPE_ID;
|
||||
use sp_application_crypto::{app_crypto, sr25519};
|
||||
app_crypto!(sr25519, TEST_KEY_TYPE_ID);
|
||||
}
|
||||
|
||||
@@ -72,8 +70,10 @@ impl AppCrypto<MultiSigner, MultiSignature> for TestAuthorityId {
|
||||
/// as canonical. This is why `native_executor_instance` also uses the compact version of the
|
||||
/// runtime.
|
||||
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.")
|
||||
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];
|
||||
@@ -101,8 +101,9 @@ pub fn executor() -> NativeExecutor<Executor> {
|
||||
}
|
||||
|
||||
pub fn executor_call<
|
||||
R:Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> std::result::Result<R, Box<dyn std::error::Error + Send + Sync>> + std::panic::UnwindSafe
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> std::result::Result<R, Box<dyn std::error::Error + Send + Sync>>
|
||||
+ std::panic::UnwindSafe,
|
||||
>(
|
||||
t: &mut TestExternalities<BlakeTwo256>,
|
||||
method: &str,
|
||||
@@ -120,20 +121,15 @@ pub fn executor_call<
|
||||
heap_pages: heap_pages.and_then(|hp| Decode::decode(&mut &hp[..]).ok()),
|
||||
};
|
||||
|
||||
executor().call::<R, NC>(
|
||||
&mut t,
|
||||
&runtime_code,
|
||||
method,
|
||||
data,
|
||||
use_native,
|
||||
native_call,
|
||||
)
|
||||
executor().call::<R, NC>(&mut t, &runtime_code, method, data, use_native, native_call)
|
||||
}
|
||||
|
||||
pub fn new_test_ext(code: &[u8], support_changes_trie: bool) -> TestExternalities<BlakeTwo256> {
|
||||
let mut ext = TestExternalities::new_with_code(
|
||||
code,
|
||||
node_testing::genesis::config(support_changes_trie, Some(code)).build_storage().unwrap(),
|
||||
node_testing::genesis::config(support_changes_trie, Some(code))
|
||||
.build_storage()
|
||||
.unwrap(),
|
||||
);
|
||||
ext.changes_trie_storage().insert(0, GENESIS_HASH.into(), Default::default());
|
||||
ext
|
||||
@@ -150,7 +146,7 @@ pub fn construct_block(
|
||||
extrinsics: Vec<CheckedExtrinsic>,
|
||||
babe_slot: Slot,
|
||||
) -> (Vec<u8>, Hash) {
|
||||
use sp_trie::{TrieConfiguration, trie_types::Layout};
|
||||
use sp_trie::{trie_types::Layout, TrieConfiguration};
|
||||
|
||||
// sign extrinsics.
|
||||
let extrinsics = extrinsics.into_iter().map(sign).collect::<Vec<_>>();
|
||||
@@ -167,15 +163,14 @@ pub fn construct_block(
|
||||
extrinsics_root,
|
||||
state_root: Default::default(),
|
||||
digest: Digest {
|
||||
logs: vec![
|
||||
DigestItem::PreRuntime(
|
||||
BABE_ENGINE_ID,
|
||||
PreDigest::SecondaryPlain(SecondaryPlainPreDigest {
|
||||
slot: babe_slot,
|
||||
authority_index: 42,
|
||||
}).encode()
|
||||
),
|
||||
],
|
||||
logs: vec![DigestItem::PreRuntime(
|
||||
BABE_ENGINE_ID,
|
||||
PreDigest::SecondaryPlain(SecondaryPlainPreDigest {
|
||||
slot: babe_slot,
|
||||
authority_index: 42,
|
||||
})
|
||||
.encode(),
|
||||
)],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -186,7 +181,9 @@ pub fn construct_block(
|
||||
&header.encode(),
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
for extrinsic in extrinsics.iter() {
|
||||
// Try to apply the `extrinsic`. It should be valid, in the sense that it passes
|
||||
@@ -197,8 +194,13 @@ pub fn construct_block(
|
||||
&extrinsic.encode(),
|
||||
true,
|
||||
None,
|
||||
).0.expect("application of an extrinsic failed").into_encoded();
|
||||
match ApplyExtrinsicResult::decode(&mut &r[..]).expect("apply result deserialization failed") {
|
||||
)
|
||||
.0
|
||||
.expect("application of an extrinsic failed")
|
||||
.into_encoded();
|
||||
match ApplyExtrinsicResult::decode(&mut &r[..])
|
||||
.expect("apply result deserialization failed")
|
||||
{
|
||||
Ok(_) => {},
|
||||
Err(e) => panic!("Applying extrinsic failed: {:?}", e),
|
||||
}
|
||||
@@ -207,10 +209,13 @@ pub fn construct_block(
|
||||
let header = match executor_call::<NeverNativeValue, fn() -> _>(
|
||||
env,
|
||||
"BlockBuilder_finalize_block",
|
||||
&[0u8;0],
|
||||
&[0u8; 0],
|
||||
true,
|
||||
None,
|
||||
).0.unwrap() {
|
||||
)
|
||||
.0
|
||||
.unwrap()
|
||||
{
|
||||
NativeOrEncoded::Native(_) => unreachable!(),
|
||||
NativeOrEncoded::Encoded(h) => Header::decode(&mut &h[..]).unwrap(),
|
||||
};
|
||||
|
||||
@@ -18,20 +18,21 @@
|
||||
use codec::{Encode, Joiner};
|
||||
use frame_support::{
|
||||
traits::Currency,
|
||||
weights::{GetDispatchInfo, constants::ExtrinsicBaseWeight, IdentityFee, WeightToFeePolynomial},
|
||||
};
|
||||
use sp_core::NeverNativeValue;
|
||||
use sp_runtime::{Perbill, traits::One};
|
||||
use node_runtime::{
|
||||
CheckedExtrinsic, Call, Runtime, Balances, TransactionPayment, Multiplier,
|
||||
TransactionByteFee,
|
||||
constants::{time::SLOT_DURATION, currency::*},
|
||||
weights::{
|
||||
constants::ExtrinsicBaseWeight, GetDispatchInfo, IdentityFee, WeightToFeePolynomial,
|
||||
},
|
||||
};
|
||||
use node_primitives::Balance;
|
||||
use node_runtime::{
|
||||
constants::{currency::*, time::SLOT_DURATION},
|
||||
Balances, Call, CheckedExtrinsic, Multiplier, Runtime, TransactionByteFee, TransactionPayment,
|
||||
};
|
||||
use node_testing::keyring::*;
|
||||
use sp_core::NeverNativeValue;
|
||||
use sp_runtime::{traits::One, Perbill};
|
||||
|
||||
pub mod common;
|
||||
use self::common::{*, sign};
|
||||
use self::common::{sign, *};
|
||||
|
||||
#[test]
|
||||
fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
@@ -60,7 +61,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(0, 0))),
|
||||
function: Call::System(frame_system::Call::fill_block(Perbill::from_percent(60))),
|
||||
}
|
||||
},
|
||||
],
|
||||
(time1 / SLOT_DURATION).into(),
|
||||
);
|
||||
@@ -79,7 +80,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(1, 0))),
|
||||
function: Call::System(frame_system::Call::remark(vec![0; 1])),
|
||||
}
|
||||
},
|
||||
],
|
||||
(time2 / SLOT_DURATION).into(),
|
||||
);
|
||||
@@ -97,7 +98,9 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
&block1.0,
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
// weight multiplier is increased for next block.
|
||||
t.execute_with(|| {
|
||||
@@ -114,7 +117,9 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
|
||||
&block2.0,
|
||||
true,
|
||||
None,
|
||||
).0.unwrap();
|
||||
)
|
||||
.0
|
||||
.unwrap();
|
||||
|
||||
// weight multiplier is increased for next block.
|
||||
t.execute_with(|| {
|
||||
@@ -131,7 +136,8 @@ fn new_account_info(free_dollars: u128) -> Vec<u8> {
|
||||
providers: 0,
|
||||
sufficients: 0,
|
||||
data: (free_dollars * DOLLARS, 0 * DOLLARS, 0 * DOLLARS, 0 * DOLLARS),
|
||||
}.encode()
|
||||
}
|
||||
.encode()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -148,7 +154,7 @@ fn transaction_fee_is_correct() {
|
||||
t.insert(<frame_system::Account<Runtime>>::hashed_key_for(bob()), new_account_info(10));
|
||||
t.insert(
|
||||
<pallet_balances::TotalIssuance<Runtime>>::hashed_key().to_vec(),
|
||||
(110 * DOLLARS).encode()
|
||||
(110 * DOLLARS).encode(),
|
||||
);
|
||||
t.insert(<frame_system::BlockHash<Runtime>>::hashed_key_for(0), vec![0u8; 32]);
|
||||
|
||||
@@ -164,7 +170,8 @@ fn transaction_fee_is_correct() {
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
|
||||
assert!(r.is_ok());
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
@@ -173,7 +180,8 @@ fn transaction_fee_is_correct() {
|
||||
&vec![].and(&xt.clone()),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
assert!(r.is_ok());
|
||||
|
||||
t.execute_with(|| {
|
||||
@@ -228,15 +236,20 @@ fn block_weight_capacity_report() {
|
||||
|
||||
loop {
|
||||
let num_transfers = block_number * factor;
|
||||
let mut xts = (0..num_transfers).map(|i| CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(nonce + i as Index, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 0)),
|
||||
}).collect::<Vec<CheckedExtrinsic>>();
|
||||
let mut xts = (0..num_transfers)
|
||||
.map(|i| CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(nonce + i as Index, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 0)),
|
||||
})
|
||||
.collect::<Vec<CheckedExtrinsic>>();
|
||||
|
||||
xts.insert(0, CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
|
||||
});
|
||||
xts.insert(
|
||||
0,
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
|
||||
},
|
||||
);
|
||||
|
||||
// NOTE: this is super slow. Can probably be improved.
|
||||
let block = construct_block(
|
||||
@@ -262,7 +275,8 @@ fn block_weight_capacity_report() {
|
||||
&block.0,
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
|
||||
println!(" || Result = {:?}", r);
|
||||
assert!(r.is_ok());
|
||||
@@ -307,7 +321,11 @@ fn block_length_capacity_report() {
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(nonce, 0))),
|
||||
function: Call::System(frame_system::Call::remark(vec![0u8; (block_number * factor) as usize])),
|
||||
function: Call::System(frame_system::Call::remark(vec![
|
||||
0u8;
|
||||
(block_number * factor)
|
||||
as usize
|
||||
])),
|
||||
},
|
||||
],
|
||||
(time * 1000 / SLOT_DURATION).into(),
|
||||
@@ -327,7 +345,8 @@ fn block_length_capacity_report() {
|
||||
&block.0,
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
|
||||
println!(" || Result = {:?}", r);
|
||||
assert!(r.is_ok());
|
||||
|
||||
@@ -15,26 +15,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::sync::Arc;
|
||||
use node_runtime::{
|
||||
Executive, Indices, Runtime, UncheckedExtrinsic,
|
||||
};
|
||||
use sp_application_crypto::AppKey;
|
||||
use sp_core::{
|
||||
offchain::{
|
||||
TransactionPoolExt,
|
||||
testing::TestTransactionPoolExt,
|
||||
},
|
||||
};
|
||||
use sp_keystore::{KeystoreExt, SyncCryptoStore, testing::KeyStore};
|
||||
use frame_system::{
|
||||
offchain::{
|
||||
Signer,
|
||||
SubmitTransaction,
|
||||
SendSignedTransaction,
|
||||
}
|
||||
};
|
||||
use codec::Decode;
|
||||
use frame_system::offchain::{SendSignedTransaction, Signer, SubmitTransaction};
|
||||
use node_runtime::{Executive, Indices, Runtime, UncheckedExtrinsic};
|
||||
use sp_application_crypto::AppKey;
|
||||
use sp_core::offchain::{testing::TestTransactionPoolExt, TransactionPoolExt};
|
||||
use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod common;
|
||||
use self::common::*;
|
||||
@@ -56,8 +43,10 @@ fn should_submit_unsigned_transaction() {
|
||||
};
|
||||
|
||||
let call = pallet_im_online::Call::heartbeat(heartbeat_data, signature);
|
||||
SubmitTransaction::<Runtime, pallet_im_online::Call<Runtime>>::submit_unsigned_transaction(call.into())
|
||||
.unwrap();
|
||||
SubmitTransaction::<Runtime, pallet_im_online::Call<Runtime>>::submit_unsigned_transaction(
|
||||
call.into(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(state.read().transactions.len(), 1)
|
||||
});
|
||||
@@ -75,23 +64,26 @@ fn should_submit_signed_transaction() {
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter1", PHRASE))
|
||||
).unwrap();
|
||||
Some(&format!("{}/hunter1", PHRASE)),
|
||||
)
|
||||
.unwrap();
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter2", PHRASE))
|
||||
).unwrap();
|
||||
Some(&format!("{}/hunter2", PHRASE)),
|
||||
)
|
||||
.unwrap();
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter3", PHRASE))
|
||||
).unwrap();
|
||||
Some(&format!("{}/hunter3", PHRASE)),
|
||||
)
|
||||
.unwrap();
|
||||
t.register_extension(KeystoreExt(Arc::new(keystore)));
|
||||
|
||||
t.execute_with(|| {
|
||||
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
|
||||
.send_signed_transaction(|_| {
|
||||
let results =
|
||||
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
|
||||
pallet_balances::Call::transfer(Default::default(), Default::default())
|
||||
});
|
||||
|
||||
@@ -112,18 +104,20 @@ fn should_submit_signed_twice_from_the_same_account() {
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter1", PHRASE))
|
||||
).unwrap();
|
||||
Some(&format!("{}/hunter1", PHRASE)),
|
||||
)
|
||||
.unwrap();
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter2", PHRASE))
|
||||
).unwrap();
|
||||
Some(&format!("{}/hunter2", PHRASE)),
|
||||
)
|
||||
.unwrap();
|
||||
t.register_extension(KeystoreExt(Arc::new(keystore)));
|
||||
|
||||
t.execute_with(|| {
|
||||
let result = Signer::<Runtime, TestAuthorityId>::any_account()
|
||||
.send_signed_transaction(|_| {
|
||||
let result =
|
||||
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
|
||||
pallet_balances::Call::transfer(Default::default(), Default::default())
|
||||
});
|
||||
|
||||
@@ -131,8 +125,8 @@ fn should_submit_signed_twice_from_the_same_account() {
|
||||
assert_eq!(state.read().transactions.len(), 1);
|
||||
|
||||
// submit another one from the same account. The nonce should be incremented.
|
||||
let result = Signer::<Runtime, TestAuthorityId>::any_account()
|
||||
.send_signed_transaction(|_| {
|
||||
let result =
|
||||
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
|
||||
pallet_balances::Call::transfer(Default::default(), Default::default())
|
||||
});
|
||||
|
||||
@@ -147,10 +141,7 @@ fn should_submit_signed_twice_from_the_same_account() {
|
||||
}
|
||||
let nonce1 = nonce(UncheckedExtrinsic::decode(&mut &*s.transactions[0]).unwrap());
|
||||
let nonce2 = nonce(UncheckedExtrinsic::decode(&mut &*s.transactions[1]).unwrap());
|
||||
assert!(
|
||||
nonce1 != nonce2,
|
||||
"Transactions should have different nonces. Got: {:?}", nonce1
|
||||
);
|
||||
assert!(nonce1 != nonce2, "Transactions should have different nonces. Got: {:?}", nonce1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,14 +152,12 @@ fn should_submit_signed_twice_from_all_accounts() {
|
||||
t.register_extension(TransactionPoolExt::new(pool));
|
||||
|
||||
let keystore = KeyStore::new();
|
||||
keystore.sr25519_generate_new(
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter1", PHRASE))
|
||||
).unwrap();
|
||||
keystore.sr25519_generate_new(
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter2", PHRASE))
|
||||
).unwrap();
|
||||
keystore
|
||||
.sr25519_generate_new(sr25519::AuthorityId::ID, Some(&format!("{}/hunter1", PHRASE)))
|
||||
.unwrap();
|
||||
keystore
|
||||
.sr25519_generate_new(sr25519::AuthorityId::ID, Some(&format!("{}/hunter2", PHRASE)))
|
||||
.unwrap();
|
||||
t.register_extension(KeystoreExt(Arc::new(keystore)));
|
||||
|
||||
t.execute_with(|| {
|
||||
@@ -217,8 +206,10 @@ fn should_submit_signed_twice_from_all_accounts() {
|
||||
#[test]
|
||||
fn submitted_transaction_should_be_valid() {
|
||||
use codec::Encode;
|
||||
use sp_runtime::transaction_validity::{TransactionSource, TransactionTag};
|
||||
use sp_runtime::traits::StaticLookup;
|
||||
use sp_runtime::{
|
||||
traits::StaticLookup,
|
||||
transaction_validity::{TransactionSource, TransactionTag},
|
||||
};
|
||||
|
||||
let mut t = new_test_ext(compact_code_unwrap(), false);
|
||||
let (pool, state) = TestTransactionPoolExt::new();
|
||||
@@ -227,13 +218,15 @@ fn submitted_transaction_should_be_valid() {
|
||||
let keystore = KeyStore::new();
|
||||
SyncCryptoStore::sr25519_generate_new(
|
||||
&keystore,
|
||||
sr25519::AuthorityId::ID, Some(&format!("{}/hunter1", PHRASE))
|
||||
).unwrap();
|
||||
sr25519::AuthorityId::ID,
|
||||
Some(&format!("{}/hunter1", PHRASE)),
|
||||
)
|
||||
.unwrap();
|
||||
t.register_extension(KeystoreExt(Arc::new(keystore)));
|
||||
|
||||
t.execute_with(|| {
|
||||
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
|
||||
.send_signed_transaction(|_| {
|
||||
let results =
|
||||
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
|
||||
pallet_balances::Call::transfer(Default::default(), Default::default())
|
||||
});
|
||||
let len = results.len();
|
||||
@@ -252,7 +245,7 @@ fn submitted_transaction_should_be_valid() {
|
||||
let author = extrinsic.signature.clone().unwrap().0;
|
||||
let address = Indices::lookup(author).unwrap();
|
||||
let data = pallet_balances::AccountData { free: 5_000_000_000_000, ..Default::default() };
|
||||
let account = frame_system::AccountInfo { data, .. Default::default() };
|
||||
let account = frame_system::AccountInfo { data, ..Default::default() };
|
||||
<frame_system::Account<Runtime>>::insert(&address, account);
|
||||
|
||||
// check validity
|
||||
@@ -260,7 +253,8 @@ fn submitted_transaction_should_be_valid() {
|
||||
source,
|
||||
extrinsic,
|
||||
frame_system::BlockHash::<Runtime>::get(0),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// We ignore res.priority since this number can change based on updates to weights and such.
|
||||
assert_eq!(res.requires, Vec::<TransactionTag>::new());
|
||||
|
||||
Reference in New Issue
Block a user