Skip to content

Commit ab837ce

Browse files
authored
fix(cli): don't deploy abstract contracts (#3669)
1 parent 03af917 commit ab837ce

12 files changed

Lines changed: 292 additions & 5 deletions

File tree

.changeset/thin-bees-hug.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@latticexyz/cli": patch
3+
"@latticexyz/common": patch
4+
---
5+
6+
CLI will no longer deploy abstract systems and contracts without bytecode.

packages/cli/src/deploy/resolveConfig.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { loadSystemsManifest, resolveSystems } from "@latticexyz/world/node";
33
import { Library, System, WorldFunction } from "./common";
44
import { Hex, isHex, toFunctionSelector, toFunctionSignature } from "viem";
55
import { getContractData } from "../utils/getContractData";
6-
import { groupBy } from "@latticexyz/common/utils";
6+
import { groupBy, isDefined } from "@latticexyz/common/utils";
77
import { findLibraries } from "./findLibraries";
88
import { createPrepareDeploy } from "./createPrepareDeploy";
99
import { World } from "@latticexyz/world";
1010
import { findUp } from "find-up";
1111
import { createRequire } from "node:module";
1212
import { excludeCallWithSignatureModule } from "./compat/excludeUnstableCallWithSignatureModule";
13+
import { debug } from "./debug";
1314

1415
// TODO: replace this with a manifest/combined config output
1516

@@ -63,7 +64,7 @@ export async function resolveConfig({
6364

6465
const systems = configSystems
6566
.filter((system) => !system.deploy.disabled)
66-
.map((system): System => {
67+
.map((system): System | undefined => {
6768
const manifest = systemsManifest.systems.find(({ systemId }) => systemId === system.systemId);
6869
if (!manifest) {
6970
throw new Error(
@@ -72,6 +73,11 @@ export async function resolveConfig({
7273
}
7374

7475
const contractData = getContractData(`${system.label}.sol`, system.label, forgeOutDir);
76+
if (!contractData.deployedBytecodeSize) {
77+
// abstract contracts have no bytecode
78+
debug(`skipping ${system.label} system with no bytecode`);
79+
return;
80+
}
7581

7682
// TODO: replace this with manifest
7783
const worldFunctions = system.deploy.registerWorldFunctions
@@ -115,7 +121,8 @@ export async function resolveConfig({
115121
worldAbi: manifest.worldAbi,
116122
},
117123
};
118-
});
124+
})
125+
.filter(isDefined);
119126

120127
// Check for overlapping system IDs (since names get truncated when turning into IDs)
121128
// TODO: move this into the world config resolve step once it resolves system IDs

packages/common/src/deploy/ensureContract.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export async function ensureContract({
3535
}
3636

3737
if (deployedBytecodeSize != null) {
38+
if (deployedBytecodeSize === 0) {
39+
throw new Error(`Empty bytecode for ${debugLabel}`);
40+
}
41+
3842
if (deployedBytecodeSize > contractSizeLimit) {
3943
console.warn(
4044
`\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n`,

packages/world/ts/node/getSystemContracts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export async function getSystemContracts({
2727

2828
const files = await Promise.all(
2929
filePaths.map(async (file) => {
30-
console.log("reading source for", file.filename);
3130
const source = await fs.readFile(path.join(rootDir, file.filename), "utf-8");
3231
return { ...file, source };
3332
}),

test/system-libraries/src/codegen/world/ISomeAbstractProgram.sol

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/system-libraries/src/codegen/world/ISomeProgram.sol

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/system-libraries/src/codegen/world/IWorld.sol

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.28;
3+
4+
import { System } from "@latticexyz/world/src/System.sol";
5+
6+
abstract contract SomeAbstractProgram is System {
7+
function abstractExecute() public {}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.8.28;
3+
4+
import { System } from "@latticexyz/world/src/System.sol";
5+
6+
contract SomeProgram is System {
7+
function execute() public {}
8+
}

test/system-libraries/src/namespaces/root/codegen/systems/SomeAbstractProgramLib.sol

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)