From a19938543807defb2b31343281684ec1fcdfade2 Mon Sep 17 00:00:00 2001 From: Erik Dubovyk Date: Fri, 9 Aug 2024 00:26:02 +0300 Subject: [PATCH] FlowERC721 Construction InitializeTest --- test/abstract/FlowERC721Test.sol | 30 ++++++++++++ .../FlowConstructionInitializeTest.sol | 49 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 test/abstract/FlowERC721Test.sol create mode 100644 test/concrete/flowErc721/FlowConstructionInitializeTest.sol diff --git a/test/abstract/FlowERC721Test.sol b/test/abstract/FlowERC721Test.sol new file mode 100644 index 00000000..7ce677b4 --- /dev/null +++ b/test/abstract/FlowERC721Test.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: CAL +pragma solidity ^0.8.18; + +import {Vm} from "forge-std/Test.sol"; + +import {InterpreterMockTest} from "test/abstract/InterpreterMockTest.sol"; +import {IFlowERC721V5} from "src/interface/unstable/IFlowERC721V5.sol"; +import {FlowERC721} from "src/concrete/erc721/FlowERC721.sol"; +import {CloneFactory} from "rain.factory/src/concrete/CloneFactory.sol"; +import {FlowUtilsAbstractTest} from "test/abstract/FlowUtilsAbstractTest.sol"; +import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/IExpressionDeployerV3.sol"; +import {REVERTING_MOCK_BYTECODE} from "test/abstract/TestConstants.sol"; + +contract FlowERC721Test is InterpreterMockTest, FlowUtilsAbstractTest { + CloneFactory internal immutable iCloneFactory; + IFlowERC721V5 internal immutable iFlowERC721Implementation; + IExpressionDeployerV3 internal immutable iDeployerForEvalHandleTransfer; + + constructor() { + vm.pauseGasMetering(); + iCloneFactory = new CloneFactory(); + iFlowERC721Implementation = new FlowERC721(); + vm.pauseGasMetering(); + iDeployerForEvalHandleTransfer = + IExpressionDeployerV3(address(uint160(uint256(keccak256("deployer.for.evalhandle.transfer.rain.test"))))); + vm.etch(address(iInterpreter), REVERTING_MOCK_BYTECODE); + + vm.resumeGasMetering(); + } +} diff --git a/test/concrete/flowErc721/FlowConstructionInitializeTest.sol b/test/concrete/flowErc721/FlowConstructionInitializeTest.sol new file mode 100644 index 00000000..4a7ab87e --- /dev/null +++ b/test/concrete/flowErc721/FlowConstructionInitializeTest.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: CAL +pragma solidity ^0.8.18; + +import {Vm} from "forge-std/Test.sol"; + +import {FlowERC721ConfigV2} from "src/interface/unstable/IFlowERC721V5.sol"; +import {EvaluableConfigV3} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol"; +import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/IExpressionDeployerV3.sol"; +import {FlowERC721Test} from "test/abstract/FlowERC721Test.sol"; + +contract FlowConstructionInitializeTest is FlowERC721Test { + function testFlowConstructionInitialize(address expression, bytes memory bytecode, uint256[] memory constants) + external + { + expressionDeployerDeployExpression2MockCall(expression, bytes(hex"0006")); + + EvaluableConfigV3[] memory flowConfig = new EvaluableConfigV3[](1); + flowConfig[0] = EvaluableConfigV3(iDeployer, bytecode, constants); + + vm.mockCall( + address(iDeployerForEvalHandleTransfer), + abi.encodeWithSelector(IExpressionDeployerV3.deployExpression2.selector), + abi.encode(iInterpreter, iStore, expression, bytes(hex"00000006")) + ); + + FlowERC721ConfigV2 memory flowERC721ConfigV2 = FlowERC721ConfigV2( + "Flow ERC721", + "F721", + "https://www.rainprotocol.xyz/nft/", + EvaluableConfigV3(iDeployerForEvalHandleTransfer, bytecode, constants), + flowConfig + ); + + vm.recordLogs(); + iCloneFactory.clone(address(iFlowERC721Implementation), abi.encode(flowERC721ConfigV2)); + + Vm.Log[] memory logs = vm.getRecordedLogs(); + bytes32 eventSignature = keccak256( + "Initialize(address,(string,string,string,(address,bytes,uint256[]),(address,bytes,uint256[])[]))" + ); + + Vm.Log memory concreteEvent = findEvent(logs, eventSignature); + (address sender, FlowERC721ConfigV2 memory config) = + abi.decode(concreteEvent.data, (address, FlowERC721ConfigV2)); + + assertEq(sender, address(iCloneFactory), "wrong sender in Initialize event"); + assertEq(keccak256(abi.encode(flowERC721ConfigV2)), keccak256(abi.encode(config)), "wrong compare Structs"); + } +}