-
Notifications
You must be signed in to change notification settings - Fork 2
/
vote_instruction_test.c
105 lines (89 loc) · 3.03 KB
/
vote_instruction_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "vote_instruction.c"
#include <assert.h>
#include <stdio.h>
void test_parse_vote_instruction_kind() {
enum VoteInstructionKind kind;
uint8_t buf[] = {0, 0, 0, 0};
Parser parser = {buf, ARRAY_LEN(buf)};
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteInitialize);
buf[0] = 1;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteAuthorize);
buf[0] = 2;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteVote);
buf[0] = 3;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteWithdraw);
buf[0] = 4;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteUpdateValidatorId);
buf[0] = 5;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteUpdateCommission);
buf[0] = 6;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteSwitchVote);
buf[0] = 7;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 0);
assert(kind == VoteAuthorizeChecked);
// Fail the first unused enum value to be sure this test gets updated
buf[0] = 8;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 1);
// Should always fail
buf[0] = 255;
buf[1] = 255;
buf[2] = 255;
buf[3] = 255;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_instruction_kind(&parser, &kind) == 1);
}
void test_parse_vote_authorize_enum() {
enum VoteAuthorize authorize;
uint8_t buf[] = {0, 0, 0, 0};
Parser parser = {buf, ARRAY_LEN(buf)};
assert(parse_vote_authorize(&parser, &authorize) == 0);
assert(authorize == VoteAuthorizeVoter);
buf[0] = 1;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_authorize(&parser, &authorize) == 0);
assert(authorize == VoteAuthorizeWithdrawer);
// Fail the first unused enum value to be sure this test gets updated
buf[0] = 2;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_authorize(&parser, &authorize) == 1);
// Should always fail
buf[0] = 255;
buf[1] = 255;
buf[2] = 255;
buf[3] = 255;
parser.buffer = buf;
parser.buffer_length = ARRAY_LEN(buf);
assert(parse_vote_authorize(&parser, &authorize) == 1);
}
int main() {
test_parse_vote_instruction_kind();
test_parse_vote_authorize_enum();
printf("passed\n");
return 0;
}