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/solana-test-validator-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/solana-test-validator-up` package ([#9210](https://github.com/MetaMask/core/pull/9210)).

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

solana-test-validator runtime installer for MetaMask E2E tests
`solana-test-validator-up` installs a pinned Solana/Agave 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, local-validator config, readiness checks, and
seeding.

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

`yarn add @metamask/solana-test-validator-up`
## Usage

or
Install the package in the consuming repo:

`npm install @metamask/solana-test-validator-up`
```bash
yarn add @metamask/solana-test-validator-up
npm install @metamask/solana-test-validator-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": {
"solana-test-validator-up": "node_modules/.bin/solana-test-validator-up",
"solana-test-validator": "node_modules/.bin/solana-test-validator",
"solana": "node_modules/.bin/solana"
}
}
```

Install solana-test-validator and the Solana CLI:

```bash
yarn solana-test-validator-up install
```

Run the installed validator wrapper:

```bash
node_modules/.bin/solana-test-validator --reset
```

For MetaMask Extension E2E tests, the Solana seeder should spawn
`node_modules/.bin/solana-test-validator`, pass its generated local-validator
ports and ledger directory, poll JSON-RPC directly, and perform all account
seeding itself.

## Installed Artifacts

`solana-test-validator-up` installs:

- a platform-specific Solana/Agave release archive
- a `node_modules/.bin/solana-test-validator` wrapper
- a `node_modules/.bin/solana` wrapper

## CLI

```bash
solana-test-validator-up [install] [options]
solana-test-validator-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`.
- `--release-url <url>` and `--release-checksum <hash>`: override the Solana
release archive for the current platform.
- `--platform <platform>`: override platform selection, for example
`linux-x64`.

## Default Release

The package currently pins Agave `v3.1.14` for `darwin-arm64`, `darwin-x64`,
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 solana-test-validator-up cache clean
```

## Package Config

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

```json
{
"solanaTestValidatorUp": {
"release": {
"version": "v3.1.14",
"platforms": {
"linux-x64": {
"url": "https://github.com/anza-xyz/agave/releases/download/v3.1.14/solana-release-x86_64-unknown-linux-gnu.tar.bz2",
"checksum": "06f97c065cc977cbec2f13ffc9bc9d3b92fef485431fcb370a269de69532ef51"
}
}
}
}
}
```

Supported package config keys are `solanaTestValidatorUp`,
`solanatestvalidatorup`, and `solana-test-validator-up`.
14 changes: 10 additions & 4 deletions packages/solana-test-validator-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/solana-test-validator-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/solana-test-validator-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/solana-test-validator-up.mjs",
"files": [
"dist/"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env node
/* eslint-disable no-restricted-globals */
import {
cleanSolanaTestValidatorCache,
installSolanaTestValidator,
parseSolanaTestValidatorInstallCliOptions,
readSolanaTestValidatorInstallOptionsFromPackageJson,
} 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 cleanSolanaTestValidatorCache({
...readSolanaTestValidatorInstallOptionsFromPackageJson(),
...parseSolanaTestValidatorInstallCliOptions(args.slice(1)),
});
console.log('[solana-test-validator-up] cache cleaned');
return;
}

const installArgs = command === 'install' ? args : process.argv.slice(2);
const result = await installSolanaTestValidator({
...readSolanaTestValidatorInstallOptionsFromPackageJson(),
...parseSolanaTestValidatorInstallCliOptions(installArgs),
});

console.log(
`[solana-test-validator-up] Solana release ${
result.cacheHit ? 'found in cache' : 'installed'
}`,
);
console.log(
`[solana-test-validator-up] solana-test-validator installed at ${result.binaryPath}`,
);
}

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

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

Commands:
install Install solana-test-validator and solana CLI. Default command.
cache clean Remove cached solana-test-validator-up artifacts.

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

This file was deleted.

24 changes: 15 additions & 9 deletions packages/solana-test-validator-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 {
SOLANA_TEST_VALIDATOR_DEFAULT_RELEASE,
cleanSolanaTestValidatorCache,
getSolanaTestValidatorCacheDirectory,
installSolanaTestValidator,
parseSolanaTestValidatorInstallCliOptions,
readSolanaTestValidatorInstallOptionsFromPackageJson,
} from './install';
export type {
SolanaTestValidatorArtifactConfig,
SolanaTestValidatorArtifactPlatformConfig,
SolanaTestValidatorInstallDependencies,
SolanaTestValidatorInstallOptions,
SolanaTestValidatorInstallResult,
} from './install';
Loading
Loading