-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): user types and route/path separation (#454)
--------- Co-authored-by: alvarius <89248902+alvrs@users.noreply.github.com>
- Loading branch information
Showing
34 changed files
with
1,044 additions
and
132 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
/* Autogenerated file. Do not edit manually. */ | ||
|
||
enum Enum1 { | ||
E1, | ||
E2, | ||
E3 | ||
} | ||
|
||
enum Enum2 { | ||
E1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import {StoreView} from "@latticexyz/store/src/StoreView.sol"; | ||
import {Table1, Table1Data} from "../src/tables/Table1.sol"; | ||
import {Enum1, Enum2} from "../src/types.sol"; | ||
|
||
contract TablegenTest is Test, StoreView { | ||
function testTable1SetAndGet() public { | ||
Table1.registerSchema(); | ||
|
||
uint256 k1 = 1; | ||
int32 k2 = -1; | ||
bytes16 k3 = hex"02"; | ||
address k4 = address(123); | ||
bool k5 = true; | ||
Enum1 k6 = Enum1.E3; | ||
Enum2 k7 = Enum2.E1; | ||
|
||
Table1.setV1(k1, k2, k3, k4, k5, k6, k7, 4); | ||
assertEq(Table1.getV1(k1, k2, k3, k4, k5, k6, k7), 4); | ||
|
||
Table1Data memory data = Table1Data(4, -5, hex"06", address(456), false, Enum1.E2, Enum2.E1); | ||
Table1.set(k1, k2, k3, k4, k5, k6, k7, data); | ||
assertEq(abi.encode(Table1.get(k1, k2, k3, k4, k5, k6, k7)), abi.encode(data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { SchemaType } from "@latticexyz/schema-type"; | ||
import { parseStoreConfig, StoreUserConfig } from "../src/config/index.js"; | ||
import { tablegen } from "../src/render-solidity/tablegen.js"; | ||
import { logError } from "../src/utils/errors.js"; | ||
import { getSrcDirectory } from "../src/utils/foundry.js"; | ||
|
||
// This config is used only for tests | ||
const config: StoreUserConfig = { | ||
tables: { | ||
Table1: { | ||
primaryKeys: { | ||
k1: SchemaType.UINT256, | ||
k2: SchemaType.INT32, | ||
k3: SchemaType.BYTES16, | ||
k4: SchemaType.ADDRESS, | ||
k5: SchemaType.BOOL, | ||
k6: "Enum1", | ||
k7: "Enum2", | ||
}, | ||
schema: { | ||
v1: SchemaType.UINT256, | ||
v2: SchemaType.INT32, | ||
v3: SchemaType.BYTES16, | ||
v4: SchemaType.ADDRESS, | ||
v5: SchemaType.BOOL, | ||
v6: "Enum1", | ||
v7: "Enum2", | ||
}, | ||
}, | ||
}, | ||
|
||
userTypes: { | ||
enums: { | ||
Enum1: ["E1", "E2", "E3"], | ||
Enum2: ["E1"], | ||
}, | ||
}, | ||
}; | ||
|
||
// Aside from avoiding `mud.config.mts` in cli package (could cause issues), | ||
// this also tests that tablegen can work as a standalone function | ||
const parsedConfig = await (async () => { | ||
try { | ||
return await parseStoreConfig(config); | ||
} catch (error: unknown) { | ||
logError(error); | ||
} | ||
})(); | ||
|
||
const srcDirectory = await getSrcDirectory(); | ||
if (parsedConfig !== undefined) { | ||
tablegen(parsedConfig, srcDirectory); | ||
} else { | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.