Feature Request: Mechanism to `use` ic-repl as a library from our Rust codebase and call as part of cargo test

Right now, there’s no good way of integration testing when developing with Rust.

ic-kit by Psychedelic tackles this with their own home-grown solution. But it breaks interoperability with ic_cdk and it’s an all or nothing approach.

ic-repl is the other alternative that I’m aware of that works with the Dfinity suite of ic_cdk and connected packages

But the thing is writing separate scripts in a somewhat limited scripting language when we could utilize Rust’s fantastic compiler is kinda disappointing.

Since ic-repl is written in Rust, I believe the internal modules could be decoupled to be called by the ic-repl CLI and be used from a Rust codebase as an integration testing framework.

That way we can write tests in our Rust codebase and co-locate them with our application code but with a #[cfg(test)] so that tests get run within their own binary like how native Rust tests are supposed to run and then only our application code gets compiled to wasm canisters as intended.


ic-repl is @chenyan’s personal project AFAIK so it would be his call. But maybe your wishes are already coming true (chore: make `ic-repl` importable as a library by smallstepman · Pull Request #37 · chenyan2002/ic-repl · GitHub)?

Under the hood, ic-repl uses the ic-agent crate, which does have a lot of the compiler support you’re looking for. Have you tried that already? And if so, why do you think it’s not appropriate for your use case?

I did get some inputs from @chenyan on this here. I’ve been told that ic-state-machine-tests is what I’m looking for.

Further conversation here

Basically I’m working on a large multi-canister backend with multiple cross canister calls and have reached the stage where simple UI based testing won’t cut it and the codebase needs unit and integration tests. Trying to figure out what’s the most modern prescripted way of doing it for canisters written in Rust

I see. Long story short: tooling is not at a point yet where we have really good solutions for larger projects. If it’s doable for you, ic-kit is probably the most advanced thing out there for now. Besides that I can only recommend that you do as much as possible in unit tests since testing integration is not really in a nice place.

Outside of ic-kit, the best I can offer right now is to write tests with ic-agent against a running dfx instance, but that’s also not ideal. If you find a better solution, please let us know so we can document it properly.

1 Like

ic-kit < 0.5 does have limited testing capabilities but it’s in the process of being deprecated

ic-kit 0.5 onwards is still missing dynamic canister creation capabilities and is a WIP. Also, it’s incompatible with ic_cdk and its siblings

I’ll explore the ic-agent route and see if I can figure out a workflow that works for us

Thank you for the inputs :slight_smile: