Simulating out of cycles with pocket-ic

i have a long running cron job setup in a rust canister. We’ve built some mechanisms that all us to continue when errors are resolved. One such error is when transferring some tokens from our ledger and the ledger runs out of cycles.

I’m using pocket-ic to create an integration. I correctly wait for the amount of time to pass for my job to start and i set up the ledger canister with not enough cycles. Indeed, i do see an error stating that the ledger is out of canisters. Because I’m doing over 1000 transactions I assume it will try to create an archive canister and so I see the following error.

UserError(UserError { code: CanisterOutOfCycles, description: "Canister installation failed with `Canister 7tjcv-pp777-77776-qaaaa-cai is out of cycles: please top up the canister with at least 89_839_070 additional cycles`" })

This is good, but i need to be able to carry on and fix the problem in my integration test so that I can check my app canister has failed payments and can resolve them.

Is there a good way to carry on after getting this error?

Are there any other ways I can induce a transaction error on the ledger at some specific point?

Thanks :slight_smile:

In a test environment, you can stop the ledger canister, for instance, and restart it later.

1 Like

You can use the add_cycles function to top up the canister with cycles. But I’d suggest to stop/start the canister instead of making it low on cycles.

1 Like