We’re trying to do the exact thing as referenced in How to mock trait in benchmarking, and we have implemented the struct + trait we need in our mocks, however, the benchmarks are calling the runtime config version and not the mock config version of the trait implementation. The mock pallet config uses T::AccountHandler
, as defined inside mock.rs, for a defined AccountProvider
trait.
NB: this was converted from an answer to a comment in the linked question, but all the code I included was cut off and I can’t edit the comment.
mock.rs:
pub struct AccountHandler;
impl AccountProvider<AccountId, BlockNumber> for AccountHandler {
fn get_msa_id(key: &AccountId) -> Option<MessageSenderId> {
// etc.
}
}
impl pallet_messages::Config for Test {
type Event = Event;
type AccountProvider = AccountHandler;
type WeightInfo = ();
type MaxMessagesPerBlock = MaxMessagesPerBlock;
type MaxMessageSizeInBytes = MaxMessageSizeInBytes;
}
Inside the pallet, it uses AccountProvider
like so:
#[pallet::config]
pub trait Config: frame_system::Config {
type AccountProvider: AccountProvider<Self::AccountId, Self::BlockNumber>;
/// etc.
}
// inside the extrinsic we want to benchmark, the trait function is called like so:
#[pallet::weight(T::WeightInfo::add(message.len() as u32, 1_000))]
pub fn add(
origin: OriginFor<T>,
message: Vec<u8>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
// etc.
let msa_id = T::AccountProvider::get_msa_id(&who);
}
We’re building the benchmarks with --runtime, and we are using substrate polkadot-v0.9.18 substrate.
why is our benchmark not using the mocked trait