Use RPC call to get account nonce (#476)

* remove code related to getting nonce from storage and use RPC call instead

* cargo fmt

* move nonce fetching into Rpc, since it's just an RPC call

* clippy
This commit is contained in:
James Wilson
2022-03-14 15:39:40 +00:00
committed by GitHub
parent 798a1d0b88
commit 8b19549560
10 changed files with 460 additions and 1086 deletions
+42
View File
@@ -30,6 +30,10 @@ use sp_core::{
Pair as _,
};
use sp_keyring::AccountKeyring;
use sp_runtime::{
AccountId32,
MultiAddress,
};
use subxt::{
Error,
Signer,
@@ -94,6 +98,44 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error<DispatchError>> {
Ok(())
}
#[async_std::test]
async fn multiple_transfers_work_nonce_incremented(
) -> Result<(), subxt::Error<DispatchError>> {
let alice = pair_signer(AccountKeyring::Alice.pair());
let bob = pair_signer(AccountKeyring::Bob.pair());
let bob_address: MultiAddress<AccountId32, u32> = bob.account_id().clone().into();
let cxt = test_context().await;
let api = &cxt.api;
let bob_pre = api
.storage()
.system()
.account(bob.account_id(), None)
.await?;
for _ in 0..3 {
api
.tx()
.balances()
.transfer(bob_address.clone(), 10_000)
.sign_and_submit_then_watch(&alice)
.await?
.wait_for_in_block() // Don't need to wait for finalization; this is quicker.
.await?
.wait_for_success()
.await?;
}
let bob_post = api
.storage()
.system()
.account(bob.account_id(), None)
.await?;
assert_eq!(bob_pre.data.free + 30_000, bob_post.data.free);
Ok(())
}
#[async_std::test]
async fn storage_total_issuance() {
let cxt = test_context().await;
+1 -4
View File
@@ -25,7 +25,6 @@ use crate::{
storage,
},
system,
DefaultAccountData,
DispatchError,
},
test_context,
@@ -63,9 +62,7 @@ impl ContractsTestContext {
self.cxt.client()
}
fn contracts_tx(
&self,
) -> TransactionApi<DefaultConfig, NodeRuntimeSignedExtra, DefaultAccountData> {
fn contracts_tx(&self) -> TransactionApi<DefaultConfig, NodeRuntimeSignedExtra> {
self.cxt.api.tx().contracts()
}