misc: Replace _isValidPk helper by foundry's bound(...)

This commit is contained in:
donosonaumczuk
2023-01-31 12:23:34 -03:00
parent d6a6de516c
commit b625508b97
5 changed files with 27 additions and 24 deletions

View File

@@ -3,3 +3,4 @@ pragma solidity ^0.8.13;
uint256 constant FIRST_PROFILE_ID = 1;
uint256 constant FIRST_PUB_ID = 1;
uint256 constant ISSECP256K1_CURVE_ORDER = 115792089237316195423570985008687907852837564279074904382605163141518161494337;

View File

@@ -4,11 +4,10 @@ pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import './MetaTxNegatives.t.sol';
import {Strings} from '@openzeppelin/contracts/utils/Strings.sol';
import './helpers/AssumptionHelpers.sol';
import {IFollowNFT} from 'contracts/interfaces/IFollowNFT.sol';
import '../../contracts/mocks/MockFollowModuleWithRevertFlag.sol';
contract FollowTest is BaseTest, AssumptionHelpers {
contract FollowTest is BaseTest {
using Strings for uint256;
uint256 constant MINT_NEW_TOKEN = 0;
@@ -98,7 +97,7 @@ contract FollowTest is BaseTest, AssumptionHelpers {
function testCannotFollowIfExecutorIsNotTheProfileOwnerOrHisApprovedExecutor(uint256 executorPk)
public
{
vm.assume(_isValidPk(executorPk));
executorPk = bound(executorPk, 1, ISSECP256K1_CURVE_ORDER - 1);
address executor = vm.addr(executorPk);
vm.assume(executor != address(0));
vm.assume(executor != followerProfileOwner);
@@ -119,7 +118,7 @@ contract FollowTest is BaseTest, AssumptionHelpers {
function testCannotFollowWithUnwrappedTokenIfExecutorIsNotTheProfileOwnerOrHisApprovedExecutor(
uint256 executorPk
) public {
vm.assume(_isValidPk(executorPk));
executorPk = bound(executorPk, 1, ISSECP256K1_CURVE_ORDER - 1);
address executor = vm.addr(executorPk);
vm.assume(executor != address(0));
vm.assume(executor != followerProfileOwner);
@@ -143,7 +142,7 @@ contract FollowTest is BaseTest, AssumptionHelpers {
function testCannotFollowWithWrappedTokenIfExecutorIsNotTheProfileOwnerOrHisApprovedExecutor(
uint256 executorPk
) public {
vm.assume(_isValidPk(executorPk));
executorPk = bound(executorPk, 1, ISSECP256K1_CURVE_ORDER - 1);
address executor = vm.addr(executorPk);
vm.assume(executor != address(0));
vm.assume(executor != followerProfileOwner);
@@ -340,7 +339,11 @@ contract FollowTest is BaseTest, AssumptionHelpers {
function testFollowAsFollowerApprovedDelegatedExecutor(uint256 approvedDelegatedExecutorPk)
public
{
vm.assume(_isValidPk(approvedDelegatedExecutorPk));
approvedDelegatedExecutorPk = bound(
approvedDelegatedExecutorPk,
1,
ISSECP256K1_CURVE_ORDER - 1
);
address approvedDelegatedExecutor = vm.addr(approvedDelegatedExecutorPk);
vm.assume(approvedDelegatedExecutor != address(0));
vm.assume(approvedDelegatedExecutor != followerProfileOwner);

View File

@@ -3,9 +3,8 @@ pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import './MetaTxNegatives.t.sol';
import './helpers/AssumptionHelpers.sol';
contract SetBlockStatusTest is BaseTest, AssumptionHelpers {
contract SetBlockStatusTest is BaseTest {
address constant PROFILE_OWNER = address(0);
uint256 constant statusSetterProfileOwnerPk = 0x7357;
@@ -76,7 +75,11 @@ contract SetBlockStatusTest is BaseTest, AssumptionHelpers {
function testCannotSetBlockStatusIfNotOwnerOrApprovedDelegatedExecutorOfSetterProfile(
uint256 nonOwnerNorDelegatedExecutorPk
) public virtual {
vm.assume(_isValidPk(nonOwnerNorDelegatedExecutorPk));
nonOwnerNorDelegatedExecutorPk = bound(
nonOwnerNorDelegatedExecutorPk,
1,
ISSECP256K1_CURVE_ORDER - 1
);
address nonOwnerNorDelegatedExecutor = vm.addr(nonOwnerNorDelegatedExecutorPk);
vm.assume(nonOwnerNorDelegatedExecutor != address(0));
vm.assume(nonOwnerNorDelegatedExecutor != statusSetterProfileOwner);
@@ -377,7 +380,11 @@ contract SetBlockStatusMetaTxTest is SetBlockStatusTest, MetaTxNegatives {
function testCannotSetBlockStatusIfNotOwnerOrApprovedDelegatedExecutorOfSetterProfile(
uint256 nonOwnerNorDelegatedExecutorPk
) public override {
vm.assume(_isValidPk(nonOwnerNorDelegatedExecutorPk));
nonOwnerNorDelegatedExecutorPk = bound(
nonOwnerNorDelegatedExecutorPk,
1,
ISSECP256K1_CURVE_ORDER - 1
);
address nonOwnerNorDelegatedExecutor = vm.addr(nonOwnerNorDelegatedExecutorPk);
vm.assume(nonOwnerNorDelegatedExecutor != address(0));
vm.assume(nonOwnerNorDelegatedExecutor != statusSetterProfileOwner);

View File

@@ -4,10 +4,9 @@ pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import './MetaTxNegatives.t.sol';
import {Strings} from '@openzeppelin/contracts/utils/Strings.sol';
import './helpers/AssumptionHelpers.sol';
import {IFollowNFT} from 'contracts/interfaces/IFollowNFT.sol';
contract UnfollowTest is BaseTest, AssumptionHelpers {
contract UnfollowTest is BaseTest {
uint256 constant MINT_NEW_TOKEN = 0;
address constant PROFILE_OWNER = address(0);
address targetProfileOwner = address(0xC0FFEE);
@@ -169,7 +168,11 @@ contract UnfollowTest is BaseTest, AssumptionHelpers {
function testUnfollowAsUnfollowerApprovedDelegatedExecutor(uint256 approvedDelegatedExecutorPk)
public
{
vm.assume(_isValidPk(approvedDelegatedExecutorPk));
approvedDelegatedExecutorPk = bound(
approvedDelegatedExecutorPk,
1,
ISSECP256K1_CURVE_ORDER - 1
);
address approvedDelegatedExecutor = vm.addr(approvedDelegatedExecutorPk);
vm.assume(approvedDelegatedExecutor != address(0));
vm.assume(approvedDelegatedExecutor != unfollowerProfileOwner);

View File

@@ -1,11 +0,0 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract AssumptionHelpers {
uint256 constant ISSECP256K1_CURVE_ORDER =
115792089237316195423570985008687907852837564279074904382605163141518161494337;
function _isValidPk(uint256 pkCandidate) internal pure returns (bool) {
return pkCandidate > 0 && pkCandidate < ISSECP256K1_CURVE_ORDER;
}
}