Skip to content

Commit c17ec5e

Browse files
committed
conflcits
1 parent 7ac3b3e commit c17ec5e

2 files changed

Lines changed: 118 additions & 124 deletions

File tree

test/int/era/root.zig

Lines changed: 117 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,117 @@
1-
<<<<<<< Conflict 1 of 1
2-
%%%%%%% Changes from base to side #1
3-
const std = @import("std");
4-
const era = @import("era");
5-
const download_era_options = @import("download_era_options");
6-
const c = @import("config");
7-
8-
const allocator = std.testing.allocator;
9-
10-
test "validate an existing era file" {
11-
const era_path = try std.fs.path.join(
12-
allocator,
13-
&[_][]const u8{ download_era_options.era_out_dir, download_era_options.era_files[0] },
14-
);
15-
defer allocator.free(era_path);
16-
17-
// First check that the era file exists
18-
if (std.fs.cwd().openFile(era_path, .{})) |f| {
19-
f.close();
20-
} else |_| {
21-
return error.SkipZigTest;
22-
}
23-
24-
var reader = try era.Reader.open(allocator, c.mainnet.config, era_path);
25-
defer reader.close(allocator);
26-
27-
// Main validation
28-
try reader.validate(allocator);
29-
}
30-
31-
test "write an era file from an existing era file" {
32-
const era_path = try std.fs.path.join(
33-
allocator,
34-
&[_][]const u8{ download_era_options.era_out_dir, download_era_options.era_files[0] },
35-
);
36-
defer allocator.free(era_path);
37-
38-
// First check that the era file exists
39-
if (std.fs.cwd().openFile(era_path, .{})) |f| {
40-
f.close();
41-
} else |_| {
42-
return error.SkipZigTest;
43-
}
44-
45-
// Read known-good era file
46-
var reader = try era.Reader.open(allocator, c.mainnet.config, era_path);
47-
defer reader.close(allocator);
48-
49-
var tmp_dir = std.testing.tmpDir(.{});
50-
defer tmp_dir.cleanup();
51-
52-
const tmp_dir_path = try tmp_dir.dir.realpathAlloc(allocator, ".");
53-
defer allocator.free(tmp_dir_path);
54-
const out_path = try std.fs.path.join(allocator, &[_][]const u8{ tmp_dir_path, "out.era" });
55-
defer allocator.free(out_path);
56-
57-
// Write known-good era to a new era file
58-
var writer = try era.Writer.open(c.mainnet.config, out_path, reader.era_number);
59-
60-
const blocks_index = reader.group_indices[0].blocks_index orelse return error.NoBlockIndex;
61-
for (blocks_index.start_slot..blocks_index.start_slot + blocks_index.offsets.len) |slot| {
62-
const block = try reader.readBlock(allocator, slot) orelse continue;
63-
defer block.deinit(allocator);
64-
65-
try writer.writeBlock(allocator, block);
66-
}
67-
var state = try reader.readState(allocator, null);
68-
- defer state.deinit(allocator);
69-
+ defer state.deinit();
70-
71-
try writer.writeState(allocator, state);
72-
73-
const final_out_path = try writer.finish(allocator);
74-
defer allocator.free(final_out_path);
75-
76-
// Now check that the two era files are equivalent
77-
78-
// Compare file names
79-
if (!std.mem.eql(u8, std.fs.path.basename(final_out_path), std.fs.path.basename(era_path))) {
80-
return error.IncorrectWrittenEraFileName;
81-
}
82-
var out_reader = try era.Reader.open(allocator, c.mainnet.config, final_out_path);
83-
defer out_reader.close(allocator);
84-
85-
// Compare struct fields
86-
if (out_reader.era_number != reader.era_number) {
87-
return error.IncorrectWrittenEraNumber;
88-
}
89-
if (!std.mem.eql(u8, &reader.short_historical_root, &out_reader.short_historical_root)) {
90-
return error.IncorrectWrittenShortHistoricalRoot;
91-
}
92-
// We can't directly compare bytes or offsets (snappy compression isn't deterministic across implementations)
93-
// if (!std.mem.eql(u8, std.mem.sliceAsBytes(reader.groups), std.mem.sliceAsBytes(out_reader.groups))) {
94-
// return error.IncorrectWrittenEraIndices;
95-
// }
96-
97-
// Compare blocks
98-
for (blocks_index.start_slot..blocks_index.start_slot + blocks_index.offsets.len) |slot| {
99-
const block = try reader.readSerializedBlock(allocator, slot) orelse continue;
100-
const out_block = try out_reader.readSerializedBlock(allocator, slot) orelse return error.MissingBlock;
101-
defer allocator.free(block);
102-
defer allocator.free(out_block);
103-
104-
if (!std.mem.eql(u8, block, out_block)) {
105-
return error.IncorrectWrittenBlock;
106-
}
107-
}
108-
// Compare state
109-
var out_state = try out_reader.readState(allocator, null);
110-
- defer out_state.deinit(allocator);
111-
+ defer out_state.deinit();
112-
113-
const serialized = try state.serialize(allocator);
114-
defer allocator.free(serialized);
115-
const out_serialized = try out_state.serialize(allocator);
116-
defer allocator.free(out_serialized);
117-
118-
if (!std.mem.eql(u8, serialized, out_serialized)) {
119-
return error.IncorrectWrittenState;
120-
}
121-
}
122-
+++++++ Contents of side #2
123-
>>>>>>> Conflict 1 of 1 ends
1+
const std = @import("std");
2+
const era = @import("era");
3+
const download_era_options = @import("download_era_options");
4+
const c = @import("config");
5+
6+
const allocator = std.testing.allocator;
7+
8+
test "validate an existing era file" {
9+
const era_path = try std.fs.path.join(
10+
allocator,
11+
&[_][]const u8{ download_era_options.era_out_dir, download_era_options.era_files[0] },
12+
);
13+
defer allocator.free(era_path);
14+
15+
// First check that the era file exists
16+
if (std.fs.cwd().openFile(era_path, .{})) |f| {
17+
f.close();
18+
} else |_| {
19+
return error.SkipZigTest;
20+
}
21+
22+
var reader = try era.Reader.open(allocator, c.mainnet.config, era_path);
23+
defer reader.close(allocator);
24+
25+
// Main validation
26+
try reader.validate(allocator);
27+
}
28+
29+
test "write an era file from an existing era file" {
30+
const era_path = try std.fs.path.join(
31+
allocator,
32+
&[_][]const u8{ download_era_options.era_out_dir, download_era_options.era_files[0] },
33+
);
34+
defer allocator.free(era_path);
35+
36+
// First check that the era file exists
37+
if (std.fs.cwd().openFile(era_path, .{})) |f| {
38+
f.close();
39+
} else |_| {
40+
return error.SkipZigTest;
41+
}
42+
43+
// Read known-good era file
44+
var reader = try era.Reader.open(allocator, c.mainnet.config, era_path);
45+
defer reader.close(allocator);
46+
47+
var tmp_dir = std.testing.tmpDir(.{});
48+
defer tmp_dir.cleanup();
49+
50+
const tmp_dir_path = try tmp_dir.dir.realpathAlloc(allocator, ".");
51+
defer allocator.free(tmp_dir_path);
52+
const out_path = try std.fs.path.join(allocator, &[_][]const u8{ tmp_dir_path, "out.era" });
53+
defer allocator.free(out_path);
54+
55+
// Write known-good era to a new era file
56+
var writer = try era.Writer.open(c.mainnet.config, out_path, reader.era_number);
57+
58+
const blocks_index = reader.group_indices[0].blocks_index orelse return error.NoBlockIndex;
59+
for (blocks_index.start_slot..blocks_index.start_slot + blocks_index.offsets.len) |slot| {
60+
const block = try reader.readBlock(allocator, slot) orelse continue;
61+
defer block.deinit(allocator);
62+
63+
try writer.writeBlock(allocator, block);
64+
}
65+
var state = try reader.readState(allocator, null);
66+
defer state.deinit();
67+
68+
try writer.writeState(allocator, state);
69+
70+
const final_out_path = try writer.finish(allocator);
71+
defer allocator.free(final_out_path);
72+
73+
// Now check that the two era files are equivalent
74+
75+
// Compare file names
76+
if (!std.mem.eql(u8, std.fs.path.basename(final_out_path), std.fs.path.basename(era_path))) {
77+
return error.IncorrectWrittenEraFileName;
78+
}
79+
var out_reader = try era.Reader.open(allocator, c.mainnet.config, final_out_path);
80+
defer out_reader.close(allocator);
81+
82+
// Compare struct fields
83+
if (out_reader.era_number != reader.era_number) {
84+
return error.IncorrectWrittenEraNumber;
85+
}
86+
if (!std.mem.eql(u8, &reader.short_historical_root, &out_reader.short_historical_root)) {
87+
return error.IncorrectWrittenShortHistoricalRoot;
88+
}
89+
// We can't directly compare bytes or offsets (snappy compression isn't deterministic across implementations)
90+
// if (!std.mem.eql(u8, std.mem.sliceAsBytes(reader.groups), std.mem.sliceAsBytes(out_reader.groups))) {
91+
// return error.IncorrectWrittenEraIndices;
92+
// }
93+
94+
// Compare blocks
95+
for (blocks_index.start_slot..blocks_index.start_slot + blocks_index.offsets.len) |slot| {
96+
const block = try reader.readSerializedBlock(allocator, slot) orelse continue;
97+
const out_block = try out_reader.readSerializedBlock(allocator, slot) orelse return error.MissingBlock;
98+
defer allocator.free(block);
99+
defer allocator.free(out_block);
100+
101+
if (!std.mem.eql(u8, block, out_block)) {
102+
return error.IncorrectWrittenBlock;
103+
}
104+
}
105+
// Compare state
106+
var out_state = try out_reader.readState(allocator, null);
107+
defer out_state.deinit();
108+
109+
const serialized = try state.serialize(allocator);
110+
defer allocator.free(serialized);
111+
const out_serialized = try out_state.serialize(allocator);
112+
defer allocator.free(out_serialized);
113+
114+
if (!std.mem.eql(u8, serialized, out_serialized)) {
115+
return error.IncorrectWrittenState;
116+
}
117+
}

zbuild.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
.tests = .{
203203
.int = .{
204204
.root_module = .{
205-
.root_source_file = "test/int/root.zig",
205+
.root_source_file = "test/int/era/root.zig",
206206
.imports = .{
207207
.config,
208208
.download_era_options,

0 commit comments

Comments
 (0)