From f3f8ec90174ba0b8f29b1ba6979748943979a73e Mon Sep 17 00:00:00 2001 From: Fuxing Loh Date: Mon, 1 Jul 2024 15:26:40 +0800 Subject: [PATCH] chore(docker): add subPath test for docker compose --- .../chainfile-agent/src/routers/probes.ts | 1 + .../tests/bitcoin-testnet.json | 78 +++++++++++++++++++ .../tests/bitcoin-testnet.test.ts | 38 +++++++++ 3 files changed, 117 insertions(+) create mode 100644 packages/chainfile-testcontainers-node/tests/bitcoin-testnet.json create mode 100644 packages/chainfile-testcontainers-node/tests/bitcoin-testnet.test.ts diff --git a/packages/chainfile-agent/src/routers/probes.ts b/packages/chainfile-agent/src/routers/probes.ts index 1c9d692..7971af0 100644 --- a/packages/chainfile-agent/src/routers/probes.ts +++ b/packages/chainfile-agent/src/routers/probes.ts @@ -269,3 +269,4 @@ class Probes { // Container: /api/condition-1 <-| // : /api/condition-2 <-| Agent: /probes/liveness // : /api/condition-3 <-| +// You should be able to check each condition individually. diff --git a/packages/chainfile-testcontainers-node/tests/bitcoin-testnet.json b/packages/chainfile-testcontainers-node/tests/bitcoin-testnet.json new file mode 100644 index 0000000..cf00d64 --- /dev/null +++ b/packages/chainfile-testcontainers-node/tests/bitcoin-testnet.json @@ -0,0 +1,78 @@ +{ + "$schema": "../node_modules/@chainfile/schema/schema.json", + "caip2": "bip122:0f9188f13cb7b2c71f2a335e3a4fc328", + "name": "Bitcoin Testnet", + "params": { + "rpc_user": "user", + "rpc_password": "pass" + }, + "volumes": { + "data": { + "type": "persistent", + "size": "10Gi" + } + }, + "containers": { + "bitcoind": { + "image": "docker.io/kylemanna/bitcoind", + "tag": "latest", + "source": "https://github.com/kylemanna/docker-bitcoind", + "command": ["btc_oneshot", "-testnet", "-fallbackfee=0.00000200", "-rpcbind=:8332", "-rpcallowip=0.0.0.0/0"], + "endpoints": { + "p2p": { + "port": 18334 + }, + "rpc": { + "port": 8332, + "protocol": "HTTP JSON-RPC 2.0", + "authorization": { + "type": "HttpBasic", + "username": { + "$param": "rpc_user" + }, + "password": { + "$param": "rpc_password" + } + }, + "probes": { + "readiness": { + "method": "getblockchaininfo", + "params": [], + "match": { + "result": { + "type": "object", + "properties": { + "blocks": { + "type": "number" + } + }, + "required": ["blocks"] + } + } + } + } + } + }, + "resources": { + "cpu": 0.25, + "memory": 256 + }, + "environment": { + "DISABLEWALLET": "0", + "RPCUSER": { + "$param": "rpc_user" + }, + "RPCPASSWORD": { + "$param": "rpc_password" + } + }, + "mounts": [ + { + "volume": "data", + "mountPath": "/bitcoin/.bitcoin", + "subPath": "bitcoind" + } + ] + } + } +} diff --git a/packages/chainfile-testcontainers-node/tests/bitcoin-testnet.test.ts b/packages/chainfile-testcontainers-node/tests/bitcoin-testnet.test.ts new file mode 100644 index 0000000..edab633 --- /dev/null +++ b/packages/chainfile-testcontainers-node/tests/bitcoin-testnet.test.ts @@ -0,0 +1,38 @@ +import { afterAll, beforeAll, describe, expect, it } from '@workspace/jest/globals'; + +import { CFContainer, CFTestcontainers } from '../src'; +import testnet from './bitcoin-testnet.json'; + +const testcontainers = new CFTestcontainers(testnet); + +beforeAll(async () => { + await testcontainers.start(); +}); + +afterAll(async () => { + await testcontainers.stop(); +}); + +describe('bitcoind', () => { + let bitcoind: CFContainer; + + beforeAll(() => { + bitcoind = testcontainers.get('bitcoind'); + }); + + it('should rpc(getblockchaininfo)', async () => { + const response = await bitcoind.rpc({ + method: 'getblockchaininfo', + }); + + expect(response.status).toStrictEqual(200); + + expect(await response.json()).toMatchObject({ + result: { + bestblockhash: '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', + chain: 'test', + blocks: 0, + }, + }); + }); +});