Skip to content

Commit

Permalink
feat: use std.log.debug replace std.debug
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZhen committed Oct 12, 2024
1 parent 6f01670 commit 2a6f186
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 19 deletions.
9 changes: 0 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,10 @@ pub fn build(b: *std.Build) void {

const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

const test_cases = b.addTest(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
});

const run_test_cases = b.addRunArtifact(test_cases);

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
test_step.dependOn(&run_test_cases.step);
}
4 changes: 2 additions & 2 deletions src/consensus/helpers/balance.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub fn getTotalBalance(state: *const consensus.BeaconState, indices: std.AutoHas
var total: primitives.Gwei = 0;
var iterator = indices.keyIterator();
while (iterator.next()) |index| {
std.debug.print("index: {}\n", .{index});
std.debug.print("state.validators()[index.*].effective_balance: {}\n", .{state.validators()[index.*].effective_balance});
std.log.debug("index: {}\n", .{index});
std.log.debug("state.validators()[index.*].effective_balance: {}\n", .{state.validators()[index.*].effective_balance});
total += state.validators()[index.*].effective_balance;
}
return @max(preset.ActivePreset.get().EFFECTIVE_BALANCE_INCREMENT, total);
Expand Down
4 changes: 2 additions & 2 deletions src/consensus/helpers/committee.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn getCommitteeCountPerSlot(state: *const consensus.BeaconState, epoch: prim
defer allocator.free(active_validator_indices);

const active_validator_count = active_validator_indices.len;
std.debug.print("active_validator_count: {}\n", .{active_validator_count});
std.log.debug("active_validator_count: {}\n", .{active_validator_count});
const slots_per_epoch = preset.ActivePreset.get().SLOTS_PER_EPOCH;
const target_committee_size = preset.ActivePreset.get().TARGET_COMMITTEE_SIZE;

Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn getBeaconCommittee(state: *const consensus.BeaconState, slot: primitives.
pub fn getBeaconProposerIndex(state: *const consensus.BeaconState, allocator: std.mem.Allocator) !primitives.ValidatorIndex {
const epoch = epoch_helper.getCurrentEpoch(state);
const seed_origin = seed_helper.getSeed(state, epoch, constants.DOMAIN_BEACON_PROPOSER) ++ std.mem.asBytes(&state.slot());
std.debug.print("seed_origin: {any}\n", .{seed_origin});
std.log.debug("seed_origin: {any}\n", .{seed_origin});
var seed: primitives.Bytes32 = undefined;
sha256.hash(seed_origin, &seed, .{});
const indices = try validator_helper.getActiveValidatorIndices(state, epoch, allocator);
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/helpers/domain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn computeForkDataRoot(current_version: primitives.Version, genesis_validato
.genesis_validators_root = genesis_validators_root,
};

std.debug.print("ForkData: {}\n", .{fork_data});
std.log.debug("ForkData: {}\n", .{fork_data});
// todo: implement hash_tree_root
return @as(primitives.Root, .{0} ** 32);
}
Expand Down
4 changes: 2 additions & 2 deletions src/consensus/helpers/signing_root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const configs = @import("../../configs/config.zig");
/// ))
pub fn computeSigningRoot(comptime sszObject: type, domain: primitives.Domain) primitives.Root {
// const objectRoot = hashTreeRoot(sszObject);
std.debug.print("sszObject: {}\n", .{sszObject});
std.log.debug("sszObject: {}\n", .{sszObject});
const objectRoot = @as(primitives.Root, .{0} ** 32);
const signingData = consensus.SigningData{
.object_root = objectRoot,
.domain = domain,
};

std.debug.print("signingData: {}\n", .{signingData});
std.log.debug("signingData: {}\n", .{signingData});
// return hashTreeRoot(signingData);
return @as(primitives.Root, .{0} ** 32);
}
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/helpers/validator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn computeProposerIndex(state: *const consensus.BeaconState, indices: []cons
var seed_plus: [40]u8 = undefined;
@memcpy(seed_plus[0..32], &seed);
std.mem.writeInt(u64, seed_plus[32..40], @divFloor(i, 32), .little);
std.debug.print("seed_plus: {any}, i: {}\n", .{ seed_plus, i });
std.log.debug("seed_plus: {any}, i: {}\n", .{ seed_plus, i });
std.crypto.hash.sha2.Sha256.hash(&seed_plus, &hash_result, .{});
const randomByte = hash_result[@mod(i, 32)];
const effectiveBalance = state.validators()[candidate_index].effective_balance;
Expand Down
1 change: 1 addition & 0 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ pub const ssz = @import("./ssz/ssz.zig");

test {
@import("std").testing.refAllDeclsRecursive(@This());
_ = @import("./spec_tests/root.zig");
}
3 changes: 3 additions & 0 deletions src/spec_tests/root.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test {
_ = @import("./ssz_static/root.zig");
}
4 changes: 2 additions & 2 deletions src/tests.zig → src/spec_tests/ssz_static/root.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const testing = std.testing;
const ssz = @import("./ssz/ssz.zig");
const types = @import("./consensus/types.zig");
const ssz = @import("../../ssz/ssz.zig");
const types = @import("../../consensus/types.zig");

test "hash tree root" {
const fork = types.Fork{
Expand Down

0 comments on commit 2a6f186

Please sign in to comment.