Skip to content

Commit 1238bd3

Browse files
authored
Merge pull request #266 from lumoswiz/test/update-erc20-unit-tests
Update ERC-20 unit tests
2 parents 98bc362 + dc58b97 commit 1238bd3

41 files changed

Lines changed: 271 additions & 243 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/diamond/example/ExampleDiamond.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ contract ExampleDiamond {
4141
/**
4242
* Setting ERC721 token details
4343
*/
44-
ERC721MetadataMod.setMetadata({_name: "ExampleDiamondNFT", _symbol: "EDN", _baseURI: "https://example.com/metadata/"});
44+
ERC721MetadataMod.setMetadata({
45+
_name: "ExampleDiamondNFT", _symbol: "EDN", _baseURI: "https://example.com/metadata/"
46+
});
4547
/**
4648
* Registering ERC165 interfaces
4749
*/

src/token/ERC20/Approve/ERC20ApproveMod.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ function getStorage() pure returns (ERC20Storage storage s) {
5151
* @dev Sets the allowance for the spender.
5252
* @param _spender The address to approve for spending.
5353
* @param _value The amount of tokens to approve.
54+
* @return True if the approval was successful.
5455
*/
55-
function approve(address _spender, uint256 _value) {
56+
function approve(address _spender, uint256 _value) returns (bool) {
5657
if (_spender == address(0)) {
5758
revert ERC20InvalidSpender(address(0));
5859
}
5960
ERC20Storage storage s = getStorage();
6061
s.allowance[msg.sender][_spender] = _value;
6162
emit Approval(msg.sender, _spender, _value);
63+
return true;
6264
}

src/token/ERC20/Transfer/ERC20TransferMod.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ function getStorage() pure returns (ERC20Storage storage s) {
9494
* @param _from The address to send tokens from.
9595
* @param _to The address to send tokens to.
9696
* @param _value The number of tokens to transfer.
97+
* @return True if the transfer was successful.
9798
*/
98-
function transferFrom(address _from, address _to, uint256 _value) {
99+
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
99100
ERC20Storage storage s = getStorage();
100101
if (_from == address(0)) {
101102
revert ERC20InvalidSender(address(0));
@@ -119,15 +120,17 @@ function transferFrom(address _from, address _to, uint256 _value) {
119120
}
120121
s.balanceOf[_to] += _value;
121122
emit Transfer(_from, _to, _value);
123+
return true;
122124
}
123125

124126
/**
125127
* @notice Transfers tokens from the caller to another address.
126128
* @dev Updates balances directly without allowance mechanism.
127129
* @param _to The address to send tokens to.
128130
* @param _value The number of tokens to transfer.
131+
* @return True if the transfer was successful.
129132
*/
130-
function transfer(address _to, uint256 _value) {
133+
function transfer(address _to, uint256 _value) returns (bool) {
131134
ERC20Storage storage s = getStorage();
132135
if (_to == address(0)) {
133136
revert ERC20InvalidReceiver(address(0));
@@ -141,5 +144,6 @@ function transfer(address _to, uint256 _value) {
141144
}
142145
s.balanceOf[_to] += _value;
143146
emit Transfer(msg.sender, _to, _value);
147+
return true;
144148
}
145149

test/Base.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ abstract contract Base_Test is Constants, Modifiers, StdAssertions, StdCheats {
3636
createTestUsers();
3737
defaults.setUsers(users);
3838

39-
setVariables(defaults, users); // set in modifier contract
39+
setVariables(defaults, users);
4040

41-
setMsgSender(users.alice); // alice default caller
41+
setMsgSender(users.alice);
4242
}
4343

4444
/*//////////////////////////////////////////////////////////////

test/harnesses/token/ERC20/ERC20/ERC20Harness.sol

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/harnesses/token/ERC20/ERC20/ERC20MetadataFacetHarness.sol

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.30;
3+
4+
/* Compose
5+
* https://compose.diamonds
6+
*/
7+
8+
import "src/token/ERC20/Approve/ERC20ApproveMod.sol" as ERC20ApproveMod;
9+
10+
/**
11+
* @title ERC20ApproveModHarness
12+
* @notice Test harness that exposes ERC20ApproveMod functions as external
13+
*/
14+
contract ERC20ApproveModHarness {
15+
/**
16+
* @notice Exposes ERC20ApproveMod.approve as an external function
17+
*/
18+
function approve(address _spender, uint256 _value) external returns (bool) {
19+
return ERC20ApproveMod.approve(_spender, _value);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.30;
3+
4+
/* Compose
5+
* https://compose.diamonds
6+
*/
7+
8+
import "src/token/ERC20/Burn/ERC20BurnMod.sol" as ERC20BurnMod;
9+
10+
/**
11+
* @title ERC20BurnModHarness
12+
* @notice Test harness that exposes ERC20BurnMod functions as external
13+
*/
14+
contract ERC20BurnModHarness {
15+
/**
16+
* @notice Exposes ERC20BurnMod.burnERC20 as an external function
17+
*/
18+
function burn(address _account, uint256 _value) external {
19+
ERC20BurnMod.burnERC20(_account, _value);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.30;
3+
4+
/* Compose
5+
* https://compose.diamonds
6+
*/
7+
8+
import "src/token/ERC20/Mint/ERC20MintMod.sol" as ERC20MintMod;
9+
10+
/**
11+
* @title ERC20MintModHarness
12+
* @notice Test harness that exposes ERC20MintMod functions as external
13+
*/
14+
contract ERC20MintModHarness {
15+
/**
16+
* @notice Exposes ERC20Mod.mintERC20 as an external function
17+
*/
18+
function mint(address _account, uint256 _value) external {
19+
ERC20MintMod.mintERC20(_account, _value);
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.30;
3+
4+
/* Compose
5+
* https://compose.diamonds
6+
*/
7+
8+
import "src/token/ERC20/Transfer/ERC20TransferMod.sol" as ERC20TransferMod;
9+
10+
/**
11+
* @title ERC20TransferModHarness
12+
* @notice Test harness that exposes ERC20TransferMod functions as external
13+
*/
14+
contract ERC20TransferModHarness {
15+
/**
16+
* @notice Exposes ERC20TransferMod.transferFrom as an external function
17+
*/
18+
function transferFrom(address _from, address _to, uint256 _value) external returns (bool) {
19+
return ERC20TransferMod.transferFrom(_from, _to, _value);
20+
}
21+
22+
/**
23+
* @notice Exposes ERC20TransferMod.transfer as an external function
24+
*/
25+
function transfer(address _to, uint256 _value) external returns (bool) {
26+
return ERC20TransferMod.transfer(_to, _value);
27+
}
28+
}

0 commit comments

Comments
 (0)