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//! The Substrate test primitives to share
1920#![cfg_attr(not(feature = "std"), no_std)]
2122extern crate alloc;
2324use codec::{Decode, DecodeWithMemTracking, Encode};
2526pub use sp_application_crypto;
27use sp_application_crypto::sr25519;
2829use alloc::vec::Vec;
30pub use sp_core::{hash::H256, RuntimeDebug};
31use sp_runtime::traits::{BlakeTwo256, ExtrinsicLike, Verify};
3233/// Extrinsic for test-runtime.
34#[derive(
35 Clone, PartialEq, Eq, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, scale_info::TypeInfo,
36)]
37pub enum Extrinsic {
38 IncludeData(Vec<u8>),
39 StorageChange(Vec<u8>, Option<Vec<u8>>),
40}
4142#[cfg(feature = "serde")]
43impl serde::Serialize for Extrinsic {
44fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error>
45where
46S: ::serde::Serializer,
47 {
48self.using_encoded(|bytes| seq.serialize_bytes(bytes))
49 }
50}
5152impl ExtrinsicLike for Extrinsic {
53fn is_signed(&self) -> Option<bool> {
54if let Extrinsic::IncludeData(_) = *self {
55Some(false)
56 } else {
57Some(true)
58 }
59 }
6061fn is_bare(&self) -> bool {
62if let Extrinsic::IncludeData(_) = *self {
63true
64} else {
65false
66}
67 }
68}
6970/// The signature type used by accounts/transactions.
71pub type AccountSignature = sr25519::Signature;
72/// An identifier for an account on this system.
73pub type AccountId = <AccountSignature as Verify>::Signer;
74/// A simple hash type for all our hashing.
75pub type Hash = H256;
76/// The block number type used in this runtime.
77pub type BlockNumber = u64;
78/// Index of a transaction.
79pub type Nonce = u64;
80/// The item of a block digest.
81pub type DigestItem = sp_runtime::generic::DigestItem;
82/// The digest of a block.
83pub type Digest = sp_runtime::generic::Digest;
84/// A test block.
85pub type Block = sp_runtime::generic::Block<Header, Extrinsic>;
86/// A test block's header.
87pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;