mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 04:28:00 +00:00
Remove codec::Encode and codec::Decode derives from generated APIs by default (#2008)
* Remove codec::Encode and codec::Decode from generated APIs by default * clippy fixes * clippy * More fixes, and CompactAs only if Encode/Decode * revert println in example * fix lightclient test * fix docs * Fix another rust doc comment * Fix failing storage test * Remove now-unnecessary test * clippy * clippy * Remove pointless clone
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use crate::{subxt_test, test_context, utils::consume_initial_blocks};
|
||||
use codec::{Compact, Encode};
|
||||
use codec::{Compact, Decode, Encode};
|
||||
use futures::StreamExt;
|
||||
|
||||
#[cfg(fullclient)]
|
||||
@@ -160,13 +160,10 @@ async fn runtime_api_call() -> Result<(), subxt::Error> {
|
||||
let block = sub.next().await.unwrap()?;
|
||||
let rt = block.runtime_api().await?;
|
||||
|
||||
// get metadata via state_call.
|
||||
let (_, meta1) = rt
|
||||
.call_raw::<(Compact<u32>, frame_metadata::RuntimeMetadataPrefixed)>(
|
||||
"Metadata_metadata",
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
// get metadata via raw state_call.
|
||||
let meta_bytes = rt.call_raw("Metadata_metadata", None).await?;
|
||||
let (_, meta1): (Compact<u32>, frame_metadata::RuntimeMetadataPrefixed) =
|
||||
Decode::decode(&mut &*meta_bytes)?;
|
||||
|
||||
// get metadata via `state_getMetadata`.
|
||||
let meta2_bytes = rpc.state_get_metadata(Some(block.hash())).await?.into_raw();
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -220,7 +220,7 @@ async fn tx_call() {
|
||||
|
||||
let info_addr = node_runtime::storage()
|
||||
.contracts()
|
||||
.contract_info_of(&contract);
|
||||
.contract_info_of(contract.clone());
|
||||
|
||||
let contract_info = cxt
|
||||
.client()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use crate::{node_runtime, subxt_test, test_context};
|
||||
use codec::Encode;
|
||||
use codec::{Decode, Encode};
|
||||
use subxt::utils::AccountId32;
|
||||
use subxt_signer::sr25519::dev;
|
||||
|
||||
@@ -81,17 +81,34 @@ async fn unchecked_extrinsic_encoding() -> Result<(), subxt::Error> {
|
||||
let mut encoded = tx_bytes.clone();
|
||||
encoded.extend(len.encode());
|
||||
|
||||
let expected_result: node_runtime::runtime_types::pallet_transaction_payment::types::FeeDetails<
|
||||
::core::primitive::u128,
|
||||
> = api
|
||||
.runtime_api()
|
||||
.at_latest()
|
||||
.await?
|
||||
.call_raw(
|
||||
"TransactionPaymentApi_query_fee_details",
|
||||
Some(encoded.as_ref()),
|
||||
)
|
||||
.await?;
|
||||
// Use the raw API to manually build an expected result.
|
||||
let expected_result = {
|
||||
let expected_result_bytes = api
|
||||
.runtime_api()
|
||||
.at_latest()
|
||||
.await?
|
||||
.call_raw(
|
||||
"TransactionPaymentApi_query_fee_details",
|
||||
Some(encoded.as_ref()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// manually decode, since our runtime types don't impl Decode by default.
|
||||
let (inclusion_fee, tip): (Option<(u128, u128, u128)>, u128) =
|
||||
Decode::decode(&mut &*expected_result_bytes)?;
|
||||
|
||||
// put the values into our generated type.
|
||||
node_runtime::runtime_types::pallet_transaction_payment::types::FeeDetails {
|
||||
inclusion_fee: inclusion_fee.map(|(base_fee, len_fee, adjusted_weight_fee)| {
|
||||
node_runtime::runtime_types::pallet_transaction_payment::types::InclusionFee {
|
||||
base_fee,
|
||||
len_fee,
|
||||
adjusted_weight_fee,
|
||||
}
|
||||
}),
|
||||
tip,
|
||||
}
|
||||
};
|
||||
|
||||
// Use the generated API to confirm the result with the raw call.
|
||||
let runtime_api_call = node_runtime::apis()
|
||||
|
||||
@@ -72,15 +72,16 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error>
|
||||
// This is what the generated code hashes a `session().key_owner(..)` key into:
|
||||
let actual_key = node_runtime::storage()
|
||||
.session()
|
||||
.key_owner(KeyTypeId([1, 2, 3, 4]), [5u8, 6, 7, 8]);
|
||||
.key_owner(KeyTypeId([1, 2, 3, 4]), vec![5, 6, 7, 8]);
|
||||
let actual_key_bytes = api.storage().address_bytes(&actual_key)?;
|
||||
|
||||
// Let's manually hash to what we assume it should be and compare:
|
||||
let expected_key_bytes = {
|
||||
// Hash the prefix to the storage entry:
|
||||
let mut bytes = sp_core::twox_128("Session".as_bytes()).to_vec();
|
||||
bytes.extend(&sp_core::twox_128("KeyOwner".as_bytes())[..]);
|
||||
// Both keys, use twox64_concat hashers:
|
||||
let key1 = KeyTypeId([1, 2, 3, 4]).encode();
|
||||
let key1 = [1u8, 2, 3, 4].encode();
|
||||
let key2 = vec![5u8, 6, 7, 8].encode();
|
||||
bytes.extend(sp_core::twox_64(&key1));
|
||||
bytes.extend(&key1);
|
||||
@@ -88,7 +89,6 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error>
|
||||
bytes.extend(&key2);
|
||||
bytes
|
||||
};
|
||||
dbg!(&expected_key_bytes);
|
||||
|
||||
assert_eq!(actual_key_bytes, expected_key_bytes);
|
||||
Ok(())
|
||||
@@ -196,7 +196,6 @@ async fn storage_partial_lookup() -> Result<(), subxt::Error> {
|
||||
let mut approvals = Vec::new();
|
||||
while let Some(Ok(kv)) = results.next().await {
|
||||
assert!(kv.key_bytes.starts_with(&addr_bytes));
|
||||
assert!(kv.keys.decoded().is_ok());
|
||||
approvals.push(kv.value);
|
||||
}
|
||||
assert_eq!(approvals.len(), 1);
|
||||
|
||||
@@ -107,9 +107,8 @@ async fn runtime_api_call(api: &Client) -> Result<(), subxt::Error> {
|
||||
let rt = block.runtime_api().await?;
|
||||
|
||||
// get metadata via state_call. if it decodes ok, it's probably all good.
|
||||
let _ = rt
|
||||
.call_raw::<(Compact<u32>, Metadata)>("Metadata_metadata", None)
|
||||
.await?;
|
||||
let result_bytes = rt.call_raw("Metadata_metadata", None).await?;
|
||||
let (_, _meta): (Compact<u32>, Metadata) = codec::Decode::decode(&mut &*result_bytes)?;
|
||||
|
||||
tracing::trace!("Made runtime API call in {:?}\n", now.elapsed());
|
||||
|
||||
|
||||
@@ -73,10 +73,7 @@ impl SubstrateNodeBuilder {
|
||||
pub fn spawn(mut self) -> Result<SubstrateNode, Error> {
|
||||
// Try to spawn the binary at each path, returning the
|
||||
// first "ok" or last error that we encountered.
|
||||
let mut res = Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"No binary path provided",
|
||||
));
|
||||
let mut res = Err(io::Error::other("No binary path provided"));
|
||||
|
||||
let path = Command::new("mktemp")
|
||||
.arg("-d")
|
||||
|
||||
Reference in New Issue
Block a user