diff --git a/.changeset/five-vans-try.md b/.changeset/five-vans-try.md new file mode 100644 index 0000000000..25991056af --- /dev/null +++ b/.changeset/five-vans-try.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": major +--- + +Renamed `CoreModule` to `InitModule` and `CoreRegistrationSystem` to `RegistrationSystem`. diff --git a/.changeset/silver-adults-sip.md b/.changeset/silver-adults-sip.md new file mode 100644 index 0000000000..b9b68abb97 --- /dev/null +++ b/.changeset/silver-adults-sip.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Updated deployer with world's new `InitModule` naming. diff --git a/packages/cli/src/deploy/ensureWorldFactory.ts b/packages/cli/src/deploy/ensureWorldFactory.ts index edd2d84b2d..3d27fb0988 100644 --- a/packages/cli/src/deploy/ensureWorldFactory.ts +++ b/packages/cli/src/deploy/ensureWorldFactory.ts @@ -1,9 +1,9 @@ import accessManagementSystemBuild from "@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json" assert { type: "json" }; import balanceTransferSystemBuild from "@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json" assert { type: "json" }; import batchCallSystemBuild from "@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json" assert { type: "json" }; -import coreRegistrationSystemBuild from "@latticexyz/world/out/CoreRegistrationSystem.sol/CoreRegistrationSystem.json" assert { type: "json" }; -import coreModuleBuild from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" }; -import coreModuleAbi from "@latticexyz/world/out/CoreModule.sol/CoreModule.abi.json" assert { type: "json" }; +import registrationSystemBuild from "@latticexyz/world/out/RegistrationSystem.sol/RegistrationSystem.json" assert { type: "json" }; +import initModuleBuild from "@latticexyz/world/out/InitModule.sol/InitModule.json" assert { type: "json" }; +import initModuleAbi from "@latticexyz/world/out/InitModule.sol/InitModule.abi.json" assert { type: "json" }; import worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" }; import worldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" }; import { Client, Transport, Chain, Account, Hex, getCreate2Address, encodeDeployData, size } from "viem"; @@ -45,33 +45,31 @@ export const batchCallSystemBytecode = encodeDeployData({ }); export const batchCallSystem = getCreate2Address({ from: deployer, bytecode: batchCallSystemBytecode, salt }); -export const coreRegistrationSystemDeployedBytecodeSize = size( - coreRegistrationSystemBuild.deployedBytecode.object as Hex -); -export const coreRegistrationSystemBytecode = encodeDeployData({ - bytecode: coreRegistrationSystemBuild.bytecode.object as Hex, +export const registrationDeployedBytecodeSize = size(registrationSystemBuild.deployedBytecode.object as Hex); +export const registrationBytecode = encodeDeployData({ + bytecode: registrationSystemBuild.bytecode.object as Hex, abi: [], }); -export const coreRegistrationSystem = getCreate2Address({ +export const registration = getCreate2Address({ from: deployer, - bytecode: coreRegistrationSystemBytecode, + bytecode: registrationBytecode, salt, }); -export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex); -export const coreModuleBytecode = encodeDeployData({ - bytecode: coreModuleBuild.bytecode.object as Hex, - abi: coreModuleAbi, - args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem], +export const initModuleDeployedBytecodeSize = size(initModuleBuild.deployedBytecode.object as Hex); +export const initModuleBytecode = encodeDeployData({ + bytecode: initModuleBuild.bytecode.object as Hex, + abi: initModuleAbi, + args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, registration], }); -export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt }); +export const initModule = getCreate2Address({ from: deployer, bytecode: initModuleBytecode, salt }); export const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex); export const worldFactoryBytecode = encodeDeployData({ bytecode: worldFactoryBuild.bytecode.object as Hex, abi: worldFactoryAbi, - args: [coreModule], + args: [initModule], }); export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt }); @@ -93,13 +91,13 @@ export const worldFactoryContracts: readonly Contract[] = [ label: "batch call system", }, { - bytecode: coreRegistrationSystemBytecode, - deployedBytecodeSize: coreRegistrationSystemDeployedBytecodeSize, + bytecode: registrationBytecode, + deployedBytecodeSize: registrationDeployedBytecodeSize, label: "core registration system", }, { - bytecode: coreModuleBytecode, - deployedBytecodeSize: coreModuleDeployedBytecodeSize, + bytecode: initModuleBytecode, + deployedBytecodeSize: initModuleDeployedBytecodeSize, label: "core module", }, { @@ -112,7 +110,7 @@ export const worldFactoryContracts: readonly Contract[] = [ export async function ensureWorldFactory( client: Client ): Promise { - // WorldFactory constructor doesn't call CoreModule, only sets its address, so we can do these in parallel since the address is deterministic + // WorldFactory constructor doesn't call InitModule, only sets its address, so we can do these in parallel since the address is deterministic return await ensureContractsDeployed({ client, contracts: worldFactoryContracts, diff --git a/packages/world-modules/test/ERC20.t.sol b/packages/world-modules/test/ERC20.t.sol index da961ad793..de1820f0f9 100644 --- a/packages/world-modules/test/ERC20.t.sol +++ b/packages/world-modules/test/ERC20.t.sol @@ -8,7 +8,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { World } from "@latticexyz/world/src/World.sol"; import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; @@ -30,8 +30,7 @@ contract ERC20Test is Test, GasReporter, IERC20Events, IERC20Errors { IERC20Mintable token; function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); world.installModule(new PuppetModule(), new bytes(0)); StoreSwitch.setStoreAddress(address(world)); diff --git a/packages/world-modules/test/ERC721.t.sol b/packages/world-modules/test/ERC721.t.sol index 9557b528b1..dfb421c77c 100644 --- a/packages/world-modules/test/ERC721.t.sol +++ b/packages/world-modules/test/ERC721.t.sol @@ -8,7 +8,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { World } from "@latticexyz/world/src/World.sol"; import { WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol"; import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; @@ -72,8 +72,7 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors { IERC721Mintable token; function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); world.installModule(new PuppetModule(), new bytes(0)); StoreSwitch.setStoreAddress(address(world)); diff --git a/packages/world-modules/test/KeysInTableModule.t.sol b/packages/world-modules/test/KeysInTableModule.t.sol index 9fac5cfac3..58b5da867b 100644 --- a/packages/world-modules/test/KeysInTableModule.t.sol +++ b/packages/world-modules/test/KeysInTableModule.t.sol @@ -18,7 +18,7 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { KeysInTableModule } from "../src/modules/keysintable/KeysInTableModule.sol"; import { getKeysInTable } from "../src/modules/keysintable/getKeysInTable.sol"; import { hasKey } from "../src/modules/keysintable/hasKey.sol"; @@ -62,8 +62,7 @@ contract KeysInTableModuleTest is Test, GasReporter { compositeKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32, SchemaType.BYTES32, SchemaType.BYTES32); singletonKeySchema = SchemaLib.encode(new SchemaType[](0)); - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); keyTuple1 = new bytes32[](1); keyTuple1[0] = key1; keyTuple2 = new bytes32[](1); diff --git a/packages/world-modules/test/KeysWithValueModule.t.sol b/packages/world-modules/test/KeysWithValueModule.t.sol index ed63a92c43..56ae3017e9 100644 --- a/packages/world-modules/test/KeysWithValueModule.t.sol +++ b/packages/world-modules/test/KeysWithValueModule.t.sol @@ -21,7 +21,7 @@ import { WorldResourceIdLib, WorldResourceIdInstance, NAME_BITS, TYPE_BITS } fro import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { KeysWithValueModule } from "../src/modules/keyswithvalue/KeysWithValueModule.sol"; import { MODULE_NAMESPACE } from "../src/modules/keyswithvalue/constants.sol"; import { KeysWithValue } from "../src/modules/keyswithvalue/tables/KeysWithValue.sol"; @@ -54,8 +54,7 @@ contract KeysWithValueModuleTest is Test, GasReporter { sourceTableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: namespace, name: sourceName }); targetTableId = getTargetTableId(MODULE_NAMESPACE, sourceTableId); - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); StoreSwitch.setStoreAddress(address(world)); keyTuple1 = new bytes32[](1); diff --git a/packages/world-modules/test/PuppetModule.t.sol b/packages/world-modules/test/PuppetModule.t.sol index f28fe01296..622462ee5a 100644 --- a/packages/world-modules/test/PuppetModule.t.sol +++ b/packages/world-modules/test/PuppetModule.t.sol @@ -13,7 +13,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld. import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; import { IDelegationControl } from "@latticexyz/world/src/IDelegationControl.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol"; import { PuppetModule } from "../src/modules/puppet/PuppetModule.sol"; @@ -47,8 +47,7 @@ contract PuppetModuleTest is Test, GasReporter { PuppetTestSystem private puppet; function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); } function _setupPuppet() internal { diff --git a/packages/world-modules/test/StandardDelegationsModule.t.sol b/packages/world-modules/test/StandardDelegationsModule.t.sol index 83a3d69611..537fcced39 100644 --- a/packages/world-modules/test/StandardDelegationsModule.t.sol +++ b/packages/world-modules/test/StandardDelegationsModule.t.sol @@ -13,7 +13,7 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld. import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; import { IDelegationControl } from "@latticexyz/world/src/IDelegationControl.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol"; import { StandardDelegationsModule } from "../src/modules/std-delegations/StandardDelegationsModule.sol"; @@ -33,8 +33,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter { address private delegatee = address(2); function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); world.installRootModule(new StandardDelegationsModule(), new bytes(0)); // Register a new system diff --git a/packages/world-modules/test/SystemSwitch.t.sol b/packages/world-modules/test/SystemSwitch.t.sol index 3e608fd203..765233bd08 100644 --- a/packages/world-modules/test/SystemSwitch.t.sol +++ b/packages/world-modules/test/SystemSwitch.t.sol @@ -7,7 +7,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { System } from "@latticexyz/world/src/System.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { World } from "@latticexyz/world/src/World.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; @@ -54,9 +54,7 @@ contract SystemSwitchTest is Test, GasReporter { function setUp() public { // Deploy world - World _world = new World(); - _world.initialize(createCoreModule()); - world = IBaseWorld(address(_world)); + world = createWorld(); // Deploy systems systemA = new EchoSystem(); diff --git a/packages/world-modules/test/UniqueEntityModule.t.sol b/packages/world-modules/test/UniqueEntityModule.t.sol index cada4ad51d..744349280c 100644 --- a/packages/world-modules/test/UniqueEntityModule.t.sol +++ b/packages/world-modules/test/UniqueEntityModule.t.sol @@ -12,7 +12,7 @@ import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol"; import { System } from "@latticexyz/world/src/System.sol"; import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { UniqueEntityModule } from "../src/modules/uniqueentity/UniqueEntityModule.sol"; import { UniqueEntity } from "../src/modules/uniqueentity/tables/UniqueEntity.sol"; import { getUniqueEntity } from "../src/modules/uniqueentity/getUniqueEntity.sol"; @@ -36,8 +36,7 @@ contract UniqueEntityModuleTest is Test, GasReporter { ResourceId _tableId = WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: NAMESPACE, name: TABLE_NAME }); function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); StoreSwitch.setStoreAddress(address(world)); } diff --git a/packages/world-modules/test/query.t.sol b/packages/world-modules/test/query.t.sol index 4ee4ebfeaf..5571f10f47 100644 --- a/packages/world-modules/test/query.t.sol +++ b/packages/world-modules/test/query.t.sol @@ -17,7 +17,7 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol"; import { RESOURCE_TABLE } from "@latticexyz/world/src/worldResourceTypes.sol"; -import { createCoreModule } from "@latticexyz/world/test/createCoreModule.sol"; +import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { KeysInTableModule } from "../src/modules/keysintable/KeysInTableModule.sol"; import { KeysWithValueModule } from "../src/modules/keyswithvalue/KeysWithValueModule.sol"; import { query, QueryFragment, QueryType } from "../src/modules/keysintable/query.sol"; @@ -52,8 +52,7 @@ contract QueryTest is Test, GasReporter { tableFieldLayout = FieldLayoutEncodeHelper.encode(32, 0); tableKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); tableValueSchema = SchemaEncodeHelper.encode(SchemaType.UINT256); - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); key1[0] = "test1"; key2[0] = "test2"; diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 117725303b..5ce4c74a7f 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -63,7 +63,7 @@ "file": "test/Factories.t.sol", "test": "testWorldFactoryGas", "name": "deploy world via WorldFactory", - "gasUsed": 12961878 + "gasUsed": 12961889 }, { "file": "test/World.t.sol", diff --git a/packages/world/mud.config.ts b/packages/world/mud.config.ts index 054cb1ffd9..08a52c769a 100644 --- a/packages/world/mud.config.ts +++ b/packages/world/mud.config.ts @@ -103,14 +103,14 @@ export default mudConfig({ }, offchainOnly: true, }, - CoreModuleAddress: { + InitModuleAddress: { keySchema: {}, valueSchema: "address", }, }, excludeSystems: [ // Worldgen currently does not support systems inheriting logic - // from other contracts, so all parts of CoreRegistrationSystem are named + // from other contracts, so all parts of RegistrationSystem are named // System too to be included in the IBaseWorld interface. // However, IStoreRegistrationSystem overlaps with IStore if // included in IBaseWorld, so it needs to be excluded from worldgen. diff --git a/packages/world/src/IWorldKernel.sol b/packages/world/src/IWorldKernel.sol index 8935707526..5a1aa67c18 100644 --- a/packages/world/src/IWorldKernel.sol +++ b/packages/world/src/IWorldKernel.sol @@ -54,7 +54,7 @@ interface IWorldCall { * @title World Kernel Interface * @notice The IWorldKernel interface includes all methods that are part of the World contract's * internal bytecode. Consumers should use the `IBaseWorld` interface instead, which includes dynamically - * registered functions selectors from the `CoreModule`. + * registered functions selectors from the `InitModule`. */ interface IWorldKernel is IWorldModuleInstallation, IWorldCall, IWorldErrors { /** @@ -78,7 +78,7 @@ interface IWorldKernel is IWorldModuleInstallation, IWorldCall, IWorldErrors { /** * @notice Initializes the World. * @dev Can only be called once by the creator. - * @param coreModule The CoreModule to be installed during initialization. + * @param initModule The InitModule to be installed during initialization. */ - function initialize(IModule coreModule) external; + function initialize(IModule initModule) external; } diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 59abfb0b09..e6480edc1d 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -19,7 +19,7 @@ import { requireInterface } from "./requireInterface.sol"; import { InstalledModules } from "./codegen/tables/InstalledModules.sol"; import { UserDelegationControl } from "./codegen/tables/UserDelegationControl.sol"; import { NamespaceDelegationControl } from "./codegen/tables/NamespaceDelegationControl.sol"; -import { CoreModuleAddress } from "./codegen/tables/CoreModuleAddress.sol"; +import { InitModuleAddress } from "./codegen/tables/InitModuleAddress.sol"; import { IModule, IModule } from "./IModule.sol"; import { IWorldKernel } from "./IWorldKernel.sol"; @@ -61,24 +61,24 @@ contract World is StoreData, IWorldKernel { /** * @notice Initializes the World by installing the core module. - * @param coreModule The core module to initialize the World with. + * @param initModule The core module to initialize the World with. * @dev Only the initial creator can initialize. This can be done only once. */ - function initialize(IModule coreModule) public prohibitDirectCallback { + function initialize(IModule initModule) public prohibitDirectCallback { // Only the initial creator of the World can initialize it if (msg.sender != creator) { revert World_AccessDenied(ROOT_NAMESPACE_ID.toString(), msg.sender); } // The World can only be initialized once - if (CoreModuleAddress.get() != address(0)) { + if (InitModuleAddress.get() != address(0)) { revert World_AlreadyInitialized(); } - CoreModuleAddress.set(address(coreModule)); + InitModuleAddress.set(address(initModule)); // Initialize the World by installing the core module - _installRootModule(coreModule, new bytes(0)); + _installRootModule(initModule, new bytes(0)); } /** diff --git a/packages/world/src/WorldFactory.sol b/packages/world/src/WorldFactory.sol index a336ddf670..0b2e452d30 100644 --- a/packages/world/src/WorldFactory.sol +++ b/packages/world/src/WorldFactory.sol @@ -11,22 +11,22 @@ import { ROOT_NAMESPACE_ID } from "./constants.sol"; /** * @title WorldFactory * @notice A factory contract to deploy new World instances. - * @dev This contract allows users to deploy a new World, install the CoreModule, and transfer the ownership. + * @dev This contract allows users to deploy a new World, install the InitModule, and transfer the ownership. */ contract WorldFactory is IWorldFactory { - /// @notice Address of the core module to be set in the World instances. - IModule public immutable coreModule; + /// @notice Address of the init module to be set in the World instances. + IModule public immutable initModule; /// @notice Counters to keep track of the number of World instances deployed per address. mapping(address creator => uint256 worldCount) public worldCounts; - /// @param _coreModule The address of the core module. - constructor(IModule _coreModule) { - coreModule = _coreModule; + /// @param _initModule The address of the init module. + constructor(IModule _initModule) { + initModule = _initModule; } /** - * @notice Deploys a new World instance, installs the CoreModule and transfers ownership to the caller. + * @notice Deploys a new World instance, installs the InitModule and transfers ownership to the caller. * @dev Uses the Create2 for deterministic deployment. * @return worldAddress The address of the newly deployed World contract. */ @@ -38,7 +38,7 @@ contract WorldFactory is IWorldFactory { IBaseWorld world = IBaseWorld(worldAddress); // Initialize the World and transfer ownership to the caller - world.initialize(coreModule); + world.initialize(initModule); world.transferOwnership(ROOT_NAMESPACE_ID, msg.sender); emit WorldDeployed(worldAddress); diff --git a/packages/world/src/codegen/index.sol b/packages/world/src/codegen/index.sol index 6a7c9dd016..9adaf020c9 100644 --- a/packages/world/src/codegen/index.sol +++ b/packages/world/src/codegen/index.sol @@ -14,4 +14,4 @@ import { SystemRegistry, SystemRegistryTableId } from "./tables/SystemRegistry.s import { SystemHooks, SystemHooksTableId } from "./tables/SystemHooks.sol"; import { FunctionSelectors, FunctionSelectorsTableId } from "./tables/FunctionSelectors.sol"; import { FunctionSignatures, FunctionSignaturesTableId } from "./tables/FunctionSignatures.sol"; -import { CoreModuleAddress, CoreModuleAddressTableId } from "./tables/CoreModuleAddress.sol"; +import { InitModuleAddress, InitModuleAddressTableId } from "./tables/InitModuleAddress.sol"; diff --git a/packages/world/src/codegen/interfaces/IBaseWorld.sol b/packages/world/src/codegen/interfaces/IBaseWorld.sol index d294f8004b..6026287465 100644 --- a/packages/world/src/codegen/interfaces/IBaseWorld.sol +++ b/packages/world/src/codegen/interfaces/IBaseWorld.sol @@ -6,12 +6,12 @@ pragma solidity >=0.8.24; import { IStore } from "@latticexyz/store/src/IStore.sol"; import { IWorldKernel } from "../../IWorldKernel.sol"; -import { ICoreRegistrationSystem } from "./ICoreRegistrationSystem.sol"; import { IAccessManagementSystem } from "./IAccessManagementSystem.sol"; import { IBalanceTransferSystem } from "./IBalanceTransferSystem.sol"; import { IBatchCallSystem } from "./IBatchCallSystem.sol"; import { IModuleInstallationSystem } from "./IModuleInstallationSystem.sol"; import { IWorldRegistrationSystem } from "./IWorldRegistrationSystem.sol"; +import { IRegistrationSystem } from "./IRegistrationSystem.sol"; /** * @title IBaseWorld @@ -22,12 +22,12 @@ import { IWorldRegistrationSystem } from "./IWorldRegistrationSystem.sol"; interface IBaseWorld is IStore, IWorldKernel, - ICoreRegistrationSystem, IAccessManagementSystem, IBalanceTransferSystem, IBatchCallSystem, IModuleInstallationSystem, - IWorldRegistrationSystem + IWorldRegistrationSystem, + IRegistrationSystem { } diff --git a/packages/world/src/codegen/interfaces/IBatchCallSystem.sol b/packages/world/src/codegen/interfaces/IBatchCallSystem.sol index 80ef51c0aa..62cf366bbb 100644 --- a/packages/world/src/codegen/interfaces/IBatchCallSystem.sol +++ b/packages/world/src/codegen/interfaces/IBatchCallSystem.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ -import { SystemCallData, SystemCallFromData } from "./../../modules/core/types.sol"; +import { SystemCallData, SystemCallFromData } from "./../../modules/init/types.sol"; /** * @title IBatchCallSystem diff --git a/packages/world/src/codegen/interfaces/ICoreRegistrationSystem.sol b/packages/world/src/codegen/interfaces/IRegistrationSystem.sol similarity index 76% rename from packages/world/src/codegen/interfaces/ICoreRegistrationSystem.sol rename to packages/world/src/codegen/interfaces/IRegistrationSystem.sol index 3e8b7fdb04..f14496a41b 100644 --- a/packages/world/src/codegen/interfaces/ICoreRegistrationSystem.sol +++ b/packages/world/src/codegen/interfaces/IRegistrationSystem.sol @@ -4,9 +4,9 @@ pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ /** - * @title ICoreRegistrationSystem + * @title IRegistrationSystem * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. */ -interface ICoreRegistrationSystem { +interface IRegistrationSystem { } diff --git a/packages/world/src/codegen/tables/CoreModuleAddress.sol b/packages/world/src/codegen/tables/InitModuleAddress.sol similarity index 98% rename from packages/world/src/codegen/tables/CoreModuleAddress.sol rename to packages/world/src/codegen/tables/InitModuleAddress.sol index edf343bbcd..8127779a7a 100644 --- a/packages/world/src/codegen/tables/CoreModuleAddress.sol +++ b/packages/world/src/codegen/tables/InitModuleAddress.sol @@ -21,15 +21,15 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol"; ResourceId constant _tableId = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_TABLE, bytes14("world"), bytes16("CoreModuleAddres"))) + bytes32(abi.encodePacked(RESOURCE_TABLE, bytes14("world"), bytes16("InitModuleAddres"))) ); -ResourceId constant CoreModuleAddressTableId = _tableId; +ResourceId constant InitModuleAddressTableId = _tableId; FieldLayout constant _fieldLayout = FieldLayout.wrap( 0x0014010014000000000000000000000000000000000000000000000000000000 ); -library CoreModuleAddress { +library InitModuleAddress { /** * @notice Get the table values' field layout. * @return _fieldLayout The field layout for the table. diff --git a/packages/world/src/modules/core/CoreModule.sol b/packages/world/src/modules/init/InitModule.sol similarity index 88% rename from packages/world/src/modules/core/CoreModule.sol rename to packages/world/src/modules/init/InitModule.sol index 580a562de9..b2207817a9 100644 --- a/packages/world/src/modules/core/CoreModule.sol +++ b/packages/world/src/modules/init/InitModule.sol @@ -20,41 +20,41 @@ import { AccessManagementSystem } from "./implementations/AccessManagementSystem import { BalanceTransferSystem } from "./implementations/BalanceTransferSystem.sol"; import { BatchCallSystem } from "./implementations/BatchCallSystem.sol"; -import { CoreRegistrationSystem } from "./CoreRegistrationSystem.sol"; -import { ACCESS_MANAGEMENT_SYSTEM_ID, BALANCE_TRANSFER_SYSTEM_ID, BATCH_CALL_SYSTEM_ID, CORE_REGISTRATION_SYSTEM_ID } from "./constants.sol"; +import { RegistrationSystem } from "./RegistrationSystem.sol"; +import { ACCESS_MANAGEMENT_SYSTEM_ID, BALANCE_TRANSFER_SYSTEM_ID, BATCH_CALL_SYSTEM_ID, REGISTRATION_SYSTEM_ID } from "./constants.sol"; import { Systems } from "../../codegen/tables/Systems.sol"; import { FunctionSelectors } from "../../codegen/tables/FunctionSelectors.sol"; import { FunctionSignatures } from "../../codegen/tables/FunctionSignatures.sol"; import { SystemHooks } from "../../codegen/tables/SystemHooks.sol"; import { SystemRegistry } from "../../codegen/tables/SystemRegistry.sol"; -import { CoreModuleAddress } from "../../codegen/tables/CoreModuleAddress.sol"; +import { InitModuleAddress } from "../../codegen/tables/InitModuleAddress.sol"; import { Balances } from "../../codegen/tables/Balances.sol"; import { WorldRegistrationSystem } from "./implementations/WorldRegistrationSystem.sol"; /** - * @title Core Module + * @title Init Module * @notice Registers internal World tables, systems, and their function selectors. * @dev This module only supports `installRoot` because it installs root tables, systems and function selectors. */ -contract CoreModule is Module { +contract InitModule is Module { address internal immutable accessManagementSystem; address internal immutable balanceTransferSystem; address internal immutable batchCallSystem; - address internal immutable coreRegistrationSystem; + address internal immutable registrationSystem; constructor( AccessManagementSystem _accessManagementSystem, BalanceTransferSystem _balanceTransferSystem, BatchCallSystem _batchCallSystem, - CoreRegistrationSystem _coreRegistrationSystem + RegistrationSystem _registrationSystem ) { accessManagementSystem = address(_accessManagementSystem); balanceTransferSystem = address(_balanceTransferSystem); batchCallSystem = address(_batchCallSystem); - coreRegistrationSystem = address(_coreRegistrationSystem); + registrationSystem = address(_registrationSystem); } /** @@ -92,7 +92,7 @@ contract CoreModule is Module { FunctionSignatures.register(); SystemHooks.register(); SystemRegistry.register(); - CoreModuleAddress.register(); + InitModuleAddress.register(); ResourceIds._setExists(ROOT_NAMESPACE_ID, true); NamespaceOwner._set(ROOT_NAMESPACE_ID, _msgSender()); @@ -114,7 +114,7 @@ contract CoreModule is Module { _registerSystem(accessManagementSystem, ACCESS_MANAGEMENT_SYSTEM_ID); _registerSystem(balanceTransferSystem, BALANCE_TRANSFER_SYSTEM_ID); _registerSystem(batchCallSystem, BATCH_CALL_SYSTEM_ID); - _registerSystem(coreRegistrationSystem, CORE_REGISTRATION_SYSTEM_ID); + _registerSystem(registrationSystem, REGISTRATION_SYSTEM_ID); } /** @@ -125,7 +125,7 @@ contract CoreModule is Module { WorldContextProviderLib.delegatecallWithContextOrRevert({ msgSender: _msgSender(), msgValue: 0, - target: coreRegistrationSystem, + target: registrationSystem, callData: abi.encodeCall(WorldRegistrationSystem.registerSystem, (systemId, System(target), true)) }); } @@ -164,7 +164,7 @@ contract CoreModule is Module { _registerRootFunctionSelector(BATCH_CALL_SYSTEM_ID, functionSignaturesBatchCall[i]); } - string[14] memory functionSignaturesCoreRegistration = [ + string[14] memory functionSignaturesRegistration = [ // --- ModuleInstallationSystem --- "installModule(address,bytes)", // --- StoreRegistrationSystem --- @@ -183,20 +183,20 @@ contract CoreModule is Module { "registerNamespaceDelegation(bytes32,bytes32,bytes)", "unregisterNamespaceDelegation(bytes32)" ]; - for (uint256 i = 0; i < functionSignaturesCoreRegistration.length; i++) { - _registerRootFunctionSelector(CORE_REGISTRATION_SYSTEM_ID, functionSignaturesCoreRegistration[i]); + for (uint256 i = 0; i < functionSignaturesRegistration.length; i++) { + _registerRootFunctionSelector(REGISTRATION_SYSTEM_ID, functionSignaturesRegistration[i]); } } /** * @notice Register the function selector in the World. - * @dev Uses the CoreRegistrationSystem's `registerRootFunctionSelector` to register the function selector. + * @dev Uses the RegistrationSystem's `registerRootFunctionSelector` to register the function selector. */ function _registerRootFunctionSelector(ResourceId systemId, string memory functionSignature) internal { WorldContextProviderLib.delegatecallWithContextOrRevert({ msgSender: _msgSender(), msgValue: 0, - target: coreRegistrationSystem, + target: registrationSystem, callData: abi.encodeCall( WorldRegistrationSystem.registerRootFunctionSelector, (systemId, functionSignature, bytes4(keccak256(bytes(functionSignature)))) diff --git a/packages/world/src/modules/core/LimitedCallContext.sol b/packages/world/src/modules/init/LimitedCallContext.sol similarity index 100% rename from packages/world/src/modules/core/LimitedCallContext.sol rename to packages/world/src/modules/init/LimitedCallContext.sol diff --git a/packages/world/src/modules/core/CoreRegistrationSystem.sol b/packages/world/src/modules/init/RegistrationSystem.sol similarity index 91% rename from packages/world/src/modules/core/CoreRegistrationSystem.sol rename to packages/world/src/modules/init/RegistrationSystem.sol index 52e149d7b9..ae019010a8 100644 --- a/packages/world/src/modules/core/CoreRegistrationSystem.sol +++ b/packages/world/src/modules/init/RegistrationSystem.sol @@ -8,11 +8,11 @@ import { StoreRegistrationSystem } from "./implementations/StoreRegistrationSyst import { WorldRegistrationSystem } from "./implementations/WorldRegistrationSystem.sol"; /** - * @title Core Registration System for World + * @title Registration System for World * @notice This system aggregates World registration and installation functionalities externalized from the World contract, aiming to keep the World contract's bytecode lean. * @dev Aggregates multiple system implementations for the World. */ -contract CoreRegistrationSystem is +contract RegistrationSystem is IWorldErrors, ModuleInstallationSystem, StoreRegistrationSystem, diff --git a/packages/world/src/modules/core/constants.sol b/packages/world/src/modules/init/constants.sol similarity index 93% rename from packages/world/src/modules/core/constants.sol rename to packages/world/src/modules/init/constants.sol index 26a92e10f8..e17ab3635a 100644 --- a/packages/world/src/modules/core/constants.sol +++ b/packages/world/src/modules/init/constants.sol @@ -34,6 +34,6 @@ ResourceId constant BATCH_CALL_SYSTEM_ID = ResourceId.wrap( * @dev Resource ID for core registration system. * @dev This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name. */ -ResourceId constant CORE_REGISTRATION_SYSTEM_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("CoreRegistration"))) +ResourceId constant REGISTRATION_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("Registration"))) ); diff --git a/packages/world/src/modules/core/implementations/AccessManagementSystem.sol b/packages/world/src/modules/init/implementations/AccessManagementSystem.sol similarity index 100% rename from packages/world/src/modules/core/implementations/AccessManagementSystem.sol rename to packages/world/src/modules/init/implementations/AccessManagementSystem.sol diff --git a/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol b/packages/world/src/modules/init/implementations/BalanceTransferSystem.sol similarity index 100% rename from packages/world/src/modules/core/implementations/BalanceTransferSystem.sol rename to packages/world/src/modules/init/implementations/BalanceTransferSystem.sol diff --git a/packages/world/src/modules/core/implementations/BatchCallSystem.sol b/packages/world/src/modules/init/implementations/BatchCallSystem.sol similarity index 100% rename from packages/world/src/modules/core/implementations/BatchCallSystem.sol rename to packages/world/src/modules/init/implementations/BatchCallSystem.sol diff --git a/packages/world/src/modules/core/implementations/ModuleInstallationSystem.sol b/packages/world/src/modules/init/implementations/ModuleInstallationSystem.sol similarity index 100% rename from packages/world/src/modules/core/implementations/ModuleInstallationSystem.sol rename to packages/world/src/modules/init/implementations/ModuleInstallationSystem.sol diff --git a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol b/packages/world/src/modules/init/implementations/StoreRegistrationSystem.sol similarity index 98% rename from packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol rename to packages/world/src/modules/init/implementations/StoreRegistrationSystem.sol index 3ee901b683..3c83e26259 100644 --- a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol +++ b/packages/world/src/modules/init/implementations/StoreRegistrationSystem.sol @@ -15,7 +15,7 @@ import { revertWithBytes } from "../../../revertWithBytes.sol"; import { IWorldErrors } from "../../../IWorldErrors.sol"; -import { CORE_REGISTRATION_SYSTEM_ID } from "../constants.sol"; +import { REGISTRATION_SYSTEM_ID } from "../constants.sol"; import { LimitedCallContext } from "../LimitedCallContext.sol"; import { WorldRegistrationSystem } from "./WorldRegistrationSystem.sol"; diff --git a/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol b/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol similarity index 100% rename from packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol rename to packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol diff --git a/packages/world/src/modules/core/types.sol b/packages/world/src/modules/init/types.sol similarity index 100% rename from packages/world/src/modules/core/types.sol rename to packages/world/src/modules/init/types.sol diff --git a/packages/world/test/BatchCall.t.sol b/packages/world/test/BatchCall.t.sol index 0dcee4db9f..0af2b6b434 100644 --- a/packages/world/test/BatchCall.t.sol +++ b/packages/world/test/BatchCall.t.sol @@ -13,9 +13,9 @@ import { RESOURCE_SYSTEM } from "../src/worldResourceTypes.sol"; import { IWorldErrors } from "../src/IWorldErrors.sol"; import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; -import { SystemCallData, SystemCallFromData } from "../src/modules/core/types.sol"; +import { SystemCallData, SystemCallFromData } from "../src/modules/init/types.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createWorld } from "./createWorld.sol"; address constant caller = address(1); address constant delegator = address(2); @@ -57,8 +57,7 @@ contract BatchCallTest is Test, GasReporter { ResourceId systemId = WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: namespace, name: name }); function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); world.registerNamespace(systemId.getNamespaceId()); } diff --git a/packages/world/test/Factories.t.sol b/packages/world/test/Factories.t.sol index 742d594fb1..f0e3a72e73 100644 --- a/packages/world/test/Factories.t.sol +++ b/packages/world/test/Factories.t.sol @@ -8,14 +8,14 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { WORLD_VERSION } from "../src/version.sol"; import { World } from "../src/World.sol"; import { ResourceId } from "../src/WorldResourceId.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { InitModule } from "../src/modules/init/InitModule.sol"; import { Create2Factory } from "../src/Create2Factory.sol"; import { WorldFactory } from "../src/WorldFactory.sol"; import { IWorldFactory } from "../src/IWorldFactory.sol"; import { InstalledModules } from "../src/codegen/tables/InstalledModules.sol"; import { NamespaceOwner } from "../src/codegen/tables/NamespaceOwner.sol"; import { ROOT_NAMESPACE_ID } from "../src/constants.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createInitModule } from "./createInitModule.sol"; contract FactoriesTest is Test, GasReporter { event ContractDeployed(address addr, uint256 salt); @@ -36,7 +36,7 @@ contract FactoriesTest is Test, GasReporter { Create2Factory create2Factory = new Create2Factory(); // Encode constructor arguments for WorldFactory - bytes memory encodedArguments = abi.encode(createCoreModule()); + bytes memory encodedArguments = abi.encode(createInitModule()); bytes memory combinedBytes = abi.encodePacked(type(WorldFactory).creationCode, encodedArguments); // Address we expect for deployed WorldFactory @@ -57,9 +57,9 @@ contract FactoriesTest is Test, GasReporter { function testWorldFactory(address account) public { vm.startPrank(account); - // Deploy WorldFactory with current CoreModule - CoreModule coreModule = createCoreModule(); - address worldFactoryAddress = address(new WorldFactory(coreModule)); + // Deploy WorldFactory with current InitModule + InitModule initModule = createInitModule(); + address worldFactoryAddress = address(new WorldFactory(initModule)); IWorldFactory worldFactory = IWorldFactory(worldFactoryAddress); // Address we expect for World @@ -87,7 +87,7 @@ contract FactoriesTest is Test, GasReporter { assertEq(uint256(worldFactory.worldCounts(account)), uint256(1)); // Confirm correct Core is installed - assertTrue(InstalledModules.get(address(coreModule), keccak256(new bytes(0)))); + assertTrue(InstalledModules.get(address(initModule), keccak256(new bytes(0)))); // Confirm the msg.sender is owner of the root namespace of the new world assertEq(NamespaceOwner.get(ROOT_NAMESPACE_ID), account); @@ -117,7 +117,7 @@ contract FactoriesTest is Test, GasReporter { StoreSwitch.setStoreAddress(calculatedAddress); // Confirm correct Core is installed - assertTrue(InstalledModules.get(address(coreModule), keccak256(new bytes(0)))); + assertTrue(InstalledModules.get(address(initModule), keccak256(new bytes(0)))); // Confirm the msg.sender is owner of the root namespace of the new world assertEq(NamespaceOwner.get(ROOT_NAMESPACE_ID), account); diff --git a/packages/world/test/CoreModule.t.sol b/packages/world/test/InitModule.t.sol similarity index 86% rename from packages/world/test/CoreModule.t.sol rename to packages/world/test/InitModule.t.sol index f9460e3298..a3a23eae63 100644 --- a/packages/world/test/CoreModule.t.sol +++ b/packages/world/test/InitModule.t.sol @@ -8,10 +8,10 @@ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { Tables } from "@latticexyz/store/src/codegen/index.sol"; import { WorldContextProviderLib } from "../src/WorldContext.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; +import { InitModule } from "../src/modules/init/InitModule.sol"; import { ResourceId, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createInitModule } from "./createInitModule.sol"; contract WorldMock is StoreRead { constructor() { @@ -28,12 +28,12 @@ contract WorldMock is StoreRead { } } -contract CoreModuleTest is Test { - CoreModule coreModule; +contract InitModuleTest is Test { + InitModule initModule; WorldMock worldMock; function setUp() public { - coreModule = createCoreModule(); + initModule = createInitModule(); worldMock = new WorldMock(); StoreSwitch.setStoreAddress(address(worldMock)); } @@ -43,7 +43,7 @@ contract CoreModuleTest is Test { bytes32[] memory tableIds = getTableIdsFromStoreAndWorldConfigs(); // Invoke installRoot - worldMock.delegatecallFromWorld(address(coreModule), abi.encodeCall(CoreModule.installRoot, (new bytes(0)))); + worldMock.delegatecallFromWorld(address(initModule), abi.encodeCall(InitModule.installRoot, (new bytes(0)))); // Confirm that each tableId is registered for (uint256 i; i < tableIds.length; i++) { diff --git a/packages/world/test/Utils.t.sol b/packages/world/test/Utils.t.sol index 8c46453df5..d9f2ff5c9a 100644 --- a/packages/world/test/Utils.t.sol +++ b/packages/world/test/Utils.t.sol @@ -12,7 +12,7 @@ import { RESOURCE_SYSTEM } from "../src/worldResourceTypes.sol"; import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createWorld } from "./createWorld.sol"; contract UtilsTestSystem is System { function systemNamespace() public view returns (bytes16) { @@ -27,8 +27,7 @@ contract UtilsTest is Test { error SomeError(uint256 someValue, string someString); function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); StoreSwitch.setStoreAddress(address(world)); } diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index cae2f6bf6a..2f4e5cbe02 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -35,13 +35,13 @@ import { Module, IModule } from "../src/Module.sol"; import { NamespaceOwner, NamespaceOwnerTableId } from "../src/codegen/tables/NamespaceOwner.sol"; import { ResourceAccess } from "../src/codegen/tables/ResourceAccess.sol"; -import { AccessManagementSystem } from "../src/modules/core/implementations/AccessManagementSystem.sol"; -import { BalanceTransferSystem } from "../src/modules/core/implementations/BalanceTransferSystem.sol"; -import { BatchCallSystem } from "../src/modules/core/implementations/BatchCallSystem.sol"; +import { AccessManagementSystem } from "../src/modules/init/implementations/AccessManagementSystem.sol"; +import { BalanceTransferSystem } from "../src/modules/init/implementations/BalanceTransferSystem.sol"; +import { BatchCallSystem } from "../src/modules/init/implementations/BatchCallSystem.sol"; -import { CoreModule } from "../src/modules/core/CoreModule.sol"; -import { CoreRegistrationSystem } from "../src/modules/core/CoreRegistrationSystem.sol"; -import { CORE_REGISTRATION_SYSTEM_ID } from "../src/modules/core/constants.sol"; +import { InitModule } from "../src/modules/init/InitModule.sol"; +import { RegistrationSystem } from "../src/modules/init/RegistrationSystem.sol"; +import { REGISTRATION_SYSTEM_ID } from "../src/modules/init/constants.sol"; import { Systems } from "../src/codegen/tables/Systems.sol"; import { SystemRegistry } from "../src/codegen/tables/SystemRegistry.sol"; import { FunctionSelectors } from "../src/codegen/tables/FunctionSelectors.sol"; @@ -54,7 +54,8 @@ import { Bool } from "./codegen/tables/Bool.sol"; import { TwoFields, TwoFieldsData } from "./codegen/tables/TwoFields.sol"; import { AddressArray } from "./codegen/tables/AddressArray.sol"; import { DelegationControlMock } from "./DelegationControlMock.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createWorld } from "./createWorld.sol"; +import { createInitModule } from "./createInitModule.sol"; interface IWorldTestSystem { function testNamespace__err(string memory input) external pure; @@ -174,8 +175,7 @@ contract WorldTest is Test, GasReporter { bytes32[] singletonKey; function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); StoreSwitch.setStoreAddress(address(world)); key = "testKey"; @@ -197,7 +197,7 @@ contract WorldTest is Test, GasReporter { } function testConstructorAndInitialize() public { - CoreModule coreModule = createCoreModule(); + InitModule initModule = createInitModule(); vm.expectEmit(true, true, true, true); emit HelloWorld(WORLD_VERSION); @@ -216,16 +216,14 @@ contract WorldTest is Test, GasReporter { address(0x4242) ) ); - newWorld.initialize(coreModule); + newWorld.initialize(initModule); // Expect the creator to be able to initialize the World - newWorld.initialize(coreModule); + newWorld.initialize(initModule); // Should have registered the core system function selectors - CoreRegistrationSystem coreRegistrationSystem = CoreRegistrationSystem( - Systems.getSystem(CORE_REGISTRATION_SYSTEM_ID) - ); - bytes4[22] memory coreFunctionSignatures = [ + RegistrationSystem registrationSystem = RegistrationSystem(Systems.getSystem(REGISTRATION_SYSTEM_ID)); + bytes4[22] memory funcSelectors = [ // --- AccessManagementSystem --- AccessManagementSystem.grantAccess.selector, AccessManagementSystem.revokeAccess.selector, @@ -238,26 +236,26 @@ contract WorldTest is Test, GasReporter { BatchCallSystem.batchCall.selector, BatchCallSystem.batchCallFrom.selector, // --- ModuleInstallationSystem --- - coreRegistrationSystem.installModule.selector, + registrationSystem.installModule.selector, // --- StoreRegistrationSystem --- - coreRegistrationSystem.registerTable.selector, - coreRegistrationSystem.registerStoreHook.selector, - coreRegistrationSystem.unregisterStoreHook.selector, + registrationSystem.registerTable.selector, + registrationSystem.registerStoreHook.selector, + registrationSystem.unregisterStoreHook.selector, // --- WorldRegistrationSystem --- - coreRegistrationSystem.registerNamespace.selector, - coreRegistrationSystem.registerSystemHook.selector, - coreRegistrationSystem.unregisterSystemHook.selector, - coreRegistrationSystem.registerSystem.selector, - coreRegistrationSystem.registerFunctionSelector.selector, - coreRegistrationSystem.registerRootFunctionSelector.selector, - coreRegistrationSystem.registerDelegation.selector, - coreRegistrationSystem.unregisterDelegation.selector, - coreRegistrationSystem.registerNamespaceDelegation.selector, - coreRegistrationSystem.unregisterNamespaceDelegation.selector + registrationSystem.registerNamespace.selector, + registrationSystem.registerSystemHook.selector, + registrationSystem.unregisterSystemHook.selector, + registrationSystem.registerSystem.selector, + registrationSystem.registerFunctionSelector.selector, + registrationSystem.registerRootFunctionSelector.selector, + registrationSystem.registerDelegation.selector, + registrationSystem.unregisterDelegation.selector, + registrationSystem.registerNamespaceDelegation.selector, + registrationSystem.unregisterNamespaceDelegation.selector ]; - for (uint256 i; i < coreFunctionSignatures.length; i++) { - assertEq(FunctionSelectors.getSystemFunctionSelector(coreFunctionSignatures[i]), coreFunctionSignatures[i]); + for (uint256 i; i < funcSelectors.length; i++) { + assertEq(FunctionSelectors.getSystemFunctionSelector(funcSelectors[i]), funcSelectors[i]); } // Should have registered the table data table (fka schema table) @@ -275,7 +273,7 @@ contract WorldTest is Test, GasReporter { // Expect it to not be possible to initialize the World again vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AlreadyInitialized.selector)); - newWorld.initialize(coreModule); + newWorld.initialize(initModule); } function testRegisterModuleRevertInterfaceNotSupported() public { diff --git a/packages/world/test/WorldBalance.t.sol b/packages/world/test/WorldBalance.t.sol index 1d983d4e02..bffbfaf8d9 100644 --- a/packages/world/test/WorldBalance.t.sol +++ b/packages/world/test/WorldBalance.t.sol @@ -12,7 +12,7 @@ import { ROOT_NAMESPACE, ROOT_NAMESPACE_ID } from "../src/constants.sol"; import { Balances } from "../src/codegen/tables/Balances.sol"; import { IWorldErrors } from "../src/IWorldErrors.sol"; import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "../src/worldResourceTypes.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createWorld } from "./createWorld.sol"; using WorldResourceIdInstance for ResourceId; @@ -35,8 +35,7 @@ contract WorldBalanceTest is Test, GasReporter { address public caller = address(4242); function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); StoreSwitch.setStoreAddress(address(world)); world.registerNamespace(namespaceId); diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 522f6df9e3..3dff138231 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -21,7 +21,7 @@ import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; import { AddressArray } from "./codegen/tables/AddressArray.sol"; -import { createCoreModule } from "./createCoreModule.sol"; +import { createWorld } from "./createWorld.sol"; import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; import { IWorldErrors } from "../src/IWorldErrors.sol"; @@ -46,8 +46,7 @@ contract UpdateInDynamicFieldTest is Test, GasReporter { bytes internal encodedData; function setUp() public { - world = IBaseWorld(address(new World())); - world.initialize(createCoreModule()); + world = createWorld(); StoreSwitch.setStoreAddress(address(world)); key = "testKey"; diff --git a/packages/world/test/createCoreModule.sol b/packages/world/test/createCoreModule.sol deleted file mode 100644 index ed8949758c..0000000000 --- a/packages/world/test/createCoreModule.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -import { AccessManagementSystem } from "../src/modules/core/implementations/AccessManagementSystem.sol"; -import { BalanceTransferSystem } from "../src/modules/core/implementations/BalanceTransferSystem.sol"; -import { BatchCallSystem } from "../src/modules/core/implementations/BatchCallSystem.sol"; - -import { CoreModule } from "../src/modules/core/CoreModule.sol"; -import { CoreRegistrationSystem } from "../src/modules/core/CoreRegistrationSystem.sol"; - -function createCoreModule() returns (CoreModule) { - return - new CoreModule( - new AccessManagementSystem(), - new BalanceTransferSystem(), - new BatchCallSystem(), - new CoreRegistrationSystem() - ); -} diff --git a/packages/world/test/createInitModule.sol b/packages/world/test/createInitModule.sol new file mode 100644 index 0000000000..8354584c5a --- /dev/null +++ b/packages/world/test/createInitModule.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import { AccessManagementSystem } from "../src/modules/init/implementations/AccessManagementSystem.sol"; +import { BalanceTransferSystem } from "../src/modules/init/implementations/BalanceTransferSystem.sol"; +import { BatchCallSystem } from "../src/modules/init/implementations/BatchCallSystem.sol"; + +import { InitModule } from "../src/modules/init/InitModule.sol"; +import { RegistrationSystem } from "../src/modules/init/RegistrationSystem.sol"; + +function createInitModule() returns (InitModule) { + return + new InitModule( + new AccessManagementSystem(), + new BalanceTransferSystem(), + new BatchCallSystem(), + new RegistrationSystem() + ); +} diff --git a/packages/world/test/createWorld.sol b/packages/world/test/createWorld.sol new file mode 100644 index 0000000000..8ea6314618 --- /dev/null +++ b/packages/world/test/createWorld.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import { World } from "../src/World.sol"; +import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; +import { createInitModule } from "./createInitModule.sol"; + +function createWorld() returns (IBaseWorld world) { + world = IBaseWorld(address(new World())); + world.initialize(createInitModule()); +}