Skip to content

fe test: set the block timestamp and number with #[test(timestamp = N, block_number = N)] - #2048

Merged
sbillig merged 2 commits into
argotorg:masterfrom
vaibhav4046:test-block-timestamp
Nov 20, 2026
Merged

sbillig merged 2 commits into
argotorg:masterfrom
vaibhav4046:test-block-timestamp

Conversation

@vaibhav4046

@vaibhav4046 vaibhav4046 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2039.

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 (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 take u256 literals and are checked the same way as balance: a missing, non-integer or oversized value is an error naming the test and the key. The harness gains RuntimeInstance::set_block_timestamp and set_block_number (next to set_chain_id), which fe test applies 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 reject balance.

The example from #2039 now passes:

PASS  [0.0001s] timestamp_is_fixed
PASS  [0.0000s] timestamp_argument

test result: ok. 2 passed; 0 failed

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 keys fe test reads) merges first, timestamp and block_number need 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 with balance) and test_fe_test_rejects_bad_block_args in cli_output.rs.

cargo test --release --workspace --exclude fe-bench --no-fail-fast on Windows: 2674 passed, 1 failed, 1 ignored. The failure is mock_client_tests::mock_lsp_checks_for_the_project_target, which fails the same way on unmodified master there. Newsfragment: newsfragments/2048.feature.md.


Found while building HARDSTOP, a Fe Builders Challenge entry, which tests its time-dependent contract logic outside fe test for this reason. Written with AI assistance (Claude); the tests above were run locally on this branch.

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

@sbillig sbillig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@sbillig
sbillig merged commit 91a6928 into argotorg:master Nov 20, 2026
11 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fe test: no way to set or advance the block timestamp

2 participants