* 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 <alanlu1023@gmail.com> Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com> Co-authored-by: Robert Kaiser <kairo@kairo.at>
61 lines
1.6 KiB
Solidity
61 lines
1.6 KiB
Solidity
pragma solidity ^0.6.0;
|
|
|
|
import "../token/ERC1155/IERC1155Receiver.sol";
|
|
import "./ERC165Mock.sol";
|
|
|
|
contract ERC1155ReceiverMock is IERC1155Receiver, ERC165Mock {
|
|
bytes4 private _recRetval;
|
|
bool private _recReverts;
|
|
bytes4 private _batRetval;
|
|
bool private _batReverts;
|
|
|
|
event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas);
|
|
event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas);
|
|
|
|
constructor (
|
|
bytes4 recRetval,
|
|
bool recReverts,
|
|
bytes4 batRetval,
|
|
bool batReverts
|
|
)
|
|
public
|
|
{
|
|
_recRetval = recRetval;
|
|
_recReverts = recReverts;
|
|
_batRetval = batRetval;
|
|
_batReverts = batReverts;
|
|
}
|
|
|
|
function onERC1155Received(
|
|
address operator,
|
|
address from,
|
|
uint256 id,
|
|
uint256 value,
|
|
bytes calldata data
|
|
)
|
|
external
|
|
override
|
|
returns(bytes4)
|
|
{
|
|
require(!_recReverts, "ERC1155ReceiverMock: reverting on receive");
|
|
emit Received(operator, from, id, value, data, gasleft());
|
|
return _recRetval;
|
|
}
|
|
|
|
function onERC1155BatchReceived(
|
|
address operator,
|
|
address from,
|
|
uint256[] calldata ids,
|
|
uint256[] calldata values,
|
|
bytes calldata data
|
|
)
|
|
external
|
|
override
|
|
returns(bytes4)
|
|
{
|
|
require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive");
|
|
emit BatchReceived(operator, from, ids, values, data, gasleft());
|
|
return _batRetval;
|
|
}
|
|
}
|