Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/bitcoin-regtest-up/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add the `@metamask/bitcoin-regtest-up` package ([#9212](https://github.com/MetaMask/core/pull/9212)).

[Unreleased]: https://github.com/MetaMask/core/
115 changes: 108 additions & 7 deletions packages/bitcoin-regtest-up/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,116 @@
# `@metamask/bitcoin-regtest-up`

Bitcoin Core regtest runtime installer for MetaMask E2E tests
`bitcoin-regtest-up` installs a pinned Bitcoin Core runtime for local
development and CI. It follows the same runtime-only shape as
`@metamask/foundryup`: this package installs external runtime artifacts into the
MetaMask cache and exposes binaries in `node_modules/.bin`; the consuming test
harness owns process startup, regtest config, readiness checks, and seeding.

## Installation
This package does not use Docker and does not start or seed a Bitcoin node.

`yarn add @metamask/bitcoin-regtest-up`
## Usage

or
Install the package in the consuming repo:

`npm install @metamask/bitcoin-regtest-up`
```bash
yarn add @metamask/bitcoin-regtest-up
npm install @metamask/bitcoin-regtest-up
```

## Contributing
For Yarn v4 projects, it is usually simplest to add package scripts in the
consuming repo:

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
```json
{
"scripts": {
"bitcoin-regtest-up": "node_modules/.bin/bitcoin-regtest-up",
"bitcoind": "node_modules/.bin/bitcoind",
"bitcoin-cli": "node_modules/.bin/bitcoin-cli"
}
}
```

Install bitcoind and bitcoin-cli:

```bash
yarn bitcoin-regtest-up install
```

Run the installed Bitcoin Core wrappers:

```bash
node_modules/.bin/bitcoind -regtest
node_modules/.bin/bitcoin-cli -regtest getblockchaininfo
```

For MetaMask Extension E2E tests, the Bitcoin seeder should spawn
`node_modules/.bin/bitcoind`, pass its generated regtest datadir and ports, use
`node_modules/.bin/bitcoin-cli` for node setup, poll JSON-RPC directly, and
perform all wallet/funding seeding itself.

## Installed Artifacts

`bitcoin-regtest-up` installs:

- a platform-specific Bitcoin Core release archive
- a `node_modules/.bin/bitcoind` wrapper
- a `node_modules/.bin/bitcoin-cli` wrapper

## CLI

```bash
bitcoin-regtest-up [install] [options]
bitcoin-regtest-up cache clean [options]
```

Options:

- `--bin-directory <path>`: directory for generated wrappers. Defaults to
`node_modules/.bin`.
- `--cache-directory <path>`: artifact cache directory. Defaults to
`.metamask/cache`.
- `--bitcoin-core-url <url>` and `--bitcoin-core-checksum <hash>`: override the
Bitcoin Core archive for the current platform.
- `--platform <platform>`: override platform selection, for example
`linux-x64`.

## Default Release

The package currently pins Bitcoin Core `30.2` for `darwin-arm64`,
`darwin-x64`, `linux-arm64`, and `linux-x64`.

## Cache

The cache defaults to `.metamask/cache` in the current repo. If `.yarnrc.yml`
contains `enableGlobalCache: true`, the cache moves to `~/.cache/metamask`,
matching the `@metamask/foundryup` behavior.

Clean only this package's cache namespace:

```bash
yarn bitcoin-regtest-up cache clean
```

## Package Config

The consuming repo can override the pinned artifact URLs and checksums in its
root `package.json`:

```json
{
"bitcoinRegtestUp": {
"bitcoinCore": {
"version": "30.2",
"platforms": {
"linux-x64": {
"url": "https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-linux-gnu.tar.gz",
"checksum": "6aa7bb4feb699c4c6262dd23e4004191f6df7f373b5d5978b5bcdd4bb72f75d8"
}
}
}
}
}
```

Supported package config keys are `bitcoinRegtestUp`, `bitcoinregtestup`, and
`bitcoin-regtest-up`.
14 changes: 10 additions & 4 deletions packages/bitcoin-regtest-up/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// The CLI entrypoint is exercised through package builds and installed-bin smoke tests.
coveragePathIgnorePatterns: [
...baseConfig.coveragePathIgnorePatterns,
'./src/bin/bitcoin-regtest-up.ts',
],

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
branches: 35,
functions: 60,
lines: 65,
statements: 65,
},
},
});
1 change: 1 addition & 0 deletions packages/bitcoin-regtest-up/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"bin": "./dist/bin/bitcoin-regtest-up.mjs",
"files": [
"dist/"
],
Expand Down
67 changes: 67 additions & 0 deletions packages/bitcoin-regtest-up/src/bin/bitcoin-regtest-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env node
/* eslint-disable no-restricted-globals */
import {
cleanBitcoinRegtestCache,
installBitcoinRegtest,
parseBitcoinRegtestInstallCliOptions,
readBitcoinRegtestInstallOptionsFromPackageJson,
} from '../install';

