1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
56// 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.
1718//! Block Builder extensions for tests.
1920use sc_block_builder::BlockBuilderApi;
21use sp_api::{ApiExt, ProvideRuntimeApi};
22use substrate_test_runtime::*;
2324/// Extension trait for test block builder.
25pub trait BlockBuilderExt {
26/// Add transfer extrinsic to the block.
27fn push_transfer(
28&mut self,
29 transfer: substrate_test_runtime::Transfer,
30 ) -> Result<(), sp_blockchain::Error>;
3132/// Add unsigned storage change extrinsic to the block.
33fn push_storage_change(
34&mut self,
35 key: Vec<u8>,
36 value: Option<Vec<u8>>,
37 ) -> Result<(), sp_blockchain::Error>;
3839/// Adds an extrinsic which pushes DigestItem to header's log
40fn push_deposit_log_digest_item(
41&mut self,
42 log: sp_runtime::generic::DigestItem,
43 ) -> Result<(), sp_blockchain::Error>;
44}
4546impl<'a, A> BlockBuilderExt for sc_block_builder::BlockBuilder<'a, substrate_test_runtime::Block, A>
47where
48A: 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{
53fn push_transfer(
54&mut self,
55 transfer: substrate_test_runtime::Transfer,
56 ) -> Result<(), sp_blockchain::Error> {
57self.push(transfer.into_unchecked_extrinsic())
58 }
5960fn push_storage_change(
61&mut self,
62 key: Vec<u8>,
63 value: Option<Vec<u8>>,
64 ) -> Result<(), sp_blockchain::Error> {
65self.push(ExtrinsicBuilder::new_storage_change(key, value).build())
66 }
6768fn push_deposit_log_digest_item(
69&mut self,
70 log: sp_runtime::generic::DigestItem,
71 ) -> Result<(), sp_blockchain::Error> {
72self.push(ExtrinsicBuilder::new_deposit_log_digest_item(log).build())
73 }
74}