Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/diamond/example/ExampleDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ contract ExampleDiamond {
/**
* Setting ERC721 token details
*/
ERC721MetadataMod.setMetadata({_name: "ExampleDiamondNFT", _symbol: "EDN", _baseURI: "https://example.com/metadata/"});
ERC721MetadataMod.setMetadata({
_name: "ExampleDiamondNFT", _symbol: "EDN", _baseURI: "https://example.com/metadata/"
});
/**
* Registering ERC165 interfaces
*/
Expand Down
4 changes: 3 additions & 1 deletion src/token/ERC20/Approve/ERC20ApproveMod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ function getStorage() pure returns (ERC20Storage storage s) {
* @dev Sets the allowance for the spender.
* @param _spender The address to approve for spending.
* @param _value The amount of tokens to approve.
* @return True if the approval was successful.
*/
function approve(address _spender, uint256 _value) {
function approve(address _spender, uint256 _value) returns (bool) {
if (_spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
ERC20Storage storage s = getStorage();
s.allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
8 changes: 6 additions & 2 deletions src/token/ERC20/Transfer/ERC20TransferMod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ function getStorage() pure returns (ERC20Storage storage s) {
* @param _from The address to send tokens from.
* @param _to The address to send tokens to.
* @param _value The number of tokens to transfer.
* @return True if the transfer was successful.
*/
function transferFrom(address _from, address _to, uint256 _value) {
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
ERC20Storage storage s = getStorage();
if (_from == address(0)) {
revert ERC20InvalidSender(address(0));
Expand All @@ -119,15 +120,17 @@ function transferFrom(address _from, address _to, uint256 _value) {
}
s.balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}

/**
* @notice Transfers tokens from the caller to another address.
* @dev Updates balances directly without allowance mechanism.
* @param _to The address to send tokens to.
* @param _value The number of tokens to transfer.
* @return True if the transfer was successful.
*/
function transfer(address _to, uint256 _value) {
function transfer(address _to, uint256 _value) returns (bool) {
ERC20Storage storage s = getStorage();
if (_to == address(0)) {
revert ERC20InvalidReceiver(address(0));
Expand All @@ -141,5 +144,6 @@ function transfer(address _to, uint256 _value) {
}
s.balanceOf[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}

4 changes: 2 additions & 2 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ abstract contract Base_Test is Constants, Modifiers, StdAssertions, StdCheats {
createTestUsers();
defaults.setUsers(users);

setVariables(defaults, users); // set in modifier contract
setVariables(defaults, users);

setMsgSender(users.alice); // alice default caller
setMsgSender(users.alice);
}

/*//////////////////////////////////////////////////////////////
Expand Down
62 changes: 0 additions & 62 deletions test/harnesses/token/ERC20/ERC20/ERC20Harness.sol

This file was deleted.

25 changes: 0 additions & 25 deletions test/harnesses/token/ERC20/ERC20/ERC20MetadataFacetHarness.sol

This file was deleted.

21 changes: 21 additions & 0 deletions test/harnesses/token/ERC20/ERC20ApproveModHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.30;

/* Compose
* https://compose.diamonds
*/

import "src/token/ERC20/Approve/ERC20ApproveMod.sol" as ERC20ApproveMod;

/**
* @title ERC20ApproveModHarness
* @notice Test harness that exposes ERC20ApproveMod functions as external
*/
contract ERC20ApproveModHarness {
/**
* @notice Exposes ERC20ApproveMod.approve as an external function
*/
function approve(address _spender, uint256 _value) external returns (bool) {
return ERC20ApproveMod.approve(_spender, _value);
}
}
21 changes: 21 additions & 0 deletions test/harnesses/token/ERC20/ERC20BurnModHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.30;

/* Compose
* https://compose.diamonds
*/

import "src/token/ERC20/Burn/ERC20BurnMod.sol" as ERC20BurnMod;

/**
* @title ERC20BurnModHarness
* @notice Test harness that exposes ERC20BurnMod functions as external
*/
contract ERC20BurnModHarness {
/**
* @notice Exposes ERC20BurnMod.burnERC20 as an external function
*/
function burn(address _account, uint256 _value) external {
ERC20BurnMod.burnERC20(_account, _value);
}
}
21 changes: 21 additions & 0 deletions test/harnesses/token/ERC20/ERC20MintModHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.30;

/* Compose
* https://compose.diamonds
*/

import "src/token/ERC20/Mint/ERC20MintMod.sol" as ERC20MintMod;

/**
* @title ERC20MintModHarness
* @notice Test harness that exposes ERC20MintMod functions as external
*/
contract ERC20MintModHarness {
/**
* @notice Exposes ERC20Mod.mintERC20 as an external function
*/
function mint(address _account, uint256 _value) external {
ERC20MintMod.mintERC20(_account, _value);
}
}
28 changes: 28 additions & 0 deletions test/harnesses/token/ERC20/ERC20TransferModHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.30;

/* Compose
* https://compose.diamonds
*/

import "src/token/ERC20/Transfer/ERC20TransferMod.sol" as ERC20TransferMod;

/**
* @title ERC20TransferModHarness
* @notice Test harness that exposes ERC20TransferMod functions as external
*/
contract ERC20TransferModHarness {
/**
* @notice Exposes ERC20TransferMod.transferFrom as an external function
*/
function transferFrom(address _from, address _to, uint256 _value) external returns (bool) {
return ERC20TransferMod.transferFrom(_from, _to, _value);
}

/**
* @notice Exposes ERC20TransferMod.transfer as an external function
*/
function transfer(address _to, uint256 _value) external returns (bool) {
return ERC20TransferMod.transfer(_to, _value);
}
}
File renamed without changes.
44 changes: 44 additions & 0 deletions test/unit/token/ERC20/Approve/facet/fuzz/approve.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.30;

/* Compose
* https://compose.diamonds
*/

import {stdError} from "forge-std/StdError.sol";
import {Base_Test} from "test/Base.t.sol";
import {ERC20StorageUtils} from "test/utils/storage/ERC20StorageUtils.sol";

import {ERC20ApproveFacet} from "src/token/ERC20/Approve/ERC20ApproveFacet.sol";

/**
* @dev BTT spec: test/trees/ERC20.tree
*/
contract Approve_ERC20ApproveFacet_Fuzz_Unit_Test is Base_Test {
using ERC20StorageUtils for address;

ERC20ApproveFacet internal facet;

function setUp() public virtual override {
Base_Test.setUp();
facet = new ERC20ApproveFacet();
vm.label(address(facet), "ERC20ApproveFacet");
}

function testFuzz_ShouldRevert_SpenderIsZeroAddress(uint256 value) external {
vm.expectRevert(abi.encodeWithSelector(ERC20ApproveFacet.ERC20InvalidSpender.selector, ADDRESS_ZERO));
facet.approve(ADDRESS_ZERO, value);
}

function testFuzz_Approve(address spender, uint256 value) external whenSpenderNotZeroAddress {
vm.assume(spender != ADDRESS_ZERO);

vm.expectEmit(address(facet));
emit ERC20ApproveFacet.Approval(users.alice, spender, value);
bool result = facet.approve(spender, value);

assertEq(result, true, "approve failed");
assertEq(address(facet).allowance(users.alice, spender), value);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ pragma solidity >=0.8.30;

import {stdError} from "forge-std/StdError.sol";
import {Base_Test} from "test/Base.t.sol";
import {ERC20Harness} from "test/harnesses/token/ERC20/ERC20/ERC20Harness.sol";
import {ERC20StorageUtils} from "test/utils/storage/ERC20StorageUtils.sol";
import {ERC20ApproveModHarness} from "test/harnesses/token/ERC20/ERC20ApproveModHarness.sol";

import "src/token/ERC20/ERC20/ERC20Mod.sol";
import "src/token/ERC20/Approve/ERC20ApproveMod.sol";

/**
* @dev BTT spec: test/trees/ERC20.tree
*/
contract Approve_ERC20Mod_Fuzz_Unit_Test is Base_Test {
ERC20Harness internal harness;
contract Approve_ERC20ApproveMod_Fuzz_Unit_Test is Base_Test {
using ERC20StorageUtils for address;

ERC20ApproveModHarness internal harness;

function setUp() public override {
Base_Test.setUp();
harness = new ERC20Harness();
harness = new ERC20ApproveModHarness();
}

function testFuzz_ShouldRevert_SpenderIsZeroAddress(uint256 value) external {
Expand All @@ -35,6 +38,6 @@ contract Approve_ERC20Mod_Fuzz_Unit_Test is Base_Test {
bool result = harness.approve(spender, value);

assertEq(result, true, "approve failed");
assertEq(harness.allowance(users.alice, spender), value);
assertEq(address(harness).allowance(users.alice, spender), value);
}
}
Loading
Loading