async function main(): Promise<void> {
const [command, ...args] = process.argv.slice(2);

if (command === '--help' || command === 'help') {
printHelp();
return;
}

if (command === 'cache' && args[0] === 'clean') {
await cleanBitcoinRegtestCache({
...readBitcoinRegtestInstallOptionsFromPackageJson(),
...parseBitcoinRegtestInstallCliOptions(args.slice(1)),
});
console.log('[bitcoin-regtest-up] cache cleaned');
return;
}

const installArgs = command === 'install' ? args : process.argv.slice(2);
const result = await installBitcoinRegtest({
...readBitcoinRegtestInstallOptionsFromPackageJson(),
...parseBitcoinRegtestInstallCliOptions(installArgs),
});

console.log(
`[bitcoin-regtest-up] Bitcoin Core ${
result.cacheHit ? 'found in cache' : 'installed'
}`,
);
console.log(
`[bitcoin-regtest-up] bitcoind installed at ${result.bitcoindBinary}`,
);
console.log(
`[bitcoin-regtest-up] bitcoin-cli installed at ${result.bitcoinCliBinary}`,
);
}

main().catch((error) => {
console.error(error);
process.exit(1);
});

function printHelp(): void {
console.log(`Usage: bitcoin-regtest-up [install] [options]
bitcoin-regtest-up cache clean [options]

Commands:
install Install Bitcoin Core bitcoind and bitcoin-cli. Default command.
cache clean Remove cached bitcoin-regtest-up artifacts.

Options:
--bin-directory <path> Directory for executable wrappers.
Defaults to node_modules/.bin.
--cache-directory <path> Cache directory. Defaults to .metamask/cache.
--bitcoin-core-url <url> Bitcoin Core archive URL for the current platform.
--bitcoin-core-checksum <hash> Expected Bitcoin Core SHA-256 checksum.
--platform <platform> Override platform key, e.g. linux-x64.
--help Show this help text.`);
}
9 changes: 0 additions & 9 deletions packages/bitcoin-regtest-up/src/index.test.ts

This file was deleted.

24 changes: 15 additions & 9 deletions packages/bitcoin-regtest-up/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* Example function that returns a greeting for the given name.
*
* @param name - The name to greet.
* @returns The greeting.
*/
export default function greeter(name: string): string {
return `Hello, ${name}!`;
}
export {
BITCOIN_REGTEST_DEFAULT_CORE,
cleanBitcoinRegtestCache,
getBitcoinRegtestCacheDirectory,
installBitcoinRegtest,
parseBitcoinRegtestInstallCliOptions,
readBitcoinRegtestInstallOptionsFromPackageJson,
} from './install';
export type {
BitcoinRegtestArtifactConfig,
BitcoinRegtestArtifactPlatformConfig,
BitcoinRegtestInstallDependencies,
BitcoinRegtestInstallOptions,
BitcoinRegtestInstallResult,
} from './install';
Loading
Loading