Skip to content

Commit

Permalink
♻️ Remove test dependencies (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized authored Apr 5, 2024
1 parent ee00574 commit feee4b3
Show file tree
Hide file tree
Showing 14 changed files with 2,784 additions and 1,131 deletions.
228 changes: 114 additions & 114 deletions .gas-snapshot

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/murky"]
path = lib/murky
url = https://github.com/dmfxyz/murky
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ optimizer_runs = 1_000
gas_limit = 1_000_000_000 # ETH is 30M, but we use a higher value.
remappings = [
"forge-std=test/utils/forge-std/",
"murky=lib/murky",
"solady=lib/solady/src"
]

Expand Down
1 change: 0 additions & 1 deletion lib/forge-std
Submodule forge-std deleted from ae570f
1 change: 0 additions & 1 deletion lib/murky
Submodule murky deleted from 40de6e
1 change: 0 additions & 1 deletion test/DN404OnlyERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.4;

import "./utils/SoladyTest.sol";
import "./utils/InvariantTest.sol";

import {DN404, MockDN404OnlyERC20} from "./utils/mocks/MockDN404OnlyERC20.sol";

Expand Down
10 changes: 3 additions & 7 deletions test/NFTMintDN404.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,23 @@ pragma solidity ^0.8.4;

import "./utils/SoladyTest.sol";
import {NFTMintDN404} from "../src/example/NFTMintDN404.sol";
import {Merkle} from "murky/src/Merkle.sol";

contract NFTMintDN404Test is SoladyTest {
uint256 internal constant _WAD = 10 ** 18;

NFTMintDN404 dn;
Merkle allowlistMerkle;

address alice = address(111);
address bob = address(222);

bytes32 allowlistRoot;
bytes32[] allowlistData = new bytes32[](2);

uint96 publicPrice = 0.02 ether;
uint96 allowlistPrice = 0.01 ether;

function setUp() public {
allowlistMerkle = new Merkle();
allowlistData[0] = bytes32(keccak256(abi.encodePacked(alice)));
allowlistRoot = allowlistMerkle.getRoot(allowlistData);
// Single leaf, so the root is the leaf.
allowlistRoot = bytes32(keccak256(abi.encodePacked(alice)));

dn = new NFTMintDN404(
"DN404",
Expand Down Expand Up @@ -76,7 +72,7 @@ contract NFTMintDN404Test is SoladyTest {
function testAllowlistMint() public {
vm.prank(bob);

bytes32[] memory proof = allowlistMerkle.getProof(allowlistData, 0);
bytes32[] memory proof; // Height one tree, so empty proof.
vm.expectRevert(NFTMintDN404.InvalidProof.selector);
dn.allowlistMint{value: 5 * allowlistPrice}(5, proof);

Expand Down
5 changes: 3 additions & 2 deletions test/invariants/BaseInvariant.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {Test} from "forge-std/Test.sol";
import {Test} from "../utils/forge-std/Test.sol";
import {StdInvariant} from "../utils/forge-std/StdInvariant.sol";
import {DN404} from "../../src/DN404.sol";
import {DN404Mirror} from "../../src/DN404Mirror.sol";
import {MockDN404} from "../utils/mocks/MockDN404.sol";
Expand All @@ -22,7 +23,7 @@ import {DN404Handler} from "./handlers/DN404Handler.sol";
/*** Vault Invariants ***/
/**************************************************************************************************************************************/
// forgefmt: disable-end
contract BaseInvariantTest is Test {
contract BaseInvariantTest is Test, StdInvariant {
address user0 = vm.addr(uint256(keccak256("User0")));
address user1 = vm.addr(uint256(keccak256("User1")));
address user2 = vm.addr(uint256(keccak256("User2")));
Expand Down
14 changes: 7 additions & 7 deletions test/invariants/handlers/DN404Handler.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {Test} from "forge-std/Test.sol";
import "../../utils/SoladyTest.sol";
import {MockDN404} from "../../utils/mocks/MockDN404.sol";
import {DN404Mirror} from "../../../src/DN404Mirror.sol";

contract DN404Handler is Test {
contract DN404Handler is SoladyTest {
uint256 private constant _WAD = 1000000000000000000;
uint256 private constant START_SLOT =
0x0000000000000000000000000000000000000000000000a20d6e21d0e5255308;
Expand Down Expand Up @@ -58,7 +58,7 @@ contract DN404Handler is Test {
}

function randomAddress(uint256 seed) private view returns (address) {
return actors[bound(seed, 0, actors.length - 1)];
return actors[_bound(seed, 0, actors.length - 1)];
}

function approve(uint256 ownerIndexSeed, uint256 spenderIndexSeed, uint256 amount) external {
Expand All @@ -74,7 +74,7 @@ contract DN404Handler is Test {
function transfer(uint256 fromIndexSeed, uint256 toIndexSeed, uint256 amount) external {
address from = randomAddress(fromIndexSeed);
address to = randomAddress(toIndexSeed);
amount = bound(amount, 0, dn404.balanceOf(from));
amount = _bound(amount, 0, dn404.balanceOf(from));
vm.startPrank(from);

uint256 fromPreBalance = dn404.balanceOf(from);
Expand All @@ -100,7 +100,7 @@ contract DN404Handler is Test {
address sender = randomAddress(senderIndexSeed);
address from = randomAddress(fromIndexSeed);
address to = randomAddress(toIndexSeed);
amount = bound(amount, 0, dn404.balanceOf(from));
amount = _bound(amount, 0, dn404.balanceOf(from));
vm.startPrank(sender);

uint256 fromPreBalance = dn404.balanceOf(from);
Expand All @@ -124,7 +124,7 @@ contract DN404Handler is Test {

function mint(uint256 toIndexSeed, uint256 amount) external {
address to = randomAddress(toIndexSeed);
amount = bound(amount, 0, 100e18);
amount = _bound(amount, 0, 100e18);

uint256 toPreBalance = dn404.balanceOf(to);

Expand All @@ -138,7 +138,7 @@ contract DN404Handler is Test {
function burn(uint256 fromIndexSeed, uint256 amount) external {
address from = randomAddress(fromIndexSeed);
vm.startPrank(from);
amount = bound(amount, 0, dn404.balanceOf(from));
amount = _bound(amount, 0, dn404.balanceOf(from));

uint256 fromPreBalance = dn404.balanceOf(from);

Expand Down
15 changes: 0 additions & 15 deletions test/utils/InvariantTest.sol

This file was deleted.

111 changes: 111 additions & 0 deletions test/utils/forge-std/StdInvariant.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;

pragma experimental ABIEncoderV2;

abstract contract StdInvariant {
struct FuzzSelector {
address addr;
bytes4[] selectors;
}

struct FuzzInterface {
address addr;
string[] artifacts;
}

address[] private _excludedContracts;
address[] private _excludedSenders;
address[] private _targetedContracts;
address[] private _targetedSenders;

string[] private _excludedArtifacts;
string[] private _targetedArtifacts;

FuzzSelector[] private _targetedArtifactSelectors;
FuzzSelector[] private _targetedSelectors;

FuzzInterface[] private _targetedInterfaces;

// Functions for users:
// These are intended to be called in tests.

function excludeContract(address newExcludedContract_) internal {
_excludedContracts.push(newExcludedContract_);
}

function excludeSender(address newExcludedSender_) internal {
_excludedSenders.push(newExcludedSender_);
}

function excludeArtifact(string memory newExcludedArtifact_) internal {
_excludedArtifacts.push(newExcludedArtifact_);
}

function targetArtifact(string memory newTargetedArtifact_) internal {
_targetedArtifacts.push(newTargetedArtifact_);
}

function targetArtifactSelector(FuzzSelector memory newTargetedArtifactSelector_) internal {
_targetedArtifactSelectors.push(newTargetedArtifactSelector_);
}

function targetContract(address newTargetedContract_) internal {
_targetedContracts.push(newTargetedContract_);
}

function targetSelector(FuzzSelector memory newTargetedSelector_) internal {
_targetedSelectors.push(newTargetedSelector_);
}

function targetSender(address newTargetedSender_) internal {
_targetedSenders.push(newTargetedSender_);
}

function targetInterface(FuzzInterface memory newTargetedInterface_) internal {
_targetedInterfaces.push(newTargetedInterface_);
}

// Functions for forge:
// These are called by forge to run invariant tests and don't need to be called in tests.

function excludeArtifacts() public view returns (string[] memory excludedArtifacts_) {
excludedArtifacts_ = _excludedArtifacts;
}

function excludeContracts() public view returns (address[] memory excludedContracts_) {
excludedContracts_ = _excludedContracts;
}

function excludeSenders() public view returns (address[] memory excludedSenders_) {
excludedSenders_ = _excludedSenders;
}

function targetArtifacts() public view returns (string[] memory targetedArtifacts_) {
targetedArtifacts_ = _targetedArtifacts;
}

function targetArtifactSelectors()
public
view
returns (FuzzSelector[] memory targetedArtifactSelectors_)
{
targetedArtifactSelectors_ = _targetedArtifactSelectors;
}

function targetContracts() public view returns (address[] memory targetedContracts_) {
targetedContracts_ = _targetedContracts;
}

function targetSelectors() public view returns (FuzzSelector[] memory targetedSelectors_) {
targetedSelectors_ = _targetedSelectors;
}

function targetSenders() public view returns (address[] memory targetedSenders_) {
targetedSenders_ = _targetedSenders;
}

function targetInterfaces() public view returns (FuzzInterface[] memory targetedInterfaces_) {
targetedInterfaces_ = _targetedInterfaces;
}
}
Loading

0 comments on commit feee4b3

Please sign in to comment.