mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-07 14:17:22 +00:00
rpc-v2/transaction: Generate Invalid events and add tests (#3784)
This PR ensures that the transaction API generates an `Invalid` events for transaction bytes that fail to decode. The spec mentioned the `Invalid` event at the jsonrpc error section, however this spec PR makes things clearer: - https://github.com/paritytech/json-rpc-interface-spec/pull/146 While at it have discovered an inconsistency with the generated events. The drop event from the transaction pool was incorrectly mapped to the `invalid` event. Added tests for the API stabilize the API soon: - https://github.com/paritytech/json-rpc-interface-spec/pull/144 Closes: https://github.com/paritytech/polkadot-sdk/issues/3083 cc @paritytech/subxt-team --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -34,12 +34,13 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_version::RuntimeVersion;
|
||||
use std::sync::Arc;
|
||||
use substrate_test_runtime::{Block, Hash, Header};
|
||||
use substrate_test_runtime::{Block, Hash, Header, H256};
|
||||
|
||||
pub struct ChainHeadMockClient<Client> {
|
||||
client: Arc<Client>,
|
||||
import_sinks: Mutex<Vec<TracingUnboundedSender<BlockImportNotification<Block>>>>,
|
||||
finality_sinks: Mutex<Vec<TracingUnboundedSender<FinalityNotification<Block>>>>,
|
||||
best_block: Mutex<Option<(H256, u64)>>,
|
||||
}
|
||||
|
||||
impl<Client> ChainHeadMockClient<Client> {
|
||||
@@ -48,6 +49,7 @@ impl<Client> ChainHeadMockClient<Client> {
|
||||
client,
|
||||
import_sinks: Default::default(),
|
||||
finality_sinks: Default::default(),
|
||||
best_block: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +88,11 @@ impl<Client> ChainHeadMockClient<Client> {
|
||||
let _ = sink.unbounded_send(notification.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the best block hash and number that is reported by the `info` method.
|
||||
pub fn set_best_block(&self, hash: H256, number: u64) {
|
||||
*self.best_block.lock() = Some((hash, number));
|
||||
}
|
||||
}
|
||||
|
||||
// ChainHead calls `import_notification_stream` and `finality_notification_stream` in order to
|
||||
@@ -309,8 +316,10 @@ impl<Block: BlockT, Client: HeaderMetadata<Block> + Send + Sync> HeaderMetadata<
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT, Client: HeaderBackend<Block> + Send + Sync> HeaderBackend<Block>
|
||||
impl<Block: BlockT<Hash = H256>, Client: HeaderBackend<Block> + Send + Sync> HeaderBackend<Block>
|
||||
for ChainHeadMockClient<Client>
|
||||
where
|
||||
<<Block as sp_runtime::traits::Block>::Header as HeaderT>::Number: From<u64>,
|
||||
{
|
||||
fn header(
|
||||
&self,
|
||||
@@ -320,7 +329,14 @@ impl<Block: BlockT, Client: HeaderBackend<Block> + Send + Sync> HeaderBackend<Bl
|
||||
}
|
||||
|
||||
fn info(&self) -> Info<Block> {
|
||||
self.client.info()
|
||||
let mut info = self.client.info();
|
||||
|
||||
if let Some((block_hash, block_num)) = self.best_block.lock().take() {
|
||||
info.best_hash = block_hash;
|
||||
info.best_number = block_num.into();
|
||||
}
|
||||
|
||||
info
|
||||
}
|
||||
|
||||
fn status(&self, hash: Block::Hash) -> sc_client_api::blockchain::Result<BlockStatus> {
|
||||
|
||||
Reference in New Issue
Block a user