Skip to content

Commit

Permalink
♻️ Add brutalized tests (Vectorized#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized authored Feb 12, 2024
1 parent efd9800 commit f40cc62
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 28 deletions.
48 changes: 24 additions & 24 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
DN404MirrorTest:testBaseERC20() (gas: 114753)
DN404MirrorTest:testLinkMirrorContract() (gas: 45802)
DN404MirrorTest:testLogTransfer() (gas: 120757)
DN404MirrorTest:testNameAndSymbol(string,string) (runs: 256, μ: 207213, ~: 207554)
DN404MirrorTest:testNotLinked() (gas: 12483)
DN404MirrorTest:testSafeTransferFrom(uint32) (runs: 256, μ: 468114, ~: 468100)
DN404MirrorTest:testSetAndGetApprovalForAll() (gas: 323616)
DN404MirrorTest:testSetAndGetApproved() (gas: 316721)
DN404MirrorTest:testNameAndSymbol(string,string) (runs: 256, μ: 207652, ~: 207995)
DN404MirrorTest:testNotLinked() (gas: 12698)
DN404MirrorTest:testSafeTransferFrom(uint32) (runs: 256, μ: 469698, ~: 469691)
DN404MirrorTest:testSetAndGetApprovalForAll() (gas: 325387)
DN404MirrorTest:testSetAndGetApproved() (gas: 318214)
DN404MirrorTest:testSupportsInterface() (gas: 7544)
DN404MirrorTest:testTokenURI(string,uint256) (runs: 256, μ: 157965, ~: 135664)
DN404MirrorTest:testTransferFrom(uint32) (runs: 256, μ: 343258, ~: 343247)
DN404MirrorTest:test__codesize() (gas: 29442)
DN404MirrorTest:testTokenURI(string,uint256) (runs: 256, μ: 158189, ~: 135888)
DN404MirrorTest:testTransferFrom(uint32) (runs: 256, μ: 344588, ~: 344576)
DN404MirrorTest:test__codesize() (gas: 30387)
DN404OnlyERC20Test:testApprove() (gas: 35912)
DN404OnlyERC20Test:testApprove(address,uint256) (runs: 256, μ: 30219, ~: 31463)
DN404OnlyERC20Test:testBurn() (gas: 49769)
DN404OnlyERC20Test:testBurn(address,uint256,uint256) (runs: 256, μ: 51016, ~: 50970)
DN404OnlyERC20Test:testBurnInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 43809, ~: 43888)
DN404OnlyERC20Test:testBurn(address,uint256,uint256) (runs: 256, μ: 50858, ~: 50970)
DN404OnlyERC20Test:testBurnInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 43805, ~: 43888)
DN404OnlyERC20Test:testInfiniteApproveTransferFrom() (gas: 102011)
DN404OnlyERC20Test:testMaxSupplyTrick(uint256) (runs: 256, μ: 541, ~: 541)
DN404OnlyERC20Test:testMetadata() (gas: 10111)
DN404OnlyERC20Test:testMint() (gas: 45320)
DN404OnlyERC20Test:testMintOverMaxLimitReverts() (gas: 40544)
DN404OnlyERC20Test:testMintz(address,uint256) (runs: 256, μ: 45731, ~: 45742)
DN404OnlyERC20Test:testMintz(address,uint256) (runs: 256, μ: 45818, ~: 45742)
DN404OnlyERC20Test:testTransfer() (gas: 74556)
DN404OnlyERC20Test:testTransfer(address,uint256) (runs: 256, μ: 74896, ~: 75013)
DN404OnlyERC20Test:testTransfer(address,uint256) (runs: 256, μ: 74899, ~: 75013)
DN404OnlyERC20Test:testTransferFrom() (gas: 84636)
DN404OnlyERC20Test:testTransferFrom(address,address,address,uint256,uint256) (runs: 256, μ: 105426, ~: 107617)
DN404OnlyERC20Test:testTransferFrom(address,address,address,uint256,uint256) (runs: 256, μ: 105698, ~: 107617)
DN404OnlyERC20Test:testTransferFromInsufficientAllowanceReverts() (gas: 68086)
DN404OnlyERC20Test:testTransferFromInsufficientAllowanceReverts(address,uint256,uint256) (runs: 256, μ: 68688, ~: 69187)
DN404OnlyERC20Test:testTransferFromInsufficientAllowanceReverts(address,uint256,uint256) (runs: 256, μ: 68600, ~: 69187)
DN404OnlyERC20Test:testTransferFromInsufficientBalanceReverts() (gas: 75030)
DN404OnlyERC20Test:testTransferFromInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 76089, ~: 76151)
DN404OnlyERC20Test:testTransferFromInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 76174, ~: 76160)
DN404OnlyERC20Test:testTransferInsufficientBalanceReverts() (gas: 66261)
DN404OnlyERC20Test:testTransferInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 67385, ~: 67357)
DN404OnlyERC20Test:testTransferInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 67396, ~: 67384)
DN404OnlyERC20Test:test__codesize() (gas: 29774)
DN404Test:testBatchNFTLog() (gas: 314471)
DN404Test:testBurnOnTransfer(uint32,address) (runs: 256, μ: 264046, ~: 264046)
DN404Test:testInitialize(uint32,address) (runs: 256, μ: 113409, ~: 116477)
DN404Test:testBurnOnTransfer(uint32,address) (runs: 256, μ: 264026, ~: 264046)
DN404Test:testInitialize(uint32,address) (runs: 256, μ: 112902, ~: 116477)
DN404Test:testMintAndBurn() (gas: 339377)
DN404Test:testMintAndBurn2() (gas: 263133)
DN404Test:testMintOnTransfer(uint32,address) (runs: 256, μ: 262620, ~: 262620)
DN404Test:testMixed(uint256) (runs: 256, μ: 595017, ~: 572067)
DN404Test:testMintOnTransfer(uint32,address) (runs: 256, μ: 262610, ~: 262620)
DN404Test:testMixed(uint256) (runs: 256, μ: 600208, ~: 572067)
DN404Test:testNameAndSymbol(string,string) (runs: 256, μ: 207282, ~: 207623)
DN404Test:testRegisterAndResolveAlias(address,address) (runs: 256, μ: 127029, ~: 127078)
DN404Test:testSetAndGetAux(address,uint88) (runs: 256, μ: 22003, ~: 22275)
DN404Test:testRegisterAndResolveAlias(address,address) (runs: 256, μ: 126873, ~: 127078)
DN404Test:testSetAndGetAux(address,uint88) (runs: 256, μ: 21968, ~: 22275)
DN404Test:testSetAndGetOperatorApprovals(address,address,bool) (runs: 256, μ: 129762, ~: 120828)
DN404Test:testSetAndGetSkipNFT() (gas: 89239)
DN404Test:testTokenURI(string,uint256) (runs: 256, μ: 158077, ~: 135776)
DN404Test:testTransfersAndBurns() (gas: 453395)
DN404Test:testWrapAround(uint32,uint256) (runs: 256, μ: 355195, ~: 347752)
DN404Test:testWrapAround(uint32,uint256) (runs: 256, μ: 354173, ~: 347752)
DN404Test:test__codesize() (gas: 40891)
ERC20Invariants:invariantBalanceSum() (runs: 256, calls: 3840, reverts: 2655)
ERC20Invariants:invariantBalanceSum() (runs: 256, calls: 3840, reverts: 2639)
ERC20Invariants:test__codesize() (gas: 16961)
SimpleDN404Test:testMint() (gas: 45198)
SimpleDN404Test:testName() (gas: 9674)
Expand Down
2 changes: 1 addition & 1 deletion src/DN404Mirror.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ contract DN404Mirror {
}

