Skip to content

Commit

Permalink
Use our own RuntimeVersion struct (for now) to avoid error decoding i…
Browse files Browse the repository at this point in the history
…nto sp_version::RuntimeVersion
  • Loading branch information
jsdw committed Jan 14, 2022
1 parent 5d0a56a commit 940c770
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use futures::future;
use sp_runtime::traits::Hash;
pub use sp_runtime::traits::SignedExtension;
pub use sp_version::RuntimeVersion;

use crate::{
error::Error,
Expand All @@ -31,6 +30,7 @@ use crate::{
rpc::{
Rpc,
RpcClient,
RuntimeVersion,
SystemProperties,
},
storage::StorageClient,
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<T: Config, E: Decode> std::fmt::Debug for Client<T, E> {
.field("metadata", &"<Metadata>")
.field("events_decoder", &"<EventsDecoder>")
.field("properties", &self.properties)
.field("runtime_version", &self.runtime_version.to_string())
.field("runtime_version", &self.runtime_version)
.field("iter_page_size", &self.iter_page_size)
.finish()
}
Expand Down
2 changes: 1 addition & 1 deletion src/extrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pub use self::{
};

use sp_runtime::traits::SignedExtension;
use sp_version::RuntimeVersion;

use crate::{
Config,
Encoded,
Error,
rpc::RuntimeVersion,
};

/// UncheckedExtrinsic type.
Expand Down
23 changes: 22 additions & 1 deletion src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ use sp_runtime::generic::{
Block,
SignedBlock,
};
use sp_version::RuntimeVersion;

/// A number type that can be serialized both as a number or a string that encodes a number in a
/// string.
Expand Down Expand Up @@ -164,6 +163,28 @@ pub enum SubstrateTransactionStatus<Hash, BlockHash> {
Invalid,
}

/// This contains the runtime version information necessary to make transactions, as obtained from
/// the RPC call `state_getRuntimeVersion`,
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RuntimeVersion {
/// Version of the runtime specification. A full-node will not attempt to use its native
/// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
/// `spec_version` and `authoring_version` are the same between Wasm and native.
pub spec_version: u32,

/// All existing dispatches are fully compatible when this number doesn't change. If this
/// number changes, then `spec_version` must change, also.
///
/// This number must change when an existing dispatchable (module ID, dispatch ID) is changed,
/// either through an alteration in its user-level semantics, a parameter
/// added/removed/changed, a dispatchable being removed, a module being removed, or a
/// dispatchable/module changing its index.
///
/// It need *not* change when a new module is added or when a dispatchable is added.
pub transaction_version: u32,
}

/// Rpc client wrapper.
/// This is workaround because adding generic types causes the macros to fail.
#[derive(Clone)]
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/frame/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ async fn transfer_error() {
.await;

if let Err(Error::Runtime(DispatchError::Module { index, error })) = res {
assert_eq!(index, 123); // TODO fix (original: Balances)
assert_eq!(error, 123); // TODO fix (original: InsufficientBalance)
assert_eq!(index, 6); // Balances
assert_eq!(error, 2); // InsufficientBalance
} else {
panic!("expected a runtime module error");
}
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/frame/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ async fn validate_not_possible_for_stash_account() -> Result<(), Error<DispatchE
.wait_for_finalized_success()
.await;
assert_matches!(announce_validator, Err(Error::Runtime(DispatchError::Module{ index, error })) => {
assert_eq!(index, 123); // TODO fix (original: Staking)
assert_eq!(error, 123); // TODO fix (original: NotAController)
assert_eq!(index, 10); // Staking
assert_eq!(error, 0); // NotAController
});
Ok(())
}
Expand Down Expand Up @@ -121,8 +121,8 @@ async fn nominate_not_possible_for_stash_account() -> Result<(), Error<DispatchE
.await;

assert_matches!(nomination, Err(Error::Runtime(DispatchError::Module{ index, error })) => {
assert_eq!(index, 123); // TODO fix (original: Staking)
assert_eq!(error, 123); // TODO fix (original: NotAController)
assert_eq!(index, 10); // Staking
assert_eq!(error, 0); // NotAController
});
Ok(())
}
Expand Down Expand Up @@ -164,8 +164,8 @@ async fn chill_works_for_controller_only() -> Result<(), Error<DispatchError>> {
.await;

assert_matches!(chill, Err(Error::Runtime(DispatchError::Module{ index, error })) => {
assert_eq!(index, 123); // TODO fix (original: Staking)
assert_eq!(error, 123); // TODO fix (original: NotAController)
assert_eq!(index, 10); // Staking
assert_eq!(error, 0); // NotAController
});

let is_chilled = cxt
Expand Down Expand Up @@ -219,8 +219,8 @@ async fn tx_bond() -> Result<(), Error<DispatchError>> {
.await;

assert_matches!(bond_again, Err(Error::Runtime(DispatchError::Module{ index, error })) => {
assert_eq!(index, 123); // TODO fix (original: Staking)
assert_eq!(error, 123); // TODO fix (original: AlreadyBonded)
assert_eq!(index, 10); // Staking
assert_eq!(error, 2); // AlreadyBonded
});
Ok(())
}
Expand Down

0 comments on commit 940c770

Please sign in to comment.