Repository navigation
fe test: set the block timestamp and number with #[test(timestamp = N, block_number = N)] - #2048
Merged
Merged
Conversation
Under `fe test` every test ran at block timestamp 1 and block number 0, with no way to change either, so contract logic that depends on time could not be tested end to end (argotorg#2039). `#[test(timestamp = N)]` and `#[test(block_number = N)]` now set the block the test runs at. The values are u256 literals, parsed and checked like `balance`: a missing, non-integer or oversized value is an error naming the test and the argument. Without them a test runs at timestamp 1, block 0, as before. Contracts the test creates or calls see the same block. The harness gains `RuntimeInstance::set_block_timestamp` and `set_block_number`, which `fe test` applies to the test's instance before calling it. Native and WebAssembly tests reject the new arguments as they reject `balance`, since they have no meaning off the EVM.
vaibhav4046
added a commit
to vaibhav4046/hardstop
that referenced
this pull request
Nov 20, 2026
vaibhav4046
added a commit
to vaibhav4046/hardstop
that referenced
this pull request
Nov 20, 2026
…ream Upstream: argotorg/fe#2048 (block time and number in fe test) was merged on 2026-11-20 and closed #2039; a maintainer added his own test commit to #2042. Every doc that lists the pull requests now says so. Docs (an audit of every number, claim and link): refusal-script and test counts, the largest verified loss, sources vs figures, the walkthrough labelled with the day it was recorded and its counts, transaction links for the previous contracts, measured timings with their files, MCP tool signatures and Node versions, "Setups for" instead of "Works with", DECISIONS (fifteen mutants, four engine functions, exposure an upper bound), stale blocker removed. Site (a crawl at 360, 768 and 1440): a styled 404 page; robots.txt and sitemap.xml; under reduced motion the vault diagram shows its end state instead of nothing; tables wrap to a phone screen and their scroll boxes take keyboard focus; the footer stacks at tablet width and links the demo film; install commands wrap instead of being cut off; evidence copy no longer says "left/right" for stacked panels; transaction links centred.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2039.
Under
fe testevery test ran at block timestamp 1 and block number 0, with no way to change either, so contract logic that depends on time (a delay before a change takes effect, a rolling spending window) could not be tested end to end.#[test(timestamp = N)]and#[test(block_number = N)]set the block a test runs at. They takeu256literals and are checked the same way asbalance: a missing, non-integer or oversized value is an error naming the test and the key. The harness gainsRuntimeInstance::set_block_timestampandset_block_number(next toset_chain_id), whichfe testapplies before calling the test; contracts the test creates or calls see the same block. Without the arguments nothing changes. Native and WebAssembly tests reject them, as they rejectbalance.The example from #2039 now passes:
Moving time forward within one test is not included: a test runs as one transaction, so that would need a cheatcode-style call caught by the harness, which is a new API rather than a small change.
If #2041 (which limits
#[test(...)]to the keysfe testreads) merges first,timestampandblock_numberneed adding to its list, or the reverse.Tests
New fixture
crates/fe/tests/fixtures/fe_test/block_env.fe(default block, timestamp 1000, block number 42, timestamp 0, a called contract seeing the test's block, combined withbalance) andtest_fe_test_rejects_bad_block_argsincli_output.rs.cargo test --release --workspace --exclude fe-bench --no-fail-faston Windows: 2674 passed, 1 failed, 1 ignored. The failure ismock_client_tests::mock_lsp_checks_for_the_project_target, which fails the same way on unmodifiedmasterthere. Newsfragment:newsfragments/2048.feature.md.Found while building HARDSTOP, a Fe Builders Challenge entry, which tests its time-dependent contract logic outside
fe testfor this reason. Written with AI assistance (Claude); the tests above were run locally on this branch.