mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 21:35:44 +00:00
add reconnecting tests for unstable_backend (#1765)
* add tests for unstable_backend --------- Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
+897
-191
File diff suppressed because it is too large
Load Diff
@@ -321,6 +321,7 @@ impl<T: Config> UnstableRpcMethods<T> {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde(tag = "event")]
|
#[serde(tag = "event")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub enum FollowEvent<Hash> {
|
pub enum FollowEvent<Hash> {
|
||||||
/// The latest finalized block.
|
/// The latest finalized block.
|
||||||
///
|
///
|
||||||
@@ -363,6 +364,8 @@ pub enum FollowEvent<Hash> {
|
|||||||
/// This is the first event generated by the `follow` subscription
|
/// This is the first event generated by the `follow` subscription
|
||||||
/// and is submitted only once.
|
/// and is submitted only once.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
|
#[cfg_attr(test, serde(rename_all = "camelCase"))]
|
||||||
pub struct Initialized<Hash> {
|
pub struct Initialized<Hash> {
|
||||||
/// The hashes of the last finalized blocks.
|
/// The hashes of the last finalized blocks.
|
||||||
pub finalized_block_hashes: Vec<Hash>,
|
pub finalized_block_hashes: Vec<Hash>,
|
||||||
@@ -404,6 +407,7 @@ impl<'de, Hash: Deserialize<'de>> Deserialize<'de> for Initialized<Hash> {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub enum RuntimeEvent {
|
pub enum RuntimeEvent {
|
||||||
/// The runtime version of this block.
|
/// The runtime version of this block.
|
||||||
Valid(RuntimeVersionEvent),
|
Valid(RuntimeVersionEvent),
|
||||||
@@ -418,6 +422,7 @@ pub enum RuntimeEvent {
|
|||||||
/// - blocks that suffered a change in runtime compared with their parents
|
/// - blocks that suffered a change in runtime compared with their parents
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct RuntimeVersionEvent {
|
pub struct RuntimeVersionEvent {
|
||||||
/// Details about this runtime.
|
/// Details about this runtime.
|
||||||
pub spec: RuntimeSpec,
|
pub spec: RuntimeSpec,
|
||||||
@@ -427,6 +432,7 @@ pub struct RuntimeVersionEvent {
|
|||||||
/// the "initialized" event of `chainHead_follow` if the `withRuntime` flag is set.
|
/// the "initialized" event of `chainHead_follow` if the `withRuntime` flag is set.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct RuntimeSpec {
|
pub struct RuntimeSpec {
|
||||||
/// Opaque string indicating the name of the chain.
|
/// Opaque string indicating the name of the chain.
|
||||||
pub spec_name: String,
|
pub spec_name: String,
|
||||||
@@ -453,13 +459,18 @@ pub struct RuntimeSpec {
|
|||||||
///
|
///
|
||||||
/// **Note:** In Substrate, the keys in the apis field consists of the hexadecimal-encoded 8-bytes blake2
|
/// **Note:** In Substrate, the keys in the apis field consists of the hexadecimal-encoded 8-bytes blake2
|
||||||
/// hash of the name of the API. For example, the `TaggedTransactionQueue` API is 0xd2bc9897eed08f15.
|
/// hash of the name of the API. For example, the `TaggedTransactionQueue` API is 0xd2bc9897eed08f15.
|
||||||
#[serde(with = "hashmap_as_tuple_list")]
|
#[serde(deserialize_with = "hashmap_as_tuple_list::deserialize")]
|
||||||
|
#[cfg_attr(
|
||||||
|
test,
|
||||||
|
serde(serialize_with = "hashmap_as_tuple_list::for_test::serialize")
|
||||||
|
)]
|
||||||
pub apis: HashMap<String, u32>,
|
pub apis: HashMap<String, u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The operation could not be processed due to an error.
|
/// The operation could not be processed due to an error.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct ErrorEvent {
|
pub struct ErrorEvent {
|
||||||
/// Reason of the error.
|
/// Reason of the error.
|
||||||
pub error: String,
|
pub error: String,
|
||||||
@@ -468,6 +479,7 @@ pub struct ErrorEvent {
|
|||||||
/// Indicate a new non-finalized block.
|
/// Indicate a new non-finalized block.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct NewBlock<Hash> {
|
pub struct NewBlock<Hash> {
|
||||||
/// The hash of the new block.
|
/// The hash of the new block.
|
||||||
pub block_hash: Hash,
|
pub block_hash: Hash,
|
||||||
@@ -485,6 +497,7 @@ pub struct NewBlock<Hash> {
|
|||||||
/// Indicate the block hash of the new best block.
|
/// Indicate the block hash of the new best block.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct BestBlockChanged<Hash> {
|
pub struct BestBlockChanged<Hash> {
|
||||||
/// The block hash of the new best block.
|
/// The block hash of the new best block.
|
||||||
pub best_block_hash: Hash,
|
pub best_block_hash: Hash,
|
||||||
@@ -493,6 +506,7 @@ pub struct BestBlockChanged<Hash> {
|
|||||||
/// Indicate the finalized and pruned block hashes.
|
/// Indicate the finalized and pruned block hashes.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct Finalized<Hash> {
|
pub struct Finalized<Hash> {
|
||||||
/// Block hashes that are finalized.
|
/// Block hashes that are finalized.
|
||||||
pub finalized_block_hashes: Vec<Hash>,
|
pub finalized_block_hashes: Vec<Hash>,
|
||||||
@@ -503,6 +517,7 @@ pub struct Finalized<Hash> {
|
|||||||
/// Indicate the operation id of the event.
|
/// Indicate the operation id of the event.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct OperationId {
|
pub struct OperationId {
|
||||||
/// The operation id of the event.
|
/// The operation id of the event.
|
||||||
pub operation_id: String,
|
pub operation_id: String,
|
||||||
@@ -511,6 +526,7 @@ pub struct OperationId {
|
|||||||
/// The response of the `chainHead_body` method.
|
/// The response of the `chainHead_body` method.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct OperationBodyDone {
|
pub struct OperationBodyDone {
|
||||||
/// The operation id of the event.
|
/// The operation id of the event.
|
||||||
pub operation_id: String,
|
pub operation_id: String,
|
||||||
@@ -521,6 +537,7 @@ pub struct OperationBodyDone {
|
|||||||
/// The response of the `chainHead_call` method.
|
/// The response of the `chainHead_call` method.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct OperationCallDone {
|
pub struct OperationCallDone {
|
||||||
/// The operation id of the event.
|
/// The operation id of the event.
|
||||||
pub operation_id: String,
|
pub operation_id: String,
|
||||||
@@ -531,6 +548,7 @@ pub struct OperationCallDone {
|
|||||||
/// The response of the `chainHead_call` method.
|
/// The response of the `chainHead_call` method.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct OperationStorageItems {
|
pub struct OperationStorageItems {
|
||||||
/// The operation id of the event.
|
/// The operation id of the event.
|
||||||
pub operation_id: String,
|
pub operation_id: String,
|
||||||
@@ -541,6 +559,7 @@ pub struct OperationStorageItems {
|
|||||||
/// Indicate a problem during the operation.
|
/// Indicate a problem during the operation.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct OperationError {
|
pub struct OperationError {
|
||||||
/// The operation id of the event.
|
/// The operation id of the event.
|
||||||
pub operation_id: String,
|
pub operation_id: String,
|
||||||
@@ -551,6 +570,7 @@ pub struct OperationError {
|
|||||||
/// The storage result.
|
/// The storage result.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct StorageResult {
|
pub struct StorageResult {
|
||||||
/// The hex-encoded key of the result.
|
/// The hex-encoded key of the result.
|
||||||
pub key: Bytes,
|
pub key: Bytes,
|
||||||
@@ -562,6 +582,7 @@ pub struct StorageResult {
|
|||||||
/// The type of the storage query.
|
/// The type of the storage query.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub enum StorageResultType {
|
pub enum StorageResultType {
|
||||||
/// Fetch the value of the provided key.
|
/// Fetch the value of the provided key.
|
||||||
Value(Bytes),
|
Value(Bytes),
|
||||||
@@ -575,6 +596,7 @@ pub enum StorageResultType {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde(tag = "result")]
|
#[serde(tag = "result")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub enum MethodResponse {
|
pub enum MethodResponse {
|
||||||
/// The method has started.
|
/// The method has started.
|
||||||
Started(MethodResponseStarted),
|
Started(MethodResponseStarted),
|
||||||
@@ -585,6 +607,7 @@ pub enum MethodResponse {
|
|||||||
/// The `started` result of a method.
|
/// The `started` result of a method.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct MethodResponseStarted {
|
pub struct MethodResponseStarted {
|
||||||
/// The operation id of the response.
|
/// The operation id of the response.
|
||||||
pub operation_id: String,
|
pub operation_id: String,
|
||||||
@@ -704,6 +727,7 @@ impl<Hash: BlockHash> Stream for TransactionSubscription<Hash> {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde(tag = "event")]
|
#[serde(tag = "event")]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub enum TransactionStatus<Hash> {
|
pub enum TransactionStatus<Hash> {
|
||||||
/// Transaction is part of the future queue.
|
/// Transaction is part of the future queue.
|
||||||
Validated,
|
Validated,
|
||||||
@@ -745,11 +769,16 @@ pub enum TransactionStatus<Hash> {
|
|||||||
|
|
||||||
/// Details of a block that a transaction is seen in.
|
/// Details of a block that a transaction is seen in.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
pub struct TransactionBlockDetails<Hash> {
|
pub struct TransactionBlockDetails<Hash> {
|
||||||
/// The block hash.
|
/// The block hash.
|
||||||
pub hash: Hash,
|
pub hash: Hash,
|
||||||
/// The index of the transaction in the block.
|
/// The index of the transaction in the block.
|
||||||
#[serde(with = "unsigned_number_as_string")]
|
#[serde(deserialize_with = "unsigned_number_as_string::deserialize")]
|
||||||
|
#[cfg_attr(
|
||||||
|
test,
|
||||||
|
serde(serialize_with = "unsigned_number_as_string::for_test::serialize")
|
||||||
|
)]
|
||||||
pub index: u64,
|
pub index: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,6 +833,18 @@ pub(crate) mod unsigned_number_as_string {
|
|||||||
Ok(v.into())
|
Ok(v.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod for_test {
|
||||||
|
use serde::ser::Serializer;
|
||||||
|
|
||||||
|
/// Serialize a number as string
|
||||||
|
pub fn serialize<S>(item: &u64, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_str(&item.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A temporary shim to decode "spec.apis" if it comes back as an array like:
|
/// A temporary shim to decode "spec.apis" if it comes back as an array like:
|
||||||
@@ -880,6 +921,28 @@ pub(crate) mod hashmap_as_tuple_list {
|
|||||||
Ok(map)
|
Ok(map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod for_test {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
use serde::ser::{Serialize, SerializeSeq, Serializer};
|
||||||
|
|
||||||
|
/// Serialize hashmap as list of tuples
|
||||||
|
pub fn serialize<S, K: Eq + Hash + Serialize, V: Serialize>(
|
||||||
|
item: &HashMap<K, V>,
|
||||||
|
serializer: S,
|
||||||
|
) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let mut seq = serializer.serialize_seq(None)?;
|
||||||
|
for i in item {
|
||||||
|
seq.serialize_element(&i)?;
|
||||||
|
}
|
||||||
|
seq.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user