open-runtime-module-library icon indicating copy to clipboard operation
open-runtime-module-library copied to clipboard

DepositFailed in benchmarks

Open cuteolaf opened this issue 2 years ago • 8 comments

deposit method of orml-currencies is not working in benchmarks

pub fn create_funded_user<T: Config>(
    seed: &'static str,
    n: u32,
    balance_factor: u32,
) -> T::AccountId {
    let user = account(seed, n, 0);
    let balance: BalanceOf<T> = balance_factor.into();
    assert_ok!(<T::MultiCurrency as MultiCurrency<
        <T as frame_system::Config>::AccountId,
    >>::deposit(CurrencyId::Native, &user, balance,));
    user
}

Reference: https://github.com/ImbueNetwork/imbue/blob/0744ca52a89b2d2a17ba379c43663c3882df2592/pallets/proposals/src/test_utils.rs#L117-L128

cuteolaf avatar Jun 06 '23 17:06 cuteolaf

I see this post on Stack Exchange, but it has been closed for some reason.

https://substrate.stackexchange.com/questions/2942/how-to-fix-depositfailed-on-orml-currencies-while-benchmarking

cuteolaf avatar Jun 06 '23 17:06 cuteolaf

what's the error?

xlc avatar Jun 06 '23 23:06 xlc

The required balance is not deposited.

cuteolaf avatar Jun 07 '23 13:06 cuteolaf

fn create_account_id<T: Config>(suri: &'static str, n: u32) -> T::AccountId {
    let user = account(suri, n, SEED);
    let _ = <T::RMultiCurrency as MultiCurrency<<T as frame_system::Config>::AccountId>>::deposit(
        CurrencyId::Native,
        &user,
        1_000_000u32.into(),
    );
    assert_eq!(
        <T::RMultiCurrency as MultiCurrency<<T as frame_system::Config>::AccountId>>::free_balance(
            CurrencyId::Native, 
            &user
        ), 
        1_000_000u32.into()
    );
    user
}

assert_eq!(...) succeeds for cargo test --release and cargo test --release --features runtime-benchmarks but fails when running the benchmark command to generate weights.

when I run ./target/release/imbue benchmark pallet --pallet pallet-grants --extrinsics '*' --execution wasm --wasm-execution compiled --steps 50 --repeat 20, I find that assert_eq! fails with the error

...
left = 0, right = 1000000
...

cuteolaf avatar Jun 07 '23 13:06 cuteolaf

what's the error you are getting from <T::RMultiCurrency as MultiCurrency<<T as frame_system::Config>::AccountId>>::deposit?

hint, don't ignore results.

xlc avatar Jun 07 '23 21:06 xlc

DepositFailed

cuteolaf avatar Jun 07 '23 22:06 cuteolaf

without looking at the code, my guess is that you have different ED configuration and the deposit amount in test is too low

xlc avatar Jun 07 '23 23:06 xlc

I checked it and it's not the case.

cuteolaf avatar Jun 08 '23 08:06 cuteolaf