In tests we use following statement to check error:

            ProfileValidation::add_citizen(RuntimeOrigin::signed(1), content.clone()),

But how to get error from another coupled pallet.

 // or 
<other_coupled_pallet::Pallet<mock::Test> as TryCollect>::Error::EvidencePeriodNotOver

It doesn't work

  • What is the error you are getting?
    – bkchr
    Jul 1, 2023 at 20:00

2 Answers 2


It's really easy.

Check this test. https://github.com/darwinia-network/darwinia/blob/12466db6d4a8d19b2d16461af05b7f155362223b/pallet/deposit/src/tests.rs#L237-L268

This will use the current pallet's Error:

    Deposit::lock(RuntimeOrigin::signed(1), UNIT, 1),

And if you want to use an Error from other (e.g. pallet_balances) pallet, simply write:

    Deposit::lock(RuntimeOrigin::signed(2), 2_001 * UNIT, 1),

To use this, make sure you have impl other_pallet::Config for mock::Runtime {}.


To get the error from another coupled pallet in a test, you can use the following syntax:

    "Expected error message"

Replace OtherCoupledPallet::some_function() with the actual function call you are testing in the other coupled pallet. Make sure to include any required parameters for the function.

In the error message, replace "Expected error message" with the specific error message you are expecting. This should be the exact error message that you anticipate the function to produce.

By using assert_err!, you can verify that the function call results in an error with the expected error message. If the error message does not match, the assertion will fail, indicating a test failure.

Remember to import the necessary macros at the beginning of your test file:

use frame_support::assert_err;

Including this code in your test should help you check for errors from another coupled pallet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.