mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
Obtain DispatchError::Module info dynamically (#453)
* Add error information back into metadata to roll back removal in #394 * Go back to obtaining runtime error info * re-do codegen too to check that it's all gravy * Convert DispatchError module errors into a module variant to make them easier to work with * Fix broken doc link
This commit is contained in:
@@ -154,9 +154,9 @@ async fn transfer_error() {
|
||||
let alice_addr = alice.account_id().clone().into();
|
||||
let hans = pair_signer(Pair::generate().0);
|
||||
let hans_address = hans.account_id().clone().into();
|
||||
let cxt = test_context().await;
|
||||
let ctx = test_context().await;
|
||||
|
||||
cxt.api
|
||||
ctx.api
|
||||
.tx()
|
||||
.balances()
|
||||
.transfer(hans_address, 100_000_000_000_000_000)
|
||||
@@ -167,7 +167,7 @@ async fn transfer_error() {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let res = cxt
|
||||
let res = ctx
|
||||
.api
|
||||
.tx()
|
||||
.balances()
|
||||
@@ -178,10 +178,9 @@ async fn transfer_error() {
|
||||
.wait_for_finalized_success()
|
||||
.await;
|
||||
|
||||
if let Err(Error::Runtime(err)) = res {
|
||||
let details = err.inner().details().unwrap();
|
||||
assert_eq!(details.pallet, "Balances");
|
||||
assert_eq!(details.error, "InsufficientBalance");
|
||||
if let Err(Error::Module(err)) = res {
|
||||
assert_eq!(err.pallet, "Balances");
|
||||
assert_eq!(err.error, "InsufficientBalance");
|
||||
} else {
|
||||
panic!("expected a runtime module error");
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ fn default_validator_prefs() -> ValidatorPrefs {
|
||||
#[async_std::test]
|
||||
async fn validate_with_controller_account() {
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let cxt = test_context().await;
|
||||
cxt.api
|
||||
let ctx = test_context().await;
|
||||
ctx.api
|
||||
.tx()
|
||||
.staking()
|
||||
.validate(default_validator_prefs())
|
||||
@@ -69,8 +69,8 @@ async fn validate_with_controller_account() {
|
||||
#[async_std::test]
|
||||
async fn validate_not_possible_for_stash_account() -> Result<(), Error<DispatchError>> {
|
||||
let alice_stash = pair_signer(get_from_seed("Alice//stash"));
|
||||
let cxt = test_context().await;
|
||||
let announce_validator = cxt
|
||||
let ctx = test_context().await;
|
||||
let announce_validator = ctx
|
||||
.api
|
||||
.tx()
|
||||
.staking()
|
||||
@@ -79,10 +79,9 @@ async fn validate_not_possible_for_stash_account() -> Result<(), Error<DispatchE
|
||||
.await?
|
||||
.wait_for_finalized_success()
|
||||
.await;
|
||||
assert_matches!(announce_validator, Err(Error::Runtime(err)) => {
|
||||
let details = err.inner().details().unwrap();
|
||||
assert_eq!(details.pallet, "Staking");
|
||||
assert_eq!(details.error, "NotController");
|
||||
assert_matches!(announce_validator, Err(Error::Module(err)) => {
|
||||
assert_eq!(err.pallet, "Staking");
|
||||
assert_eq!(err.error, "NotController");
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -91,9 +90,9 @@ async fn validate_not_possible_for_stash_account() -> Result<(), Error<DispatchE
|
||||
async fn nominate_with_controller_account() {
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let bob = pair_signer(AccountKeyring::Bob.pair());
|
||||
let cxt = test_context().await;
|
||||
let ctx = test_context().await;
|
||||
|
||||
cxt.api
|
||||
ctx.api
|
||||
.tx()
|
||||
.staking()
|
||||
.nominate(vec![bob.account_id().clone().into()])
|
||||
@@ -109,9 +108,9 @@ async fn nominate_with_controller_account() {
|
||||
async fn nominate_not_possible_for_stash_account() -> Result<(), Error<DispatchError>> {
|
||||
let alice_stash = pair_signer(get_from_seed("Alice//stash"));
|
||||
let bob = pair_signer(AccountKeyring::Bob.pair());
|
||||
let cxt = test_context().await;
|
||||
let ctx = test_context().await;
|
||||
|
||||
let nomination = cxt
|
||||
let nomination = ctx
|
||||
.api
|
||||
.tx()
|
||||
.staking()
|
||||
@@ -121,10 +120,9 @@ async fn nominate_not_possible_for_stash_account() -> Result<(), Error<DispatchE
|
||||
.wait_for_finalized_success()
|
||||
.await;
|
||||
|
||||
assert_matches!(nomination, Err(Error::Runtime(err)) => {
|
||||
let details = err.inner().details().unwrap();
|
||||
assert_eq!(details.pallet, "Staking");
|
||||
assert_eq!(details.error, "NotController");
|
||||
assert_matches!(nomination, Err(Error::Module(err)) => {
|
||||
assert_eq!(err.pallet, "Staking");
|
||||
assert_eq!(err.error, "NotController");
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -134,10 +132,10 @@ async fn chill_works_for_controller_only() -> Result<(), Error<DispatchError>> {
|
||||
let alice_stash = pair_signer(get_from_seed("Alice//stash"));
|
||||
let bob_stash = pair_signer(get_from_seed("Bob//stash"));
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let cxt = test_context().await;
|
||||
let ctx = test_context().await;
|
||||
|
||||
// this will fail the second time, which is why this is one test, not two
|
||||
cxt.api
|
||||
ctx.api
|
||||
.tx()
|
||||
.staking()
|
||||
.nominate(vec![bob_stash.account_id().clone().into()])
|
||||
@@ -146,7 +144,7 @@ async fn chill_works_for_controller_only() -> Result<(), Error<DispatchError>> {
|
||||
.wait_for_finalized_success()
|
||||
.await?;
|
||||
|
||||
let ledger = cxt
|
||||
let ledger = ctx
|
||||
.api
|
||||
.storage()
|
||||
.staking()
|
||||
@@ -155,7 +153,7 @@ async fn chill_works_for_controller_only() -> Result<(), Error<DispatchError>> {
|
||||
.unwrap();
|
||||
assert_eq!(alice_stash.account_id(), &ledger.stash);
|
||||
|
||||
let chill = cxt
|
||||
let chill = ctx
|
||||
.api
|
||||
.tx()
|
||||
.staking()
|
||||
@@ -165,13 +163,12 @@ async fn chill_works_for_controller_only() -> Result<(), Error<DispatchError>> {
|
||||
.wait_for_finalized_success()
|
||||
.await;
|
||||
|
||||
assert_matches!(chill, Err(Error::Runtime(err)) => {
|
||||
let details = err.inner().details().unwrap();
|
||||
assert_eq!(details.pallet, "Staking");
|
||||
assert_eq!(details.error, "NotController");
|
||||
assert_matches!(chill, Err(Error::Module(err)) => {
|
||||
assert_eq!(err.pallet, "Staking");
|
||||
assert_eq!(err.error, "NotController");
|
||||
});
|
||||
|
||||
let is_chilled = cxt
|
||||
let is_chilled = ctx
|
||||
.api
|
||||
.tx()
|
||||
.staking()
|
||||
@@ -189,9 +186,9 @@ async fn chill_works_for_controller_only() -> Result<(), Error<DispatchError>> {
|
||||
#[async_std::test]
|
||||
async fn tx_bond() -> Result<(), Error<DispatchError>> {
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let cxt = test_context().await;
|
||||
let ctx = test_context().await;
|
||||
|
||||
let bond = cxt
|
||||
let bond = ctx
|
||||
.api
|
||||
.tx()
|
||||
.staking()
|
||||
@@ -207,7 +204,7 @@ async fn tx_bond() -> Result<(), Error<DispatchError>> {
|
||||
|
||||
assert!(bond.is_ok());
|
||||
|
||||
let bond_again = cxt
|
||||
let bond_again = ctx
|
||||
.api
|
||||
.tx()
|
||||
.staking()
|
||||
@@ -221,26 +218,25 @@ async fn tx_bond() -> Result<(), Error<DispatchError>> {
|
||||
.wait_for_finalized_success()
|
||||
.await;
|
||||
|
||||
assert_matches!(bond_again, Err(Error::Runtime(err)) => {
|
||||
let details = err.inner().details().unwrap();
|
||||
assert_eq!(details.pallet, "Staking");
|
||||
assert_eq!(details.error, "AlreadyBonded");
|
||||
assert_matches!(bond_again, Err(Error::Module(err)) => {
|
||||
assert_eq!(err.pallet, "Staking");
|
||||
assert_eq!(err.error, "AlreadyBonded");
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn storage_history_depth() -> Result<(), Error<DispatchError>> {
|
||||
let cxt = test_context().await;
|
||||
let history_depth = cxt.api.storage().staking().history_depth(None).await?;
|
||||
let ctx = test_context().await;
|
||||
let history_depth = ctx.api.storage().staking().history_depth(None).await?;
|
||||
assert_eq!(history_depth, 84);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn storage_current_era() -> Result<(), Error<DispatchError>> {
|
||||
let cxt = test_context().await;
|
||||
let _current_era = cxt
|
||||
let ctx = test_context().await;
|
||||
let _current_era = ctx
|
||||
.api
|
||||
.storage()
|
||||
.staking()
|
||||
@@ -252,8 +248,8 @@ async fn storage_current_era() -> Result<(), Error<DispatchError>> {
|
||||
|
||||
#[async_std::test]
|
||||
async fn storage_era_reward_points() -> Result<(), Error<DispatchError>> {
|
||||
let cxt = test_context().await;
|
||||
let current_era_result = cxt
|
||||
let ctx = test_context().await;
|
||||
let current_era_result = ctx
|
||||
.api
|
||||
.storage()
|
||||
.staking()
|
||||
|
||||
Reference in New Issue
Block a user