I want to call the instruction which makes a change at the account's states after some time passed (so after some slots passed). The logic is related to the passed slots, so I want to test this logic. I've tried to see if there's some related functions at anchor.provider.connection
, but couldn't find any. Is there a way to skip several blocks or slots forward at anchor test?
Add a comment
|
1 Answer
You are probably using mocha tests with chai assertion. Thats the standart in anchor test. Anchor is starting a local validator for you where it deploys your program and then runs the tests against it. You can see whats actually called in the anchor toml.
I dont think you can skip forward blocks. You have a few options though:
- You can just wait in the test frontend js a bit
- You can use solana bank run time travel feature. Here is the docs: https://kevinheavey.github.io/solana-bankrun/tutorial/#time-travel https://github.com/kevinheavey/anchor-bankrun Here is a working example of the time travel: https://github.com/solana-developers/solana-game-preset/blob/main/program/jesttests/energy-refill-time.test.ts and here a video explaining it: https://www.youtube.com/watch?v=rut9l6nPZls
Basically you replace your anchor provider with the bankrun provider and then do smth like this:
const currentClock = await client.getClock();
context.setClock(
new Clock(
currentClock.slot,
currentClock.epochStartTimestamp,
currentClock.epoch,
currentClock.leaderScheduleEpoch,
BigInt(timestamp) + BigInt(60 * 11)
)
);
- You can also do that with https://luzid.app/ but i havent tried that yet.