Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sxcamacho committed Sep 28, 2023
1 parent cbabbd8 commit a38bd8e
Show file tree
Hide file tree
Showing 3 changed files with 592 additions and 328 deletions.
59 changes: 59 additions & 0 deletions packages/faucets/contracts/FaucetsERC1155.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ event Withdrawn(address indexed faucet, address indexed receiver, uint256[] toke
modifier exists(address faucet)
```

Modifier to check if the faucet exists.


Parameters:

| Name | Type | Description |
| :----- | :------ | :------------------------- |
| faucet | address | The address of the faucet. |

## Functions info

Expand Down Expand Up @@ -183,6 +191,40 @@ Parameters:
| faucet | address | The address of the faucet. |
| newLimit | uint256 | The new maximum amount of tokens a user can claim at once. |

### faucetExists (0x860ddec0)

```solidity
function faucetExists(address faucet) public view returns (bool)
```

External function to check the existence of a given faucet.


Parameters:

| Name | Type | Description |
| :----- | :------ | :------------------------- |
| faucet | address | The address of the faucet. |

### tokenExistsInFaucet (0xab9a7f86)

```solidity
function tokenExistsInFaucet(
address faucet,
uint256 tokenId
) public view exists(faucet) returns (bool)
```

External function to check the existence of a given faucet and token.


Parameters:

| Name | Type | Description |
| :------ | :------ | :-------------------------- |
| faucet | address | The address of the faucet. |
| tokenId | uint256 | The id of the token. |

### addFaucet (0xe2337fa8)

```solidity
Expand Down Expand Up @@ -253,6 +295,23 @@ Parameters:
| :----- | :------ | :------------------------------------ |
| faucet | address | Address of the faucet to be disabled. |

### isFaucetEnabled (0xfc490550)

```solidity
function isFaucetEnabled(
address faucet
) public view exists(faucet) returns (bool)
```

Determines whether a faucet is enabled.


Parameters:

| Name | Type | Description |
| :----- | :------ | :--------------------- |
| faucet | address | Address of the faucet. |

### removeTokens (0xecae5383)

```solidity
Expand Down
44 changes: 41 additions & 3 deletions packages/faucets/contracts/FaucetsERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,40 @@ contract FaucetsERC1155 is Ownable, ERC1155Holder, ReentrancyGuard {
emit LimitUpdated(faucet, newLimit);
}

// Modifier to check if the faucet exists.
/**
* @dev Internal function to check the existence of a given faucet.
* @param faucet The address of the faucet.
*/
function _exists(address faucet) internal view returns (bool) {
return faucets[faucet].isFaucet;
}

/**
* @dev External function to check the existence of a given faucet.
* @param faucet The address of the faucet.
*/
function faucetExists(address faucet) public view returns (bool) {
return _exists(faucet);
}

/**
* @dev Modifier to check if the faucet exists.
* @param faucet The address of the faucet.
*/
modifier exists(address faucet) {
require(faucets[faucet].isFaucet, "Faucets: FAUCET_DOES_NOT_EXIST");
require(_exists(faucet), "Faucets: FAUCET_DOES_NOT_EXIST");
_;
}

/**
* @dev External function to check the existence of a given faucet and token.
* @param faucet The address of the faucet.
* @param tokenId The id of the token.
*/
function tokenExistsInFaucet(address faucet, uint256 tokenId) public view exists(faucet) returns (bool) {
return faucets[faucet].tokenIdExists[tokenId];
}

/**
* @dev Add a new faucet to the system.
* @param faucet The address of the ERC1155 token contract to be used as faucet.
Expand All @@ -102,7 +130,7 @@ contract FaucetsERC1155 is Ownable, ERC1155Holder, ReentrancyGuard {
* @param tokenIds List of token IDs that this faucet will distribute.
*/
function addFaucet(address faucet, uint256 period, uint256 limit, uint256[] memory tokenIds) public onlyOwner {
require(!faucets[faucet].isFaucet, "Faucets: FAUCET_ALREADY_EXISTS");
require(!_exists(faucet), "Faucets: FAUCET_ALREADY_EXISTS");
require(limit > 0, "Faucets: LIMIT_ZERO");
require(tokenIds.length > 0, "Faucets: TOKENS_CANNOT_BE_EMPTY");

Expand Down Expand Up @@ -155,6 +183,15 @@ contract FaucetsERC1155 is Ownable, ERC1155Holder, ReentrancyGuard {
emit FaucetStatusChanged(faucet, false);
}

/**
* @dev Determines whether a faucet is enabled.
* @param faucet Address of the faucet.
*/
function isFaucetEnabled(address faucet) public view exists(faucet) returns (bool) {
FaucetInfo storage faucetInfo = faucets[faucet];
return faucetInfo.isEnabled;
}

/**
* @dev Remove specific tokens from a faucet.
* @param faucet Address of the faucet.
Expand All @@ -173,6 +210,7 @@ contract FaucetsERC1155 is Ownable, ERC1155Holder, ReentrancyGuard {
bool shouldSkip = false;
for (uint256 j = 0; j < tokenIds.length; j++) {
if (currentTokenIds[i] == tokenIds[j]) {
faucetInfo.tokenIdExists[currentTokenIds[i]] = false;
shouldSkip = true;
break;
}
Expand Down
Loading

1 comment on commit a38bd8e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/faucets/contracts
   FaucetsERC1155.sol84.80%66.30%100%100%121, 132–135, 145, 157, 168, 179, 190, 200, 200, 200, 253, 263, 263, 265–266, 290–291, 298, 304, 327, 327, 349, 57, 66, 76, 85, 85–86

Please sign in to comment.