-
Hi, everyone. I am testing a ERC-721 Contract Mint Function. But after calling the minting function in the contract, I get the error "transfer to non ERC721Receiver implementer" .
I get the error:
|
Beta Was this translation helpful? Give feedback.
Answered by
ChiHaoLu
Mar 17, 2022
Replies: 1 comment
-
I solved it: need to implement the _checkOnERC721Received in the test contract: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "ds-test/test.sol";
import '../Contract.sol';
contract CarManTest is DSTest {
CarMan carman;
address DEPLOYER_ADDRESS;
address[] temp;
// The state of the contract gets reset before each
// test is run, with the `setUp()` function being called
// each time after deployment. Think of this like a JavaScript
// `beforeEach` block
function setUp() public {
carman = new CarMan("CarMan_Metaverse", "CMM", "ipfs://QmYvJEw4LHBpaehH6mYZV9YXC372QSWL4BPFVJvUkKqRCg/", "ipfs://.../");
DEPLOYER_ADDRESS = carman.owner();
}
function onERC721Received(
address,
address,
uint256,
bytes calldata
)external pure returns(bytes4) {
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
/*
_checkOnERC721Received has the verification logic. If to address is a contract,
then the contract should implement onERC721Received interface of ERC-721 and return correct 4 bytes hash to receive ERC-721 token as below.
*/
function testDeployerCanMint() public {
carman.addController(DEPLOYER_ADDRESS); // deployer can addController
carman.whitelistUsers(temp);
carman.setPreSalePause(false); // deployer/controller can setPreSalePause
assertEq(carman.totalSupply(), 0); // nothing minted before
carman.preSaleMint(1);
assertEq(carman.totalSupply(), 1);
}
// function testWithdraw() public {
// payable(address(safe)).transfer(1 ether);
// uint256 preBalance = address(this).balance;
// safe.withdraw();
// uint256 postBalance = address(this).balance;
// assertEq(preBalance + 1 ether, postBalance);
// }
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
onbjerg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I solved it: need to implement the _checkOnERC721Received in the test contract: