mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
cf7e2db1b7
* add follow_stream impl * follow_stream_unpin first draft * add tests for follow_stream_unpin * more tests and fixes for follow_stream_unpin * first pass follow_stream_driver * follow_stream_driver: add tests, fix things, buffer events from last finalized * First pass finishing Backend impl * Fix test compile issues * clippy fixes * clippy fix and consistify light_client * revert lightclient tweak * revert other lightclient thing * cargo fmt * start testing unstable backend behind feature flag * more test fixes and move test-runtime metadata path just incase * fix compile error * ensure transaction progress stream actually used and fix another test * cargo fmt * CI tweak * improve some comments and address some feedback bits * update CI to use our own nightly binary * wait for finalized block perhaps
107 lines
2.8 KiB
Rust
107 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_allow_death(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(())
|
|
}
|