Let's take an example, where we have a stake function, with the stake's endTimestamp in uin64.

function stake(uint256 amount, uin64 endTimestamp)

It is assumed endTimestamp should never be less than the timestamp at which the stake function was called. What is the best way of creating such a limit in a Foundry test?

1 Answer 1


Foundry implements function bound(uint256 x, uint256 min, uint256 max), which bounds a variable parameter to a certain range. To bound an input parameter, you can do something like this:

function stake(uint256 amount, uin64 endTimestamp) {
        endtimestamp = uint64(bound(endTimestamp, block.timestamp, type(uint64).max))

You can read more about it here: https://book.getfoundry.sh/reference/forge-std/bound

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.