onERC721Received must be called by the NFT only
This commit is contained in:
parent
f3a07496fa
commit
8e7ab9ebc9
|
@ -148,6 +148,7 @@ contract NFTBucket is IERC165, IERC721Receiver {
|
|||
}
|
||||
|
||||
function onERC721Received(address _operator, address _from, uint256 _tokenID, bytes calldata _data) external override(IERC721Receiver) returns(bytes4) {
|
||||
require(msg.sender == address(tokenContract), "only the NFT contract can call this");
|
||||
require((_operator == owner) || (_from == owner), "only the owner can create gifts");
|
||||
require(_data.length == 52, "invalid data field");
|
||||
|
||||
|
|
|
@ -197,6 +197,16 @@ contract("NFTBucket", function () {
|
|||
|
||||
});
|
||||
|
||||
it("cannot create two gifts for the same token", async function() {
|
||||
try {
|
||||
await NFTBucket.methods.onERC721Received(shop, shop, 0xcafe, createGiftData(keycard_3)).send({from: shop});
|
||||
assert.fail("transfer should have failed");
|
||||
} catch(e) {
|
||||
assert.match(e.message, /only the NFT/);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
async function testRedeem(receiver, recipient, signer, relayer, redeemCode, blockNumber, blockHash) {
|
||||
let gift = await NFTBucket.methods.gifts(recipient).call();
|
||||
const tokenID = gift.tokenID;
|
||||
|
|
Loading…
Reference in New Issue