Skip to content

Commit 190411f

Browse files
committed
channel: Add test for channel state max
Adds a test so CI will fail if CHANNEL_STATE_MAX isn’t updated when new channel states are added. Changelog-None
1 parent 57be277 commit 190411f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

common/test/run-channel_type.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ccan/tal/str/str.h>
55
#include <common/setup.h>
66
#include <stdio.h>
7+
#include <lightningd/channel_state.h>
78

89
/* AUTOGENERATED MOCKS START */
910
/* Generated stub for amount_asset_is_main */
@@ -114,6 +115,42 @@ static void assert_names_eq(const char **names, const char *expected)
114115
assert(streq(expected_names[i], names[i]));
115116
}
116117

118+
static enum channel_state calc_channel_state_max(void)
119+
{
120+
enum channel_state largest_state = 0;
121+
122+
assert(DUALOPEND_OPEN_INIT == 1);
123+
for (enum channel_state state = 1;; state++) {
124+
bool known_state;
125+
switch(state) {
126+
case DUALOPEND_OPEN_INIT:
127+
case CHANNELD_AWAITING_LOCKIN:
128+
case CHANNELD_NORMAL:
129+
case CHANNELD_SHUTTING_DOWN:
130+
case CLOSINGD_SIGEXCHANGE:
131+
case CLOSINGD_COMPLETE:
132+
case AWAITING_UNILATERAL:
133+
case FUNDING_SPEND_SEEN:
134+
case ONCHAIN:
135+
case CLOSED:
136+
case DUALOPEND_OPEN_COMMITTED:
137+
case DUALOPEND_AWAITING_LOCKIN:
138+
case CHANNELD_AWAITING_SPLICE:
139+
case DUALOPEND_OPEN_COMMIT_READY:
140+
largest_state = state;
141+
known_state = true;
142+
break;
143+
default:
144+
known_state = false;
145+
break;
146+
}
147+
if (!known_state)
148+
break;
149+
}
150+
151+
return largest_state;
152+
}
153+
117154
int main(int argc, char *argv[])
118155
{
119156
struct channel_type t;
@@ -125,6 +162,8 @@ int main(int argc, char *argv[])
125162
assert_names_eq(channel_type_name(tmpctx, channel_type_anchors_zero_fee_htlc(tmpctx)),
126163
"static_remotekey/even anchors/even");
127164

165+
assert(calc_channel_state_max() == CHANNEL_STATE_MAX);
166+
128167
t.features = tal_arr(tmpctx, u8, 0);
129168
set_feature_bit(&t.features, 1000);
130169
assert_names_eq(channel_type_name(tmpctx, &t), "unknown_1000/even");

0 commit comments

Comments
 (0)