Skip to content

Commit

Permalink
feat: add solana-test-validator.json
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Mar 18, 2024
1 parent 260de90 commit 5277e3e
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ permissions:
contents: read
packages: read

env:
BUILDKIT_PROGRESS: plain

jobs:
build:
name: Build
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
permissions:
contents: read

env:
BUILDKIT_PROGRESS: plain

jobs:
version:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion definitions/eip155-31337/hardhat.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Hardhat",
"containers": {
"hardhat": {
"image": "ghcr.io/fuxingloh/hardhat-container:2.19.4",
"image": "ghcr.io/fuxingloh/hardhat-container:2.22.1",
"source": "https://github.com/fuxingloh/hardhat-container",
"resources": {
"cpu": 0.25,
Expand Down
373 changes: 373 additions & 0 deletions definitions/solana-test-validator/LICENSE

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions definitions/solana-test-validator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@karfia/solana-test-validator",
"version": "0.0.0",
"private": false,
"repository": {
"url": "git+https://github.com/fuxingloh/karfia"
},
"license": "MPL-2.0",
"scripts": {
"lint": "eslint .",
"test": "jest"
},
"lint-staged": {
"*": [
"prettier --write --ignore-unknown"
],
"*.{ts,tsx}": [
"eslint --fix",
"prettier --write"
]
},
"jest": {
"preset": "@workspace/jest-preset"
},
"devDependencies": {
"@workspace/jest-preset": "workspace:*",
"@workspace/tsconfig": "workspace:*",
"karfia-definition": "workspace:*",
"karfia-testcontainers": "workspace:*"
}
}
33 changes: 33 additions & 0 deletions definitions/solana-test-validator/solana-test-validator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "./node_modules/karfia-definition/index.json",
"id": "solana:test-validator/solana-test-validator:1.17.26",
"caip2": "solana:test-validator",
"name": "Solana Test Validator",
"containers": {
"solana-test-validator": {
"image": "ghcr.io/fuxingloh/solana-container:1.17.26",
"source": "https://github.com/fuxingloh/solana-container",
"resources": {
"cpu": 0.25,
"memory": 256
},
"endpoints": {
"rpc": {
"port": 8899,
"protocol": "HTTP JSON-RPC 2.0",
"probes": {
"readiness": {
"params": [],
"method": "getBlockHeight",
"match": {
"result": {
"type": "number"
}
}
}
}
}
}
}
}
}
93 changes: 93 additions & 0 deletions definitions/solana-test-validator/solana-test-validator.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { KarfiaAgentContainer, KarfiaTestContainer, KarfiaTestcontainers } from 'karfia-testcontainers';

import definition from './solana-test-validator.json';

describe('testcontainers', () => {
let testcontainers: KarfiaTestcontainers;

beforeAll(async () => {
testcontainers = await KarfiaTestcontainers.start(definition);
});

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

describe('solana-test-validator', () => {
let validator: KarfiaTestContainer;

beforeAll(() => {
validator = testcontainers.getContainer('solana-test-validator');
});

it('should rpc(getBlockHeight)', async () => {
const response = await validator.rpc({
method: 'getBlockHeight',
});

expect(response.status).toStrictEqual(200);

expect(await response.json()).toMatchObject({
result: 0,
});
});
});

describe('karfia-agent', () => {
let agent: KarfiaAgentContainer;

beforeAll(() => {
agent = testcontainers.getKarfiaAgent();
});

it('should get karfia-agent/deployment', async () => {
const result = await agent.getDeployment();
expect(result).toMatchObject({
deploymentId: testcontainers.getDeploymentId(),
definitionId: definition.id,
caip2: definition.caip2,
name: definition.name,
});
});

it('should get karfia-agent/definition', async () => {
const result = await agent.getDefinition();
const expected = {
...definition,
$schema: undefined,
};
delete expected.$schema;
expect(result).toMatchObject(expected);
});

it('should get karfia-agent/probes/startup', async () => {
const response = await agent.probe('startup');
expect(response.status).toStrictEqual(200);
expect(await response.json()).toMatchObject({
ok: true,
});
});

it('should get karfia-agent/probes/liveness', async () => {
const response = await agent.probe('liveness');
expect(response.status).toStrictEqual(200);
expect(await response.json()).toMatchObject({
ok: true,
});
});

it('should get karfia-agent/probes/readiness', async () => {
const response = await agent.probe('readiness');
expect(response.status).toStrictEqual(200);
expect(await response.json()).toMatchObject({
containers: {
'solana-test-validator': {
ok: true,
},
},
ok: true,
});
});
});
});
3 changes: 3 additions & 0 deletions definitions/solana-test-validator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@workspace/tsconfig"
}
2 changes: 1 addition & 1 deletion packages/karfia-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:docker": "docker build -t ghcr.io/fuxingloh/karfia-agent:$(node -p \"require('./package.json').version\") -f Dockerfile ../../",
"clean": "tsc --build --clean",
"lint": "eslint .",
"push:docker": "docker buildx build -t ghcr.io/fuxingloh/karfia-agent:$(node -p \"require('./package.json').version\") -f Dockerfile ../../ --output type=registry --platform linux/amd64,linux/arm64",
"push:docker": "docker buildx build -t ghcr.io/fuxingloh/karfia-agent:$(node -p \"require('./package.json').version\") -f Dockerfile ../../ --output type=registry --platform linux/amd64,linux/arm64",
"test": "jest --passWithNoTests"
},
"lint-staged": {
Expand Down
2 changes: 2 additions & 0 deletions packages/karfia-agent/routers/probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function createProbeFunctionHttp(
const scheme = endpoint.protocol.startsWith('HTTPS') ? 'https' : 'http';
const url = `${scheme}://${containerName}:${endpoint.port}${probe.path ?? ''}`;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(endpoint.authorization ? getHttpAuthorizationHeaders(endpoint.authorization) : {}),
};
const body = probe.body ? JSON.stringify(probe.body) : undefined;
Expand Down Expand Up @@ -180,6 +181,7 @@ function createProbeFunctionHttpJsonRpc(
const url = `${scheme}://${containerName}:${endpoint.port}${endpoint.path ?? ''}`;
const version = endpoint.protocol.endsWith('2.0') ? '2.0' : '1.0';
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(endpoint.authorization ? getHttpAuthorizationHeaders(endpoint.authorization) : {}),
};

Expand Down
1 change: 1 addition & 0 deletions packages/karfia-testcontainers/karfia-testcontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class KarfiaTestContainer extends AbstractStartedContainer {
const hostPort = this.getMappedPort(endpoint.port);
const hostEndpoint = `${scheme}://${this.getHost()}:${hostPort}${jsonRpc.path ?? ''}`;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(jsonRpc.authorization ? this.getHttpAuthorizationHeaders(jsonRpc.authorization) : {}),
...(options.headers ?? {}),
};
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 5277e3e

Please sign in to comment.