@@ -9,10 +9,6 @@ const Yaml = @import("../../yaml/yaml.zig").Yaml;
9
9
const gpa = testing .allocator ;
10
10
11
11
/// Loads and parses a YAML file into a Yaml object
12
- /// Parameters:
13
- /// file_path: Path to the YAML file to load
14
- /// Returns:
15
- /// Parsed Yaml object or error
16
12
fn loadFromFile (file_path : []const u8 ) ! Yaml {
17
13
const file = try std .fs .cwd ().openFile (file_path , .{});
18
14
defer file .close ();
@@ -26,42 +22,105 @@ fn loadFromFile(file_path: []const u8) !Yaml {
26
22
const Roots = struct {
27
23
root : [32 ]u8 ,
28
24
};
25
+
26
+ const structMultiPhase = union {
27
+ Attestation : types.Attestation ,
28
+ BeaconBlockBody : types.BeaconBlockBody ,
29
+ BeaconState : types.BeaconState ,
30
+ BlobIdentifier : types.BlobIdentifier ,
31
+ BlobSidecar : types.BlobSidecar ,
32
+ BLSToExecutionChange : types.BLSToExecutionChange ,
33
+ ConsolidationRequest : types.ConsolidationRequest ,
34
+ ContributionAndProof : types.ContributionAndProof ,
35
+ DepositRequest : types.DepositRequest ,
36
+ ExecutionPayload : types.ExecutionPayload ,
37
+ ExecutionPayloadHeader : types.ExecutionPayloadHeader ,
38
+ HistoricalSummary : types.HistoricalSummary ,
39
+ LightClientBootstrap : types.LightClientBootstrap ,
40
+ LightClientFinalityUpdate : types.LightClientFinalityUpdate ,
41
+ LightClientHeader : types.LightClientHeader ,
42
+ LightClientOptimisticUpdate : types.LightClientOptimisticUpdate ,
43
+ LightClientUpdate : types.LightClientUpdate ,
44
+ PendingBalanceDeposit : types.PendingBalanceDeposit ,
45
+ PendingConsolidation : types.PendingConsolidation ,
46
+ PendingPartialWithdrawal : types.PendingPartialWithdrawal ,
47
+ PowBlock : types.PowBlock ,
48
+ SignedBLSToExecutionChange : types.SignedBLSToExecutionChange ,
49
+ SignedContributionAndProof : types.SignedContributionAndProof ,
50
+ SignedVoluntaryExit : types.SignedVoluntaryExit ,
51
+ SyncAggregate : types.SyncAggregate ,
52
+ SyncCommittee : types.SyncCommittee ,
53
+ SyncCommitteeContribution : types.SyncCommitteeContribution ,
54
+ SyncCommitteeMessage : types.SyncCommitteeMessage ,
55
+ Withdrawal : types.Withdrawal ,
56
+ WithdrawalRequest : types.WithdrawalRequest ,
57
+ };
58
+
59
+ const altair = union {
60
+ SyncAggregatorSelectionData : types.SyncAggregatorSelectionData ,
61
+ };
62
+
29
63
// test cases for all phases
30
- const CommonUnion = union {
64
+ const commonUnion = union {
65
+ // AggregateAndProof: types.AggregateAndProof,
66
+ // AttestationData: types.AttestationData,
67
+ // AttesterSlashing: types.AttesterSlashing,
68
+ // BeaconBlock: types.BeaconBlock,
69
+ // BeaconBlockHeader: types.BeaconBlockHeader,
70
+ Checkpoint : types.Checkpoint ,
71
+ // Deposit: types.Deposit,
72
+ // DepositData: types.DepositData,
73
+ // DepositMessage: types.DepositMessage,
74
+ // Eth1Block: types.Eth1Block,
75
+ // Eth1Data: types.Eth1Data,
31
76
Fork : types.Fork ,
77
+ ForkData : types.ForkData ,
78
+ // HistoricalBatch: types.HistoricalBatch,
79
+ // IndexedAttestation: types.IndexedAttestation,
80
+ // PendingAttestation: types.PendingAttestation,
81
+ // ProposerSlashing: types.ProposerSlashing,
82
+ // SignedBeaconBlock: types.SignedBeaconBlock,
83
+ // SignedBeaconBlockHeader: types.SignedBeaconBlockHeader,
84
+ // SigningData: types.SigningData,
85
+ SyncAggregatorSelectionData : types.SyncAggregatorSelectionData , // only exist in altair or later
86
+ // Validator: types.Validator,
87
+ VoluntaryExit : types.VoluntaryExit ,
32
88
};
33
89
90
+ const forks = [_ ][]const u8 { "phase0" , "altair" , "bellatrix" , "capella" , "deneb" , "electra" };
91
+
34
92
test "ssz static" {
35
93
const testPath = "consensus-spec-tests/tests/mainnet" ;
36
94
const gpa1 = testing .allocator ;
37
- const fields = @typeInfo (CommonUnion ).@"union" .fields ;
95
+ const fields = @typeInfo (commonUnion ).@"union" .fields ;
38
96
inline for (fields ) | field | {
39
97
const fieldType = field .type ;
40
98
const fieldName = field .name ;
41
- const ssz_type_path = try std .fmt .allocPrint (gpa1 , "{s}/phase0/ssz_static/{s}" , .{ testPath , fieldName });
42
-
43
- var dirs = try getLeafDirs (gpa1 , ssz_type_path );
44
-
45
- // deinit the dirs array
46
- defer {
47
- for (dirs .items ) | item | {
48
- gpa1 .free (item );
99
+ for (forks ) | fork | {
100
+ const ssz_type_path = try std .fmt .allocPrint (gpa1 , "{s}/{s}/ssz_static/{s}" , .{ testPath , fork , fieldName });
101
+
102
+ var dirs = getLeafDirs (gpa1 , ssz_type_path ) catch | err | {
103
+ if (err == error .FileNotFound ) {
104
+ continue ;
105
+ }
106
+ return err ;
107
+ };
108
+ // deinit the dirs array
109
+ defer {
110
+ for (dirs .items ) | item | {
111
+ gpa1 .free (item );
112
+ }
113
+ dirs .deinit ();
49
114
}
50
- dirs .deinit ();
51
- }
52
115
53
- for (dirs .items ) | dir | {
54
- try testSSZStatic (dir , fieldType );
116
+ for (dirs .items ) | dir | {
117
+ try testSSZStatic (dir , fieldType );
118
+ }
55
119
}
56
120
}
57
121
}
58
122
59
123
/// Recursively finds all leaf directories (directories with no subdirectories) starting from the given path
60
- /// Parameters:
61
- /// allocator: Memory allocator for dynamic allocations
62
- /// path: Starting directory path to search from
63
- /// Returns:
64
- /// ArrayList containing paths to all leaf directories
65
124
fn getLeafDirs (allocator : std.mem.Allocator , path : []const u8 ) ! std. ArrayList ([]const u8 ) {
66
125
var leafDirs = std .ArrayList ([]const u8 ).init (allocator );
67
126
// defer leafDirs.deinit();
@@ -101,12 +160,6 @@ fn getLeafDirs(allocator: std.mem.Allocator, path: []const u8) !std.ArrayList([]
101
160
}
102
161
103
162
/// Tests SSZ (Simple Serialize) static functionality by performing:
104
- /// 1. YAML parsing
105
- /// 2. Hash tree root verification
106
- /// 3. SSZ encoding/decoding with snappy compression
107
- /// Parameters:
108
- /// path: Directory path containing test files
109
- /// t: Type to test SSZ operations against
110
163
fn testSSZStatic (path : []const u8 , t : type ) ! void {
111
164
// parse from yaml
112
165
const valueFile = try std .fmt .allocPrint (testing .allocator , "{s}/value.yaml" , .{path });
0 commit comments