Skip to content

Commit 6e93bbc

Browse files
committed
Check api example cbor in CI
1 parent 3dc46cc commit 6e93bbc

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -uo pipefail
3+
4+
# Check consistency of .cbor files against .cddl in the repository.
5+
6+
# TODO: check whether 'cddl' is installed
7+
8+
# Check that given cbor is valid against all given cddls files concatenated
9+
function check_cbor() {
10+
local cbor_file=$1
11+
shift
12+
local cddl_files=("$@")
13+
local cddl=$(cat "${cddl_files[@]}")
14+
# NOTE: cddl spams stdout on invalid cbor, so we drop everything after '-- cannot complete'
15+
out=$(cddl <(echo "${cddl}") validate <(xxd -r -p "${cbor_file}") 2> /dev/null | \
16+
awk -v RS='--' 'NR==1{print} NR==2{exit}')
17+
if [ $? -ne 0 ]; then
18+
echo "Invalid cbor file: ${cbor_file}"
19+
echo "Error: ${out%--*}"
20+
printf "CDDL: \n${cddl}"
21+
exit 1
22+
fi
23+
}
24+
25+
cd src/api
26+
check_cbor examples/getSystemStart/query.cbor cddl/local-state-query.cddl cddl/getSystemStart.cddl
27+
check_cbor examples/getSystemStart/result.cbor cddl/local-state-query.cddl cddl/getSystemStart.cddl
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check cbor examples
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
schedule:
9+
# Everyday at 4:00 AM
10+
- cron: "0 4 * * *"
11+
12+
jobs:
13+
check-cbor-examples:
14+
name: Check cbor examples
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install nix
20+
uses: cachix/install-nix-action@V27
21+
with:
22+
extra_nix_config: |
23+
accept-flake-config = true
24+
log-lines = 1000
25+
26+
- name: Enter nix shell
27+
uses: nicknovitski/nix-develop@v1
28+
29+
- run: ./.github/workflows/check-examples.sh

flake.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@
2525
mdbook-katex
2626
mdbook-alerts
2727
mdbook-toc
28+
29+
# to validate cbor / cddl
30+
cddl
31+
xxd
2832
];
2933
phases = [ "unpackPhase" "buildPhase" ];
3034
buildPhase = ''
3135
mdbook build -d $out
3236
'';
3337
}
3438
);
35-
defaultPackage = packages.mdbook;
39+
packages.default = packages.mdbook;
3640
}
3741
);
3842
}

src/client/node-to-client/state-query/getSystemStart.cddl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$query /= 1
1+
$query /= [1]
22
$result /= [year, dayOfYear, timeOfDayPico]
33

44
year = bigint

src/client/node-to-client/state-query/messages.cddl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ acquireFailurePointNotOnChain = 1
1818
failure = acquireFailurePointTooOld
1919
/ acquireFailurePointNotOnChain
2020

21-
$query = any
22-
$result = any
23-
2421
msgAcquire = [0, point]
2522
/ [8]
2623
/ [10]

0 commit comments

Comments
 (0)