3

I have some code in a Substrate client that needs to call one of my runtime apis. I'd like an easy way to mock the client and custom runtime api functions to check that they're called.

Is there an easy way to mock both? I was trying out substrate-test-runtime but don't see a proper way to get it working, and am wondering if there's something better.

Here's a simplified example of a function that I would like to test looks like:

fn example_call<B, C>(
    client: Arc<C>,
)
where
    B: BlockT,
    C: ProvideRuntimeApi<B> + HeaderBackend<B>,
    C::Api: ConstructExtrinsicApi<B>,
{
    let best_hash = client.info().best_hash;
    client.runtime_api()
        .my_arbitrary_runtime_api_fn(&generic::BlockId::Hash(best_hash));
}

2

0

Your Answer

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

Browse other questions tagged or ask your own question.