Skip to content

Commit

Permalink
Adds tests for granular token holder.
Browse files Browse the repository at this point in the history
  • Loading branch information
steven2308 committed Sep 25, 2023
1 parent e27e0be commit fffdf58
Show file tree
Hide file tree
Showing 14 changed files with 1,007 additions and 97 deletions.
13 changes: 5 additions & 8 deletions contracts/RMRK/extension/tokenHolder/ERC1155Holder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
pragma solidity ^0.8.18;

import "./IERC1155Holder.sol";
import "./HolderErrors.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

error InvalidValueForERC1155();
error InvalidAddressForERC1155();
error InsufficientBalance();

abstract contract ERC1155Holder is IERC1155Holder {
mapping(uint256 tokenHolderId => mapping(address erc1155Address => mapping(uint256 tokenHeldId => uint256 balance)))
private _balances;
Expand Down Expand Up @@ -43,10 +40,10 @@ abstract contract ERC1155Holder is IERC1155Holder {
bytes memory data
) internal {
if (amount == 0) {
revert InvalidValueForERC1155();
revert InvalidValue();
}
if (to == address(0) || erc1155Contract == address(0)) {
revert InvalidAddressForERC1155();
revert InvalidAddress();
}
if (
_balances[tokenHolderId][erc1155Contract][tokenToTransferId] <
Expand Down Expand Up @@ -100,10 +97,10 @@ abstract contract ERC1155Holder is IERC1155Holder {
bytes memory data
) external {
if (amount == 0) {
revert InvalidValueForERC1155();
revert InvalidValue();
}
if (erc1155Contract == address(0)) {
revert InvalidAddressForERC1155();
revert InvalidAddress();
}
_beforeTransferERC1155ToToken(
erc1155Contract,
Expand Down
15 changes: 6 additions & 9 deletions contracts/RMRK/extension/tokenHolder/ERC20Holder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
pragma solidity ^0.8.18;

import "./IERC20Holder.sol";
import "./HolderErrors.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

error InvalidValueForERC20();
error InvalidAddressForERC20();
error InsufficientBalanceForERC20();

abstract contract ERC20Holder is IERC20Holder {
mapping(uint256 tokenId => mapping(address erc20Address => uint256 balance))
private _balances;
Expand Down Expand Up @@ -40,13 +37,13 @@ abstract contract ERC20Holder is IERC20Holder {
bytes memory data
) internal {
if (amount == 0) {
revert InvalidValueForERC20();
revert InvalidValue();
}
if (to == address(0) || erc20Contract == address(0)) {
revert InvalidAddressForERC20();
revert InvalidAddress();
}
if (_balances[tokenId][erc20Contract] < amount) {
revert InsufficientBalanceForERC20();
revert InsufficientBalance();
}
_beforeTransferHeldERC20FromToken(
erc20Contract,
Expand Down Expand Up @@ -79,10 +76,10 @@ abstract contract ERC20Holder is IERC20Holder {
bytes memory data
) external {
if (amount == 0) {
revert InvalidValueForERC20();
revert InvalidValue();
}
if (erc20Contract == address(0)) {
revert InvalidAddressForERC20();
revert InvalidAddress();
}
_beforeTransferERC20ToToken(
erc20Contract,
Expand Down
10 changes: 4 additions & 6 deletions contracts/RMRK/extension/tokenHolder/ERC721Holder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
pragma solidity ^0.8.18;

import "./IERC721Holder.sol";
import "./HolderErrors.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

error InvalidAddressForERC721();
error TokenNotHeldForERC721();

abstract contract ERC721Holder is IERC721Holder {
mapping(uint256 tokenHolderId => mapping(address erc721Address => mapping(uint256 tokenHeldId => uint256 balance)))
private _balances;
Expand Down Expand Up @@ -40,10 +38,10 @@ abstract contract ERC721Holder is IERC721Holder {
bytes memory data
) internal {
if (to == address(0) || erc721Contract == address(0)) {
revert InvalidAddressForERC721();
revert InvalidAddress();
}
if (_balances[tokenHolderId][erc721Contract][tokenToTransferId] == 0) {
revert TokenNotHeldForERC721();
revert TokenNotHeld();
}
_beforeTransferHeldERC721FromToken(
erc721Contract,
Expand Down Expand Up @@ -86,7 +84,7 @@ abstract contract ERC721Holder is IERC721Holder {
bytes memory data
) external {
if (erc721Contract == address(0)) {
revert InvalidAddressForERC721();
revert InvalidAddress();
}
_beforeTransferERC721ToToken(
erc721Contract,
Expand Down
8 changes: 8 additions & 0 deletions contracts/RMRK/extension/tokenHolder/HolderErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.21;

error InvalidValue();
error InvalidAddress();
error InsufficientBalance();
error TokenNotHeld();
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ contract RMRKUniversalHolderMock is
string memory symbol
) ERC721(name, symbol) {}

function mint(address to, uint256 tokenId) public {
_mint(to, tokenId);
}

function supportsInterface(
bytes4 interfaceId
)
Expand Down
8 changes: 4 additions & 4 deletions docs/RMRK/extension/tokenHolder/ERC1155Holder.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,21 @@ Used to notify the listeners that the ERC-1155 tokens have been transferred.

## Errors

### InvalidAddressForERC1155
### InvalidAddress

```solidity
error InvalidAddressForERC1155()
error InvalidAddress()
```






### InvalidValueForERC1155
### InvalidValue

```solidity
error InvalidValueForERC1155()
error InvalidValue()
```


Expand Down
8 changes: 4 additions & 4 deletions docs/RMRK/extension/tokenHolder/ERC20Holder.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ Used to notify the listeners that the ERC-20 tokens have been transferred.

## Errors

### InvalidAddressForERC20
### InvalidAddress

```solidity
error InvalidAddressForERC20()
error InvalidAddress()
```






### InvalidValueForERC20
### InvalidValue

```solidity
error InvalidValueForERC20()
error InvalidValue()
```


Expand Down
4 changes: 2 additions & 2 deletions docs/RMRK/extension/tokenHolder/ERC721Holder.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ Used to notify the listeners that the ERC-721 tokens have been transferred.

## Errors

### InvalidAddressForERC721
### InvalidAddress

```solidity
error InvalidAddressForERC721()
error InvalidAddress()
```


Expand Down
8 changes: 4 additions & 4 deletions docs/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,21 +487,21 @@ error InsufficientBalance()



### InvalidAddressForERC1155
### InvalidAddress

```solidity
error InvalidAddressForERC1155()
error InvalidAddress()
```






### InvalidValueForERC1155
### InvalidValue

```solidity
error InvalidValueForERC1155()
error InvalidValue()
```


Expand Down
12 changes: 6 additions & 6 deletions docs/mocks/extensions/tokenHolder/RMRKERC20HolderMock.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,32 +445,32 @@ Used to notify the listeners that the ERC-20 tokens have been transferred.

## Errors

### InsufficientBalanceForERC20
### InsufficientBalance

```solidity
error InsufficientBalanceForERC20()
error InsufficientBalance()
```






### InvalidAddressForERC20
### InvalidAddress

```solidity
error InvalidAddressForERC20()
error InvalidAddress()
```






### InvalidValueForERC20
### InvalidValue

```solidity
error InvalidValueForERC20()
error InvalidValue()
```


Expand Down
8 changes: 4 additions & 4 deletions docs/mocks/extensions/tokenHolder/RMRKERC721HolderMock.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ Used to notify the listeners that the ERC-721 tokens have been transferred.

## Errors

### InvalidAddressForERC721
### InvalidAddress

```solidity
error InvalidAddressForERC721()
error InvalidAddress()
```


Expand All @@ -493,10 +493,10 @@ error OnlyNFTOwnerCanTransferTokensFromIt()



### TokenNotHeldForERC721
### TokenNotHeld

```solidity
error TokenNotHeldForERC721()
error TokenNotHeld()
```


Expand Down
Loading

0 comments on commit fffdf58

Please sign in to comment.