Skip to content

Commit a8c404b

Browse files
authored
fix(world): support expectRevert and unusual nameless arguments in system libraries (#3680)
1 parent 2ade90f commit a8c404b

14 files changed

Lines changed: 299 additions & 51 deletions

File tree

.changeset/light-seals-sip.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@latticexyz/store": patch
3+
"@latticexyz/world-module-metadata": patch
4+
"@latticexyz/world": patch
5+
---
6+
7+
Support expectRevert and unusual nameless arguments in system libraries.

packages/store/ts/flattenStoreLogs.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ describe("flattenStoreLogs", async () => {
154154
"Store_SetRecord store__ResourceIds (0x74626d657461646174610000000000005265736f757263655461670000000000)",
155155
"Store_SetRecord store__ResourceIds (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
156156
"Store_SetRecord world__Systems (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
157-
"Store_SetRecord world__SystemRegistry (0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
158-
"Store_SetRecord world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
157+
"Store_SetRecord world__SystemRegistry (0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
158+
"Store_SetRecord world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
159159
"Store_SetRecord world__FunctionSelector (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
160160
"Store_SetRecord world__FunctionSignatur (0xc6972e9300000000000000000000000000000000000000000000000000000000)",
161161
"Store_SetRecord world__FunctionSignatur (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
@@ -165,7 +165,7 @@ describe("flattenStoreLogs", async () => {
165165
"Store_SetRecord world__FunctionSelector (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
166166
"Store_SetRecord world__FunctionSignatur (0xf128760200000000000000000000000000000000000000000000000000000000)",
167167
"Store_SetRecord world__FunctionSignatur (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
168-
"Store_SetRecord world__InstalledModules (0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
168+
"Store_SetRecord world__InstalledModules (0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
169169
"Store_SetRecord metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x6162690000000000000000000000000000000000000000000000000000000000)",
170170
"Store_SetRecord metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x776f726c64416269000000000000000000000000000000000000000000000000)",
171171
"Store_SetRecord Position (0x0000000000000000000000001d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e)",

packages/store/ts/getStoreLogs.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ describe("getStoreLogs", async () => {
172172
"Store_SetRecord world__FunctionSignatur (0x1fae630800000000000000000000000000000000000000000000000000000000)",
173173
"Store_SetRecord world__FunctionSignatur (0x1fae630800000000000000000000000000000000000000000000000000000000)",
174174
"Store_SpliceStaticData world__InstalledModules (0x00000000000000000000000051bd8d2de7017c23ee5bdc885e70dfdd0862b837,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
175-
"Store_SpliceStaticData world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3)",
175+
"Store_SpliceStaticData world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a)",
176176
"Store_SpliceStaticData store__ResourceIds (0x6e736d6574616461746100000000000000000000000000000000000000000000)",
177177
"Store_SpliceStaticData world__NamespaceOwner (0x6e736d6574616461746100000000000000000000000000000000000000000000)",
178178
"Store_SpliceStaticData world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266)",
179179
"Store_SetRecord store__Tables (0x74626d657461646174610000000000005265736f757263655461670000000000)",
180180
"Store_SpliceStaticData store__ResourceIds (0x74626d657461646174610000000000005265736f757263655461670000000000)",
181181
"Store_SpliceStaticData store__ResourceIds (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
182182
"Store_SetRecord world__Systems (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
183-
"Store_SpliceStaticData world__SystemRegistry (0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
184-
"Store_SpliceStaticData world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
183+
"Store_SpliceStaticData world__SystemRegistry (0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
184+
"Store_SpliceStaticData world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
185185
"Store_SetRecord world__FunctionSelector (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
186186
"Store_SetRecord world__FunctionSignatur (0xc6972e9300000000000000000000000000000000000000000000000000000000)",
187187
"Store_SetRecord world__FunctionSignatur (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
@@ -191,8 +191,8 @@ describe("getStoreLogs", async () => {
191191
"Store_SetRecord world__FunctionSelector (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
192192
"Store_SetRecord world__FunctionSignatur (0xf128760200000000000000000000000000000000000000000000000000000000)",
193193
"Store_SetRecord world__FunctionSignatur (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
194-
"Store_SpliceStaticData world__InstalledModules (0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
195-
"Store_DeleteRecord world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3)",
194+
"Store_SpliceStaticData world__InstalledModules (0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
195+
"Store_DeleteRecord world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a)",
196196
"Store_SpliceDynamicData metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x6162690000000000000000000000000000000000000000000000000000000000)",
197197
"Store_SpliceDynamicData metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x776f726c64416269000000000000000000000000000000000000000000000000)",
198198
"Store_SetRecord Position (0x0000000000000000000000001d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e)",

packages/world-module-metadata/gas-report.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"file": "test/MetadataModule.t.sol:MetadataModuleTest",
1010
"test": "testInstall",
1111
"name": "install metadata module",
12-
"gasUsed": 1053341
12+
"gasUsed": 1053458
1313
},
1414
{
1515
"file": "test/MetadataModule.t.sol:MetadataModuleTest",

packages/world-module-metadata/src/codegen/experimental/systems/MetadataSystemLib.sol

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

packages/world/src/codegen/experimental/systems/BatchCallSystemLib.sol

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

packages/world/src/codegen/experimental/systems/WorldRegistrationSystemLib.sol

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

packages/world/ts/node/render-solidity/renderSystemLibrary.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export function renderSystemLibrary(options: RenderSystemLibraryOptions) {
2626
const functions = functionsInput.map((func) => ({
2727
...func,
2828
// Format parameters (add auxiliary argument names, replace calldata location)
29-
parameters: formatParams(func.parameters),
29+
parameters: formatParams("__auxArg", func.parameters),
30+
returnParameters: formatParams("__auxRet", func.returnParameters),
3031
// Remove `payable` from stateMutability for library functions
3132
stateMutability: func.stateMutability.replace("payable", ""),
3233
}));
@@ -308,7 +309,10 @@ function renderAbiDecode(expression: string, returnParameters: string[]) {
308309
const returnTypes = returnParameters.map((param) => param.split(" ")[0]).join(", ");
309310
return `
310311
bytes memory result = ${expression};
311-
return abi.decode(result, (${returnTypes}));
312+
// skip decoding an empty result, which can happen after expectRevert
313+
if (result.length != 0) {
314+
return abi.decode(result, (${returnTypes}));
315+
}
312316
`;
313317
}
314318

@@ -318,15 +322,15 @@ function renderReturnParameters(returnParameters: string[]) {
318322
return `returns (${renderArguments(returnParameters)})`;
319323
}
320324

321-
function formatParams(params: string[]) {
325+
function formatParams(auxPrefix: string, params: string[]) {
322326
// Use auxiliary argument names for arguments without names
323327
let auxCount = 0;
324328

325329
return params
326-
.map((arg) => arg.replace(/ calldata /, " memory "))
330+
.map((arg) => arg.replace(/ calldata( |$)/, " memory$1"))
327331
.map((arg) => {
328332
const items = arg.split(" ");
329-
const needsAux = items.length === 1 || (items.length === 2 && items[1] === "memory");
330-
return needsAux ? `${arg} __aux${auxCount++}` : arg;
333+
const needsAux = items.length === 1 || (items.length === 2 && ["memory", "payable"].includes(items[1]));
334+
return needsAux ? `${arg} ${auxPrefix}${auxCount++}` : arg;
331335
});
332336
}

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

Lines changed: 11 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/namespaces/a/ASystem.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ contract ASystem is System {
4545
return addr;
4646
}
4747

48+
function setWithNamelessParameters(
49+
address payable,
50+
bytes calldata b,
51+
bytes calldata,
52+
string[] memory
53+
) external returns (address payable, bytes calldata, string[] memory) {
54+
address addr = _msgSender();
55+
AddressValue.set(addr);
56+
return (payable(addr), b, new string[](0));
57+
}
58+
59+
function getValueWithRevert() external pure returns (uint256) {
60+
revert("reverted successfully");
61+
}
62+
63+
function setAddressWithRevert() external returns (address) {
64+
address addr = _msgSender();
65+
AddressValue.set(addr);
66+
revert("reverted successfully");
67+
}
68+
4869
function setValuesStaticArray(uint256[1] memory values) external {
4970
Value.set(values[0]);
5071
}

0 commit comments

Comments
 (0)