near / near-workspaces-js

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment
https://near.github.io/near-workspaces-js/
GNU General Public License v3.0
42 stars 21 forks source link

Fast-forwarding support #105

Open danielwpz opened 2 years ago

danielwpz commented 2 years ago

hey, I saw this issue: https://github.com/near/workspaces-js/issues/1 , do we support fast-forwarding now?

I'm working on a contract that interacts with validator staking contract, it will be hard to test without the ability to fast-forward epoch numbers.

ailisp commented 2 years ago

nearcore side work to support fast-forwarding is recently accomplished by @ChaoticTempest , support in workspaces-js is not added yet

ChaoticTempest commented 2 years ago

relevant PRs for reference: block fast forwarding: https://github.com/near/nearcore/pull/6158 fast-forward API addition: https://github.com/near/workspaces-rs/pull/73

still waiting on https://github.com/near/nearcore/pull/6211 for timestamps/epoch

danielwpz commented 2 years ago

cool, thanks for the update!

june07 commented 1 year ago

Any ideas on when this will be available for this api? I see it's already made it to workspaces-rs.

volovyks commented 1 year ago

@june07 it is on our roadmap but looks like we will have the capacity ~Q1 2023. Feel free to contribute if it's something that interests you. We will provide all the support.

june07 commented 1 year ago

@volovyks So it seems that it's possible in workspace-js simply using the following:

await worker.manager.provider.sendJsonRpc('sandbox_fast_forward', { delta_height: 2000 });

I forked the repo and considered contributing in this regard... but it doesn't seem like much more abstraction is needed?!

HOWEVER... while it does appear to work somewhat, it seems rather buggy with the block forwarding halting (verified by logs from rpc) more than half the time... at which time the test simply needs to be cancelled and restarted... else the test hangs until the test framework timeout.

More important... when spooning a staking contract from testnet, the .get_account_total_balance method isn't showing any increase in value... in other words it seems that the spooned contract isn't being affected by the sandbox_fast_forward action. Since it has been spooned to the sandbox... it seems to be that it should be running its own code per blocks being fast forwarded, and as such I should see some increase in account balance...

Any idea's on this...

ChaoticTempest commented 1 year ago

@june07 how are you using it with other calls? Any full code snippets I can take a look at to get more context? Its working as intended for me when I utilize the same contract in workspaces-rs/fast_forward.rs for workspaces-js

Also, just noting that sandbox_fast_forward RPC call blocks any sort of transaction from being processed. It's more for forwarding in time, with the only relevant data affected being block height, block timestamp and epoch height; so actual blocks/transaction being processed are not guaranteed.