Skip to content

Commit

Permalink
chore: cli improvements for pulling deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Aug 29, 2024
1 parent e4e18d4 commit b84783e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"README.md"
],
"scripts": {
"fetch:deployment": "bun run ./scripts/fetch:deployment.ts && bun run lint --apply-unsafe",
"format": "biome format . --write",
"lint": "biome check .",
"lint:fix": "bun run lint --apply",
Expand All @@ -74,7 +73,9 @@
"cjs:watch:aliases": "tsc-alias -p ./tsconfig/tsconfig.cjs.json --watch",
"build:cjs": "tsc --project ./tsconfig/tsconfig.cjs.json && tsc-alias -p ./tsconfig/tsconfig.cjs.json && echo > ./dist/_cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project ./tsconfig/tsconfig.esm.json && tsc-alias -p ./tsconfig/tsconfig.esm.json && echo > ./dist/_esm/package.json '{\"type\": \"module\",\"sideEffects\":false}'",
"build:types": "tsc --project ./tsconfig/tsconfig.types.json && tsc-alias -p ./tsconfig/tsconfig.types.json"
"build:types": "tsc --project ./tsconfig/tsconfig.types.json && tsc-alias -p ./tsconfig/tsconfig.types.json",
"fetch:deployment": "bun run ./scripts/fetch:deployment.ts && bun run lint --apply-unsafe",
"fetch:deployment:raw": "bun run ./scripts/fetch:deployment.ts"
},
"devDependencies": {
"@biomejs/biome": "1.6.0",
Expand All @@ -88,6 +89,7 @@
"@size-limit/esbuild-why": "^11",
"@size-limit/preset-small-lib": "^11",
"@types/bun": "latest",
"@types/yargs": "^17.0.33",
"@vitest/coverage-v8": "^1.3.1",
"buffer": "^6.0.3",
"concurrently": "^8.2.2",
Expand All @@ -105,7 +107,8 @@
"tsc-alias": "^1.8.8",
"tslib": "^2.6.3",
"typedoc": "^0.25.9",
"vitest": "^1.3.1"
"vitest": "^1.3.1",
"yargs": "^17.7.2"
},
"peerDependencies": {
"typescript": "^5",
Expand Down
21 changes: 15 additions & 6 deletions scripts/fetch:deployment.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import fs from "node:fs"
import { STARTING_PORT } from "../tests/src/testUtils"

const pathToDeployment = "../node_modules/nexus/deployments" // "../../nexus/deployments" also potentially useful
const deploymentChainName = `anvil-${STARTING_PORT}`
const abisInSrc = ["K1ValidatorFactory", "Nexus", "K1Validator"]
import { hideBin } from "yargs/helpers"
import yargs from "yargs/yargs"

const relativePath = `${__dirname}/${pathToDeployment}/${deploymentChainName}`
type FetchDetails = {
nexusDeploymentPath: string
chainName: string
forSrc: string[]
}
const {
nexusDeploymentPath = "../node_modules/nexus/deployments",
chainName = "anvil-55000",
forSrc = ["K1ValidatorFactory", "Nexus", "K1Validator"]
} = yargs(hideBin(process.argv)).argv as unknown as FetchDetails

type DeployedContract = {
address: string
}

export const getDeployments = async () => {
const relativePath = `${__dirname}/${nexusDeploymentPath}/${chainName}`
console.log("Fetching deployments from:", relativePath)
const files = fs.readdirSync(relativePath)
const deployedContracts: Record<string, DeployedContract> = {}

Expand All @@ -28,7 +37,7 @@ export const getDeployments = async () => {
)
const { address, abi } = JSON.parse(contents)

const isForCore = abisInSrc.includes(name)
const isForCore = forSrc.includes(name)
if (isForCore) {
coreFiles.push(name)
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/__contracts/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten

import type { Hex } from "viem"
export const addresses: Record<string, Hex> = {
Nexus: "0x776d63154D2aa9256D72C420416c930F3B735464",
Expand Down
11 changes: 11 additions & 0 deletions tests/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ The script performs the following:
- **Addresses**: Moved to `./src/addresses.ts`
- **Additional Fixtures**: Copied to `tests__/contracts`

The script accepts a number of args from the command line:
- nexusDeploymentPath (default: "../node_modules/nexus/deployments")
- chainName (default: "anvil-55000")
- forSrc (default: ["K1ValidatorFactory", "Nexus", "K1Validator"]);

Example usage:
```bash
bun run fetch:deployment:raw --chainName="anvil-52878" -forSrc=K1Validator -forSrc=Nexus --nexusDeploymentPath=../../nexus/deployments
bun run lint --apply-unsafe
```

> **Note**:
> - Do not edit these files manually; they will be overridden if/when a new Nexus deployment occurs.
> - Avoid hardcoding important addresses (e.g., `const K1_VALIDATOR_ADDRESS = "0x"`). Use `./src/addresses.ts` instead.
Expand Down
2 changes: 2 additions & 0 deletions tests/src/__contracts/mockAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten

import type { Hex } from "viem"
export const mockAddresses: Record<string, Hex> = {
MockHook: "0xAB9733982E5b98bdDc4f00314E8EA4911A9D1BA5",
Expand Down
1 change: 0 additions & 1 deletion tests/src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ export const toConfiguredAnvil = async ({
return instance
}

export const STARTING_PORT = 55000
const portOptions = { exclude: [] as number[] }
export const initAnvilPayload = async (): Promise<AnvilDto> => {
const rpcPort = await getPort(portOptions)
Expand Down

0 comments on commit b84783e

Please sign in to comment.