Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1300 support approved for all for erc721 tokens for schain #1301

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ contract TokenManagerERC721 is TokenManager, ITokenManagerERC721 {
isMainChainToken = true;
}
require(address(contractOnSchain).isContract(), "No token clone on schain");
require(contractOnSchain.getApproved(tokenId) == address(this), "Not allowed ERC721 Token");
require(
contractOnSchain.getApproved(tokenId) == address(this) ||
contractOnSchain.isApprovedForAll(msg.sender, address(this)),
"Not allowed ERC721 Token"
);
bytes memory data = Messages.encodeTransferErc721Message(contractOnMainChain, to, tokenId);
if (isMainChainToken) {
require(chainHash != MAINNET_HASH, "Main chain token could not be transfered to Mainnet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ contract TokenManagerERC721WithMetadata is TokenManagerERC721 {
isMainChainToken = true;
}
require(address(contractOnSchain).isContract(), "No token clone on schain");
require(contractOnSchain.getApproved(tokenId) == address(this), "Not allowed ERC721 Token");
require(
contractOnSchain.getApproved(tokenId) == address(this) ||
contractOnSchain.isApprovedForAll(msg.sender, address(this)),
"Not allowed ERC721 Token"
);
bytes memory data = Messages.encodeTransferErc721MessageWithMetadata(
contractOnMainChain,
to,
Expand Down
18 changes: 18 additions & 0 deletions proxy/test/TokenManagerERC721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ describe("TokenManagerERC721", () => {
outgoingMessagesCounterMainnet.should.be.deep.equal(BigNumber.from(1));
});

it("should send token if TokenManager was approved for all transfers by user", async () => {
await tokenManagerERC721.connect(schainOwner).addERC721TokenByOwner(mainnetName, token.address, tokenClone.address);
await tokenClone.connect(deployer).mint(user.address, tokenId);
await messageProxyForSchain.registerExtraContract("Mainnet", tokenManagerERC721.address);

await tokenManagerERC721.connect(user).exitToMainERC721(token.address, tokenId)
.should.be.eventually.rejectedWith("Not allowed ERC721 Token");

await tokenClone.connect(user).setApprovalForAll(tokenManagerERC721.address, true);

await tokenManagerERC721.connect(user).exitToMainERC721(token.address, tokenId);

const outgoingMessagesCounterMainnet = BigNumber.from(
await messageProxyForSchain.getOutgoingMessagesCounter("Mainnet")
);
outgoingMessagesCounterMainnet.should.be.deep.equal(BigNumber.from(1));
});

it("should be rejected when call exitToMainERC721 if remove contract for all chains", async () => {
await tokenManagerERC721.connect(schainOwner).addERC721TokenByOwner(mainnetName, token.address, tokenClone.address);
await tokenClone.connect(deployer).mint(user.address, tokenId);
Expand Down
18 changes: 18 additions & 0 deletions proxy/test/TokenManagerERC721WithMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ describe("TokenManagerERC721WithMetadata", () => {
outgoingMessagesCounterMainnet.should.be.deep.equal(BigNumber.from(1));
});

it("should send token if TokenManager was approved for all transfers by user", async () => {
await tokenManagerERC721WithMetadata.connect(schainOwner).addERC721TokenByOwner(mainnetName, token.address, tokenClone.address);
await tokenClone.connect(deployer).mint(user.address, tokenId);
await messageProxyForSchain.registerExtraContract("Mainnet", tokenManagerERC721WithMetadata.address);

await tokenManagerERC721WithMetadata.connect(user).exitToMainERC721(token.address, tokenId)
.should.be.eventually.rejectedWith("Not allowed ERC721 Token");

await tokenClone.connect(user).setApprovalForAll(tokenManagerERC721WithMetadata.address, true);

await tokenManagerERC721WithMetadata.connect(user).exitToMainERC721(token.address, tokenId);

const outgoingMessagesCounterMainnet = BigNumber.from(
await messageProxyForSchain.getOutgoingMessagesCounter("Mainnet")
);
outgoingMessagesCounterMainnet.should.be.deep.equal(BigNumber.from(1));
});

it("should be rejected when call exitToMainERC721 if remove contract for all chains", async () => {
await tokenManagerERC721WithMetadata.connect(schainOwner).addERC721TokenByOwner(mainnetName, token.address, tokenClone.address);
await tokenClone.connect(deployer).mint(user.address, tokenId);
Expand Down