Page MenuHomePhabricator

[chronik-client] Add chronik-info endpoint to in-node chronik-client
ClosedPublic

Authored by bytesofman on Jan 9 2024, 22:14.

Details

Summary

Add support for available chronik-info endpoint to in-node chronik-client

Because we do not want to build everything for every different endpoint, rename blockchain_info test to api_endpoints

Add test for chronik-info endpoint before mining more blocks.

Note: we can use the mining more blocks logic to test other endpoints that find blocks, e.g. demonstrating a new blockheight is available.

Test Plan

Check CI result of built chronik tests

Event Timeline

Tail of the build log:

  run `npm fund` for details

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> chronik-client@0.10.1 integration-tests
> mocha -j1 -r ts-node/register test/integration/*.ts --reporter mocha-junit-reporter --reporter-options mochaFile=test_results/chronik-client-integration-tests-junit.xml --reporter-options testsuitesTitle=Chronik Client Integration Tests --reporter-options rootSuiteTitle=Chronik Client


Error: ENOENT: no such file or directory, open '/work/modules/..chronik/chronik-http/Cargo.toml'
    at Object.openSync (node:fs:590:3)
    at Object.readFileSync (node:fs:458:35)
    at Object.<anonymous> (/work/modules/chronik-client/test/integration/api_endpoints.ts:13:35)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Module.replacementCompile (/usr/lib/node_modules/nyc/node_modules/append-transform/index.js:60:13)
    at Module.m._compile (/work/modules/chronik-client/node_modules/ts-node/src/index.ts:1618:23)
    at module.exports (/usr/lib/node_modules/nyc/node_modules/default-require-extensions/js.js:7:9)
    at /usr/lib/node_modules/nyc/node_modules/append-transform/index.js:64:4
    at require.extensions.<computed> (/work/modules/chronik-client/node_modules/ts-node/src/index.ts:1621:12)
    at Object.<anonymous> (/usr/lib/node_modules/nyc/node_modules/append-transform/index.js:64:4)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Module.require (node:internal/modules/cjs/loader:1100:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.exports.requireOrImport (/work/modules/chronik-client/node_modules/mocha/lib/nodejs/esm-utils.js:60:20)
    at async Object.exports.loadFilesAsync (/work/modules/chronik-client/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
    at async singleRun (/work/modules/chronik-client/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/work/modules/chronik-client/node_modules/mocha/lib/cli/run.js:374:5)
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |    5.37 |     0.64 |    1.47 |    5.36 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |     4.9 |     0.67 |    1.72 |    4.89 |                                   
  chronik.ts           |    5.44 |     0.84 |    1.81 |    5.42 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |    4.15 |     0.45 |    1.59 |    4.17 | ...,2682-2729,2740-2804,2808-2813 
 chronik-client/src    |    8.73 |        0 |       0 |    8.69 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 29-159,174-218,286-686            
  ChronikClientNode.ts |      25 |        0 |       0 |      25 | 23-59                             
  failoverProxy.ts     |    4.44 |        0 |       0 |    4.59 | 27-276                            
  hex.ts               |   31.57 |        0 |       0 |   33.33 | 30-34,38-42,46-59,63-65           
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='156']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='2901']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='21']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='3278']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='8']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='541']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='154']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='2873']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/chronik-client-integration-tests-junit.xml': No such file or directory
Build chronik-client-integration-tests failed with exit code 1

hardcode version for CI test

Tail of the build log:

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> chronik-client@0.11.0 integration-tests
> mocha -j1 -r ts-node/register test/integration/*.ts --reporter mocha-junit-reporter --reporter-options mochaFile=test_results/chronik-client-integration-tests-junit.xml --reporter-options testsuitesTitle=Chronik Client Integration Tests --reporter-options rootSuiteTitle=Chronik Client

Starting test_runner
Test runner started
2024-01-09T22:49:41.053000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240109_224940/setup_scripts/chronik-client_blockchain_info_0
Setting chronik url to  http://127.0.0.1:30001
2024-01-09T22:49:42.225000Z TestFramework (INFO): Step 1: Mine 10 more blocks
2024-01-09T22:49:42.240000Z TestFramework (INFO): Step 2: Mine again 10 more blocks
2024-01-09T22:49:42.253000Z TestFramework (INFO): Step 3: Park the last block
2024-01-09T22:49:42.258000Z TestFramework (INFO): Step 4: Unpark the last block
2024-01-09T22:49:42.262000Z TestFramework (INFO): Got a next message but no more step, exiting
2024-01-09T22:49:42.312000Z TestFramework (INFO): Stopping nodes
2024-01-09T22:49:42.515000Z TestFramework (INFO): Cleaning up /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240109_224940/setup_scripts/chronik-client_blockchain_info_0 on exit
2024-01-09T22:49:42.515000Z TestFramework (INFO): Tests successful
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_blockchain_info.py started
setup_scripts/chronik-client_blockchain_info.py passed, Duration: 2 s

TEST                                            | STATUS    | DURATION

setup_scripts/chronik-client_blockchain_info.py | ✓ Passed  | 2 s

ALL                                             | ✓ Passed  | 2 s (accumulated) 
Runtime: 2 s

Test runner error, aborting: Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |    7.16 |     1.12 |    3.88 |     7.1 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |    5.44 |     0.86 |    2.15 |    5.44 |                                   
  chronik.ts           |    5.44 |     0.84 |    1.81 |    5.42 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |    5.44 |      0.9 |    2.65 |    5.47 | ...,2682-2729,2740-2804,2808-2813 
 chronik-client/src    |   21.03 |     5.95 |    14.1 |   20.73 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 29-159,174-218,286-686            
  ChronikClientNode.ts |   56.25 |        0 |      50 |   56.25 | 28,40-42,56-59                    
  failoverProxy.ts     |   35.55 |    25.64 |   30.43 |   35.63 | ...,85,93,129-142,167-178,188-276 
  hex.ts               |   44.73 |        0 |      25 |   45.45 | 30-34,46-59,63-65                 
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='208']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='2901']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='37']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='3278']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='21']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='541']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='204']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='2873']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/chronik-client-integration-tests-junit.xml': No such file or directory
Build chronik-client-integration-tests failed with exit code 1

@bot chronik-client-integration-tests

Failed tests logs:

====== Available api endpoints: gives us the chronik info.Available api endpoints gives us the chronik info ======
TypeError: Cannot read properties of undefined (reading 'length')
    at new FailoverProxy (src/failoverProxy.ts:6:177)
    at new ChronikClientNode (src/ChronikClientNode.ts:14:22)
    at /work/modules/chronik-client/test/integration/api_endpoints.ts:119:25
    at Generator.next (<anonymous>)
    at fulfilled (test/integration/api_endpoints.ts:28:58)
====== Available api endpoints: "before each" hook for "gives us the blockchain info".Available api endpoints "before each" hook for "gives us the blockchain info" ======
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/work/modules/chronik-client/test/integration/api_endpoints.ts)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

Each failure log is accessible here:
Available api endpoints: gives us the chronik info.Available api endpoints gives us the chronik info
Available api endpoints: "before each" hook for "gives us the blockchain info".Available api endpoints "before each" hook for "gives us the blockchain info"

@bot chronik-client-integration-tests

Tail of the build log:

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> chronik-client@0.11.0 integration-tests
> mocha -j1 -r ts-node/register test/integration/*.ts --reporter mocha-junit-reporter --reporter-options mochaFile=test_results/chronik-client-integration-tests-junit.xml --reporter-options testsuitesTitle=Chronik Client Integration Tests --reporter-options rootSuiteTitle=Chronik Client

Starting test_runner
Test runner started
2024-01-10T23:08:03.207000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240110_230803/setup_scripts/chronik-client_blockchain_info_0
Setting chronik url to  http://127.0.0.1:30001
2024-01-10T23:08:04.744000Z TestFramework (INFO): Step 1: Mine 10 more blocks
2024-01-10T23:08:04.761000Z TestFramework (INFO): Step 2: Mine again 10 more blocks
2024-01-10T23:08:04.773000Z TestFramework (INFO): Step 3: Park the last block
2024-01-10T23:08:04.777000Z TestFramework (INFO): Step 4: Unpark the last block
2024-01-10T23:08:04.780000Z TestFramework (INFO): Got a next message but no more step, exiting
2024-01-10T23:08:04.831000Z TestFramework (INFO): Stopping nodes
2024-01-10T23:08:05.636000Z TestFramework (INFO): Cleaning up /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240110_230803/setup_scripts/chronik-client_blockchain_info_0 on exit
2024-01-10T23:08:05.636000Z TestFramework (INFO): Tests successful
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_blockchain_info.py started
setup_scripts/chronik-client_blockchain_info.py passed, Duration: 3 s

TEST                                            | STATUS    | DURATION

setup_scripts/chronik-client_blockchain_info.py | ✓ Passed  | 3 s

ALL                                             | ✓ Passed  | 3 s (accumulated) 
Runtime: 3 s

Test runner error, aborting: Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |    7.16 |     1.12 |    3.88 |     7.1 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |    5.44 |     0.86 |    2.15 |    5.44 |                                   
  chronik.ts           |    5.44 |     0.84 |    1.81 |    5.42 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |    5.44 |      0.9 |    2.65 |    5.47 | ...,2682-2729,2740-2804,2808-2813 
 chronik-client/src    |   21.03 |     5.95 |    14.1 |   20.73 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 29-159,174-218,286-686            
  ChronikClientNode.ts |   56.25 |        0 |      50 |   56.25 | 28,40-42,56-59                    
  failoverProxy.ts     |   35.55 |    25.64 |   30.43 |   35.63 | ...,85,93,129-142,167-178,188-276 
  hex.ts               |   44.73 |        0 |      25 |   45.45 | 30-34,46-59,63-65                 
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='208']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='2901']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='37']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='3278']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='21']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='541']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='204']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='2873']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/chronik-client-integration-tests-junit.xml': No such file or directory
Build chronik-client-integration-tests failed with exit code 1

Fix bugs in implementing the unit test

better organization for unit tests, hardcode version number

Fabien requested changes to this revision.Jan 18 2024, 20:05
Fabien added a subscriber: Fabien.
Fabien added inline comments.
modules/chronik-client/package.json
3 ↗(On Diff #44335)

why is the version different from the package-lock.json?

modules/chronik-client/test/integration/chronik_info.ts
10 ↗(On Diff #44335)

We need to figure out how to avoid to copy all this fixture only to change a name in 3 places

test/functional/setup_scripts/chronik-client_chronik_info.py
2 ↗(On Diff #44335)
18 ↗(On Diff #44335)

You can use the default and omit it, I added in the other test mostly for the sake of documenting that it exists

27 ↗(On Diff #44335)

This can be inlined for such a simple script

This revision now requires changes to proceed.Jan 18 2024, 20:05
bytesofman marked 3 inline comments as done.

Move (most of) testRunner initialization to own file, respond to feedback, match linter version to what arc lint was calling

modules/chronik-client/package.json
28 ↗(On Diff #44340)

I was getting an arc lint error that would not allow me to update the diff, resolved by matching eslint version to what arc lint was using

3 ↗(On Diff #44335)

This weirdness happens if you

  • bump the version in package-lock.json
  • do not run npm i

Pretty standard, as then package-lock.json retains the last version where something changed about the dependencies.

in this case it is weird because I probably messed with dependencies in the course of draft testing, then decided not to.

fixed by

rm -rf node_modules
rm package-lock.json
npm i
modules/chronik-client/test/integration/blockchain_info.ts
19 ↗(On Diff #44340)

I wasn't able to move this into testRunner.ts and still get the chronik urls. It probably is possible.

test/functional/setup_scripts/chronik-client_chronik_info.py
27 ↗(On Diff #44335)

...not sure how to do this

test/functional/setup_scripts/chronik-client_chronik_info.py
27 ↗(On Diff #44335)

No black magic here :) :

def run_test(self):
    send_ipc_message({"chronik": f"http://127.0.0.1:{self.nodes[0].chronik_port}"})

and remove the send_chronik_info function.

This revision is now accepted and ready to land.Jan 19 2024, 08:30