Skip to content

Commit

Permalink
FlowERC721 Construction InitializeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikd-dev committed Aug 8, 2024
1 parent 1457569 commit a199385
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/abstract/FlowERC721Test.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
49 changes: 49 additions & 0 deletions test/concrete/flowErc721/FlowConstructionInitializeTest.sol
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit a199385

Please sign in to comment.