Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erc6909claims tests #698

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {ERC6909Claims} from "../ERC6909Claims.sol";
import {Currency} from "../types/Currency.sol";
import {Currency, CurrencyLibrary} from "../types/Currency.sol";

/// @notice Mock contract for testing ERC6909Claims
contract MockERC6909Claims is ERC6909Claims {
contract ERC6909ClaimsImplementation is ERC6909Claims {
using CurrencyLibrary for Currency;
dianakocsis marked this conversation as resolved.
Show resolved Hide resolved

/// @notice mocked mint logic
function mint(address to, uint256 id, uint256 amount) public {
_mint(to, id, amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,74 @@
pragma solidity ^0.8.15;

import {Test} from "forge-std/Test.sol";
import {Currency} from "../src/types/Currency.sol";
import {MockERC6909Claims} from "../src/test/MockERC6909Claims.sol";
import {CurrencyLibrary, Currency} from "../src/types/Currency.sol";
import {ERC6909ClaimsImplementation} from "../src/test/ERC6909ClaimsImplementation.sol";
import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol";
import {stdError} from "forge-std/StdError.sol";

contract ERC6909ClaimsTest is Test, GasSnapshot {
MockERC6909Claims token;
using CurrencyLibrary for Currency;
dianakocsis marked this conversation as resolved.
Show resolved Hide resolved

ERC6909ClaimsImplementation token;

function setUp() public {
token = new MockERC6909Claims();
token = new ERC6909ClaimsImplementation();
}

function test_burnFrom_withApproval(address sender, uint256 id, uint256 mintAmount, uint256 transferAmount)
function test_fuzz_burnFrom_withApproval(address sender, uint256 id, uint256 mintAmount, uint256 burnAmount)
public
{
token.mint(sender, id, mintAmount);

vm.prank(sender);
token.approve(address(this), id, mintAmount);

if (transferAmount > mintAmount) {
vm.expectRevert();
if (burnAmount > mintAmount) {
vm.expectRevert(stdError.arithmeticError);
}
token.burnFrom(sender, id, transferAmount);
token.burnFrom(sender, id, burnAmount);

if (transferAmount <= mintAmount) {
if (burnAmount <= mintAmount) {
if (mintAmount == type(uint256).max) {
assertEq(token.allowance(sender, address(this), id), type(uint256).max);
} else {
if (sender != address(this)) {
assertEq(token.allowance(sender, address(this), id), mintAmount - transferAmount);
assertEq(token.allowance(sender, address(this), id), mintAmount - burnAmount);
} else {
assertEq(token.allowance(sender, address(this), id), mintAmount);
}
}
assertEq(token.balanceOf(sender, id), mintAmount - transferAmount);
assertEq(token.balanceOf(sender, id), mintAmount - burnAmount);
}
}

function test_fuzz_burnFrom_withOperator(address sender, uint256 id, uint256 mintAmount, uint256 burnAmount)
public
{
token.mint(sender, id, mintAmount);

assertFalse(token.isOperator(sender, address(this)));

vm.prank(sender);
token.setOperator(address(this), true);

assertTrue(token.isOperator(sender, address(this)));

if (burnAmount > mintAmount) {
vm.expectRevert(stdError.arithmeticError);
}
token.burnFrom(sender, id, burnAmount);

if (burnAmount <= mintAmount) {
assertEq(token.balanceOf(sender, id), mintAmount - burnAmount);
}
}

function test_burnFrom_revertsWithNoApproval() public {
token.mint(address(this), 1337, 100);

vm.prank(address(0xBEEF));
vm.expectRevert();
vm.expectRevert(stdError.arithmeticError);
token.burnFrom(address(this), 1337, 100);
}

Expand Down
Loading