|
| 1 | +// test/RIKLauncher.t.sol |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +pragma solidity ^0.8.24; |
| 4 | + |
| 5 | +import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; |
| 6 | +import {Test} from "forge-std/Test.sol"; |
| 7 | +import {IAirlock, RIKLauncher} from "../src/RIKLauncher.sol"; |
| 8 | + |
| 9 | +contract MockAirlock is IAirlock { |
| 10 | + address public asset = address(0xA55E7); |
| 11 | + address public lastCaller; |
| 12 | + uint256 public lastInitialSupply; |
| 13 | + uint256 public lastNumTokensToSell; |
| 14 | + address public lastNumeraire; |
| 15 | + address public lastTokenFactory; |
| 16 | + bytes public lastTokenFactoryData; |
| 17 | + |
| 18 | + function create(CreateParams calldata p) |
| 19 | + external |
| 20 | + returns (address asset_, address pool, address governance, address timelock, address migrationPool) |
| 21 | + { |
| 22 | + lastCaller = msg.sender; |
| 23 | + lastInitialSupply = p.initialSupply; |
| 24 | + lastNumTokensToSell = p.numTokensToSell; |
| 25 | + lastNumeraire = p.numeraire; |
| 26 | + lastTokenFactory = p.tokenFactory; |
| 27 | + lastTokenFactoryData = p.tokenFactoryData; |
| 28 | + |
| 29 | + return (asset, address(0xB001), address(0xC0DE), address(0xD00D), address(0xE5C0)); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +contract MockRegistry { |
| 34 | + mapping(uint256 => address) public ownerOf; |
| 35 | + |
| 36 | + function setOwner(uint256 repoId, address owner) external { |
| 37 | + ownerOf[repoId] = owner; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +contract RIKLauncher_T is Test { |
| 42 | + MockAirlock airlock; |
| 43 | + MockRegistry registry; |
| 44 | + RIKLauncher launcher; |
| 45 | + |
| 46 | + uint256 repoId = 11112; |
| 47 | + address owner = address(0xA11CE); |
| 48 | + |
| 49 | + function setUp() public { |
| 50 | + airlock = new MockAirlock(); |
| 51 | + registry = new MockRegistry(); |
| 52 | + launcher = new RIKLauncher(airlock, IERC721(address(registry))); |
| 53 | + |
| 54 | + registry.setOwner(repoId, owner); |
| 55 | + } |
| 56 | + |
| 57 | + function test_LaunchRoutesThroughAirlockAndStoresMarket() public { |
| 58 | + IAirlock.CreateParams memory p = _params(); |
| 59 | + |
| 60 | + vm.expectEmit(true, true, true, true); |
| 61 | + emit RIKLauncher.MarketLaunched(repoId, airlock.asset(), owner); |
| 62 | + |
| 63 | + vm.prank(owner); |
| 64 | + address asset = launcher.launch(repoId, p); |
| 65 | + |
| 66 | + assertEq(asset, airlock.asset()); |
| 67 | + assertEq(launcher.marketOf(repoId), asset); |
| 68 | + assertEq(launcher.repoOf(asset), repoId); |
| 69 | + assertEq(airlock.lastCaller(), address(launcher)); |
| 70 | + assertEq(airlock.lastInitialSupply(), p.initialSupply); |
| 71 | + assertEq(airlock.lastNumTokensToSell(), p.numTokensToSell); |
| 72 | + assertEq(airlock.lastNumeraire(), p.numeraire); |
| 73 | + assertEq(airlock.lastTokenFactory(), p.tokenFactory); |
| 74 | + assertEq(airlock.lastTokenFactoryData(), p.tokenFactoryData); |
| 75 | + } |
| 76 | + |
| 77 | + function test_RejectsNonRikOwner() public { |
| 78 | + address bob = address(0xB0B); |
| 79 | + |
| 80 | + vm.prank(bob); |
| 81 | + vm.expectRevert(abi.encodeWithSelector(RIKLauncher.NotRikOwner.selector, repoId, bob)); |
| 82 | + |
| 83 | + launcher.launch(repoId, _params()); |
| 84 | + } |
| 85 | + |
| 86 | + function test_RejectsDuplicateLaunch() public { |
| 87 | + vm.prank(owner); |
| 88 | + address asset = launcher.launch(repoId, _params()); |
| 89 | + |
| 90 | + vm.prank(owner); |
| 91 | + vm.expectRevert(abi.encodeWithSelector(RIKLauncher.AlreadyLaunched.selector, repoId, asset)); |
| 92 | + |
| 93 | + launcher.launch(repoId, _params()); |
| 94 | + } |
| 95 | + |
| 96 | + function _params() internal pure returns (IAirlock.CreateParams memory p) { |
| 97 | + p.initialSupply = 1_000_000 ether; |
| 98 | + p.numTokensToSell = 500_000 ether; |
| 99 | + p.numeraire = address(0x4200000000000000000000000000000000000006); |
| 100 | + p.tokenFactory = address(0x70E3); |
| 101 | + p.tokenFactoryData = hex"1234"; |
| 102 | + p.governanceFactory = address(0x90C0); |
| 103 | + p.governanceFactoryData = hex"5678"; |
| 104 | + p.poolInitializer = address(0xB001); |
| 105 | + p.poolInitializerData = hex"abcd"; |
| 106 | + p.liquidityMigrator = address(0x1111); |
| 107 | + p.liquidityMigratorData = hex"dcba"; |
| 108 | + p.integrator = address(0x2222); |
| 109 | + p.salt = bytes32(uint256(1)); |
| 110 | + } |
| 111 | +} |
0 commit comments