From 66cc35a8ccb21c50a1882d6c741dd045acd8bc11 Mon Sep 17 00:00:00 2001 From: dk1a Date: Wed, 12 Jul 2023 15:30:01 +0300 Subject: [PATCH] feat(gas-report): create package, move relevant files to it (#1147) * feat(gas-reporter): create package, move relevant files to it * make gas-report a default command for mud-gas-report * refactor(store): use gas-reporter * refactor(world): use gas-reporter * rename gas-reporter to gas-report * use GasReporter in testEncodeDecodeSchema * actions: install again after build * gas-report readme * Create quick-numbers-flash.md * update playwright * Revert "update playwright" This reverts commit c9f0d4b9c6b6411f93c69f3e7002a34a529887d5. --- .changeset/quick-numbers-flash.md | 7 ++ .github/actions/build/action.yml | 4 + packages/cli/package.json | 3 +- packages/cli/src/commands/index.ts | 5 +- packages/gas-report/.gitignore | 11 +++ packages/gas-report/.npmignore | 9 +++ packages/gas-report/.solhint.json | 8 ++ packages/gas-report/CHANGELOG.md | 4 + packages/gas-report/README.md | 26 +++++++ packages/gas-report/foundry.toml | 11 +++ packages/gas-report/package.json | 49 ++++++++++++ packages/gas-report/remappings.txt | 2 + .../test => gas-report/src}/GasReporter.sol | 0 .../test/GasReporter.t.sol | 2 +- .../gas-report.ts => gas-report/ts/index.ts} | 0 packages/gas-report/ts/mud-gas-report.ts | 35 +++++++++ packages/gas-report/tsconfig.json | 20 +++++ packages/gas-report/tsup.config.ts | 11 +++ packages/store/gas-report.json | 6 ++ packages/store/package.json | 3 +- packages/store/test/Bytes.t.sol | 2 +- packages/store/test/Gas.t.sol | 2 +- packages/store/test/KeyEncoding.t.sol | 2 +- packages/store/test/Mixed.t.sol | 2 +- packages/store/test/PackedCounter.t.sol | 2 +- packages/store/test/Schema.t.sol | 7 +- packages/store/test/Slice.t.sol | 2 +- packages/store/test/Storage.t.sol | 2 +- packages/store/test/StoreCoreDynamic.t.sol | 2 +- packages/store/test/StoreCoreGas.t.sol | 2 +- packages/store/test/StoreMetadata.t.sol | 2 +- packages/store/test/StoreSwitch.t.sol | 2 +- packages/store/test/Vector2.t.sol | 2 +- packages/store/test/tables/Callbacks.t.sol | 2 +- packages/store/test/tables/Hooks.t.sol | 2 +- .../store/test/tightcoder/DecodeSlice.t.sol | 2 +- .../store/test/tightcoder/EncodeArray.t.sol | 2 +- .../store/test/tightcoder/TightCoder.t.sol | 2 +- packages/world/package.json | 3 +- packages/world/test/KeysInTableModule.t.sol | 2 +- packages/world/test/KeysWithValueModule.t.sol | 2 +- packages/world/test/SnapSyncModule.t.sol | 2 +- packages/world/test/UniqueEntityModule.t.sol | 2 +- packages/world/test/World.t.sol | 2 +- packages/world/test/WorldDynamicUpdate.t.sol | 2 +- packages/world/test/query.t.sol | 2 +- pnpm-lock.yaml | 74 +++++++++++++++---- 47 files changed, 298 insertions(+), 50 deletions(-) create mode 100644 .changeset/quick-numbers-flash.md create mode 100644 packages/gas-report/.gitignore create mode 100644 packages/gas-report/.npmignore create mode 100644 packages/gas-report/.solhint.json create mode 100644 packages/gas-report/CHANGELOG.md create mode 100644 packages/gas-report/README.md create mode 100644 packages/gas-report/foundry.toml create mode 100644 packages/gas-report/package.json create mode 100644 packages/gas-report/remappings.txt rename packages/{std-contracts/src/test => gas-report/src}/GasReporter.sol (100%) rename packages/{std-contracts => gas-report}/test/GasReporter.t.sol (88%) rename packages/{cli/src/commands/gas-report.ts => gas-report/ts/index.ts} (100%) create mode 100755 packages/gas-report/ts/mud-gas-report.ts create mode 100644 packages/gas-report/tsconfig.json create mode 100644 packages/gas-report/tsup.config.ts diff --git a/.changeset/quick-numbers-flash.md b/.changeset/quick-numbers-flash.md new file mode 100644 index 0000000000..6dc2200e1a --- /dev/null +++ b/.changeset/quick-numbers-flash.md @@ -0,0 +1,7 @@ +--- +"@latticexyz/cli": minor +"@latticexyz/gas-report": minor +"@latticexyz/store": minor +--- + +Create gas-report package, move gas-report cli command and GasReporter contract to it diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index a770021ecb..d9b74edfd9 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -17,5 +17,9 @@ runs: shell: bash run: pnpm turbo run build --cache-dir=.turbo --concurrency 10 + - name: Install node dependencies again to update workspace binaries + shell: bash + run: pnpm install --frozen-lockfile + - name: Outdated files, run `pnpm build` and commit them uses: ./.github/actions/require-empty-diff diff --git a/packages/cli/package.json b/packages/cli/package.json index 6c94e5b3c4..219e316155 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -33,6 +33,7 @@ "@improbable-eng/grpc-web-node-http-transport": "^0.15.0", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", + "@latticexyz/gas-report": "workspace:*", "@latticexyz/schema-type": "workspace:*", "@latticexyz/services": "workspace:*", "@latticexyz/solecs": "workspace:*", @@ -51,8 +52,6 @@ "nice-grpc-web": "^2.0.1", "openurl": "^1.1.1", "path": "^0.12.7", - "strip-ansi": "^7.1.0", - "table": "^6.8.1", "throttle-debounce": "^5.0.0", "typechain": "^8.1.1", "typescript": "^4.9.5", diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 69177e2863..ef7c853983 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -1,8 +1,9 @@ import { CommandModule } from "yargs"; +import gasReport from "@latticexyz/gas-report"; + import devnode from "./devnode"; import faucet from "./faucet"; -import gasReport from "./gas-report"; import hello from "./hello"; import tablegen from "./tablegen"; import tsgen from "./tsgen"; @@ -18,7 +19,7 @@ export const commands: CommandModule[] = [ deploy, devnode, faucet, - gasReport, + gasReport as CommandModule, hello, tablegen, tsgen, diff --git a/packages/gas-report/.gitignore b/packages/gas-report/.gitignore new file mode 100644 index 0000000000..574cef0484 --- /dev/null +++ b/packages/gas-report/.gitignore @@ -0,0 +1,11 @@ +cache +abi +out +docs +_docs +DOCS.md +artifacts +yarn-error.log +API +dist +types/ethers-contracts diff --git a/packages/gas-report/.npmignore b/packages/gas-report/.npmignore new file mode 100644 index 0000000000..523900e14e --- /dev/null +++ b/packages/gas-report/.npmignore @@ -0,0 +1,9 @@ +* + +!abi/** +!src/** +!ts/** +!types/** +!package.json +!README.md +!dist/** diff --git a/packages/gas-report/.solhint.json b/packages/gas-report/.solhint.json new file mode 100644 index 0000000000..4e2baa8be7 --- /dev/null +++ b/packages/gas-report/.solhint.json @@ -0,0 +1,8 @@ +{ + "extends": "solhint:recommended", + "rules": { + "compiler-version": ["error", ">=0.8.0"], + "avoid-low-level-calls": "off", + "func-visibility": ["warn", { "ignoreConstructors": true }] + } +} diff --git a/packages/gas-report/CHANGELOG.md b/packages/gas-report/CHANGELOG.md new file mode 100644 index 0000000000..e4d87c4d45 --- /dev/null +++ b/packages/gas-report/CHANGELOG.md @@ -0,0 +1,4 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. diff --git a/packages/gas-report/README.md b/packages/gas-report/README.md new file mode 100644 index 0000000000..7e6a41a40d --- /dev/null +++ b/packages/gas-report/README.md @@ -0,0 +1,26 @@ +# Gas Report + +Gas reporter for specific lines within forge tests + +Add some reports to your forge tests + +```solidity +import { Test } from "forge-std/Test.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; + +contract ExampleTest is Test, GasReporter { + function testGas() public { + startGasReport("Describe what is being gas-reported on"); + // do something here + endGasReport(); + } +} +``` + +Then use the cli command to run tests and save the report: + +```console +pnpm mud-gas-report --save gas-report.json +``` + +Run `pnpm mud-gas-report --help` for more details. diff --git a/packages/gas-report/foundry.toml b/packages/gas-report/foundry.toml new file mode 100644 index 0000000000..9489e40e2a --- /dev/null +++ b/packages/gas-report/foundry.toml @@ -0,0 +1,11 @@ +[profile.default] +solc_version = '0.8.13' +ffi = false +fuzz_runs = 256 +optimizer = true +optimizer_runs = 3000 +verbosity = 2 +allow_paths= ["../../node_modules"] +src = "src" +out = "out" +bytecode_hash = "none" diff --git a/packages/gas-report/package.json b/packages/gas-report/package.json new file mode 100644 index 0000000000..6408ffb513 --- /dev/null +++ b/packages/gas-report/package.json @@ -0,0 +1,49 @@ +{ + "name": "@latticexyz/gas-report", + "version": "1.42.0", + "description": "Gas reporter for specific lines within forge tests", + "repository": { + "type": "git", + "url": "https://github.com/latticexyz/mud.git", + "directory": "packages/gas-report" + }, + "license": "MIT", + "type": "module", + "exports": { + ".": "./dist/index.js" + }, + "typesVersions": { + "*": { + "index": [ + "./ts/index.ts" + ] + } + }, + "bin": { + "mud-gas-report": "./dist/mud-gas-report.js" + }, + "scripts": { + "build": "tsup", + "clean": "rimraf dist", + "dev": "tsup --watch", + "test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests && forge test" + }, + "dependencies": { + "chalk": "^5.3.0", + "dotenv": "^16.0.3", + "execa": "^7.0.0", + "strip-ansi": "^7.1.0", + "table": "^6.8.1", + "yargs": "^17.7.1" + }, + "devDependencies": { + "@types/node": "^18.15.11", + "@types/yargs": "^17.0.10", + "ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084", + "forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3", + "rimraf": "^3.0.2", + "tsup": "^6.7.0", + "vitest": "0.31.4" + }, + "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f" +} diff --git a/packages/gas-report/remappings.txt b/packages/gas-report/remappings.txt new file mode 100644 index 0000000000..fff7781446 --- /dev/null +++ b/packages/gas-report/remappings.txt @@ -0,0 +1,2 @@ +ds-test/=node_modules/ds-test/src/ +forge-std/=node_modules/forge-std/src/ diff --git a/packages/std-contracts/src/test/GasReporter.sol b/packages/gas-report/src/GasReporter.sol similarity index 100% rename from packages/std-contracts/src/test/GasReporter.sol rename to packages/gas-report/src/GasReporter.sol diff --git a/packages/std-contracts/test/GasReporter.t.sol b/packages/gas-report/test/GasReporter.t.sol similarity index 88% rename from packages/std-contracts/test/GasReporter.t.sol rename to packages/gas-report/test/GasReporter.t.sol index 993dd63536..0780642d12 100644 --- a/packages/std-contracts/test/GasReporter.t.sol +++ b/packages/gas-report/test/GasReporter.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "../src/test/GasReporter.sol"; +import { GasReporter } from "../src/GasReporter.sol"; contract GasReporterTest is Test, GasReporter { function testGasReporterGas() public { diff --git a/packages/cli/src/commands/gas-report.ts b/packages/gas-report/ts/index.ts similarity index 100% rename from packages/cli/src/commands/gas-report.ts rename to packages/gas-report/ts/index.ts diff --git a/packages/gas-report/ts/mud-gas-report.ts b/packages/gas-report/ts/mud-gas-report.ts new file mode 100755 index 0000000000..a65e95a086 --- /dev/null +++ b/packages/gas-report/ts/mud-gas-report.ts @@ -0,0 +1,35 @@ +#!/usr/bin/env node + +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; +import gasReport from "."; + +// Load .env file into process.env +import * as dotenv from "dotenv"; +import chalk from "chalk"; +dotenv.config(); + +// $0 makes this a default command (as opposed to a sub-command), +// which replaces `mud-gas-report gas-report` with just `mud-gas-report` +gasReport.command = "$0"; + +yargs(hideBin(process.argv)) + .scriptName("mud-gas-report") + // Use the commands directory to scaffold + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- command array overload isn't typed, see https://github.com/yargs/yargs/blob/main/docs/advanced.md#esm-hierarchy + .command(gasReport as any) + // Enable strict mode. + .strict() + // Custom error handler + .fail((msg, err) => { + console.error(chalk.red(msg)); + if (msg.includes("Missing required argument")) { + console.log( + chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`) + ); + } + + process.exit(1); + }) + // Useful aliases. + .alias({ h: "help" }).argv; diff --git a/packages/gas-report/tsconfig.json b/packages/gas-report/tsconfig.json new file mode 100644 index 0000000000..5e655de9b7 --- /dev/null +++ b/packages/gas-report/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + "target": "es2021", + "types": ["node"], + "module": "esnext", + "moduleResolution": "node", + "declaration": true, + "sourceMap": true, + "rootDir": ".", + "outDir": "dist", + "isolatedModules": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + }, + "include": ["ts"] +} diff --git a/packages/gas-report/tsup.config.ts b/packages/gas-report/tsup.config.ts new file mode 100644 index 0000000000..1f0444cc6e --- /dev/null +++ b/packages/gas-report/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["ts/index.ts", "ts/mud-gas-report.ts"], + target: "esnext", + format: ["esm"], + dts: false, + sourcemap: true, + clean: true, + minify: true, +}); diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 7df41d1e35..96127af650 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -149,6 +149,12 @@ "name": "get total of PackedCounter", "gasUsed": 27 }, + { + "file": "test/Schema.t.sol", + "test": "testEncodeDecodeSchema", + "name": "encode schema with 6 entries [SchemaLib.encode]", + "gasUsed": 6040 + }, { "file": "test/Schema.t.sol", "test": "testEncodeDecodeSchema", diff --git a/packages/store/package.json b/packages/store/package.json index bab6b295ee..59a821c7de 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -46,7 +46,7 @@ "clean:typechain": "rimraf types", "dev": "tsup --watch", "docs": "rimraf API && hardhat docgen", - "gas-report": "../cli/dist/mud.js gas-report --save gas-report.json", + "gas-report": "mud-gas-report --save gas-report.json", "generate-tightcoder": "tsx ./scripts/generate-tightcoder.ts && prettier --write '**/tightcoder/*.sol'", "lint": "solhint --config ./.solhint.json 'src/**/*.sol'", "test": "vitest typecheck --run && vitest --run --passWithNoTests && forge test" @@ -56,6 +56,7 @@ "@ethersproject/providers": "^5.7.2", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", + "@latticexyz/gas-report": "workspace:*", "@latticexyz/schema-type": "workspace:*", "abitype": "0.8.7", "ethers": "^5.7.2", diff --git a/packages/store/test/Bytes.t.sol b/packages/store/test/Bytes.t.sol index ca81dbb337..c89fb3e12d 100644 --- a/packages/store/test/Bytes.t.sol +++ b/packages/store/test/Bytes.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Bytes } from "../src/Bytes.sol"; contract BytesTest is Test, GasReporter { diff --git a/packages/store/test/Gas.t.sol b/packages/store/test/Gas.t.sol index e5663afda4..156ced0905 100644 --- a/packages/store/test/Gas.t.sol +++ b/packages/store/test/Gas.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test, console } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Bytes } from "../src/Bytes.sol"; import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; diff --git a/packages/store/test/KeyEncoding.t.sol b/packages/store/test/KeyEncoding.t.sol index 9f6c5f8c03..a6cc367fa1 100644 --- a/packages/store/test/KeyEncoding.t.sol +++ b/packages/store/test/KeyEncoding.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { KeyEncoding, KeyEncodingTableId } from "../src/codegen/Tables.sol"; import { ExampleEnum } from "../src/codegen/Types.sol"; import { StoreCore } from "../src/StoreCore.sol"; diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index c59375b3a7..bf335cf496 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { Mixed, MixedData, MixedTableId } from "../src/codegen/Tables.sol"; import { StoreCore } from "../src/StoreCore.sol"; diff --git a/packages/store/test/PackedCounter.t.sol b/packages/store/test/PackedCounter.t.sol index 542cc55e01..4ad489a756 100644 --- a/packages/store/test/PackedCounter.t.sol +++ b/packages/store/test/PackedCounter.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; contract PackedCounterTest is Test, GasReporter { diff --git a/packages/store/test/Schema.t.sol b/packages/store/test/Schema.t.sol index d197f60116..11af647889 100644 --- a/packages/store/test/Schema.t.sol +++ b/packages/store/test/Schema.t.sol @@ -2,14 +2,14 @@ pragma solidity >=0.8.0; import { Test, console } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { Schema, SchemaLib } from "../src/Schema.sol"; // TODO add tests for all schema types contract SchemaTest is Test, GasReporter { function testEncodeDecodeSchema() public { - uint256 gas = gasleft(); + startGasReport("encode schema with 6 entries [SchemaLib.encode]"); Schema schema = SchemaLib.encode( SchemaType.UINT8, // 1 byte SchemaType.UINT16, // 2 bytes @@ -18,8 +18,7 @@ contract SchemaTest is Test, GasReporter { SchemaType.UINT256, // 32 bytes SchemaType.UINT32_ARRAY // 0 bytes (because it's dynamic) ); - gas = gas - gasleft(); - console.log("GAS REPORT: encode schema with 6 entries [SchemaLib.encode]: %s", gas); + endGasReport(); startGasReport("get schema type at index"); SchemaType schemaType1 = schema.atIndex(0); diff --git a/packages/store/test/Slice.t.sol b/packages/store/test/Slice.t.sol index e7cd28c856..02856114f5 100644 --- a/packages/store/test/Slice.t.sol +++ b/packages/store/test/Slice.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Memory } from "../src/Memory.sol"; import { Slice, SliceLib } from "../src/Slice.sol"; diff --git a/packages/store/test/Storage.t.sol b/packages/store/test/Storage.t.sol index c6bbcd2908..a85d9b98ad 100644 --- a/packages/store/test/Storage.t.sol +++ b/packages/store/test/Storage.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Storage } from "../src/Storage.sol"; import { Utils } from "../src/Utils.sol"; import { Bytes } from "../src/Bytes.sol"; diff --git a/packages/store/test/StoreCoreDynamic.t.sol b/packages/store/test/StoreCoreDynamic.t.sol index b651059ff3..10aac65a36 100644 --- a/packages/store/test/StoreCoreDynamic.t.sol +++ b/packages/store/test/StoreCoreDynamic.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test, console } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { SliceLib } from "../src/Slice.sol"; diff --git a/packages/store/test/StoreCoreGas.t.sol b/packages/store/test/StoreCoreGas.t.sol index a05d7257a9..e7f222d7cc 100644 --- a/packages/store/test/StoreCoreGas.t.sol +++ b/packages/store/test/StoreCoreGas.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { StoreCore, StoreCoreInternal } from "../src/StoreCore.sol"; import { Utils } from "../src/Utils.sol"; diff --git a/packages/store/test/StoreMetadata.t.sol b/packages/store/test/StoreMetadata.t.sol index 4d98cc10f1..811cb5d18c 100644 --- a/packages/store/test/StoreMetadata.t.sol +++ b/packages/store/test/StoreMetadata.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreMetadata, StoreMetadataData } from "../src/codegen/Tables.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; diff --git a/packages/store/test/StoreSwitch.t.sol b/packages/store/test/StoreSwitch.t.sol index 1d186136e7..12b25fb931 100644 --- a/packages/store/test/StoreSwitch.t.sol +++ b/packages/store/test/StoreSwitch.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; import { StoreSwitch } from "../src/StoreSwitch.sol"; diff --git a/packages/store/test/Vector2.t.sol b/packages/store/test/Vector2.t.sol index 16791ddd8c..53fbd4c2a1 100644 --- a/packages/store/test/Vector2.t.sol +++ b/packages/store/test/Vector2.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Vector2, Vector2Data, Vector2TableId } from "../src/codegen/Tables.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol"; diff --git a/packages/store/test/tables/Callbacks.t.sol b/packages/store/test/tables/Callbacks.t.sol index 609ee6dedc..8916fd98c1 100644 --- a/packages/store/test/tables/Callbacks.t.sol +++ b/packages/store/test/tables/Callbacks.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreReadWithStubs } from "../../src/StoreReadWithStubs.sol"; import { Callbacks } from "../../src/codegen/Tables.sol"; diff --git a/packages/store/test/tables/Hooks.t.sol b/packages/store/test/tables/Hooks.t.sol index 4f93ced1d0..5e2a62a237 100644 --- a/packages/store/test/tables/Hooks.t.sol +++ b/packages/store/test/tables/Hooks.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreReadWithStubs } from "../../src/StoreReadWithStubs.sol"; import { Hooks } from "../../src/codegen/Tables.sol"; diff --git a/packages/store/test/tightcoder/DecodeSlice.t.sol b/packages/store/test/tightcoder/DecodeSlice.t.sol index 7bd2f417b1..e3b4989f5d 100644 --- a/packages/store/test/tightcoder/DecodeSlice.t.sol +++ b/packages/store/test/tightcoder/DecodeSlice.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SliceLib } from "../../src/Slice.sol"; contract DecodeSliceTest is Test, GasReporter { diff --git a/packages/store/test/tightcoder/EncodeArray.t.sol b/packages/store/test/tightcoder/EncodeArray.t.sol index 79a1fc4010..989cfc0038 100644 --- a/packages/store/test/tightcoder/EncodeArray.t.sol +++ b/packages/store/test/tightcoder/EncodeArray.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Bytes } from "../../src/Bytes.sol"; import { EncodeArray } from "../../src/tightcoder/EncodeArray.sol"; diff --git a/packages/store/test/tightcoder/TightCoder.t.sol b/packages/store/test/tightcoder/TightCoder.t.sol index a41dbe48c3..0f1e183769 100644 --- a/packages/store/test/tightcoder/TightCoder.t.sol +++ b/packages/store/test/tightcoder/TightCoder.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; import { SliceLib } from "../../src/Slice.sol"; import { EncodeArray } from "../../src/tightcoder/EncodeArray.sol"; diff --git a/packages/world/package.json b/packages/world/package.json index e53e005648..155cfa052f 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -47,7 +47,7 @@ "clean:typechain": "rimraf types", "dev": "tsup --watch", "docs": "rimraf API && hardhat docgen", - "gas-report": "../cli/dist/mud.js gas-report --save gas-report.json", + "gas-report": "mud-gas-report --save gas-report.json", "lint": "solhint --config ./.solhint.json 'src/**/*.sol'", "test": "tsc --noEmit && vitest --run && forge test" }, @@ -56,6 +56,7 @@ "@ethersproject/providers": "^5.7.2", "@latticexyz/common": "workspace:*", "@latticexyz/config": "workspace:*", + "@latticexyz/gas-report": "workspace:*", "@latticexyz/schema-type": "workspace:*", "@latticexyz/store": "workspace:*", "ethers": "^5.7.2", diff --git a/packages/world/test/KeysInTableModule.t.sol b/packages/world/test/KeysInTableModule.t.sol index 51a7ca8b0e..4656a03b6e 100644 --- a/packages/world/test/KeysInTableModule.t.sol +++ b/packages/world/test/KeysInTableModule.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; diff --git a/packages/world/test/KeysWithValueModule.t.sol b/packages/world/test/KeysWithValueModule.t.sol index 1e0e0f08fc..4cca1745e2 100644 --- a/packages/world/test/KeysWithValueModule.t.sol +++ b/packages/world/test/KeysWithValueModule.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; diff --git a/packages/world/test/SnapSyncModule.t.sol b/packages/world/test/SnapSyncModule.t.sol index 4209deb0d9..0ad935c0ce 100644 --- a/packages/world/test/SnapSyncModule.t.sol +++ b/packages/world/test/SnapSyncModule.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; diff --git a/packages/world/test/UniqueEntityModule.t.sol b/packages/world/test/UniqueEntityModule.t.sol index 7b8a5dfa73..7d8c18b4f7 100644 --- a/packages/world/test/UniqueEntityModule.t.sol +++ b/packages/world/test/UniqueEntityModule.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { World } from "../src/World.sol"; import { IBaseWorld } from "../src/interfaces/IBaseWorld.sol"; diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index be1e3c3349..11d9ed1af1 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 4e8acb9462..040ec307c1 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test, console } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; diff --git a/packages/world/test/query.t.sol b/packages/world/test/query.t.sol index 45c8e79c1e..27dd77c2b3 100644 --- a/packages/world/test/query.t.sol +++ b/packages/world/test/query.t.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.0; import { Test } from "forge-std/Test.sol"; -import { GasReporter } from "@latticexyz/std-contracts/src/test/GasReporter.sol"; +import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e129aa01e7..c11f505d2c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -102,6 +102,9 @@ importers: '@latticexyz/config': specifier: workspace:* version: link:../config + '@latticexyz/gas-report': + specifier: workspace:* + version: link:../gas-report '@latticexyz/schema-type': specifier: workspace:* version: link:../schema-type @@ -156,12 +159,6 @@ importers: path: specifier: ^0.12.7 version: 0.12.7 - strip-ansi: - specifier: ^7.1.0 - version: 7.1.0 - table: - specifier: ^6.8.1 - version: 6.8.1 throttle-debounce: specifier: ^5.0.0 version: 5.0.0 @@ -412,6 +409,49 @@ importers: specifier: ^6.7.0 version: 6.7.0(typescript@4.9.5) + packages/gas-report: + dependencies: + chalk: + specifier: ^5.3.0 + version: 5.3.0 + dotenv: + specifier: ^16.0.3 + version: 16.0.3 + execa: + specifier: ^7.0.0 + version: 7.0.0 + strip-ansi: + specifier: ^7.1.0 + version: 7.1.0 + table: + specifier: ^6.8.1 + version: 6.8.1 + yargs: + specifier: ^17.7.1 + version: 17.7.1 + devDependencies: + '@types/node': + specifier: ^18.15.11 + version: 18.15.11 + '@types/yargs': + specifier: ^17.0.10 + version: 17.0.23 + ds-test: + specifier: https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084 + version: github.com/dapphub/ds-test/c9ce3f25bde29fc5eb9901842bf02850dfd2d084 + forge-std: + specifier: https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3 + version: github.com/foundry-rs/forge-std/b4f121555729b3afb3c5ffccb62ff4b6e2818fd3 + rimraf: + specifier: ^3.0.2 + version: 3.0.2 + tsup: + specifier: ^6.7.0 + version: 6.7.0(typescript@4.9.5) + vitest: + specifier: 0.31.4 + version: 0.31.4 + packages/network: dependencies: '@ethersproject/abi': @@ -959,6 +999,9 @@ importers: '@latticexyz/config': specifier: workspace:* version: link:../config + '@latticexyz/gas-report': + specifier: workspace:* + version: link:../gas-report '@latticexyz/schema-type': specifier: workspace:* version: link:../schema-type @@ -1143,6 +1186,9 @@ importers: '@latticexyz/config': specifier: workspace:* version: link:../config + '@latticexyz/gas-report': + specifier: workspace:* + version: link:../gas-report '@latticexyz/schema-type': specifier: workspace:* version: link:../schema-type @@ -1236,13 +1282,6 @@ packages: '@jridgewell/trace-mapping': 0.3.18 dev: true - /@babel/code-frame@7.18.6: - resolution: {integrity: sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/highlight': 7.18.6 - dev: true - /@babel/code-frame@7.21.4: resolution: {integrity: sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==} engines: {node: '>=6.9.0'} @@ -4592,6 +4631,11 @@ packages: resolution: {integrity: sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + /chalk@5.3.0: + resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + dev: false + /char-regex@1.0.2: resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} engines: {node: '>=10'} @@ -5542,7 +5586,7 @@ packages: engines: {node: ^6.14.0 || ^8.10.0 || >=9.10.0} hasBin: true dependencies: - '@babel/code-frame': 7.18.6 + '@babel/code-frame': 7.21.4 ajv: 6.12.6 chalk: 2.4.2 cross-spawn: 6.0.5