Revision 89d5a48543c9960d9c77da1bfe7be4d8eac9b854 authored by Marge Bot on 17 January 2024, 13:34:34 UTC, committed by Marge Bot on 17 January 2024, 13:34:34 UTC
Co-authored-by: Ole Krüger <ole.kruger@trili.tech> Approved-by: Victor Dumitrescu <victor.dumitrescu@nomadic-labs.com> Approved-by: Felix Puscasu <felix.puscasu@trili.tech> Approved-by: Emma Turner <1623821-emturner@users.noreply.gitlab.com> See merge request https://gitlab.com/tezos/tezos/-/merge_requests/11463
generate.sh
#!/bin/sh
# This script launches a sandbox node, activates Granada, gets the RPC descriptions
# as JSON, and converts this JSON into an OpenAPI specification.
# You must compile the node and the client before running it.
#
# When the python tests framework becomes a standalone library, this script
# should be removed and replaced by a python script calling the test's core
# logic.
# Ensure we are running from the root directory of the Tezos repository.
cd "$(dirname "$0")"/../.. || exit
# Tezos binaries.
tezos_node=./octez-node
tezos_client=./octez-client
smart_rollup_node=./octez-smart-rollup-node
# Protocol configuration.
protocol_hash=ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH
protocol_parameters=src/proto_018_Proxford/parameters/sandbox-parameters.json
protocol_name=oxford
# Secret key to activate the protocol.
activator_secret_key="unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
# RPC port.
rpc_port=8732
# Temporary files.
tmp=openapi-tmp
data_dir=$tmp/octez-sandbox
client_dir=$tmp/octez-client
api_json=$tmp/rpc-api.json
proto_api_json=$tmp/proto-api.json
mempool_api_json=$tmp/mempool-api.json
# Generated files.
openapi_json=docs/api/rpc-openapi-rc.json
proto_openapi_json=docs/api/$protocol_name-openapi-rc.json
mempool_openapi_json=docs/api/$protocol_name-mempool-openapi-rc.json
smart_rollup_node_openapi_json=docs/api/$protocol_name-smart-rollup-node-openapi-rc.json
# Get version number.
version=$(dune exec octez-version)
# Start a sandbox node.
$tezos_node config init --data-dir $data_dir \
--network sandbox \
--expected-pow 0 \
--local-rpc-addr localhost:$rpc_port \
--no-bootstrap-peer \
--synchronisation-threshold 0
$tezos_node identity generate --data-dir $data_dir
$tezos_node run --data-dir $data_dir --connections 0 &
node_pid="$!"
# Wait for the node to be ready (sorry for the hackish way...)
sleep 1
# Activate the protocol.
mkdir $client_dir
$tezos_client --base-dir $client_dir import secret key activator $activator_secret_key
$tezos_client --base-dir $client_dir activate protocol $protocol_hash \
with fitness 1 \
and key activator \
and parameters $protocol_parameters \
--timestamp "$(TZ='AAA+1' date +%FT%TZ)"
# Wait a bit again...
sleep 1
# Get the RPC descriptions.
curl "http://localhost:$rpc_port/describe/?recurse=yes" > $api_json
curl "http://localhost:$rpc_port/describe/chains/main/blocks/head?recurse=yes" > $proto_api_json
curl "http://localhost:$rpc_port/describe/chains/main/mempool?recurse=yes" > $mempool_api_json
# Kill the node.
kill -9 "$node_pid"
# Remove RPC starting with "/private/"
clean_private_rpc() {
jq 'delpaths([paths | select(.[-1] | strings | startswith("/private/"))])'
}
# Convert the RPC descriptions.
dune exec src/bin_openapi/rpc_openapi.exe -- \
"$version" \
"Octez RPC" \
"The RPC API served by the Octez node." \
$api_json |
clean_private_rpc "$@" > $openapi_json
echo "Generated OpenAPI specification: $openapi_json"
dune exec src/bin_openapi/rpc_openapi.exe -- \
"$version" \
"Octez Protocol $protocol_name RPC" \
"The RPC API for protocol $protocol_name served by the Octez node." \
$proto_api_json |
clean_private_rpc "$@" > $proto_openapi_json
echo "Generated OpenAPI specification: $proto_openapi_json"
dune exec src/bin_openapi/rpc_openapi.exe -- \
"$version" \
"Octez Mempool RPC" "The RPC API for the mempool served by the Octez node." \
$mempool_api_json |
clean_private_rpc "$@" > $mempool_openapi_json
echo "Generated OpenAPI specification: $mempool_openapi_json"
# Gernerate openapi file for rollup node
$smart_rollup_node generate openapi -P $protocol_hash > $smart_rollup_node_openapi_json
echo "Generated OpenAPI specification: $smart_rollup_node_openapi_json"
echo "You can now clean up with: rm -rf $tmp"
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...