mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
feat: refactor signing in order to more easily be able to dryrun (#547)
* feat: refactor signing in order to more easily be able to dryrun Co-authored-by: Sander Bosma <sanderbosma@gmail.com> Co-authored-by: Daniel Savu <savudani04@yahoo.ro> * chore: move dry_run to rpc file * fix: failing dryrun test * fix: run cargo fmt * chore(dryrun): Replace complex SubmittableExtrinsic type with bytes array * cargo fmt * feat: add dry_run method to signed submittable extrinsic * fmt Co-authored-by: Sander Bosma <sanderbosma@gmail.com>
This commit is contained in:
@@ -17,14 +17,24 @@
|
||||
use crate::{
|
||||
test_node_process,
|
||||
test_node_process_with,
|
||||
utils::node_runtime::system,
|
||||
utils::{
|
||||
node_runtime::system,
|
||||
pair_signer,
|
||||
test_context,
|
||||
},
|
||||
};
|
||||
|
||||
use sp_core::storage::{
|
||||
well_known_keys,
|
||||
StorageKey,
|
||||
use sp_core::{
|
||||
sr25519::Pair,
|
||||
storage::{
|
||||
well_known_keys,
|
||||
StorageKey,
|
||||
},
|
||||
Pair as _,
|
||||
};
|
||||
use sp_keyring::AccountKeyring;
|
||||
use sp_runtime::DispatchOutcome;
|
||||
use subxt::Error;
|
||||
|
||||
#[tokio::test]
|
||||
async fn insert_key() {
|
||||
@@ -131,3 +141,86 @@ async fn fetch_system_info() {
|
||||
assert_eq!(client.rpc().system_name().await.unwrap(), "Substrate Node");
|
||||
assert!(!client.rpc().system_version().await.unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dry_run_passes() {
|
||||
let node_process = test_node_process().await;
|
||||
let client = node_process.client();
|
||||
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let bob = pair_signer(AccountKeyring::Bob.pair());
|
||||
let bob_address = bob.account_id().clone().into();
|
||||
let cxt = test_context().await;
|
||||
let api = &cxt.api;
|
||||
let signed_extrinsic = api
|
||||
.tx()
|
||||
.balances()
|
||||
.transfer(bob_address, 10_000)
|
||||
.unwrap()
|
||||
.create_signed(&alice, Default::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
client
|
||||
.rpc()
|
||||
.dry_run(signed_extrinsic.encoded(), None)
|
||||
.await
|
||||
.expect("dryrunning failed")
|
||||
.expect("expected dryrunning to be successful")
|
||||
.unwrap();
|
||||
signed_extrinsic
|
||||
.submit_and_watch()
|
||||
.await
|
||||
.unwrap()
|
||||
.wait_for_finalized_success()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dry_run_fails() {
|
||||
let node_process = test_node_process().await;
|
||||
let client = node_process.client();
|
||||
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let hans = pair_signer(Pair::generate().0);
|
||||
let hans_address = hans.account_id().clone().into();
|
||||
let cxt = test_context().await;
|
||||
let api = &cxt.api;
|
||||
let signed_extrinsic = api
|
||||
.tx()
|
||||
.balances()
|
||||
.transfer(
|
||||
hans_address,
|
||||
100_000_000_000_000_000_000_000_000_000_000_000,
|
||||
)
|
||||
.unwrap()
|
||||
.create_signed(&alice, Default::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let dry_run_res: DispatchOutcome = client
|
||||
.rpc()
|
||||
.dry_run(signed_extrinsic.encoded(), None)
|
||||
.await
|
||||
.expect("dryrunning failed")
|
||||
.expect("expected dryrun transaction to be valid");
|
||||
if let Err(sp_runtime::DispatchError::Module(module_error)) = dry_run_res {
|
||||
assert_eq!(module_error.index, 6);
|
||||
assert_eq!(module_error.error, 2);
|
||||
} else {
|
||||
panic!("expected a module error when dryrunning");
|
||||
}
|
||||
let res = signed_extrinsic
|
||||
.submit_and_watch()
|
||||
.await
|
||||
.unwrap()
|
||||
.wait_for_finalized_success()
|
||||
.await;
|
||||
if let Err(Error::Module(err)) = res {
|
||||
assert_eq!(err.pallet, "Balances");
|
||||
assert_eq!(err.error, "InsufficientBalance");
|
||||
} else {
|
||||
panic!("expected a runtime module error");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user