mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
codegen for root level error (#930)
* code gen for root error * cargo fmt * polkadot.rs regenerated * use pallet name and decode with metadata * remove pallet by name fn * test that we can decode a ModuleError via as_root_error * nits --------- Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
@@ -350,6 +350,43 @@ async fn submit_large_extrinsic() {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn decode_a_module_error() {
|
||||
use node_runtime::runtime_types::pallet_assets::pallet as assets;
|
||||
|
||||
let ctx = test_context().await;
|
||||
let api = ctx.client();
|
||||
|
||||
let alice = pair_signer(AccountKeyring::Alice.pair());
|
||||
let alice_addr = alice.account_id().clone().into();
|
||||
|
||||
// Trying to work with an asset ID 1 which doesn't exist should return an
|
||||
// "unknown" module error from the assets pallet.
|
||||
let freeze_unknown_asset = node_runtime::tx().assets().freeze(1, alice_addr);
|
||||
|
||||
let err = api
|
||||
.tx()
|
||||
.sign_and_submit_then_watch_default(&freeze_unknown_asset, &alice)
|
||||
.await
|
||||
.unwrap()
|
||||
.wait_for_finalized_success()
|
||||
.await
|
||||
.expect_err("an 'unknown asset' error");
|
||||
|
||||
let Error::Runtime(DispatchError::Module(module_err)) = err else {
|
||||
panic!("Expected a ModuleError, got {err:?}");
|
||||
};
|
||||
|
||||
// Decode the error into our generated Error type.
|
||||
let decoded_err = module_err.as_root_error::<node_runtime::Error>().unwrap();
|
||||
|
||||
// Decoding should result in an Assets.Unknown error:
|
||||
assert_eq!(
|
||||
decoded_err,
|
||||
node_runtime::Error::Assets(assets::Error::Unknown)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unsigned_extrinsic_is_same_shape_as_polkadotjs() {
|
||||
let ctx = test_context().await;
|
||||
|
||||
Reference in New Issue
Block a user