Skip to content

Commit 956d663

Browse files
frangiocagnventuroKaiRo-at
authored
ERC1155 feature pending tasks (#2014)
* Initial ERC1155 implementation with some tests (#1803) * Initial ERC1155 implementation with some tests * Remove mocked isERC1155TokenReceiver * Revert reason edit nit * Remove parameters associated with isERC1155TokenReceiver call * Add tests for approvals and single transfers * Add tests for transferring to contracts * Add tests for batch transfers * Make expectEvent.inTransaction tests async * Renamed "owner" to "account" and "holder" * Document unspecified balanceOfBatch reversion on zero behavior * Ensure accounts can't set their own operator status * Specify descriptive messages for underflow errors * Bring SafeMath.add calls in line with OZ style * Explicitly prevent _burn on the zero account * Implement batch minting/burning * Refactored operator approval check into isApprovedForAll calls * Renamed ERC1155TokenReceiver to ERC1155Receiver * Added ERC1155Holder * Fix lint issues * Migrate tests to @openzeppelin/test-environment * Port ERC 1155 branch to Solidity 0.6 (and current master) (#2130) * port ERC1155 to Solidity 0.6 * make ERC1155 constructor more similar to ERC721 one * also migrate mock contracts to Solidity 0.6 * mark all non-view functions as virtual Co-authored-by: Alan Lu <[email protected]> Co-authored-by: Nicolás Venturo <[email protected]> Co-authored-by: Robert Kaiser <[email protected]>
1 parent 0c7b2ec commit 956d663

12 files changed

+1508
-0
lines changed

contracts/mocks/ERC1155Mock.sol

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
pragma solidity ^0.6.0;
2+
3+
import "../token/ERC1155/ERC1155.sol";
4+
5+
/**
6+
* @title ERC1155Mock
7+
* This mock just publicizes internal functions for testing purposes
8+
*/
9+
contract ERC1155Mock is ERC1155 {
10+
function mint(address to, uint256 id, uint256 value, bytes memory data) public {
11+
_mint(to, id, value, data);
12+
}
13+
14+
function mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) public {
15+
_mintBatch(to, ids, values, data);
16+
}
17+
18+
function burn(address owner, uint256 id, uint256 value) public {
19+
_burn(owner, id, value);
20+
}
21+
22+
function burnBatch(address owner, uint256[] memory ids, uint256[] memory values) public {
23+
_burnBatch(owner, ids, values);
24+
}
25+
26+
function doSafeTransferAcceptanceCheck(address operator, address from, address to, uint256 id, uint256 value, bytes memory data) public {
27+
_doSafeTransferAcceptanceCheck(operator, from, to, id, value, data);
28+
}
29+
30+
function doSafeBatchTransferAcceptanceCheck(address operator, address from, address to, uint256[] memory ids, uint256[] memory values, bytes memory data) public {
31+
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data);
32+
}
33+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
pragma solidity ^0.6.0;
2+
3+
import "../token/ERC1155/IERC1155Receiver.sol";
4+
import "./ERC165Mock.sol";
5+
6+
contract ERC1155ReceiverMock is IERC1155Receiver, ERC165Mock {
7+
bytes4 private _recRetval;
8+
bool private _recReverts;
9+
bytes4 private _batRetval;
10+
bool private _batReverts;
11+
12+
event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas);
13+
event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas);
14+
15+
constructor (
16+
bytes4 recRetval,
17+
bool recReverts,
18+
bytes4 batRetval,
19+
bool batReverts
20+
)
21+
public
22+
{
23+
_recRetval = recRetval;
24+
_recReverts = recReverts;
25+
_batRetval = batRetval;
26+
_batReverts = batReverts;
27+
}
28+
29+
function onERC1155Received(
30+
address operator,
31+
address from,
32+
uint256 id,
33+
uint256 value,
34+
bytes calldata data
35+
)
36+
external
37+
override
38+
returns(bytes4)
39+
{
40+
require(!_recReverts, "ERC1155ReceiverMock: reverting on receive");
41+
emit Received(operator, from, id, value, data, gasleft());
42+
return _recRetval;
43+
}
44+
45+
function onERC1155BatchReceived(
46+
address operator,
47+
address from,
48+
uint256[] calldata ids,
49+
uint256[] calldata values,
50+
bytes calldata data
51+
)
52+
external
53+
override
54+
returns(bytes4)
55+
{
56+
require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive");
57+
emit BatchReceived(operator, from, ids, values, data, gasleft());
58+
return _batRetval;
59+
}
60+
}

0 commit comments

Comments
 (0)