Skip to content

Commit 118b483

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
Add tests for when contract is not approved to transfer tokens
1 parent 817907d commit 118b483

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/test/Multiwrap.t.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,45 @@ contract MultiwrapTest is BaseTest {
274274
multiwrap.wrap(wrappedContent, uriForWrappedToken, recipient);
275275
}
276276

277+
/**
278+
* note: Testing revert condition; token owner calls `wrap` to wrap un-owned ERC20 tokens.
279+
*/
280+
function test_revert_wrap_notApprovedTransfer_ERC20() public {
281+
tokenOwner.setAllowanceERC20(address(erc20), address(multiwrap), 0);
282+
283+
address recipient = address(0x123);
284+
285+
vm.prank(address(tokenOwner));
286+
vm.expectRevert("ERC20: insufficient allowance");
287+
multiwrap.wrap(wrappedContent, uriForWrappedToken, recipient);
288+
}
289+
290+
/**
291+
* note: Testing revert condition; token owner calls `wrap` to wrap un-owned ERC721 tokens.
292+
*/
293+
function test_revert_wrap_notApprovedTransfer_ERC721() public {
294+
tokenOwner.setApprovalForAllERC721(address(erc721), address(multiwrap), false);
295+
296+
address recipient = address(0x123);
297+
298+
vm.prank(address(tokenOwner));
299+
vm.expectRevert("ERC721: transfer caller is not owner nor approved");
300+
multiwrap.wrap(wrappedContent, uriForWrappedToken, recipient);
301+
}
302+
303+
/**
304+
* note: Testing revert condition; token owner calls `wrap` to wrap un-owned ERC1155 tokens.
305+
*/
306+
function test_revert_wrap_notApprovedTransfer_ERC1155() public {
307+
tokenOwner.setApprovalForAllERC1155(address(erc1155), address(multiwrap), false);
308+
309+
address recipient = address(0x123);
310+
311+
vm.prank(address(tokenOwner));
312+
vm.expectRevert("ERC1155: caller is not owner nor approved");
313+
multiwrap.wrap(wrappedContent, uriForWrappedToken, recipient);
314+
}
315+
277316
function test_revert_wrap_noTokensToWrap() public {
278317
ITokenBundle.Token[] memory emptyContent;
279318

0 commit comments

Comments
 (0)