Skip to content

Commit

Permalink
fix: add test case for an array function argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Kooshaba committed Dec 20, 2024
1 parent 6d4cbec commit 6aaed39
Show file tree
Hide file tree
Showing 9 changed files with 477 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ function renderFunctionInterface(contractFunction: ContractInterfaceFunction) {

function functionInterfaceName(contractFunction: ContractInterfaceFunction) {
const { name, parameters } = contractFunction;
const paramTypes = parameters.map((param) => param.split(" ")[0]).join("_");
const paramTypes = parameters
.map((param) => param.split(" ")[0])
.map((type) => type.replace("[]", "Array"))
.join("_");
return `_I${name}${paramTypes.length === 0 ? "" : `_${paramTypes}`}`;
}

Expand Down
8 changes: 8 additions & 0 deletions test/system-libraries/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export default defineWorld({
},
key: [],
},
PositionValue: {
schema: {
x: "uint256",
y: "uint256",
z: "uint256",
},
key: [],
},
},
},
b: {},
Expand Down
8 changes: 7 additions & 1 deletion 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.

17 changes: 16 additions & 1 deletion test/system-libraries/src/namespaces/a/ASystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ pragma solidity >=0.8.28;

import { System } from "@latticexyz/world/src/System.sol";
import { Value } from "./codegen/tables/Value.sol";
import { PositionValue } from "./codegen/tables/PositionValue.sol";
import { AddressValue } from "./codegen/tables/AddressValue.sol";
import { ASystemThing } from "./ASystemTypes.sol";
import { ASystemThing, Position } from "./ASystemTypes.sol";

contract ASystem is System {
function setValue(ASystemThing memory value) external {
Expand All @@ -15,6 +16,20 @@ contract ASystem is System {
Value.set(value);
}

function setPosition(Position memory position) external {
PositionValue.set(position.x, position.y, position.z);
}

function setPosition(uint256 x, uint256 y, uint256 z) external {
PositionValue.set(x, y, z);
}

function setPositions(Position[] memory positions) external {
for (uint256 i = 0; i < positions.length; i++) {
PositionValue.set(positions[i].x, positions[i].y, positions[i].z);
}
}

function getValue() external view returns (uint256) {
return Value.get();
}
Expand Down
6 changes: 6 additions & 0 deletions test/system-libraries/src/namespaces/a/ASystemTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ pragma solidity >=0.8.28;
struct ASystemThing {
uint256 a;
}

struct Position {
uint256 x;
uint256 y;
uint256 z;
}
1 change: 1 addition & 0 deletions test/system-libraries/src/namespaces/a/codegen/index.sol

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.

Loading

0 comments on commit 6aaed39

Please sign in to comment.