Skip to content

Add bitcoin-regtest-up package#8827

Closed
ulissesferreira wants to merge 1 commit into
mainfrom
add-bitcoin-regtest-up-package
Closed

Add bitcoin-regtest-up package#8827
ulissesferreira wants to merge 1 commit into
mainfrom
add-bitcoin-regtest-up-package

Conversation

@ulissesferreira

@ulissesferreira ulissesferreira commented May 15, 2026

Copy link
Copy Markdown
Contributor

Description

Adds @metamask/bitcoin-regtest-up to the core monorepo using the generated package structure, then replaces the scaffold with the existing Bitcoin Core regtest runtime installer implementation.

Ownership follows the runtime tooling/platform pattern and includes Networks, matching the Tron Snap ownership direction.

Changes

  • Adds the Bitcoin Core regtest runtime installer package under packages/bitcoin-regtest-up.
  • Publishes the bitcoin-regtest-up CLI bin from dist/bin/bitcoin-regtest-up.mjs.
  • Adds package references, lockfile entry, README package listing, CODEOWNERS, and teams.json ownership.
  • Keeps the current installer implementation pin at Bitcoin Core 30.2 and updates the migrated README to match.

Verification

  • yarn workspace @metamask/bitcoin-regtest-up run build
  • yarn workspace @metamask/bitcoin-regtest-up run test
  • yarn eslint packages/bitcoin-regtest-up
  • yarn constraints
  • yarn lint:misc --check packages/bitcoin-regtest-up/package.json packages/bitcoin-regtest-up/README.md packages/bitcoin-regtest-up/src/index.ts packages/bitcoin-regtest-up/src/install.ts packages/bitcoin-regtest-up/src/install.test.ts packages/bitcoin-regtest-up/src/bin/bitcoin-regtest-up.ts packages/bitcoin-regtest-up/jest.config.js .github/CODEOWNERS teams.json README.md tsconfig.json tsconfig.build.json
  • yarn readme-content:check
  • yarn lint:teams
  • yarn workspace @metamask/bitcoin-regtest-up run changelog:validate
  • node packages/bitcoin-regtest-up/dist/bin/bitcoin-regtest-up.mjs --help
  • git diff --check

Note

Low Risk
New standalone dev/CI tooling package with no changes to wallet controllers or production runtime paths; risk is limited to consumers opting into the installer CLI.

Overview
Introduces @metamask/bitcoin-regtest-up, a new runtime installer (modeled on @metamask/foundryup) that downloads and caches pinned Bitcoin Core 30.2 for local dev/CI and exposes bitcoind / bitcoin-cli via node_modules/.bin wrappers. The package does not start or seed a node—test harnesses own process lifecycle and regtest setup.

The installer supports SHA-256 verification, platform-specific archives (darwin/linux arm64/x64), cache reuse with invalidation when binaries aren’t runnable, handling of alternate daemon layouts (bitcoind, bitcoin-node, bitcoin launcher), CLI/package.json overrides, and a scoped cache clean command. Monorepo wiring adds CODEOWNERS / teams.json (mobile, extension, networks), README listing, tsconfig references, and yarn.lock workspace entry.

Reviewed by Cursor Bugbot for commit f827182. Bugbot is set up for automated code reviews on this repo. Configure here.

@ulissesferreira ulissesferreira requested a review from a team as a code owner May 15, 2026 11:40
@ulissesferreira

Copy link
Copy Markdown
Contributor Author

Code sync follow-up:

  • Pushed commit ab3364713 to align the package test fixture with @ulissesferreira/bitcoin-regtest-up@0.1.2.
  • The implementation, CLI, and tests now match the latest released source, with only expected MetaMask/core adaptations (@metamask package metadata, Jest test harness, lint/type annotations, ts-bridge build config).
  • Verified in MetaMask/core: yarn workspace @metamask/bitcoin-regtest-up run test and yarn workspace @metamask/bitcoin-regtest-up run build both completed successfully.

process.kill(process.pid, result.signal);
}

process.exit(result.status ?? 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapper exits zero when child is killed by signal

Low Severity

When the child process is killed by a signal, spawnSync returns status: null and signal: '<name>'. The expression result.status ?? 0 evaluates to 0, so process.exit(0) runs, making signal-based termination appear as a clean successful exit. The preceding process.kill(process.pid, result.signal) is ineffective because Node.js delivers signals asynchronously via the event loop, and process.exit(0) runs synchronously before the signal handler fires. Parent processes and CI scripts checking the exit code would incorrectly see success.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ab33647. Configure here.

}

