diff --git a/test/foundry/portals/ERC1155BatchPortal.t.sol b/test/foundry/portals/ERC1155BatchPortal.t.sol index 4b4c4de1..84bb7011 100644 --- a/test/foundry/portals/ERC1155BatchPortal.t.sol +++ b/test/foundry/portals/ERC1155BatchPortal.t.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.22; import {IERC1155, ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; -import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {ERC1155BatchPortal} from "contracts/portals/ERC1155BatchPortal.sol"; @@ -25,8 +24,6 @@ contract NormalToken is ERC1155 { } } -contract TokenHolder is ERC1155Holder {} - contract ERC1155BatchPortalTest is ERC165Test { address _alice; address _app; @@ -77,17 +74,17 @@ contract ERC1155BatchPortalTest is ERC165Test { vm.mockCall(address(_token), safeBatchTransferFrom, abi.encode()); vm.expectCall(address(_token), safeBatchTransferFrom, 1); - bytes memory payload = _encodePayload( + bytes memory payload = encodePayload( tokenIds, values, baseLayerData, execLayerData ); - bytes memory addInputCall = _encodeAddInput(payload); + bytes memory addInput = _encodeAddInput(payload); - vm.mockCall(address(_inputBox), addInputCall, abi.encode(bytes32(0))); - vm.expectCall(address(_inputBox), addInputCall, 1); + vm.mockCall(address(_inputBox), addInput, abi.encode(bytes32(0))); + vm.expectCall(address(_inputBox), addInput, 1); vm.prank(_alice); _portal.depositBatchERC1155Token( @@ -116,16 +113,16 @@ contract ERC1155BatchPortalTest is ERC165Test { vm.mockCall(address(_token), safeBatchTransferFrom, abi.encode()); vm.mockCallRevert(address(_token), safeBatchTransferFrom, errorData); - bytes memory payload = _encodePayload( + bytes memory payload = encodePayload( tokenIds, values, baseLayerData, execLayerData ); - bytes memory addInputCall = _encodeAddInput(payload); + bytes memory addInput = _encodeAddInput(payload); - vm.mockCall(address(_inputBox), addInputCall, abi.encode(bytes32(0))); + vm.mockCall(address(_inputBox), addInput, abi.encode(bytes32(0))); vm.expectRevert(errorData); @@ -156,27 +153,35 @@ contract ERC1155BatchPortalTest is ERC165Test { } _token = new NormalToken(_alice, tokenIds, supplies); - _app = address(new TokenHolder()); vm.startPrank(_alice); // Allow the portal to withdraw tokens from Alice _token.setApprovalForAll(address(_portal), true); - vm.mockCall( - address(_inputBox), - abi.encodeWithSelector(IInputBox.addInput.selector), - abi.encode(bytes32(0)) + bytes memory payload = this.encodePayload( + tokenIds, + values, + baseLayerData, + execLayerData ); + bytes memory addInput = _encodeAddInput(payload); + + vm.mockCall(address(_inputBox), addInput, abi.encode(bytes32(0))); + // balances before for (uint256 i; i < numOfTokenIds; ++i) { - assertEq(_token.balanceOf(_alice, tokenIds[i]), supplies[i]); - assertEq(_token.balanceOf(_app, tokenIds[i]), 0); - assertEq(_token.balanceOf(address(_portal), tokenIds[i]), 0); + uint256 tokenId = tokenIds[i]; + uint256 supply = supplies[i]; + assertEq(_token.balanceOf(_alice, tokenId), supply); + assertEq(_token.balanceOf(_app, tokenId), 0); + assertEq(_token.balanceOf(address(_portal), tokenId), 0); } - vm.expectEmit(true, true, true, true); + vm.expectCall(address(_inputBox), addInput, 1); + + vm.expectEmit(true, true, true, true, address(_token)); emit IERC1155.TransferBatch( address(_portal), _alice, @@ -197,21 +202,21 @@ contract ERC1155BatchPortalTest is ERC165Test { // balances after for (uint256 i; i < numOfTokenIds; ++i) { - assertEq( - _token.balanceOf(_alice, tokenIds[i]), - supplies[i] - values[i] - ); - assertEq(_token.balanceOf(_app, tokenIds[i]), values[i]); - assertEq(_token.balanceOf(address(_portal), tokenIds[i]), 0); + uint256 tokenId = tokenIds[i]; + uint256 value = values[i]; + uint256 supply = supplies[i]; + assertEq(_token.balanceOf(_alice, tokenId), supply - value); + assertEq(_token.balanceOf(_app, tokenId), value); + assertEq(_token.balanceOf(address(_portal), tokenId), 0); } } - function _encodePayload( + function encodePayload( uint256[] calldata tokenIds, uint256[] calldata values, bytes calldata baseLayerData, bytes calldata execLayerData - ) internal view returns (bytes memory) { + ) public view returns (bytes memory) { return InputEncoding.encodeBatchERC1155Deposit( _token,