/// @dev Returns the total NFT supply from the base DN404 contract.
function totalSupply() public view returns (uint256 result) {
function totalSupply() public view virtual returns (uint256 result) {
address base = baseERC20();
/// @solidity memory-safe-assembly
assembly {
Expand Down
6 changes: 3 additions & 3 deletions test/DN404Mirror.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.4;

import "./utils/SoladyTest.sol";
import {DN404, MockDN404} from "./utils/mocks/MockDN404.sol";
import {DN404Mirror} from "../src/DN404Mirror.sol";
import {DN404Mirror, MockDN404Mirror} from "./utils/mocks/MockDN404Mirror.sol";

contract Invalid721Receiver {}

Expand All @@ -17,11 +17,11 @@ contract DN404MirrorTest is SoladyTest {
uint256 private constant _WAD = 1000000000000000000;

MockDN404 dn;
DN404Mirror mirror;
MockDN404Mirror mirror;

function setUp() public {
dn = new MockDN404();
mirror = new DN404Mirror(address(this));
mirror = new MockDN404Mirror(address(this));
}

function testNotLinked() public {
Expand Down
123 changes: 123 additions & 0 deletions test/utils/mocks/MockDN404Mirror.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "../../../src/DN404Mirror.sol";

contract MockDN404Mirror is DN404Mirror {
constructor(address deployer) DN404Mirror(deployer) {}

function name() public view virtual override brutalizeMemory returns (string memory result) {
result = DN404Mirror.name();
}

function symbol() public view virtual override brutalizeMemory returns (string memory result) {
result = DN404Mirror.symbol();
}

function tokenURI(uint256 id)
public
view
virtual
override
brutalizeMemory
returns (string memory result)
{
result = DN404Mirror.tokenURI(id);
}

function totalSupply() public view virtual override brutalizeMemory returns (uint256 result) {
result = DN404Mirror.totalSupply();
}

function balanceOf(address owner)
public
view
virtual
override
brutalizeMemory
returns (uint256 result)
{
result = DN404Mirror.balanceOf(_brutalized(owner));
}

function ownerOf(uint256 id)
public
view
virtual
override
brutalizeMemory
returns (address result)
{
result = DN404Mirror.ownerOf(id);
}

function approve(address spender, uint256 id) public virtual override brutalizeMemory {
DN404Mirror.approve(_brutalized(spender), id);
}

function getApproved(uint256 id)
public
view
virtual
override
brutalizeMemory
returns (address result)
{
result = DN404Mirror.getApproved(id);
}

function setApprovalForAll(address operator, bool approved)
public
virtual
override
brutalizeMemory
{
DN404Mirror.setApprovalForAll(_brutalized(operator), approved);
}

function isApprovedForAll(address owner, address operator)
public
view
virtual
override
brutalizeMemory
returns (bool result)
{
result = DN404Mirror.isApprovedForAll(owner, operator);
}

function transferFrom(address from, address to, uint256 id)
public
virtual
override
brutalizeMemory
{
DN404Mirror.transferFrom(_brutalized(from), _brutalized(to), id);
}

function _brutalized(address a) internal pure returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := or(0xf348aeebbad597df99cf9f4f0000000000000000000000000000000000000000, a)
}
}

modifier brutalizeMemory() {
uint256 r = gasleft();
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, r)
r := keccak256(0x00, 0x20)
mstore(0x00, r)
mstore(0x20, r)
let m := mload(0x40)
mstore(add(m, 0x00), r)
mstore(add(m, 0x20), r)
mstore(add(m, 0x40), r)
mstore(add(m, 0x60), r)
mstore(add(m, 0x80), r)
mstore(add(m, 0xa0), r)
}
_;
}
}

0 comments on commit f40cc62

Please sign in to comment.