Skip to content

Commit

Permalink
Fix libraries test
Browse files Browse the repository at this point in the history
  • Loading branch information
vdrg committed Dec 12, 2024
1 parent 25731d2 commit b2cf1c7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion test/system-libraries/src/codegen/world/IBSystem.sol

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

4 changes: 3 additions & 1 deletion test/system-libraries/src/codegen/world/IRootSystem.sol

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

4 changes: 2 additions & 2 deletions test/system-libraries/src/namespaces/b/BSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ASystemThing } from "../a/ASystemTypes.sol";
import { aSystem } from "../a/codegen/systems/ASystemLib.sol";

contract BSystem is System {
function setValueInA(ASystemThing memory value) external {
aSystem.setValue(value);
function setValueInA(ASystemThing memory thing) external {
aSystem.setValue(thing);
}

function getValueFromA() external view returns (uint256) {
Expand Down

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

6 changes: 3 additions & 3 deletions test/system-libraries/src/namespaces/root/RootSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity >=0.8.28;

import { System } from "@latticexyz/world/src/System.sol";
import { aSystem } from "../a/codegen/systems/ASystemLib.sol";
import { aSystem, ASystemThing } from "../a/codegen/systems/ASystemLib.sol";

contract RootSystem is System {
function setValueInA(uint256 value) external {
aSystem.callAsRoot().setValue(value);
function setValueInA(ASystemThing memory thing) external {
aSystem.callAsRoot().setValue(thing);
}

function getValueFromA() external view returns (uint256) {
Expand Down

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

11 changes: 7 additions & 4 deletions test/system-libraries/test/Libraries.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { SYSTEMBOUND_DELEGATION } from "@latticexyz/world-modules/src/modules/st

import { Value } from "../src/namespaces/a/codegen/tables/Value.sol";
import { AddressValue } from "../src/namespaces/a/codegen/tables/AddressValue.sol";
import { aSystem } from "../src/namespaces/a/codegen/systems/ASystemLib.sol";
import { aSystem, ASystemThing } from "../src/namespaces/a/codegen/systems/ASystemLib.sol";
import { bSystem } from "../src/namespaces/b/codegen/systems/BSystemLib.sol";
import { rootSystem } from "../src/namespaces/root/codegen/systems/RootSystemLib.sol";

Expand All @@ -26,14 +26,16 @@ contract LibrariesTest is MudTest {

function testCanCallSystemWithLibrary() public {
uint256 value = 0xDEADBEEF;
aSystem.setValue(value);
ASystemThing memory thing = ASystemThing(value);
aSystem.setValue(thing);
assertEq(Value.get(), value);
assertEq(aSystem.getValue(), value);
}

function testCanCallSystemFromOtherSystem() public {
uint256 value = 0xDEADBEEF;
bSystem.setValueInA(value);
ASystemThing memory thing = ASystemThing(value);
bSystem.setValueInA(thing);
assertEq(Value.get(), value);
assertEq(bSystem.getValueFromA(), value);
}
Expand All @@ -56,8 +58,9 @@ contract LibrariesTest is MudTest {

function testCanCallFromRootSystemWithLibrary() public {
uint256 value = 0xDEADBEEF;
ASystemThing memory thing = ASystemThing(value);
// internally, rootSystem uses callAsRoot to call aSystem
rootSystem.setValueInA(value);
rootSystem.setValueInA(thing);
assertEq(Value.get(), value);
assertEq(aSystem.getValue(), value);
assertEq(rootSystem.getValueFromA(), value);
Expand Down

0 comments on commit b2cf1c7

Please sign in to comment.