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 5 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 @@ -6,7 +6,7 @@ import {ERC6909Claims} from "../ERC6909Claims.sol";
import {CurrencyLibrary, Currency} 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,58 @@ pragma solidity ^0.8.15;

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

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

MockERC6909Claims token;
ERC6909ClaimsImplementation token;

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

function test_burnFrom_withApproval(address sender, uint256 id, uint256 mintAmount, uint256 transferAmount)
public
{
function test_burnFrom_withApproval(address sender, uint256 id, uint256 mintAmount, uint256 burnAmount) public {
dianakocsis marked this conversation as resolved.
Show resolved Hide resolved
token.mint(sender, id, mintAmount);

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

if (transferAmount > mintAmount) {
if (burnAmount > mintAmount) {
vm.expectRevert();
hensha256 marked this conversation as resolved.
Show resolved Hide resolved
}
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_burnFrom_withOperator(address sender, uint256 id, uint256 mintAmount, uint256 burnAmount) public {
hensha256 marked this conversation as resolved.
Show resolved Hide resolved
token.mint(sender, id, mintAmount);

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

if (burnAmount > mintAmount) {
vm.expectRevert();
hensha256 marked this conversation as resolved.
Show resolved Hide resolved
}
token.burnFrom(sender, id, burnAmount);

if (burnAmount <= mintAmount) {
assertEq(token.balanceOf(sender, id), mintAmount - burnAmount);
}
assertEq(token.allowance(sender, address(this), id), 0);
hensha256 marked this conversation as resolved.
Show resolved Hide resolved
}

function test_burnFrom_revertsWithNoApproval() public {
Expand Down
Loading