mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Make sp_core and sp_runtime dependencies optional, and bump to latest (#760)
* begin porting over traits; remove Config use of Hash * port over the Header bits that we need * sp_core_hashing where possible, move Verify to PairSigner, remove unused errors * tidy up Config things and move related bits into one place * fix codegen * copy Era over * move AccountId, Address, Signer to Signer trait and a pass over fixing examples * impl MultiAddress, MultiSignature, AccountId32 and add back to Config (for decoding later) * Copy over StorageKey, StorageData, StorageChangeSet * subxt core compiling with no sp_core or sp_runtime * Get examples compiling * pass over fixing tests * cargo fmt * clippy tweaks and update polkadot.rs * fix codegen docs * port over special DigestItem encoding/decoding * clippy and doc fixes * cargo fmt and example fix * more cargo fmt-ing... * substrate-extra to substrate-compat * cargo.toml comments * simplify PairSigner trait bounds * move RPC types to a separate file * fix docs * Add some tests for things and other PR feedback * bump to latest sp deps * avoid needing substrate-compat feature in a test
This commit is contained in:
@@ -75,8 +75,8 @@ async fn missing_block_headers_will_be_filled_in() -> Result<(), subxt::Error> {
|
||||
while let Some(header) = all_finalized_blocks.next().await {
|
||||
let header = header?;
|
||||
|
||||
use sp_runtime::traits::Header;
|
||||
let block_number: u128 = (*header.number()).into();
|
||||
use subxt::config::Header;
|
||||
let block_number: u128 = header.number().into();
|
||||
|
||||
if let Some(last) = last_block_number {
|
||||
assert_eq!(last + 1, block_number);
|
||||
|
||||
@@ -17,7 +17,10 @@ use sp_core::{
|
||||
Pair,
|
||||
};
|
||||
use sp_keyring::AccountKeyring;
|
||||
use subxt::error::DispatchError;
|
||||
use subxt::{
|
||||
error::DispatchError,
|
||||
rpc::types::DryRunError,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn insert_key() {
|
||||
@@ -162,8 +165,7 @@ async fn dry_run_passes() {
|
||||
.dry_run(None)
|
||||
.await
|
||||
.expect("dryrunning failed")
|
||||
.expect("expected dryrunning to be successful")
|
||||
.unwrap();
|
||||
.expect("dry run should be successful");
|
||||
|
||||
signed_extrinsic
|
||||
.submit_and_watch()
|
||||
@@ -198,15 +200,9 @@ async fn dry_run_fails() {
|
||||
let dry_run_res = signed_extrinsic
|
||||
.dry_run(None)
|
||||
.await
|
||||
.expect("dryrunning failed")
|
||||
.expect("expected dryrun transaction to be valid");
|
||||
.expect("dryrunning failed");
|
||||
|
||||
if let Err(sp_runtime::DispatchError::Module(module_error)) = dry_run_res {
|
||||
assert_eq!(module_error.index, 6);
|
||||
assert_eq!(module_error.error, [2, 0, 0, 0]);
|
||||
} else {
|
||||
panic!("expected a module error when dryrunning");
|
||||
}
|
||||
assert_eq!(dry_run_res, Err(DryRunError::DispatchError));
|
||||
|
||||
let res = signed_extrinsic
|
||||
.submit_and_watch()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
/// Generate by:
|
||||
///
|
||||
/// - run `polkadot --dev --tmp` node locally
|
||||
/// - `cargo run --release -p subxt-cli -- codegen | rustfmt > integration-tests/src/codegen/polkadot.rs`
|
||||
/// - `cargo run -p subxt-cli -- codegen | rustfmt > testing/integration-tests/src/codegen/polkadot.rs`
|
||||
#[rustfmt::skip]
|
||||
#[allow(clippy::all)]
|
||||
mod polkadot;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -18,13 +18,15 @@ use sp_core::{
|
||||
Pair as _,
|
||||
};
|
||||
use sp_keyring::AccountKeyring;
|
||||
use sp_runtime::{
|
||||
AccountId32,
|
||||
MultiAddress,
|
||||
};
|
||||
use subxt::error::{
|
||||
DispatchError,
|
||||
Error,
|
||||
use subxt::{
|
||||
error::{
|
||||
DispatchError,
|
||||
Error,
|
||||
},
|
||||
utils::{
|
||||
AccountId32,
|
||||
MultiAddress,
|
||||
},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
@@ -250,8 +252,9 @@ async fn storage_total_issuance() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn storage_balance_lock() -> Result<(), subxt::Error> {
|
||||
let bob = pair_signer(AccountKeyring::Bob.pair());
|
||||
let charlie = AccountKeyring::Charlie.to_account_id();
|
||||
let bob_signer = pair_signer(AccountKeyring::Bob.pair());
|
||||
let bob: AccountId32 = AccountKeyring::Bob.to_account_id().into();
|
||||
let charlie: AccountId32 = AccountKeyring::Charlie.to_account_id().into();
|
||||
let ctx = test_context().await;
|
||||
let api = ctx.client();
|
||||
|
||||
@@ -262,16 +265,14 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> {
|
||||
);
|
||||
|
||||
api.tx()
|
||||
.sign_and_submit_then_watch_default(&tx, &bob)
|
||||
.sign_and_submit_then_watch_default(&tx, &bob_signer)
|
||||
.await?
|
||||
.wait_for_finalized_success()
|
||||
.await?
|
||||
.find_first::<system::events::ExtrinsicSuccess>()?
|
||||
.expect("No ExtrinsicSuccess Event found");
|
||||
|
||||
let locks_addr = node_runtime::storage()
|
||||
.balances()
|
||||
.locks(AccountKeyring::Bob.to_account_id());
|
||||
let locks_addr = node_runtime::storage().balances().locks(bob);
|
||||
|
||||
let locks = api.storage().fetch_or_default(&locks_addr, None).await?;
|
||||
|
||||
@@ -330,12 +331,13 @@ async fn transfer_error() {
|
||||
#[tokio::test]
|
||||
async fn transfer_implicit_subscription() {
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let bob = AccountKeyring::Bob.to_account_id();
|
||||
let bob_addr = bob.clone().into();
|
||||
let bob: AccountId32 = AccountKeyring::Bob.to_account_id().into();
|
||||
let ctx = test_context().await;
|
||||
let api = ctx.client();
|
||||
|
||||
let to_bob_tx = node_runtime::tx().balances().transfer(bob_addr, 10_000);
|
||||
let to_bob_tx = node_runtime::tx()
|
||||
.balances()
|
||||
.transfer(bob.clone().into(), 10_000);
|
||||
|
||||
let event = api
|
||||
.tx()
|
||||
@@ -353,7 +355,7 @@ async fn transfer_implicit_subscription() {
|
||||
event,
|
||||
balances::events::Transfer {
|
||||
from: alice.account_id().clone(),
|
||||
to: bob.clone(),
|
||||
to: bob,
|
||||
amount: 10_000
|
||||
}
|
||||
);
|
||||
|
||||
@@ -18,12 +18,12 @@ use crate::{
|
||||
TestContext,
|
||||
};
|
||||
use sp_core::sr25519::Pair;
|
||||
use sp_runtime::MultiAddress;
|
||||
use subxt::{
|
||||
tx::{
|
||||
PairSigner,
|
||||
TxProgress,
|
||||
},
|
||||
utils::MultiAddress,
|
||||
Config,
|
||||
Error,
|
||||
OnlineClient,
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::{
|
||||
utils::wait_for_blocks,
|
||||
};
|
||||
use sp_keyring::AccountKeyring;
|
||||
use subxt::utils::AccountId32;
|
||||
|
||||
#[tokio::test]
|
||||
async fn storage_plain_lookup() -> Result<(), subxt::Error> {
|
||||
@@ -32,7 +33,7 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> {
|
||||
let api = ctx.client();
|
||||
|
||||
let signer = pair_signer(AccountKeyring::Alice.pair());
|
||||
let alice = AccountKeyring::Alice.to_account_id();
|
||||
let alice: AccountId32 = AccountKeyring::Alice.to_account_id().into();
|
||||
|
||||
// Do some transaction to bump the Alice nonce to 1:
|
||||
let remark_tx = node_runtime::tx().system().remark(vec![1, 2, 3, 4, 5]);
|
||||
@@ -43,7 +44,7 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> {
|
||||
.await?;
|
||||
|
||||
// Look up the nonce for the user (we expect it to be 1).
|
||||
let nonce_addr = node_runtime::storage().system().account(&alice);
|
||||
let nonce_addr = node_runtime::storage().system().account(alice);
|
||||
let entry = api.storage().fetch_or_default(&nonce_addr, None).await?;
|
||||
assert_eq!(entry.nonce, 1);
|
||||
|
||||
@@ -90,8 +91,8 @@ async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> {
|
||||
// we "approveTransfer" of some of this asset class. This gives us an
|
||||
// entry in the `Approvals` StorageNMap that we can try to look up.
|
||||
let signer = pair_signer(AccountKeyring::Alice.pair());
|
||||
let alice = AccountKeyring::Alice.to_account_id();
|
||||
let bob = AccountKeyring::Bob.to_account_id();
|
||||
let alice: AccountId32 = AccountKeyring::Alice.to_account_id().into();
|
||||
let bob: AccountId32 = AccountKeyring::Bob.to_account_id().into();
|
||||
|
||||
let tx1 = node_runtime::tx()
|
||||
.assets()
|
||||
@@ -111,7 +112,7 @@ async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> {
|
||||
.await?;
|
||||
|
||||
// The actual test; look up this approval in storage:
|
||||
let addr = node_runtime::storage().assets().approvals(99, &alice, &bob);
|
||||
let addr = node_runtime::storage().assets().approvals(99, alice, bob);
|
||||
let entry = api.storage().fetch(&addr, None).await?;
|
||||
assert_eq!(entry.map(|a| a.amount), Some(123));
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user