diff --git a/proxy/contracts/mainnet/DepositBoxes/DepositBoxERC721.sol b/proxy/contracts/mainnet/DepositBoxes/DepositBoxERC721.sol index b6674f9ad..d9ea0cfe9 100644 --- a/proxy/contracts/mainnet/DepositBoxes/DepositBoxERC721.sol +++ b/proxy/contracts/mainnet/DepositBoxes/DepositBoxERC721.sol @@ -80,7 +80,8 @@ contract DepositBoxERC721 is DepositBox, IDepositBoxERC721 { address contractReceiver = schainLinks[schainHash]; require(contractReceiver != address(0), "Unconnected chain"); require( - IERC721Upgradeable(erc721OnMainnet).getApproved(tokenId) == address(this), + IERC721Upgradeable(erc721OnMainnet).getApproved(tokenId) == address(this) || + IERC721Upgradeable(erc721OnMainnet).isApprovedForAll(msg.sender, address(this)), "DepositBox was not approved for ERC721 token" ); bytes memory data = _receiveERC721( diff --git a/proxy/test/DepositBoxERC721.ts b/proxy/test/DepositBoxERC721.ts index 9088cb31d..8d6901cf7 100644 --- a/proxy/test/DepositBoxERC721.ts +++ b/proxy/test/DepositBoxERC721.ts @@ -155,7 +155,6 @@ describe("DepositBoxERC721", () => { // preparation const error = "DepositBox was not approved for ERC721 token"; const contractHere = erc721OnChain.address; - const to = user.address; const tokenId = 10; // the wei should be MORE than (55000 * 1000000000) // GAS_AMOUNT_POST_MESSAGE * AVERAGE_TX_PRICE constants in DepositBox.sol @@ -172,6 +171,32 @@ describe("DepositBoxERC721", () => { .should.be.eventually.rejectedWith(error); }); + it("should send token if DepositBox was approved for all transfers by user", async () => { + // preparation + const contractHere = erc721OnChain.address; + const tokenId = 10; + // the wei should be MORE than (55000 * 1000000000) + // GAS_AMOUNT_POST_MESSAGE * AVERAGE_TX_PRICE constants in DepositBox.sol + // add schain to avoid the `Unconnected chain` error + await linker + .connect(deployer) + .connectSchain(schainName, [deployer.address, deployer.address, deployer.address]); + await depositBoxERC721.connect(user).disableWhitelist(schainName); + + await depositBoxERC721 + .connect(deployer) + .depositERC721(schainName, contractHere, tokenId) + .should.be.eventually.rejectedWith("DepositBox was not approved for ERC721 token"); + + await erc721OnChain.connect(deployer).setApprovalForAll(depositBoxERC721.address, true); + await depositBoxERC721 + .connect(deployer) + .depositERC721(schainName, contractHere, tokenId); + // console.log("Gas for depositERC721:", res.receipt.gasUsed); + // expectation + expect(await erc721OnChain.ownerOf(tokenId)).to.equal(depositBoxERC721.address); + }); + it("should invoke `depositERC721` without mistakes", async () => { // preparation const contractHere = erc721OnChain.address;