@@ -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,101 @@ 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
+
29
59
// test cases for all phases
30
60
const CommonUnion = union {
61
+ // AggregateAndProof: types.AggregateAndProof,
62
+ // AttestationData: types.AttestationData,
63
+ // AttesterSlashing: types.AttesterSlashing,
64
+ // BeaconBlock: types.BeaconBlock,
65
+ // BeaconBlockHeader: types.BeaconBlockHeader,
66
+ Checkpoint : types.Checkpoint ,
67
+ // Deposit: types.Deposit,
68
+ // DepositData: types.DepositData,
69
+ // DepositMessage: types.DepositMessage,
70
+ // Eth1Block: types.Eth1Block,
71
+ // Eth1Data: types.Eth1Data,
31
72
Fork : types.Fork ,
73
+ ForkData : types.ForkData ,
74
+ // HistoricalBatch: types.HistoricalBatch,
75
+ // IndexedAttestation: types.IndexedAttestation,
76
+ // PendingAttestation: types.PendingAttestation,
77
+ // ProposerSlashing: types.ProposerSlashing,
78
+ // SignedBeaconBlock: types.SignedBeaconBlock,
79
+ // SignedBeaconBlockHeader: types.SignedBeaconBlockHeader,
80
+ // SigningData: types.SigningData,
81
+ SyncAggregatorSelectionData : types.SyncAggregatorSelectionData , // only exist in altair or later
82
+ // Validator: types.Validator,
83
+ VoluntaryExit : types.VoluntaryExit ,
32
84
};
33
85
86
+ const forkDirs = [_ ][]const u8 { "phase0" , "altair" , "bellatrix" , "capella" , "deneb" , "electra" };
87
+
34
88
test "ssz static" {
35
89
const testPath = "consensus-spec-tests/tests/mainnet" ;
36
90
const gpa1 = testing .allocator ;
37
91
const fields = @typeInfo (CommonUnion ).@"union" .fields ;
38
92
inline for (fields ) | field | {
39
93
const fieldType = field .type ;
40
94
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 );
95
+ for (forkDirs ) | fork | {
96
+ const ssz_type_path = try std .fmt .allocPrint (gpa1 , "{s}/{s}/ssz_static/{s}" , .{ testPath , fork , fieldName });
97
+
98
+ var dirs = getLeafDirs (gpa1 , ssz_type_path ) catch | err | {
99
+ if (err == error .FileNotFound ) {
100
+ continue ;
101
+ }
102
+ return err ;
103
+ };
104
+ // deinit the dirs array
105
+ defer {
106
+ for (dirs .items ) | item | {
107
+ gpa1 .free (item );
108
+ }
109
+ dirs .deinit ();
49
110
}
50
- dirs .deinit ();
51
- }
52
111
53
- for (dirs .items ) | dir | {
54
- try testSSZStatic (dir , fieldType );
112
+ for (dirs .items ) | dir | {
113
+ try testSSZStatic (dir , fieldType );
114
+ }
55
115
}
56
116
}
57
117
}
58
118
59
119
/// 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
120
fn getLeafDirs (allocator : std.mem.Allocator , path : []const u8 ) ! std. ArrayList ([]const u8 ) {
66
121
var leafDirs = std .ArrayList ([]const u8 ).init (allocator );
67
122
// defer leafDirs.deinit();
@@ -101,12 +156,6 @@ fn getLeafDirs(allocator: std.mem.Allocator, path: []const u8) !std.ArrayList([]
101
156
}
102
157
103
158
/// 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
159
fn testSSZStatic (path : []const u8 , t : type ) ! void {
111
160
// parse from yaml
112
161
const valueFile = try std .fmt .allocPrint (testing .allocator , "{s}/value.yaml" , .{path });
0 commit comments