Skip to content

Commit 9200e61

Browse files
committed
ci: add nixosTests for db tools vs node and cli compatibility
1 parent 9d6c7ff commit 9200e61

3 files changed

Lines changed: 115 additions & 0 deletions

File tree

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@
495495
cardano-cli
496496
cardano-node
497497
cardano-submit-api
498+
cardano-testnet
498499
cardano-tracer
499500
db-analyser
500501
db-synthesizer
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{pkgs, ...}: let
2+
inherit (lib) getExe;
3+
inherit (pkgs) cardanoNodePackages lib;
4+
5+
# NixosTest script fns supporting a timeout have a default of 900 seconds.
6+
globalTimeout = 30;
7+
8+
testDir = "testnet";
9+
in {
10+
inherit globalTimeout;
11+
12+
name = "cardano-node-dbtools-test";
13+
nodes = {
14+
machine = _: {
15+
nixpkgs.pkgs = pkgs;
16+
17+
environment = {
18+
systemPackages = with cardanoNodePackages; [
19+
cardano-cli
20+
cardano-node
21+
cardano-testnet
22+
db-analyser
23+
db-synthesizer
24+
db-truncater
25+
] ++ (with pkgs; [
26+
gnugrep
27+
]);
28+
29+
variables = {
30+
CARDANO_CLI = getExe cardanoNodePackages.cardano-cli;
31+
CARDANO_NODE = getExe cardanoNodePackages.cardano-node;
32+
KES_KEY = "${testDir}/pools-keys/pool1/kes.skey";
33+
OPCERT = "${testDir}/pools-keys/pool1/opcert.cert";
34+
VRF_KEY = "${testDir}/pools-keys/pool1/vrf.skey";
35+
};
36+
};
37+
38+
# The default disk size of 1024 MB is insufficient for the binary artifact
39+
# and tar gzip expansion.
40+
virtualisation.diskSize = 2048;
41+
};
42+
};
43+
44+
testScript = ''
45+
import re
46+
countRegex = r'Counted (\d+) blocks\.'
47+
48+
start_all()
49+
print(machine.succeed("cardano-node --version"))
50+
print(machine.succeed("cardano-cli --version"))
51+
print(machine.succeed("cardano-testnet version"))
52+
print(machine.succeed("cardano-testnet create-env --output ${testDir}"))
53+
54+
# TODO: Until db-synthesizer is fixed upstream
55+
# print(machine.succeed("db-synthesizer \
56+
# --config ${testDir}/configuration.yaml \
57+
# --db db \
58+
# --shelley-operational-certificate $OPCERT \
59+
# --shelley-vrf-key $VRF_KEY \
60+
# --shelley-kes-key $KES_KEY \
61+
# --epochs 1 \
62+
# 2>&1")
63+
64+
print(machine.succeed("echo Analyze synthesized chain"))
65+
out = machine.succeed("db-analyser \
66+
--db db \
67+
--verbose \
68+
--count-blocks \
69+
--v2-in-mem \
70+
--config ${testDir}/configuration.yaml \
71+
2>&1"
72+
)
73+
print(out)
74+
match = re.search(countRegex, out)
75+
assert match is not None, f"Could not find block count in post-synthesis output: {out}"
76+
blocks_before = int(match.group(1))
77+
print(f"Found {blocks_before} blocks post synthesis")
78+
79+
# TODO: Until db-synthesizer is fixed upstream
80+
# assert blocks_before > 0, f"No blocks were synthesized: {blocks_before}"
81+
82+
print(machine.succeed("echo Truncate synthesized chain"))
83+
print(machine.succeed("db-truncater \
84+
--db db \
85+
--truncate-after-block 1 \
86+
--verbose \
87+
--config ${testDir}/configuration.yaml \
88+
2>&1")
89+
)
90+
91+
print(machine.succeed("echo Analyze truncated chain"))
92+
out = machine.succeed("db-analyser \
93+
--db db \
94+
--verbose \
95+
--count-blocks \
96+
--v2-in-mem \
97+
--config ${testDir}/configuration.yaml \
98+
2>&1"
99+
)
100+
print(out)
101+
match = re.search(countRegex, out)
102+
assert match is not None, f"Could not find block count in post-truncation output: {out}"
103+
blocks_after = int(match.group(1))
104+
print(f"Found {blocks_after} blocks post truncation")
105+
106+
# TODO: Until db-synthesizer is fixed upstream
107+
# assert blocks_after == 1, f"Expected exactly 1 block after truncation, got {blocks_after}"
108+
# assert blocks_before > blocks_after, f"Pre-truncation blockHeight of {blocks_before} should be larger than post-truncation blockHeight of {blocks_after}"
109+
110+
'';
111+
}

nix/nixos/tests/default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ in {
2525
# Tests the linux release binary envs with pre-bundled config.
2626
cardanoNodeArtifact = callTest ./cardano-node-artifact.nix {inherit cardano-node-linux;};
2727

28+
# Tests db-tools (synthesizer, analyser, truncater) against a cardano-testnet create-env environment.
29+
cardanoNodeDbtools= callTest ./cardano-node-dbtools.nix {};
30+
2831
# Tests a mainnet edge node with submit-api using nixos service config.
2932
cardanoNodeEdge = callTest ./cardano-node-edge.nix {};
3033
}

0 commit comments

Comments
 (0)