Skip to content

fix(world): support expectRevert and unusual nameless arguments in system libraries #3680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/light-seals-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@latticexyz/store": patch
"@latticexyz/world-module-metadata": patch
"@latticexyz/world": patch
---

Support expectRevert and unusual nameless arguments in system libraries.
6 changes: 3 additions & 3 deletions packages/store/ts/flattenStoreLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ describe("flattenStoreLogs", async () => {
"Store_SetRecord store__ResourceIds (0x74626d657461646174610000000000005265736f757263655461670000000000)",
"Store_SetRecord store__ResourceIds (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
"Store_SetRecord world__Systems (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
"Store_SetRecord world__SystemRegistry (0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
"Store_SetRecord world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
"Store_SetRecord world__SystemRegistry (0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
"Store_SetRecord world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
"Store_SetRecord world__FunctionSelector (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0xc6972e9300000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
Expand All @@ -165,7 +165,7 @@ describe("flattenStoreLogs", async () => {
"Store_SetRecord world__FunctionSelector (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0xf128760200000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__InstalledModules (0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
"Store_SetRecord world__InstalledModules (0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
"Store_SetRecord metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x6162690000000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x776f726c64416269000000000000000000000000000000000000000000000000)",
"Store_SetRecord Position (0x0000000000000000000000001d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e)",
Expand Down
10 changes: 5 additions & 5 deletions packages/store/ts/getStoreLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ describe("getStoreLogs", async () => {
"Store_SetRecord world__FunctionSignatur (0x1fae630800000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0x1fae630800000000000000000000000000000000000000000000000000000000)",
"Store_SpliceStaticData world__InstalledModules (0x00000000000000000000000051bd8d2de7017c23ee5bdc885e70dfdd0862b837,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
"Store_SpliceStaticData world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3)",
"Store_SpliceStaticData world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a)",
"Store_SpliceStaticData store__ResourceIds (0x6e736d6574616461746100000000000000000000000000000000000000000000)",
"Store_SpliceStaticData world__NamespaceOwner (0x6e736d6574616461746100000000000000000000000000000000000000000000)",
"Store_SpliceStaticData world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266)",
"Store_SetRecord store__Tables (0x74626d657461646174610000000000005265736f757263655461670000000000)",
"Store_SpliceStaticData store__ResourceIds (0x74626d657461646174610000000000005265736f757263655461670000000000)",
"Store_SpliceStaticData store__ResourceIds (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
"Store_SetRecord world__Systems (0x73796d657461646174610000000000004d6574616461746153797374656d0000)",
"Store_SpliceStaticData world__SystemRegistry (0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
"Store_SpliceStaticData world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x000000000000000000000000bdb70930001e32533d1adfa3b008962112f5ff95)",
"Store_SpliceStaticData world__SystemRegistry (0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
"Store_SpliceStaticData world__ResourceAccess (0x6e736d6574616461746100000000000000000000000000000000000000000000,0x00000000000000000000000080c073931547e92d858c7556a7b711f161354d29)",
"Store_SetRecord world__FunctionSelector (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0xc6972e9300000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0xff66f05f00000000000000000000000000000000000000000000000000000000)",
Expand All @@ -191,8 +191,8 @@ describe("getStoreLogs", async () => {
"Store_SetRecord world__FunctionSelector (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0xf128760200000000000000000000000000000000000000000000000000000000)",
"Store_SetRecord world__FunctionSignatur (0x5ce7ca1a00000000000000000000000000000000000000000000000000000000)",
"Store_SpliceStaticData world__InstalledModules (0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
"Store_DeleteRecord world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000003604b87ecb7dfcc5ff9ee26763a5704e57377fe3)",
"Store_SpliceStaticData world__InstalledModules (0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a,0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)",
"Store_DeleteRecord world__UserDelegationCo (0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x00000000000000000000000086bf82828d798a6a795087a2a6190ba451a16d3a)",
"Store_SpliceDynamicData metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x6162690000000000000000000000000000000000000000000000000000000000)",
"Store_SpliceDynamicData metadata__ResourceTag (0x737900000000000000000000000000004d6f766553797374656d000000000000,0x776f726c64416269000000000000000000000000000000000000000000000000)",
"Store_SetRecord Position (0x0000000000000000000000001d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e)",
Expand Down
2 changes: 1 addition & 1 deletion packages/world-module-metadata/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"file": "test/MetadataModule.t.sol:MetadataModuleTest",
"test": "testInstall",
"name": "install metadata module",
"gasUsed": 1053341
"gasUsed": 1053458
},
{
"file": "test/MetadataModule.t.sol:MetadataModuleTest",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions packages/world/ts/node/render-solidity/renderSystemLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function renderSystemLibrary(options: RenderSystemLibraryOptions) {
const functions = functionsInput.map((func) => ({
...func,
// Format parameters (add auxiliary argument names, replace calldata location)
parameters: formatParams(func.parameters),
parameters: formatParams("__auxArg", func.parameters),
returnParameters: formatParams("__auxRet", func.returnParameters),
// Remove `payable` from stateMutability for library functions
stateMutability: func.stateMutability.replace("payable", ""),
}));
Expand Down Expand Up @@ -308,7 +309,10 @@ function renderAbiDecode(expression: string, returnParameters: string[]) {
const returnTypes = returnParameters.map((param) => param.split(" ")[0]).join(", ");
return `
bytes memory result = ${expression};
return abi.decode(result, (${returnTypes}));
// skip decoding an empty result, which can happen after expectRevert
if (result.length != 0) {
return abi.decode(result, (${returnTypes}));
}
`;
}

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

function formatParams(params: string[]) {
function formatParams(auxPrefix: string, params: string[]) {
// Use auxiliary argument names for arguments without names
let auxCount = 0;

return params
.map((arg) => arg.replace(/ calldata /, " memory "))
.map((arg) => arg.replace(/ calldata( |$)/, " memory$1"))
.map((arg) => {
const items = arg.split(" ");
const needsAux = items.length === 1 || (items.length === 2 && items[1] === "memory");
return needsAux ? `${arg} __aux${auxCount++}` : arg;
const needsAux = items.length === 1 || (items.length === 2 && ["memory", "payable"].includes(items[1]));
return needsAux ? `${arg} ${auxPrefix}${auxCount++}` : arg;
});
}
11 changes: 11 additions & 0 deletions test/system-libraries/src/codegen/world/IASystem.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/system-libraries/src/namespaces/a/ASystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ contract ASystem is System {
return addr;
}

function setWithNamelessParameters(
address payable,
bytes calldata b,
bytes calldata,
string[] memory
) external returns (address payable, bytes calldata, string[] memory) {
address addr = _msgSender();
AddressValue.set(addr);
return (payable(addr), b, new string[](0));
}

function getValueWithRevert() external pure returns (uint256) {
revert("reverted successfully");
}

function setAddressWithRevert() external returns (address) {
address addr = _msgSender();
AddressValue.set(addr);
revert("reverted successfully");
}

function setValuesStaticArray(uint256[1] memory values) external {
Value.set(values[0]);
}
Expand Down
Loading
Loading