referrerpolicy=no-referrer-when-downgrade

sp_test_primitives/
lib.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//! The Substrate test primitives to share
19
20#![cfg_attr(not(feature = "std"), no_std)]
21
22extern crate alloc;
23
24use codec::{Decode, DecodeWithMemTracking, Encode};
25
26pub use sp_application_crypto;
27use sp_application_crypto::sr25519;
28
29use alloc::vec::Vec;
30pub use sp_core::{hash::H256, RuntimeDebug};
31use sp_runtime::traits::{BlakeTwo256, ExtrinsicLike, Verify};
32
33/// 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}
41
42#[cfg(feature = "serde")]
43impl serde::Serialize for Extrinsic {
44	fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error>
45	where
46		S: ::serde::Serializer,
47	{
48		self.using_encoded(|bytes| seq.serialize_bytes(bytes))
49	}
50}
51
52impl ExtrinsicLike for Extrinsic {
53	fn is_signed(&self) -> Option<bool> {
54		if let Extrinsic::IncludeData(_) = *self {
55			Some(false)
56		} else {
57			Some(true)
58		}
59	}
60
61	fn is_bare(&self) -> bool {
62		if let Extrinsic::IncludeData(_) = *self {
63			true
64		} else {
65			false
66		}
67	}
68}
69
70/// 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>;