Page MenuHomePhabricator

[Chronik] Use the test framework's CScript in plugins instead of our own version
ClosedPublic

Authored by tobias_ruck on Jul 30 2024, 12:20.

Details

Summary

D16544 revealed that to write plugins, a good way to construct Scripts is needed. The test framework already provides such a class, and after moving some functions out of script.py, we have an independent module that we can just import to the plugin system.

Depends on D16550.

Test Plan

cargo test -p chronik-plugin-impl

Event Timeline

Tail of the build log:

  File "/work/test/functional/setup_scripts/../test_framework/util.py", line 296, in wait_until_helper
    raise AssertionError(
AssertionError: Predicate ''''
            self.wait_until(lambda: is_finalblock(next_blockhash))
''' not true after 60.0 seconds
2024-07-30T13:09:25.505000Z TestFramework (INFO): Stopping nodes
2024-07-30T13:09:25.710000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240730_130813/setup_scripts/chronik-client_websocket_0
2024-07-30T13:09:25.710000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240730_130813/setup_scripts/chronik-client_websocket_0/test_framework.log
2024-07-30T13:09:25.710000Z TestFramework (ERROR): 
2024-07-30T13:09:25.711000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_₿₵_🏃_20240730_130813/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2024-07-30T13:09:25.711000Z TestFramework (ERROR): 
2024-07-30T13:09:25.711000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2024-07-30T13:09:25.711000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2024-07-30T13:09:25.712000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_websocket.py started
setup_scripts/chronik-client_websocket.py failed, Duration: 73 s

stdout:

stderr:


TEST                                      | STATUS    | DURATION

setup_scripts/chronik-client_websocket.py | ✖ Failed  | 73 s

ALL                                       | ✖ Failed  | 73 s (accumulated) 
Runtime: 73 s

Test runner for chronik-client_websocket completed with code 1
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |   28.35 |     8.64 |   24.57 |   28.35 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |    21.6 |     6.07 |    13.9 |   21.74 |                                   
  chronik.ts           |     6.1 |     0.83 |    2.54 |    6.09 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |   33.03 |    10.56 |    23.6 |   33.28 | ...,4991-5030,5038-5111,5146-5151 
 chronik-client/src    |   65.77 |    42.39 |   63.41 |   65.38 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 33-163,178-222,290-692            
  ChronikClientNode.ts |   90.84 |     72.8 |   96.38 |   90.84 | ...,1068,1078,1103,1115,1121,1127 
  failoverProxy.ts     |   75.22 |    51.61 |   62.06 |   74.52 | ...67,275-285,294,301,305,310,314 
  hex.ts               |   89.47 |       50 |      75 |   87.87 | 58,66-68                          
  validation.ts        |   93.33 |    81.81 |     100 |   92.59 | 33,39                             
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='1188']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='4189']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='337']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='3897']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='187']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='761']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='1176']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='4148']
##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

Failed tests logs:

====== Bitcoin ABC functional tests: chronik_plugins.py ======

------- Stdout: -------
2024-07-30T13:13:25.567000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-chronik-plugins/test/tmp/test_runner_₿₵_🏃_20240730_130633/chronik_plugins_272
2024-07-30T13:13:28.525000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 147, in main
    self._run_test_internal()
  File "/work/test/functional/test_framework/test_framework.py", line 137, in _run_test_internal
    self.run_test()
  File "/work/test/functional/chronik_plugins.py", line 112, in run_test
    proto_tx1 = chronik.tx(tx1.hash).ok()
  File "/work/test/functional/test_framework/chronik/client.py", line 30, in ok
    raise AssertionError(
AssertionError: Expected OK response, but got status 404, error: msg: "404: Transaction de0975bfc6ddeb7ef76b6cc1d04e1f66b6993fe508e99c54f536ca1cdbc31788 not found in the index"

2024-07-30T13:13:28.576000Z TestFramework (INFO): Stopping nodes
[node 0] Cleaning up leftover process
------- Stderr: -------
Traceback (most recent call last):
  File "/work/test/functional/chronik_plugins.py", line 279, in <module>
    ChronikPlugins().main()
  File "/work/test/functional/test_framework/test_framework.py", line 170, in main
    exit_code = self.shutdown()
  File "/work/test/functional/test_framework/test_framework.py", line 396, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 645, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 512, in stop_node
    self.stop(wait=wait)
  File "/work/test/functional/test_framework/coverage.py", line 46, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 176, in __call__
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 124, in _request
    self.__conn.request(method, path, postdata, headers)
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3.9/http/client.py", line 921, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Each failure log is accessible here:
Bitcoin ABC functional tests: chronik_plugins.py

fix chronik_plugins.py using CScript

I'm not very familiar with the chronik plugin system, so just to clarify, is the CScript class now something that chronik users will be encouraged to use when writing plugins? If so, do we have a clear idea of how we will handle API deprecation in case we want to refactor the test framework in the future (how long in advance we will give users notice and maintain the legacy API, how we will log deprecation notifications)?

In D16551#374824, @PiRK wrote:

I'm not very familiar with the chronik plugin system, so just to clarify, is the CScript class now something that chronik users will be encouraged to use when writing plugins?

Well, it’s the only option, the bridged tx has CScript instances in inputs and outputs.

If so, do we have a clear idea of how we will handle API deprecation in case we want to refactor the test framework in the future (how long in advance we will give users notice and maintain the legacy API, how we will log deprecation notifications)?

This is currently completely undefined, but I think it’s better that we start without a clear deprecation protocol, and later we can establish something more automated.

It will be tricky to have the plugin tell the required version as it will likely fail during imports without ever constructing a Plugin instance that could tell us the required version. In the future we might have a manifest toml or so for each plugin.

Long term, I think we should strive to build a common Python library that can be used by the test framework, Electrum ABC and the plugin system, and commit to certain stability guarantees.

This revision is now accepted and ready to land.Jul 31 2024, 08:44