mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 06:47:58 +00:00
Cli tool tests (#977)
* add tests and fix some minor things * implement output writer and some tests * formatting * adjust tests and formatting * clippy fix * cargo fmt * revert change in substrate runner * clippy suggestions * mode make_type to test mod
This commit is contained in:
@@ -7,7 +7,7 @@ use clap::Parser as ClapParser;
|
||||
use codec::{Decode, Encode};
|
||||
use color_eyre::eyre::{self, bail};
|
||||
use frame_metadata::{v15::RuntimeMetadataV15, RuntimeMetadata, RuntimeMetadataPrefixed};
|
||||
use std::io::{self, Write};
|
||||
use std::io::Write;
|
||||
use subxt_metadata::Metadata;
|
||||
|
||||
/// Download metadata from a substrate node, for use with `subxt` codegen.
|
||||
@@ -34,7 +34,7 @@ pub struct Opts {
|
||||
runtime_apis: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
pub async fn run(opts: Opts) -> color_eyre::Result<()> {
|
||||
pub async fn run(opts: Opts, output: &mut impl Write) -> color_eyre::Result<()> {
|
||||
let bytes = opts.file_or_url.fetch().await?;
|
||||
let mut metadata = RuntimeMetadataPrefixed::decode(&mut &bytes[..])?;
|
||||
|
||||
@@ -72,17 +72,18 @@ pub async fn run(opts: Opts) -> color_eyre::Result<()> {
|
||||
match opts.format.as_str() {
|
||||
"json" => {
|
||||
let json = serde_json::to_string_pretty(&metadata)?;
|
||||
println!("{json}");
|
||||
write!(output, "{json}")?;
|
||||
Ok(())
|
||||
}
|
||||
"hex" => {
|
||||
let hex_data = format!("0x{:?}", hex::encode(metadata.encode()));
|
||||
println!("{hex_data}");
|
||||
write!(output, "{hex_data}")?;
|
||||
Ok(())
|
||||
}
|
||||
"bytes" => {
|
||||
let bytes = metadata.encode();
|
||||
Ok(io::stdout().write_all(&bytes)?)
|
||||
output.write_all(&bytes)?;
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(eyre::eyre!(
|
||||
"Unsupported format `{}`, expected `json`, `hex` or `bytes`",
|
||||
|
||||
Reference in New Issue
Block a user