From 652d7b3092fda284b28241e1556c84035ccf5539 Mon Sep 17 00:00:00 2001 From: Erik Dubovyk Date: Fri, 27 Sep 2024 22:38:43 +0300 Subject: [PATCH] updated for new abstraction structure --- test/abstract/FlowERC1155Test.sol | 7 +- test/concrete/flowErc1155/Erc1155FlowTest.sol | 106 ++++++++---------- test/concrete/flowErc20/Erc20FlowTest.sol | 41 ++----- test/concrete/flowErc721/Erc721FlowTest.sol | 24 ++-- 4 files changed, 69 insertions(+), 109 deletions(-) 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 d95eb5a6..b4713bf0 100644 --- a/test/concrete/flowErc1155/Erc1155FlowTest.sol +++ b/test/concrete/flowErc1155/Erc1155FlowTest.sol @@ -36,90 +36,76 @@ contract Erc1155FlowTest is FlowERC1155Test { using LibUint256Array for uint256[]; using Address for address; - function testFlowERC1155SupportsTransferPreflightHook( - address alice, - uint256 tokenIdA, - uint256 tokenIdB, - uint256 amountA, - uint256 amountB, - address expressionA, - address expressionB - ) external { + /** + * @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(expressionA != expressionB); - vm.assume(!alice.isContract()); - vm.assume(sentinel != tokenIdA); - vm.assume(sentinel != tokenIdB); - vm.assume(sentinel != amountA); - vm.assume(sentinel != amountB); - - address[] memory expressions = new address[](1); - expressions[0] = expressionA; + vm.assume(amount != 0); - (IFlowERC1155V5 flow, EvaluableV2[] memory evaluables) = - deployIFlowERC1155V5(expressions, expressionB, new uint256[][](1), "uri"); + (IFlowERC1155V5 flow, EvaluableV2 memory evaluable) = deployIFlowERC1155V5("https://www.rainprotocol.xyz/nft/"); assumeEtchable(alice, address(flow)); // Mint tokens to Alice { - ERC1155SupplyChange[] memory mints = new ERC1155SupplyChange[](2); - mints[0] = ERC1155SupplyChange({account: alice, id: tokenIdA, amount: amountA}); - mints[1] = ERC1155SupplyChange({account: alice, id: tokenIdB, amount: amountB}); - - uint256[] memory stack = generateFlowStack( - FlowERC1155IOV1( - mints, - new ERC1155SupplyChange[](0), - FlowTransferV1(new ERC20Transfer[](0), new ERC721Transfer[](0), new ERC1155Transfer[](0)) - ) - ); + (uint256[] memory stack,) = mintFlowStack(alice, amount, id, transferEmpty()); interpreterEval2MockCall(stack, new uint256[](0)); } - // Attempt a token transfer - uint256[][] memory contextTransferA = LibContextWrapper.buildAndSetContext( - LibUint256Array.arrayFrom( - uint256(uint160(address(alice))), uint256(uint160(address(flow))), tokenIdA, amountA - ).matrixFrom(), + 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) ); - // Expect call token transfer - interpreterEval2ExpectCall( - address(flow), - LibEncodedDispatch.encode2( - expressionB, FLOW_ERC1155_HANDLE_TRANSFER_ENTRYPOINT, FLOW_ERC1155_HANDLE_TRANSFER_MAX_OUTPUTS - ), - contextTransferA - ); - flow.flow(evaluables[0], new uint256[](0), new SignedContextV1[](0)); - - vm.startPrank(alice); - IERC1155(address(flow)).safeTransferFrom(alice, address(flow), tokenIdA, amountA, ""); - vm.stopPrank(); - { - uint256[][] memory contextTransferB = LibContextWrapper.buildAndSetContext( - LibUint256Array.arrayFrom(uint256(uint160(address(alice))), uint256(uint160(address(flow))), tokenIdB) - .matrixFrom(), - 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( - expressionB, FLOW_ERC1155_HANDLE_TRANSFER_ENTRYPOINT, FLOW_ERC1155_HANDLE_TRANSFER_MAX_OUTPUTS + address(uint160(uint256(keccak256("configExpression")))), + FLOW_ERC1155_HANDLE_TRANSFER_ENTRYPOINT, + FLOW_ERC1155_HANDLE_TRANSFER_MAX_OUTPUTS ), - contextTransferB + context ); + flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0)); + + vm.expectRevert("REVERT_EVAL2_CALL"); vm.startPrank(alice); - // vm.expectRevert("REVERT_EVAL2_CALL"); - IERC1155(address(flow)).safeTransferFrom(alice, address(flow), tokenIdB, amountB, ""); + IERC1155(address(flow)).safeTransferFrom(alice, address(flow), id, amount, ""); vm.stopPrank(); } } diff --git a/test/concrete/flowErc20/Erc20FlowTest.sol b/test/concrete/flowErc20/Erc20FlowTest.sol index 07ea757e..c3204a81 100644 --- a/test/concrete/flowErc20/Erc20FlowTest.sol +++ b/test/concrete/flowErc20/Erc20FlowTest.sol @@ -36,37 +36,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)); } @@ -82,12 +59,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); @@ -98,12 +77,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 5282ef9e..3dfb601c 100644 --- a/test/concrete/flowErc721/Erc721FlowTest.sol +++ b/test/concrete/flowErc721/Erc721FlowTest.sol @@ -41,27 +41,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)); } { @@ -84,13 +72,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)