From 68811f7301aee9307ddb3059525d55025ce55697 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Fri, 27 Sep 2024 17:21:45 +0400 Subject: [PATCH] Add testFlowErc721HaltIfEnsureRequirementNotMet --- test/concrete/flowErc721/Erc721FlowTest.sol | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/concrete/flowErc721/Erc721FlowTest.sol b/test/concrete/flowErc721/Erc721FlowTest.sol index 5d9e0f08..f968e35e 100644 --- a/test/concrete/flowErc721/Erc721FlowTest.sol +++ b/test/concrete/flowErc721/Erc721FlowTest.sol @@ -28,6 +28,9 @@ import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpr import {DEFAULT_STATE_NAMESPACE} from "rain.interpreter.interface/interface/IInterpreterV2.sol"; import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol"; import {MissingSentinel} from "rain.solmem/lib/LibStackSentinel.sol"; +import {FLOW_ENTRYPOINT, FLOW_MAX_OUTPUTS} from "src/abstract/FlowCommon.sol"; +import {LibEncodedDispatch} from "rain.interpreter.interface/lib/caller/LibEncodedDispatch.sol"; +import {LibContextWrapper} from "test/lib/LibContextWrapper.sol"; contract Erc721FlowTest is FlowERC721Test { using LibEvaluable for EvaluableV2; @@ -499,4 +502,29 @@ contract Erc721FlowTest is FlowERC721Test { flowInvalid.flow(evaluablesInvalid[0], new uint256[](0), new SignedContextV1[](0)); vm.stopPrank(); } + + /** + * @notice Tests that the flow halts if it does not meet the 'ensure' requirement. + */ + /// forge-config: default.fuzz.runs = 100 + function testFlowErc721HaltIfEnsureRequirementNotMet() external { + (IFlowERC721V5 flow, EvaluableV2 memory evaluable) = + deployFlowERC721("FlowERC721", "F721", "https://www.rainprotocol.xyz/nft/"); + + assumeEtchable(address(0), address(flow)); + + (uint256[] memory stack,) = mintAndBurnFlowStack(address(this), 20 ether, 10 ether, 5, transferEmpty()); + interpreterEval2MockCall(stack, new uint256[](0)); + + uint256[][] memory context = LibContextWrapper.buildAndSetContext( + new uint256[](0), new SignedContextV1[](0), address(this), address(flow) + ); + + interpreterEval2RevertCall( + address(flow), LibEncodedDispatch.encode2(evaluable.expression, FLOW_ENTRYPOINT, FLOW_MAX_OUTPUTS), context + ); + + vm.expectRevert("REVERT_EVAL2_CALL"); + flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0)); + } }