Skip to content

Commit

Permalink
Merge branch 'main' into holic/sync-indexer-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Dec 1, 2023
2 parents f1886bc + 6bae338 commit 74921c7
Show file tree
Hide file tree
Showing 25 changed files with 317 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-baboons-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/store": patch
"@latticexyz/world": patch
---

Fixed an issue where `mud.config.ts` source file was not included in the package, causing TS errors downstream.
5 changes: 5 additions & 0 deletions .changeset/mighty-years-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-mud": patch
---

Templates now correctly include their respective `.gitignore` files
5 changes: 5 additions & 0 deletions .changeset/odd-bags-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Deploys will now always rebuild `IWorld.sol` interface (a workaround for https://github.com/foundry-rs/foundry/issues/6241)
5 changes: 5 additions & 0 deletions .changeset/tasty-balloons-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/react": patch
---

Fixed an issue where `useComponentValue` would not detect a change and re-render if the component value was immediately removed.
5 changes: 5 additions & 0 deletions .changeset/thick-masks-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Fixed invalid value when decoding records in `postgres-decoded` storage adapter
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ MUD is MIT-licensed, open source and free to use.
## Quickstart

```
pnpm create mud@canary my-project
pnpm create mud@next my-project
```

For more information on how to get started, have a look at the [MUD documentation](https://mud.dev/quick-start).
Expand Down
26 changes: 25 additions & 1 deletion packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { privateKeyToAccount } from "viem/accounts";
import { loadConfig } from "@latticexyz/config/node";
import { StoreConfig } from "@latticexyz/store";
import { WorldConfig } from "@latticexyz/world";
import { forge, getOutDirectory, getRemappings, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
import {
forge,
getForgeConfig,
getOutDirectory,
getRemappings,
getRpcUrl,
getSrcDirectory,
} from "@latticexyz/common/foundry";
import chalk from "chalk";
import { execa } from "execa";
import { MUDError } from "@latticexyz/common/errors";
Expand All @@ -18,6 +25,9 @@ import { WorldDeploy } from "./deploy/common";
import { tablegen } from "@latticexyz/store/codegen";
import { worldgen } from "@latticexyz/world/node";
import { getExistingContracts } from "./utils/getExistingContracts";
import { debug as parentDebug } from "./debug";

const debug = parentDebug.extend("runDeploy");

export const deployOptions = {
configPath: { type: "string", desc: "Path to the config file" },
Expand Down Expand Up @@ -63,6 +73,20 @@ export async function runDeploy(opts: DeployOptions): Promise<WorldDeploy> {
if (!opts.skipBuild) {
const outPath = path.join(srcDir, config.codegenDirectory);
await Promise.all([tablegen(config, outPath, remappings), worldgen(config, getExistingContracts(srcDir), outPath)]);

// TODO remove when https://github.com/foundry-rs/foundry/issues/6241 is resolved
const forgeConfig = await getForgeConfig(profile);
if (forgeConfig.cache) {
const cacheFilePath = path.join(forgeConfig.cache_path, "solidity-files-cache.json");
if (existsSync(cacheFilePath)) {
debug("Unsetting cached content hash of IWorld.sol to force it to regenerate");
const solidityFilesCache = JSON.parse(readFileSync(cacheFilePath, "utf8"));
const worldInterfacePath = path.join(outPath, "world", "IWorld.sol");
solidityFilesCache["files"][worldInterfacePath]["contentHash"] = "";
writeFileSync(cacheFilePath, JSON.stringify(solidityFilesCache, null, 2));
}
}

await forge(["build"], { profile });
await execa("mud", ["abi-ts"], { stdio: "inherit" });
}
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/foundry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface ForgeConfig {
script: string;
out: string;
libs: string[];
cache: boolean;
cache_path: string;
eth_rpc_url: string | null;

// compiler
Expand Down
9 changes: 9 additions & 0 deletions packages/create-mud/scripts/copy-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ if grep -r -E 'link:' ./dist/templates; then
echo "Linked dependencies found in dist/templates"
exit 1
fi

# Since npm-packlist does not include ".gitignore" files in the packaging process,
# these files are renamed to "gitignore".
# create-create-app automatically renames them back to ".gitignore" upon execution.
find ./dist/templates/* -name ".gitignore" -type f | while read -r file; do
newfile="$(dirname "$file")/gitignore"
echo "Renaming $file to $newfile"
mv "$file" "$newfile"
done
2 changes: 2 additions & 0 deletions packages/faucet/bin/faucet-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ const faucetAccount = privateKeyToAccount(env.FAUCET_PRIVATE_KEY);
// @see https://fastify.dev/docs/latest/
const server = fastify({
maxParamLength: 5000,
logger: true,
});

await server.register(import("@fastify/compress"));
await server.register(import("@fastify/cors"));

// k8s healthchecks
Expand Down
1 change: 1 addition & 0 deletions packages/faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@fastify/compress": "^6.5.0",
"@fastify/cors": "^8.3.0",
"@trpc/client": "10.34.0",
"@trpc/server": "10.34.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"clean": "pnpm run clean:js",
"clean:js": "rimraf dist",
"dev": "tsup --watch",
"test": "tsc --noEmit && vitest --run",
"test:ci": "pnpm run test"
"test": "tsc --noEmit && vitest",
"test:ci": "tsc --noEmit && vitest --run"
},
"dependencies": {
"@latticexyz/recs": "workspace:*",
Expand Down
22 changes: 22 additions & 0 deletions packages/react/src/useComponentValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe("useComponentValue", () => {
removeComponent(Position, entity);
});
expect(result.current).toBe(undefined);

act(() => {
setComponent(Position, entity, { x: 0, y: 0 });
});
expect(result.current).toEqual({ x: 0, y: 0 });
});

it("should re-render only when Position changes for entity", () => {
Expand Down Expand Up @@ -70,6 +75,23 @@ describe("useComponentValue", () => {
expect(result.current).toBe(undefined);
});

it("should re-render when Position is removed", () => {
const entity = createEntity(world, [withValue(Position, { x: 1, y: 1 })]);

const { result } = renderHook(() => useComponentValue(Position, entity));
expect(result.current).toEqual({ x: 1, y: 1 });

act(() => {
removeComponent(Position, entity);
});
expect(result.current).toBe(undefined);

act(() => {
setComponent(Position, entity, { x: 0, y: 0 });
});
expect(result.current).toEqual({ x: 0, y: 0 });
});

it("should return default value when Position is not set", () => {
const entity = createEntity(world);

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/useComponentValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useComponentValue<S extends Schema>(
setValue(entity != null ? getComponentValue(component, entity) : undefined);
if (entity == null) return;

const queryResult = defineQuery([Has(component)], { runOnInit: false });
const queryResult = defineQuery([Has(component)], { runOnInit: true });
const subscription = queryResult.update$.subscribe((update) => {
if (isComponentUpdate(update, component) && update.entity === entity) {
const [nextValue] = update.value;
Expand Down
2 changes: 2 additions & 0 deletions packages/store-indexer/bin/postgres-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ const database = drizzle(postgres(env.DATABASE_URL));
// @see https://fastify.dev/docs/latest/
const server = fastify({
maxParamLength: 5000,
logger: true,
});

await server.register(import("@fastify/compress"));
await server.register(import("@fastify/cors"));

// k8s healthchecks
Expand Down
1 change: 1 addition & 0 deletions packages/store-indexer/bin/sqlite-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const server = fastify({
maxParamLength: 5000,
});

await server.register(import("@fastify/compress"));
await server.register(import("@fastify/cors"));

// k8s healthchecks
Expand Down
1 change: 1 addition & 0 deletions packages/store-indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@fastify/compress": "^6.5.0",
"@fastify/cors": "^8.3.0",
"@latticexyz/block-logs-stream": "workspace:*",
"@latticexyz/common": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ describe("createStorageAdapter", async () => {
"__keyBytes": "0x",
"__lastUpdatedBlockNumber": 12n,
"value": [
0,
0,
420,
69,
],
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function createStorageAdapter<TConfig extends StoreConfig = StoreCo
const value = decodeValueArgs(table.valueSchema, {
staticData: record.staticData ?? "0x",
encodedLengths: record.encodedLengths ?? "0x",
dynamicData: record.encodedLengths ?? "0x",
dynamicData: record.dynamicData ?? "0x",
});

debug("upserting record", {
Expand Down
1 change: 1 addition & 0 deletions packages/store/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!out/**/*.abi.json.d.ts
!src/**
!ts/**
!mud.config.ts
!package.json
!README.md
!dist/**
42 changes: 42 additions & 0 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@
"name": "transferFrom",
"gasUsed": 130250
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveAllGas",
"name": "setApprovalForAll",
"gasUsed": 113956
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveGas",
"name": "approve",
"gasUsed": 87965
},
{
"file": "test/ERC721.t.sol",
"test": "testBurnGas",
"name": "burn",
"gasUsed": 101835
},
{
"file": "test/ERC721.t.sol",
"test": "testMintGas",
"name": "mint",
"gasUsed": 169433
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeMintToEOAGas",
"name": "safeMint",
"gasUsed": 169704
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeTransferFromToEOAGas",
"name": "safeTransferFrom",
"gasUsed": 143638
},
{
"file": "test/ERC721.t.sol",
"test": "testTransferFromGas",
"name": "transferFrom",
"gasUsed": 136798
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
Expand Down
47 changes: 47 additions & 0 deletions packages/world-modules/test/ERC721.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
vm.assume(owner != address(0));

_expectMintEvent(owner, id);
startGasReport("mint");
token.mint(owner, id);
endGasReport();

assertEq(token.balanceOf(owner), 1);
assertEq(token.ownerOf(id), owner);
Expand All @@ -182,7 +184,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
assertEq(token.balanceOf(owner), 1, "after mint");

_expectBurnEvent(owner, id);
startGasReport("burn");
token.burn(id);
endGasReport();

assertEq(token.balanceOf(owner), 0, "after burn");

Expand All @@ -207,7 +211,10 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
token.mint(owner, tokenId);

vm.prank(owner);

startGasReport("transferFrom");
token.transferFrom(owner, to, tokenId);
endGasReport();

assertEq(token.balanceOf(owner), 0);
assertEq(token.balanceOf(to), 1);
Expand All @@ -221,7 +228,11 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {

vm.prank(owner);
_expectApprovalEvent(owner, spender, id);

startGasReport("approve");
token.approve(spender, id);
endGasReport();

assertEq(token.getApproved(id), spender);
}

Expand All @@ -230,7 +241,11 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {

vm.prank(owner);
_expectApprovalForAllEvent(owner, operator, approved);

startGasReport("setApprovalForAll");
token.setApprovalForAll(operator, approved);
endGasReport();

assertEq(token.isApprovedForAll(owner, operator), approved);
}

Expand Down Expand Up @@ -276,7 +291,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
token.setApprovalForAll(operator, true);

vm.prank(operator);
startGasReport("safeTransferFrom");
token.safeTransferFrom(from, to, id);
endGasReport();

assertEq(token.getApproved(id), address(0));
assertEq(token.ownerOf(id), to);
Expand Down Expand Up @@ -340,7 +357,9 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
_assumeEOA(to);
vm.assume(to != address(0));

startGasReport("safeMint");
token.safeMint(to, id);
endGasReport();

assertEq(token.ownerOf(id), to);
assertEq(token.balanceOf(to), 1);
Expand Down Expand Up @@ -577,4 +596,32 @@ contract ERC721Test is Test, GasReporter, IERC721Events, IERC721Errors {
vm.expectRevert(abi.encodeWithSelector(ERC721NonexistentToken.selector, id));
token.ownerOf(id);
}

function testMintGas() public {
testMint(1e18, address(0xABCD));
}

function testBurnGas() public {
testBurn(1e18, address(0xABCD));
}

function testTransferFromGas() public {
testTransferFrom(address(0xABCD), address(0xBEEF), 1e18);
}

function testApproveGas() public {
testApprove(address(0xABCD), 1e18, address(0xBEEF));
}

function testApproveAllGas() public {
testApproveAll(address(0xABCD), address(0xBEEF), true);
}

function testSafeTransferFromToEOAGas() public {
testSafeTransferFromToEOA(1, address(0xABCD), address(0xBEEF), address(0xDEFE));
}

function testSafeMintToEOAGas() public {
testSafeMintToEOA(1, address(0xABCD));
}
}

0 comments on commit 74921c7

Please sign in to comment.