Skip to content

PriceIsRight.t.sol fuzz test: missing vm.deal for second buy causes revert for wrong reason #46

@al0x23

Description

@al0x23

In the PriceIsRight.t.sol, the test doesn't vm.deal for the second call that checks if 'msg.value == 1 ether', so it reverts for the wrong reason. This is a working test, that accounts also for the possibility of overflowing while fuzzing (causing a revert) with the 'bound' function for 'amount' (the order is important).

function testBuy(uint256 amount) external {
        amount = bound(amount, 0, type(uint256).max - 1 ether);
        amount = amount == 1 ether ? 2 ether : amount;

        vm.deal(address(this), 1 ether + amount);
        priceIsRight.buy{value: 1 ether}();

        vm.expectRevert();
        priceIsRight.buy{value: amount}();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions