diff --git a/test/abstract/FlowERC1155Test.sol b/test/abstract/FlowERC1155Test.sol index a6a4b7b5..807691a1 100644 --- a/test/abstract/FlowERC1155Test.sol +++ b/test/abstract/FlowERC1155Test.sol @@ -23,7 +23,7 @@ abstract contract FlowERC1155Test is FlowTest { internal returns (IFlowERC1155V5 flowErc1155, EvaluableV2 memory evaluable) { - (flowErc1155, evaluable) = deployIFlowERC1155V5(address(0), uri); + (flowErc1155, evaluable) = deployIFlowERC1155V5(address(uint160(uint256(keccak256("expression")))), uri); } function deployIFlowERC1155V5(address expression, string memory uri) @@ -33,8 +33,9 @@ abstract contract FlowERC1155Test is FlowTest { address[] memory expressions = new address[](1); expressions[0] = expression; uint256[] memory constants = new uint256[](0); - (IFlowERC1155V5 flowErc1155, EvaluableV2[] memory evaluables) = - deployIFlowERC1155V5(expressions, address(1), constants.matrixFrom(), uri); + (IFlowERC1155V5 flowErc1155, EvaluableV2[] memory evaluables) = deployIFlowERC1155V5( + expressions, address(uint160(uint256(keccak256("configExpression")))), constants.matrixFrom(), uri + ); return (flowErc1155, evaluables[0]); } diff --git a/test/concrete/flowErc1155/Erc1155FlowTest.sol b/test/concrete/flowErc1155/Erc1155FlowTest.sol index 4456fe61..80f89395 100644 --- a/test/concrete/flowErc1155/Erc1155FlowTest.sol +++ b/test/concrete/flowErc1155/Erc1155FlowTest.sol @@ -36,8 +36,83 @@ contract Erc1155FlowTest is FlowERC1155Test { using LibEvaluable for EvaluableV2; using SignContextLib for Vm; using LibUint256Matrix for uint256[]; + using LibUint256Array for uint256[]; using Address for address; + /** + * @notice Tests the support for the transferPreflight hook. + */ + /// forge-config: default.fuzz.runs = 100 + function testFlowERC1155SupportsTransferPreflightHook(address alice, uint128 amount, uint256 id) external { + vm.assume(alice != address(0)); + vm.assume(amount != 0); + + (IFlowERC1155V5 flow, EvaluableV2 memory evaluable) = deployIFlowERC1155V5("https://www.rainprotocol.xyz/nft/"); + assumeEtchable(alice, address(flow)); + + // Mint tokens to Alice + { + (uint256[] memory stack,) = mintFlowStack(alice, amount, id, transferEmpty()); + interpreterEval2MockCall(stack, new uint256[](0)); + } + + uint256[] memory ids = new uint256[](1); + ids[0] = id; + + uint256[] memory amounts = new uint256[](1); + amounts[0] = amount; + + uint256[][] memory context = LibContextWrapper.buildAndSetContext( + LibUint256Matrix.matrixFrom( + LibUint256Array.arrayFrom( + uint256(uint160(alice)), uint256(uint160(alice)), uint256(uint160(address(flow))) + ), + ids, + amounts + ), + new SignedContextV1[](0), + address(alice), + address(flow) + ); + + { + interpreterEval2ExpectCall( + address(flow), + LibEncodedDispatch.encode2( + address(uint160(uint256(keccak256("configExpression")))), + FLOW_ERC1155_HANDLE_TRANSFER_ENTRYPOINT, + FLOW_ERC1155_HANDLE_TRANSFER_MAX_OUTPUTS + ), + context + ); + + flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0)); + + vm.startPrank(alice); + IERC1155(address(flow)).safeTransferFrom(alice, address(flow), id, amount, ""); + vm.stopPrank(); + } + + { + interpreterEval2RevertCall( + address(flow), + LibEncodedDispatch.encode2( + address(uint160(uint256(keccak256("configExpression")))), + FLOW_ERC1155_HANDLE_TRANSFER_ENTRYPOINT, + FLOW_ERC1155_HANDLE_TRANSFER_MAX_OUTPUTS + ), + context + ); + + flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0)); + + vm.expectRevert("REVERT_EVAL2_CALL"); + vm.startPrank(alice); + IERC1155(address(flow)).safeTransferFrom(alice, address(flow), id, amount, ""); + vm.stopPrank(); + } + } + /// Tests the flow between ERC721 and ERC1155 on the good path. /// forge-config: default.fuzz.runs = 100 function testFlowERC1155FlowERC721ToERC1155( @@ -171,7 +246,7 @@ contract Erc1155FlowTest is FlowERC1155Test { mints[0] = ERC1155SupplyChange({account: alice, id: erc721InTokenId, amount: amount}); ERC1155SupplyChange[] memory burns = new ERC1155SupplyChange[](1); - burns[0] = ERC1155SupplyChange({account: alice, id: erc721InTokenId, amount: 0 ether}); + burns[0] = ERC1155SupplyChange({account: alice, id: erc721InTokenId, amount: amount}); uint256[] memory stack = generateFlowStack( FlowERC1155IOV1( diff --git a/test/concrete/flowErc20/Erc20FlowTest.sol b/test/concrete/flowErc20/Erc20FlowTest.sol index 5c97a0b3..7e25a2a6 100644 --- a/test/concrete/flowErc20/Erc20FlowTest.sol +++ b/test/concrete/flowErc20/Erc20FlowTest.sol @@ -39,37 +39,14 @@ contract Erc20FlowTest is FlowERC20Test { * @notice Tests the support for the transferPreflight hook. */ /// forge-config: default.fuzz.runs = 100 - function testFlowERC20SupportsTransferPreflightHook( - address alice, - uint128 amount, - address expressionA, - address expressionB - ) external { + function testFlowERC20SupportsTransferPreflightHook(address alice, uint128 amount) external { vm.assume(alice != address(0)); - vm.assume(sentinel != amount); - vm.assume(expressionA != expressionB); - - address[] memory expressions = new address[](1); - expressions[0] = expressionA; - (IFlowERC20V5 flow, EvaluableV2[] memory evaluables) = - deployFlowERC20(expressions, expressionB, new uint256[][](1), "Flow ERC20", "F20"); + (IFlowERC20V5 flow, EvaluableV2 memory evaluable) = deployFlowERC20("Flow ERC20", "F20"); assumeEtchable(alice, address(flow)); { - ERC20SupplyChange[] memory mints = new ERC20SupplyChange[](1); - mints[0] = ERC20SupplyChange({account: alice, amount: amount}); - - ERC20SupplyChange[] memory burns = new ERC20SupplyChange[](1); - burns[0] = ERC20SupplyChange({account: alice, amount: 0 ether}); - - uint256[] memory stack = generateFlowStack( - FlowERC20IOV1( - mints, - burns, - FlowTransferV1(new ERC20Transfer[](0), new ERC721Transfer[](0), new ERC1155Transfer[](0)) - ) - ); + (uint256[] memory stack,) = mintFlowStack(alice, amount, 0, transferEmpty()); interpreterEval2MockCall(stack, new uint256[](0)); } @@ -85,12 +62,14 @@ contract Erc20FlowTest is FlowERC20Test { interpreterEval2ExpectCall( address(flow), LibEncodedDispatch.encode2( - expressionB, FLOW_ERC20_HANDLE_TRANSFER_ENTRYPOINT, FLOW_ERC20_HANDLE_TRANSFER_MAX_OUTPUTS + address(uint160(uint256(keccak256("configExpression")))), + FLOW_ERC20_HANDLE_TRANSFER_ENTRYPOINT, + FLOW_ERC20_HANDLE_TRANSFER_MAX_OUTPUTS ), context ); - flow.flow(evaluables[0], new uint256[](0), new SignedContextV1[](0)); + flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0)); vm.startPrank(alice); IERC20(address(flow)).transfer(address(flow), amount); @@ -101,12 +80,14 @@ contract Erc20FlowTest is FlowERC20Test { interpreterEval2RevertCall( address(flow), LibEncodedDispatch.encode2( - expressionB, FLOW_ERC20_HANDLE_TRANSFER_ENTRYPOINT, FLOW_ERC20_HANDLE_TRANSFER_MAX_OUTPUTS + address(uint160(uint256(keccak256("configExpression")))), + FLOW_ERC20_HANDLE_TRANSFER_ENTRYPOINT, + FLOW_ERC20_HANDLE_TRANSFER_MAX_OUTPUTS ), context ); - flow.flow(evaluables[0], new uint256[](0), new SignedContextV1[](0)); + flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0)); vm.startPrank(alice); vm.expectRevert("REVERT_EVAL2_CALL"); diff --git a/test/concrete/flowErc721/Erc721FlowTest.sol b/test/concrete/flowErc721/Erc721FlowTest.sol index ec566936..caa2146a 100644 --- a/test/concrete/flowErc721/Erc721FlowTest.sol +++ b/test/concrete/flowErc721/Erc721FlowTest.sol @@ -46,27 +46,15 @@ contract Erc721FlowTest is FlowERC721Test { /// forge-config: default.fuzz.runs = 100 function testFlowERC721SupportsTransferPreflightHook(address alice, uint256 tokenIdA, uint256 tokenIdB) external { vm.assume(alice != address(0)); - vm.assume(sentinel != tokenIdA); - vm.assume(sentinel != tokenIdB); vm.assume(tokenIdA != tokenIdB); - vm.assume(!alice.isContract()); (IFlowERC721V5 flow, EvaluableV2 memory evaluable) = deployFlowERC721({name: "", symbol: "", baseURI: ""}); assumeEtchable(alice, address(flow)); { - ERC721SupplyChange[] memory mints = new ERC721SupplyChange[](2); - mints[0] = ERC721SupplyChange({account: alice, id: tokenIdA}); - mints[1] = ERC721SupplyChange({account: alice, id: tokenIdB}); - - uint256[] memory stack = generateFlowStack( - FlowERC721IOV1( - mints, - new ERC721SupplyChange[](0), - FlowTransferV1(new ERC20Transfer[](0), new ERC721Transfer[](0), new ERC1155Transfer[](0)) - ) - ); + (uint256[] memory stack,) = mintFlowStack(alice, 0, tokenIdA, transferEmpty()); interpreterEval2MockCall(stack, new uint256[](0)); + IFlowERC721V5(flow).flow(evaluable, new uint256[](0), new SignedContextV1[](0)); } { @@ -89,13 +77,17 @@ contract Erc721FlowTest is FlowERC721Test { contextTransferA ); - IFlowERC721V5(flow).flow(evaluable, new uint256[](0), new SignedContextV1[](0)); - vm.startPrank(alice); IERC721(address(flow)).transferFrom({from: alice, to: address(flow), tokenId: tokenIdA}); vm.stopPrank(); } + { + (uint256[] memory stack,) = mintFlowStack(alice, 0, tokenIdB, transferEmpty()); + interpreterEval2MockCall(stack, new uint256[](0)); + IFlowERC721V5(flow).flow(evaluable, new uint256[](0), new SignedContextV1[](0)); + } + { uint256[][] memory contextTransferB = LibContextWrapper.buildAndSetContext( LibUint256Array.arrayFrom(uint256(uint160(address(alice))), uint256(uint160(address(flow))), tokenIdB)