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 knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const config: KnipConfig = {
ignoreBinaries: ['anvil', 'sysctl'],
ignoreDependencies: ['yargs-parser'],
},
'packages/java-tron-up': {
// `sysctl` is an external system binary, not an npm package.
ignoreBinaries: ['sysctl'],
},
'packages/gas-fee-controller': {
ignoreDependencies: ['@metamask/ethjs-unit', 'jest-when'],
},
Expand Down
4 changes: 4 additions & 0 deletions packages/java-tron-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/java-tron-up` package ([#9208](https://github.com/MetaMask/core/pull/9208)).

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

java-tron runtime installer for MetaMask E2E tests
`java-tron-up` installs a pinned native java-tron 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, private-network config, readiness checks, and seeding.

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

`yarn add @metamask/java-tron-up`
## Usage

or
Install the package in the consuming repo:

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

Install java-tron and its managed Java runtime:

```bash
yarn java-tron-up install
```

Run the installed node wrapper:

```bash
node_modules/.bin/java-tron -c /absolute/path/to/fullnode.conf --witness
```

For MetaMask Extension E2E tests, the Tron seeder should spawn
`node_modules/.bin/java-tron`, pass its generated private-network config, poll
java-tron's HTTP APIs directly, and perform all account/token/staking seeding
itself.

## Installed Artifacts

`java-tron-up` installs:

- a platform-specific `FullNode.jar`
- a managed Java runtime matching java-tron's architecture requirements
- a `node_modules/.bin/java-tron` wrapper that runs:

```bash
java -jar FullNode.jar "$@"
```

## CLI

```bash
java-tron-up [install] [options]
java-tron-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`.
- `--full-node-url <url>` and `--full-node-checksum <hash>`: override the
FullNode jar for the current platform.
- `--java-runtime-url <url>` and `--java-runtime-checksum <hash>`: override the
Java runtime archive for the current platform.
- `--platform <platform>`: override platform selection, for example
`linux-x64`.

## Default Release

The package currently pins java-tron `GreatVoyage-v4.8.1` for `darwin-arm64`,
`darwin-x64`, `linux-arm64`, and `linux-x64`.

java-tron `4.8.1` requires JDK 8 for x86_64 and JDK 17 for arm64, so this
package installs Azul Zulu Java 8 on x64 platforms and Azul Zulu Java 17 on
arm64 platforms.

## 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 java-tron-up cache clean
```

## Package Config

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

```json
{
"javaTronUp": {
"fullNode": {
"version": "GreatVoyage-v4.8.1",
"platforms": {
"linux-x64": {
"url": "https://github.com/tronprotocol/java-tron/releases/download/GreatVoyage-v4.8.1/FullNode.jar",
"checksum": "0e67b2fe75d7077750e73c4fa20725c6e9824657275d96be256ae5da681f9945"
}
}
}
}
}
```

Supported package config keys are `javaTronUp`, `javatronup`, and
`java-tron-up`.
14 changes: 10 additions & 4 deletions packages/java-tron-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/java-tron-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/java-tron-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/java-tron-up.mjs",
"files": [
"dist/"
],
Expand Down
65 changes: 65 additions & 0 deletions packages/java-tron-up/src/bin/java-tron-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env node
/* eslint-disable no-restricted-globals */
import {
cleanJavaTronCache,
installJavaTron,
parseJavaTronInstallCliOptions,
readJavaTronInstallOptionsFromPackageJson,
} 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 cleanJavaTronCache({
...readJavaTronInstallOptionsFromPackageJson(),
...parseJavaTronInstallCliOptions(args.slice(1)),
});
console.log('[java-tron-up] cache cleaned');
return;
}

const installArgs = command === 'install' ? args : process.argv.slice(2);
const result = await installJavaTron({
...readJavaTronInstallOptionsFromPackageJson(),
...parseJavaTronInstallCliOptions(installArgs),
});

console.log(
`[java-tron-up] java-tron ${
result.cacheHit ? 'found in cache' : 'installed'
} at ${result.fullNodeJar}`,
);
console.log(`[java-tron-up] Java runtime installed at ${result.javaBinary}`);
console.log(`[java-tron-up] binary installed at ${result.binaryPath}`);
}

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

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

Commands:
install Install java-tron and the managed Java runtime. Default command.
cache clean Remove cached java-tron-up artifacts.

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

This file was deleted.

27 changes: 18 additions & 9 deletions packages/java-tron-up/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
/**
* 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 {
JAVA_TRON_DEFAULT_FULL_NODE,
JAVA_TRON_DEFAULT_JAVA_RUNTIME,
cleanJavaTronCache,
getJavaTronCacheDirectory,
installJavaRuntime,
installJavaTron,
parseJavaTronInstallCliOptions,
readJavaTronInstallOptionsFromPackageJson,
} from './install';
export type {
JavaTronArtifactConfig,
JavaTronArtifactPlatformConfig,
JavaTronInstallDependencies,
JavaTronInstallOptions,
JavaTronInstallResult,
JavaTronJavaRuntimeConfig,
} from './install';
Loading
Loading