referrerpolicy=no-referrer-when-downgrade

substrate_test_runtime_client/
block_builder_ext.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Block Builder extensions for tests.
19
20use sc_block_builder::BlockBuilderApi;
21use sp_api::{ApiExt, ProvideRuntimeApi};
22use substrate_test_runtime::*;
23
24/// Extension trait for test block builder.
25pub trait BlockBuilderExt {
26	/// Add transfer extrinsic to the block.
27	fn push_transfer(
28		&mut self,
29		transfer: substrate_test_runtime::Transfer,
30	) -> Result<(), sp_blockchain::Error>;
31
32	/// Add unsigned storage change extrinsic to the block.
33	fn push_storage_change(
34		&mut self,
35		key: Vec<u8>,
36		value: Option<Vec<u8>>,
37	) -> Result<(), sp_blockchain::Error>;
38
39	/// Adds an extrinsic which pushes DigestItem to header's log
40	fn push_deposit_log_digest_item(
41		&mut self,
42		log: sp_runtime::generic::DigestItem,
43	) -> Result<(), sp_blockchain::Error>;
44}
45
46impl<'a, A> BlockBuilderExt for sc_block_builder::BlockBuilder<'a, substrate_test_runtime::Block, A>
47where
48	A: ProvideRuntimeApi<substrate_test_runtime::Block>
49		+ sp_api::CallApiAt<substrate_test_runtime::Block>
50		+ 'a,
51	A::Api: BlockBuilderApi<substrate_test_runtime::Block> + ApiExt<substrate_test_runtime::Block>,
52{
53	fn push_transfer(
54		&mut self,
55		transfer: substrate_test_runtime::Transfer,
56	) -> Result<(), sp_blockchain::Error> {
57		self.push(transfer.into_unchecked_extrinsic())
58	}
59
60	fn push_storage_change(
61		&mut self,
62		key: Vec<u8>,
63		value: Option<Vec<u8>>,
64	) -> Result<(), sp_blockchain::Error> {
65		self.push(ExtrinsicBuilder::new_storage_change(key, value).build())
66	}
67
68	fn push_deposit_log_digest_item(
69		&mut self,
70		log: sp_runtime::generic::DigestItem,
71	) -> Result<(), sp_blockchain::Error> {
72		self.push(ExtrinsicBuilder::new_deposit_log_digest_item(log).build())
73	}
74}