mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 11:27:58 +00:00
fd8f60c8a9
* codegen: Add uncheckedExtrinsic substitute Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Add uncheckedExtrinsic replacement Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Test uncheckedExtrinsic encoding Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Apply clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Implement encode_to instead of encode for uncheckedExtrinsic Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Remove encode_as_fields from uncheckedExtrinsic Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Extend the UncheckedExtrinsic interface Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Use Static<Encoded> for uncheckedExtrinsic Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Remove extra impl on the uncheckedExtrinsic Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Add back the EncodeAsType Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Simplify the decode_as_type Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Use encode_as_type Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: impl Decode for UncheckedExtrinsic Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update subxt/src/utils/unchecked_extrinsic.rs Co-authored-by: James Wilson <james@jsdw.me> * utils: Apply cargo fmt Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils: Check encoding / decoding of uncheckedExtrinsic Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * utils/tests: Use an already encoded tx bytes to start with Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: James Wilson <james@jsdw.me>
105 lines
2.8 KiB
Rust
105 lines
2.8 KiB
Rust
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
|
// see LICENSE for license details.
|
|
|
|
use crate::{node_runtime, test_context};
|
|
use codec::Encode;
|
|
use subxt::utils::AccountId32;
|
|
use subxt_signer::sr25519::dev;
|
|
|
|
#[tokio::test]
|
|
async fn account_nonce() -> Result<(), subxt::Error> {
|
|
let ctx = test_context().await;
|
|
let api = ctx.client();
|
|
|
|
let alice = dev::alice();
|
|
let alice_account_id: AccountId32 = alice.public_key().into();
|
|
|
|
// Check Alice nonce is starting from 0.
|
|
let runtime_api_call = node_runtime::apis()
|
|
.account_nonce_api()
|
|
.account_nonce(alice_account_id.clone());
|
|
let nonce = api
|
|
.runtime_api()
|
|
.at_latest()
|
|
.await?
|
|
.call(runtime_api_call)
|
|
.await?;
|
|
assert_eq!(nonce, 0);
|
|
|
|
// Do some transaction to bump the Alice nonce to 1:
|
|
let remark_tx = node_runtime::tx().system().remark(vec![1, 2, 3, 4, 5]);
|
|
api.tx()
|
|
.sign_and_submit_then_watch_default(&remark_tx, &alice)
|
|
.await?
|
|
.wait_for_finalized_success()
|
|
.await?;
|
|
|
|
let runtime_api_call = node_runtime::apis()
|
|
.account_nonce_api()
|
|
.account_nonce(alice_account_id);
|
|
let nonce = api
|
|
.runtime_api()
|
|
.at_latest()
|
|
.await?
|
|
.call(runtime_api_call)
|
|
.await?;
|
|
assert_eq!(nonce, 1);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn unchecked_extrinsic_encoding() -> Result<(), subxt::Error> {
|
|
let ctx = test_context().await;
|
|
let api = ctx.client();
|
|
|
|
let alice = dev::alice();
|
|
let bob = dev::bob();
|
|
let bob_address = bob.public_key().to_address();
|
|
|
|
// Construct a tx from Alice to Bob.
|
|
let tx = node_runtime::tx().balances().transfer(bob_address, 10_000);
|
|
|
|
let signed_extrinsic = api
|
|
.tx()
|
|
.create_signed(&tx, &alice, Default::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
let tx_bytes = signed_extrinsic.into_encoded();
|
|
let len = tx_bytes.len() as u32;
|
|
|
|
// Manually encode the runtime API call arguments to make a raw call.
|
|
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 generated API to confirm the result with the raw call.
|
|
let runtime_api_call = node_runtime::apis()
|
|
.transaction_payment_api()
|
|
.query_fee_details(tx_bytes.into(), len);
|
|
|
|
let result = api
|
|
.runtime_api()
|
|
.at_latest()
|
|
.await?
|
|
.call(runtime_api_call)
|
|
.await?;
|
|
|
|
assert_eq!(expected_result, result);
|
|
|
|
Ok(())
|
|
}
|