process.exit(result.status ?? 0);
`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated wrapper uses CJS in ESM-incompatible way

Medium Severity

The generated node_modules/.bin/bitcoind and bitcoin-cli wrapper scripts use require('node:child_process'), but these extensionless files are written without any module-type hint. In consuming projects whose package.json declares "type": "module", Node.js resolves these wrappers as ESM (since there's no .cjs extension and the nearest package.json governs), causing require to be undefined at runtime. The foundryup sibling package avoids this by symlinking directly to extracted binaries instead of generating script wrappers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bbe4c1f. Configure here.

@ulissesferreira

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

1 similar comment
@ulissesferreira

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

}

return options;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling crashes CLI without package.json

Medium Severity

readBitcoinRegtestInstallOptionsFromPackageJson calls readFileSync on package.json without any try-catch, so it throws an unhelpful ENOENT error if no package.json exists in the working directory. Since package config is optional (the function reads optional overrides), it should return empty options {} when the file is missing, matching how getBitcoinRegtestCacheDirectory gracefully handles a missing .yarnrc.yml. The CLI calls this function unconditionally on both the install and cache clean paths, so any invocation from a directory without package.json crashes.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 82e0808. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.4.0-preview-82e080825
@metamask-previews/accounts-controller@38.1.1-preview-82e080825
@metamask-previews/address-book-controller@7.1.2-preview-82e080825
@metamask-previews/ai-controllers@0.6.3-preview-82e080825
@metamask-previews/analytics-controller@1.0.1-preview-82e080825
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-82e080825
@metamask-previews/announcement-controller@8.1.0-preview-82e080825
@metamask-previews/app-metadata-controller@2.0.1-preview-82e080825
@metamask-previews/approval-controller@9.0.1-preview-82e080825
@metamask-previews/assets-controller@7.1.2-preview-82e080825
@metamask-previews/assets-controllers@108.1.0-preview-82e080825
@metamask-previews/authenticated-user-storage@2.0.0-preview-82e080825
@metamask-previews/base-controller@9.1.0-preview-82e080825
@metamask-previews/base-data-service@0.1.3-preview-82e080825
@metamask-previews/bitcoin-regtest-up@0.0.0-preview-82e080825
@metamask-previews/bridge-controller@72.0.4-preview-82e080825
@metamask-previews/bridge-status-controller@71.1.4-preview-82e080825
@metamask-previews/build-utils@3.0.4-preview-82e080825
@metamask-previews/chain-agnostic-permission@1.6.1-preview-82e080825
@metamask-previews/chomp-api-service@3.1.0-preview-82e080825
@metamask-previews/claims-controller@0.5.1-preview-82e080825
@metamask-previews/client-controller@1.0.1-preview-82e080825
@metamask-previews/compliance-controller@2.0.1-preview-82e080825
@metamask-previews/composable-controller@12.0.1-preview-82e080825
@metamask-previews/config-registry-controller@0.3.1-preview-82e080825
@metamask-previews/connectivity-controller@0.2.0-preview-82e080825
@metamask-previews/controller-utils@12.1.0-preview-82e080825
@metamask-previews/core-backend@6.3.0-preview-82e080825
@metamask-previews/delegation-controller@3.0.0-preview-82e080825
@metamask-previews/earn-controller@12.1.2-preview-82e080825
@metamask-previews/eip-5792-middleware@3.0.4-preview-82e080825
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-82e080825
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-82e080825
@metamask-previews/ens-controller@19.1.3-preview-82e080825
@metamask-previews/eth-block-tracker@15.0.1-preview-82e080825
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-82e080825
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-82e080825
@metamask-previews/foundryup@1.0.1-preview-82e080825
@metamask-previews/gas-fee-controller@26.2.1-preview-82e080825
@metamask-previews/gator-permissions-controller@4.1.2-preview-82e080825
@metamask-previews/geolocation-controller@0.1.3-preview-82e080825
@metamask-previews/json-rpc-engine@10.5.0-preview-82e080825
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-82e080825
@metamask-previews/keyring-controller@25.5.0-preview-82e080825
@metamask-previews/logging-controller@8.0.2-preview-82e080825
@metamask-previews/message-manager@14.1.2-preview-82e080825
@metamask-previews/messenger@1.2.0-preview-82e080825
@metamask-previews/messenger-cli@0.2.0-preview-82e080825
@metamask-previews/money-account-balance-service@1.0.2-preview-82e080825
@metamask-previews/money-account-controller@0.3.0-preview-82e080825
@metamask-previews/money-account-upgrade-controller@2.0.2-preview-82e080825
@metamask-previews/multichain-account-service@10.0.0-preview-82e080825
@metamask-previews/multichain-api-middleware@3.1.2-preview-82e080825
@metamask-previews/multichain-network-controller@3.1.1-preview-82e080825
@metamask-previews/multichain-transactions-controller@7.1.0-preview-82e080825
@metamask-previews/name-controller@9.1.2-preview-82e080825
@metamask-previews/network-controller@32.0.0-preview-82e080825
@metamask-previews/network-enablement-controller@5.1.1-preview-82e080825
@metamask-previews/notification-services-controller@24.1.0-preview-82e080825
@metamask-previews/passkey-controller@2.0.1-preview-82e080825
@metamask-previews/permission-controller@13.1.1-preview-82e080825
@metamask-previews/permission-log-controller@5.1.0-preview-82e080825
@metamask-previews/perps-controller@6.1.0-preview-82e080825
@metamask-previews/phishing-controller@17.2.0-preview-82e080825
@metamask-previews/polling-controller@16.0.5-preview-82e080825
@metamask-previews/preferences-controller@23.1.0-preview-82e080825
@metamask-previews/profile-metrics-controller@3.1.4-preview-82e080825
@metamask-previews/profile-sync-controller@28.1.0-preview-82e080825
@metamask-previews/ramps-controller@13.3.1-preview-82e080825
@metamask-previews/rate-limit-controller@7.0.1-preview-82e080825
@metamask-previews/react-data-query@0.2.1-preview-82e080825
@metamask-previews/remote-feature-flag-controller@4.2.1-preview-82e080825
@metamask-previews/sample-controllers@5.0.1-preview-82e080825
@metamask-previews/seedless-onboarding-controller@9.1.0-preview-82e080825
@metamask-previews/selected-network-controller@26.1.3-preview-82e080825
@metamask-previews/shield-controller@5.1.2-preview-82e080825
@metamask-previews/signature-controller@39.2.2-preview-82e080825
@metamask-previews/snap-account-service@0.1.0-preview-82e080825
@metamask-previews/social-controllers@2.2.1-preview-82e080825
@metamask-previews/storage-service@1.0.1-preview-82e080825
@metamask-previews/subscription-controller@6.1.3-preview-82e080825
@metamask-previews/transaction-controller@65.4.0-preview-82e080825
@metamask-previews/transaction-pay-controller@22.5.0-preview-82e080825
@metamask-previews/user-operation-controller@41.2.2-preview-82e080825
@metamask-previews/wallet@0.0.0-preview-82e080825

@jeremytsng jeremytsng self-requested a review May 26, 2026 07:40
jeremytsng
jeremytsng previously approved these changes May 26, 2026

@jeremytsng jeremytsng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeremytsng jeremytsng force-pushed the add-bitcoin-regtest-up-package branch from 82e0808 to f7eec1a Compare May 26, 2026 09:00
@jeremytsng jeremytsng self-requested a review May 26, 2026 09:01
jeremytsng
jeremytsng previously approved these changes May 26, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit faa5ead. Configure here.

bitcoinCore,
platformKey,
'Bitcoin Core archive',
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial config replaces default platforms

Medium Severity

When package.json includes a bitcoinCore block, installBitcoinRegtest uses that object instead of BITCOIN_REGTEST_DEFAULT_CORE, without merging platforms. A documented override for one platform (e.g. linux-x64) removes pinned defaults for other hosts, so install fails on macOS with no archive configured for that platform.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit faa5ead. Configure here.

Battambang
Battambang previously approved these changes Jun 5, 2026
jeremytsng added a commit to MetaMask/metamask-extension that referenced this pull request Jun 14, 2026
Wires `bitcoin-regtest-up` (the BTC counterpart of Foundryup) into the
extension so local BTC E2E tests can spawn a real `bitcoind -regtest`.

- Adds `bitcoin-regtest-up` as a dev dependency. Sourced from
  `github:ulissesferreira/bitcoin-regtest-up` as a stopgap until the
  MetaMask-published version (MetaMask/core#8827) lands on npm. A
  follow-up commit will swap the spec and package name.
- Adds a `bitcoin-regtest-up:install` script that downloads the pinned
  Bitcoin Core release and exposes `bitcoind` + `bitcoin-cli` under
  `node_modules/.bin`. Not run via `postinstall` — opt-in for BTC
  E2E devs only, unlike the universal Anvil install.
- Allowlists the prototype repo in `approvedGitRepositories` so yarn 4
  accepts the git spec.
- Adds a short README under `test/e2e/seeder/bitcoin/` describing the
  local install + run flow. The actual BTC seeder lands in a separate
  PR.

The PoC BTC seeder reads `node_modules/.bin/bitcoind` via its
`binaryPath` option, so this bootstrap is sufficient on its own.
@ulissesferreira ulissesferreira force-pushed the add-bitcoin-regtest-up-package branch 2 times, most recently from 8fcd392 to aad4451 Compare June 17, 2026 15:26
@ulissesferreira ulissesferreira force-pushed the add-bitcoin-regtest-up-package branch from aad4451 to b323be6 Compare June 17, 2026 15:31
jeremytsng added a commit to MetaMask/metamask-extension that referenced this pull request Jun 19, 2026
Wires `bitcoin-regtest-up` (the BTC counterpart of Foundryup) into the
extension so local BTC E2E tests can spawn a real `bitcoind -regtest`.

- Adds `bitcoin-regtest-up` as a dev dependency. Sourced from
  `github:ulissesferreira/bitcoin-regtest-up` as a stopgap until the
  MetaMask-published version (MetaMask/core#8827) lands on npm. A
  follow-up commit will swap the spec and package name.
- Adds a `bitcoin-regtest-up:install` script that downloads the pinned
  Bitcoin Core release and exposes `bitcoind` + `bitcoin-cli` under
  `node_modules/.bin`. Not run via `postinstall` — opt-in for BTC
  E2E devs only, unlike the universal Anvil install.
- Allowlists the prototype repo in `approvedGitRepositories` so yarn 4
  accepts the git spec.
- Adds a short README under `test/e2e/seeder/bitcoin/` describing the
  local install + run flow. The actual BTC seeder lands in a separate
  PR.

The PoC BTC seeder reads `node_modules/.bin/bitcoind` via its
`binaryPath` option, so this bootstrap is sufficient on its own.
pull Bot pushed a commit to dmrazzy/core that referenced this pull request Jun 22, 2026
## Summary

This PR is the **first of two PRs** splitting MetaMask#8827 into
cleanly-reviewable pieces.

It contains **only** the pure scaffold output of `yarn create-package`
plus ownership configuration — zero implementation logic.

### What's included

- `packages/bitcoin-regtest-up/` — scaffolded package skeleton (source
placeholder, tests, CHANGELOG, README, LICENSE, jest/tsconfig configs)
generated by `yarn create-package --name bitcoin-regtest-up
--description "Bitcoin Core regtest runtime installer for MetaMask E2E
tests"`
- `tsconfig.json` / `tsconfig.build.json` — monorepo-level references
updated by the tool
- `yarn.lock` — updated by `yarn install` run inside the tool
- `README.md` — package list updated by `yarn readme-content:update`
- `.github/CODEOWNERS` — ownership entries for the package (alphabetical
list after `foundryup` + Package Release section), mirroring the
`foundryup`/`solana-test-validator-up` pattern with `@MetaMask/networks`
added
- `teams.json` — issue-label routing entry, directly after the
`foundryup` entry

