Skip to content

Commit

Permalink
chore(schema): add description to schema (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh authored Jun 12, 2024
1 parent 83304d7 commit 6865f5e
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 50 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ updates:
patterns:
- 'eslint'
- '@eslint/*'

- package-ecosystem: npm
directory: '/'
schedule:
interval: 'daily'
groups:
chainfile-definitions:
patterns:
- 'chainfile-*'
26 changes: 25 additions & 1 deletion packages/chainfile-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"$schema": {
"type": "string"
},
"description": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"caip2": {
"type": "string",
"pattern": "^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$",
Expand Down Expand Up @@ -85,6 +90,11 @@
},
"required": ["length", "encoding"],
"additionalProperties": false
},
"description": {
"type": "string",
"minLength": 1,
"maxLength": 1024
}
},
"allOf": [
Expand Down Expand Up @@ -128,7 +138,14 @@
"source": {
"type": "string",
"description": "Source of the container image.",
"format": "uri"
"format": "uri",
"minLength": 1,
"maxLength": 256
},
"description": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"endpoints": {
"type": "object",
Expand Down Expand Up @@ -203,6 +220,13 @@
"Endpoint": {
"type": "object",
"description": "Extension to ports, endpoints are used to expose the container to the outside world with a specific protocol for interfacing.",
"properties": {
"description": {
"type": "string",
"minLength": 1,
"maxLength": 1024
}
},
"oneOf": [
{
"$ref": "#/definitions/EndpointPort"
Expand Down
3 changes: 1 addition & 2 deletions packages/chainfile-testcontainers/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { randomInt } from 'node:crypto';

import {
Container,
Endpoint,
EndpointHttpAuthorization,
EndpointHttpJsonRpc,
EndpointHttpRest,
Expand Down Expand Up @@ -34,7 +33,7 @@ export class ChainfileContainer extends AbstractStartedContainer {
return this.getMappedPort(endpoint.port);
}

private getEndpoint<E extends Endpoint>(name: string): E {
private getEndpoint<E>(name: string): E {
const endpoint = this.container.endpoints?.[name];
if (endpoint === undefined) {
throw new Error(`Endpoint: '${name}' not found.`);
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions website/components/ChainfileDefinition.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
### Values

These values have reasonable defaults or are randomly generated values for secured fields
which will determine how the Chainfile is run.
You may override these values to customize the Chainfile for your specific needs.

{Object.entries(props.schema.values).map(([key, value]) => {
const defaultValue = typeof value === 'string' ? value : value.default;

return (

<>
<h5>{key} {value.required && <code className="nx-text-xs nx-font-normal">required</code>}</h5>

{value.description && <p>{value.description}</p>}
{defaultValue && <p>Default: <code>{defaultValue}</code></p>}

{value.random?.type === 'bytes' && <p>Random: <code>randomBytes({value.random.length}).toString({value.random.encoding})</code></p>}

</>
)})}

### Containers

{Object.entries(props.schema.containers).map(([key, container]) => {
return (

<>
<h4>{key}</h4>

{container.description && <p>{container.description}</p>}

{Object.entries(container.endpoints).map(([key, endpoint]) => {

return (

<>

<h5>
endpoint: <code>{key}</code>
</h5>

{endpoint.description && <p>{endpoint.description}</p>}

<ul>
{endpoint.port && (
<li>
Port: <code>{endpoint.port}</code>
</li>
)}
{endpoint.protocol && (
<li>
Protocol: <code>{endpoint.protocol}</code>
</li>
)}
{endpoint.path && (
<li>
Path: <code>{endpoint.path}</code>
</li>
)}
{endpoint.probes && <li>Probes: {Object.keys(endpoint.probes).join(', ')}</li>}
{endpoint.authorization && <li>Authorization: required</li>}
</ul>

</>
)})}

</>
)})}
3 changes: 3 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"@types/react": "^18.3.3",
"@workspace/eslint-config-next": "workspace:*",
"autoprefixer": "^10.4.19",
"chainfile-ganache": "^0.1.0",
"chainfile-hardhat": "^0.4.3",
"chainfile-solana": "^0.2.1",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.4"
}
Expand Down
2 changes: 2 additions & 0 deletions website/pages/definitions/bitcoin.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Bitcoin

Definition(s) is maintained by the Chainfile maintainers.
3 changes: 3 additions & 0 deletions website/pages/definitions/defichain.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Defichain

Definition(s) is maintained by the Chainfile maintainers.
2 changes: 2 additions & 0 deletions website/pages/definitions/ethereum.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Ethereum

Definition(s) is maintained by the Chainfile maintainers.
16 changes: 10 additions & 6 deletions website/pages/definitions/ganache.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Callout } from 'nextra/components';
import ChainfileDefinition from '../../components/ChainfileDefinition.mdx';
import ganache from 'chainfile-ganache/ganache.json';

# Ganache

import { Callout } from 'nextra/components';
Definition(s) is maintained by the Chainfile maintainers.

<Callout type="warning">
The Truffle Suite has deprecated Ganache in favor of [Hardhat](hardhat). This Chainfile definition is created for
legacy compatibility only.

The Truffle Suite has deprecated Ganache in favor of [Hardhat](hardhat).
This Chainfile definition is created for legacy compatibility only.

</Callout>

## ganache.json

```txt filename="Location" copy
chainfile-ganache/ganache.json
```
<ChainfileDefinition schema={ganache} />
44 changes: 6 additions & 38 deletions website/pages/definitions/hardhat.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import ChainfileDefinition from '../../components/ChainfileDefinition.mdx';
import hardhat from 'chainfile-hardhat/hardhat.json';

# Hardhat

Definition(s) is maintained by the Chainfile maintainers.

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
You can use Hardhat directly within your Node.js.
This definition provides a containerized version of Hardhat for local toolchain isolation,
Expand All @@ -12,41 +17,4 @@ You should not use this definition for any production purposes.

## hardhat.json

```txt filename="Location" copy
chainfile-hardhat/hardhat.json
```

### Values

- `version`: the version of Hardhat to use see [vetumorg/chainfile-hardhat/pkgs](https://github.com/vetumorg/chainfile-hardhat/pkgs/container/hardhat)

## Using `hardhat-testcontainers` with `viem`

If you're using Node.js and want to take advantage of `viem` for type-safe JSON-RPC.
We provide a NPM only package for `hardhat-testcontainers`:

```shell filename="Installation" copy
npm i -D hardhat-testcontainers viem
```

```typescript filename="hardhat.test.ts" {9} copy
import { afterAll, beforeAll, expect, it } from '@jest/globals';
import { HardClient, HardhatContainer, StartedHardhatContainer } from 'hardhat-testcontainers';

let container: StartedHardhatContainer;
let client: HardClient;

beforeAll(async () => {
container = await new HardhatContainer().start();
client = container.client;
});

afterAll(async () => {
await container.stop();
});

it('should rpc(eth_blockNumber) via viem using container.client', async () => {
const blockNumber = await client.getBlockNumber();
expect(blockNumber).toStrictEqual(BigInt(0));
});
```
<ChainfileDefinition schema={hardhat} />
9 changes: 6 additions & 3 deletions website/pages/definitions/solana.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import ChainfileDefinition from '../../components/ChainfileDefinition.mdx';
import test_validator from 'chainfile-solana/test-validator.json';

# Solana

Definition(s) is maintained by the Chainfile maintainers.

## test-validator.json

```txt filename="Location" copy
chainfile-solana/test-validator.json
```
<ChainfileDefinition schema={test_validator} />

0 comments on commit 6865f5e

Please sign in to comment.