### What's NOT included

No implementation source, no `bin` field, no new runtime dependencies,
no `knip.config.ts` changes, no unrelated monorepo churn.

### Stacked PR

The implementation (real installer source, CLI bin, tests, full README)
follows in a stacked PR based on this branch.

## Verification

```
yarn workspace @metamask/bitcoin-regtest-up run build
yarn workspace @metamask/bitcoin-regtest-up run test
yarn constraints
yarn lint:teams
yarn readme-content:check
```

All passed ✓

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Boilerplate package creation and metadata only; no production runtime
behavior or security-sensitive logic.
> 
> **Overview**
> Adds **`@metamask/bitcoin-regtest-up`** to the monorepo as a
scaffold-only package (intended for a future Bitcoin Core regtest
installer for E2E tests). The diff is **`yarn create-package`** output
plus wiring—no real installer logic, CLI `bin`, or new runtime deps yet.
> 
> **Monorepo integration:** `tsconfig.json` / `tsconfig.build.json`
references, `yarn.lock`, and root **`README.md`** package list +
dependency graph node.
> 
> **Ownership:** **`.github/CODEOWNERS`** (joint ownership after
`foundryup`, matching `java-tron-up` / `solana-test-validator-up` with
**`@MetaMask/networks`**) and **`teams.json`** issue routing.
> 
> The package currently ships placeholder **`greeter`** source and a
sample Jest test so build/test pipelines pass until the stacked
implementation PR lands.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
87095cc. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@ulissesferreira

Copy link
Copy Markdown
Contributor Author

This PR has been superseded and split into two smaller PRs for easier review:

Closing in favor of those PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants