Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ultd committed Jul 18, 2023
1 parent fcbc9f6 commit c6dd232
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/bloom/bitvec.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const BitVec = struct {

pub fn initFromBitSet(bitset: DynamicBitSet) Self {
if (bitset.capacity() > 0) {
return Self {
return Self{
.bits = bitset.unmanaged.masks[0..(bitset.unmanaged.bit_length / 64)],
.len = @as(u64, bitset.unmanaged.bit_length),
};
Expand All @@ -37,7 +37,7 @@ pub const BitVec = struct {
var bitset = try DynamicBitSet.initEmpty(allocator, self.len);
errdefer bitset.deinit();

if (self.bits) |bits| {
if (self.bits) |bits| {
for (0..(self.len / 64)) |i| {
bitset.unmanaged.masks[i] = bits[i];
}
Expand Down
12 changes: 6 additions & 6 deletions src/bloom/bloom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub const Bloom = struct {

pub fn init(allocator: std.mem.Allocator, num_bits: u64) Self {
// need to be power of 2 for serialization to match rust
if (num_bits != 0) {
if (num_bits != 0) {
std.debug.assert((num_bits & (num_bits - 1) == 0));
}
return Self{
Expand All @@ -38,7 +38,7 @@ pub const Bloom = struct {
self.keys.deinit();
}

pub fn add_key(self: *Self, key: u64) !void {
pub fn add_key(self: *Self, key: u64) !void {
try self.keys.append(key);
}

Expand Down Expand Up @@ -112,13 +112,13 @@ test "bloom: rust: serialized bytes equal rust (no keys)" {
defer bloom.deinit();
try bloom.add_key(1);

const v: [1]u8 = .{ 1 };
const v: [1]u8 = .{1};
bloom.add(&v);

var buf: [10000]u8 = undefined;
var bytes = try bincode.writeToSlice(buf[0..], bloom, bincode.Params.standard);

const rust_bytes = .{1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0};
const rust_bytes = .{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 };

try testing.expectEqualSlices(u8, &rust_bytes, bytes[0..bytes.len]);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ test "bloom: rust: serialized bytes equal rust (multiple keys)" {
// bloom.add(&[3, 4]);
// println!("{:?}", bincode::serialize(&bloom).unwrap());

const rust_bytes = .{3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 66, 16, 32, 0, 128, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0};
const rust_bytes = .{ 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 66, 16, 32, 0, 128, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0 };

try testing.expectEqualSlices(u8, &rust_bytes, bytes[0..bytes.len]);
}
}
8 changes: 4 additions & 4 deletions src/crypto/fnv.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ pub const FnvHasher = struct {
};

test "fnv hasher with default is correct" {
const exp: u64 = 12638152016183539244;
const exp: u64 = 12638152016183539244;

var hasher = FnvHasher.init();
hasher.update(&.{ 1 });
hasher.update(&.{1});
const result = hasher.final();
try std.testing.expectEqual(exp, result);
}

test "fnv hasher with offset is correct" {
const exp: u64 = 11233064889143142093;
const exp: u64 = 11233064889143142093;

var hasher = FnvHasher.initWithOffset(19);
hasher.update(&.{ 1, 2, 3 });
const result = hasher.final();
try std.testing.expectEqual(exp, result);
}
}
1 change: 0 additions & 1 deletion src/gossip/cluster_info.zig
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ pub const ClusterInfo = struct {
std.time.sleep(std.time.ns_per_ms(GOSSIP_SLEEP_MILLIS - elapsed));
}
}

};
6 changes: 4 additions & 2 deletions src/gossip/cmd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ pub fn getOrInitIdentity(allocator: std.mem.Allocator) !Keypair {
error.FileNotFound => {
// create ~/.sig dir
var dir = try std.mem.concat(allocator, u8, &[_][]const u8{ home_dir, IDENTITY_KEYPAIR_DIR });
std.fs.makeDirAbsolute(dir) catch { logger.debug("sig directory already exists...", .{}); };
std.fs.makeDirAbsolute(dir) catch {
logger.debug("sig directory already exists...", .{});
};

// create new keypair
// create new keypair
const file = try std.fs.createFileAbsolute(path, .{ .truncate = true });
defer file.close();

Expand Down
21 changes: 10 additions & 11 deletions src/gossip/crds.zig
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ pub const SnapshotHashes = struct {
wallclock: u64,
};


test "gossip.crds: default crds filter matches rust bytes" {
const rust_bytes = [_]u8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0};
const rust_bytes = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0 };
var filter = CrdsFilter.init(std.testing.allocator);
defer filter.deinit();

Expand All @@ -342,18 +341,18 @@ test "gossip.crds: default crds filter matches rust bytes" {
try std.testing.expectEqualSlices(u8, rust_bytes[0..], bytes);
}

test "gossip.crds: contact info serialization matches rust" {
test "gossip.crds: contact info serialization matches rust" {
var kp_bytes = [_]u8{1} ** 32;
const kp = try KeyPair.create(kp_bytes);
const pk = kp.public_key;
const id = Pubkey.fromPublicKey(&pk, true);

const gossip_addr = SocketAddr.init_ipv4(.{127, 0, 0, 1}, 1234);
const gossip_addr = SocketAddr.init_ipv4(.{ 127, 0, 0, 1 }, 1234);
const unspecified_addr = SocketAddr.unspecified();

var buf = [_]u8{0} ** 1024;

var legacy_contact_info = LegacyContactInfo {
var legacy_contact_info = LegacyContactInfo{
.id = id,
.gossip = gossip_addr,
.tvu = unspecified_addr,
Expand All @@ -369,7 +368,7 @@ test "gossip.crds: contact info serialization matches rust" {
.shred_version = 0,
};

var contact_info_rust = [_]u8 { 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var contact_info_rust = [_]u8{ 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var bytes = try bincode.writeToSlice(buf[0..], legacy_contact_info, bincode.Params.standard);
try std.testing.expectEqualSlices(u8, bytes[0..bytes.len], contact_info_rust[0..bytes.len]);
}
Expand All @@ -380,12 +379,12 @@ test "gossip.crds: crds data serialization matches rust" {
const pk = kp.public_key;
const id = Pubkey.fromPublicKey(&pk, true);

const gossip_addr = SocketAddr.init_ipv4(.{127, 0, 0, 1}, 1234);
const gossip_addr = SocketAddr.init_ipv4(.{ 127, 0, 0, 1 }, 1234);
const unspecified_addr = SocketAddr.unspecified();

var buf = [_]u8{0} ** 1024;

var legacy_contact_info = LegacyContactInfo {
var legacy_contact_info = LegacyContactInfo{
.id = id,
.gossip = gossip_addr,
.tvu = unspecified_addr,
Expand All @@ -401,11 +400,11 @@ test "gossip.crds: crds data serialization matches rust" {
.shred_version = 0,
};

var crds_data = CrdsData {
var crds_data = CrdsData{
.LegacyContactInfo = legacy_contact_info,
};

var rust_crds_data = [_]u8 { 0, 0, 0, 0, 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var rust_crds_data = [_]u8{ 0, 0, 0, 0, 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var bytes = try bincode.writeToSlice(buf[0..], crds_data, bincode.Params.standard);
try std.testing.expectEqualSlices(u8, bytes[0..bytes.len], rust_crds_data[0..bytes.len]);
}
}
24 changes: 10 additions & 14 deletions src/gossip/gossip_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ pub const GossipService = struct {
gossip_loop_handle.join();
}


fn responder(self: *Self) !void {
while (self.responder_channel.receive()) |p| {
fn responder(self: *Self) !void {
while (self.responder_channel.receive()) |p| {
_ = try self.gossip_socket.sendTo(p.from, p.data[0..p.size]);
}
}
Expand All @@ -94,7 +93,7 @@ pub const GossipService = struct {
}
}

fn send_ping(self: *Self, peer: *const EndPoint) !void {
fn send_ping(self: *Self, peer: *const EndPoint) !void {
var protocol = Protocol{ .PingMessage = Ping.random(self.cluster_info.our_keypair) };
var out = [_]u8{0} ** PACKET_DATA_SIZE;
var bytes = try bincode.writeToSlice(out[0..], protocol, bincode.Params.standard);
Expand All @@ -103,14 +102,14 @@ pub const GossipService = struct {
);
}

fn push_contact_info(self: *Self, peer: *const EndPoint) !void {
fn push_contact_info(self: *Self, peer: *const EndPoint) !void {
const id = self.cluster_info.our_contact_info.pubkey;
const gossip_endpoint = try self.gossip_socket.getLocalEndPoint();
const gossip_addr = SocketAddr.init_ipv4(gossip_endpoint.address.ipv4.value, gossip_endpoint.port);
const unspecified_addr = SocketAddr.init_ipv4(.{0, 0, 0, 0}, 0);
const unspecified_addr = SocketAddr.init_ipv4(.{ 0, 0, 0, 0 }, 0);
const wallclock = @as(u64, @intCast(std.time.milliTimestamp()));

var legacy_contact_info = crds.LegacyContactInfo {
var legacy_contact_info = crds.LegacyContactInfo{
.id = id,
.gossip = gossip_addr,
.tvu = unspecified_addr,
Expand All @@ -125,17 +124,14 @@ pub const GossipService = struct {
.wallclock = wallclock,
.shred_version = 0,
};
var crds_data = crds.CrdsData {
var crds_data = crds.CrdsData{
.LegacyContactInfo = legacy_contact_info,
};
var crds_value = try crds.CrdsValue.initSigned(crds_data, self.cluster_info.our_keypair);
var values = [_]crds.CrdsValue{ crds_value };
var values = [_]crds.CrdsValue{crds_value};

const msg = Protocol {
.PushMessage = .{
id,
&values
},
const msg = Protocol{
.PushMessage = .{ id, &values },
};

var buf = [_]u8{0} ** PACKET_DATA_SIZE;
Expand Down
10 changes: 5 additions & 5 deletions src/gossip/node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -286,25 +286,25 @@ test "new contact info" {
defer ci.deinit();
}

test "socketaddr bincode serialize matches rust" {
const Tmp = struct {
test "socketaddr bincode serialize matches rust" {
const Tmp = struct {
addr: SocketAddr,
};
const tmp = Tmp{ .addr = SocketAddr.init_ipv4(.{127, 0, 0, 1}, 1234) };
const tmp = Tmp{ .addr = SocketAddr.init_ipv4(.{ 127, 0, 0, 1 }, 1234) };
var buf = [_]u8{0} ** 1024;
var bytes = try bincode.writeToSlice(buf[0..], tmp, bincode.Params.standard);

std.debug.print("tmp socketaddr serialized: {any}\n", .{bytes});

// #[derive(Serialize, Debug, Clone, Copy)]
// pub struct Tmp {
// pub struct Tmp {
// addr: SocketAddr
// }
// let tmp = Tmp { addr: socketaddr!(Ipv4Addr::LOCALHOST, 1234) };
// println!("{:?}", bincode::serialize(&tmp).unwrap());

// Enum discriminants are encoded as u32 (4 leading zeros)
const rust_bytes = [_]u8 { 0, 0, 0, 0, 127, 0, 0, 1, 210, 4 };
const rust_bytes = [_]u8{ 0, 0, 0, 0, 127, 0, 0, 1, 210, 4 };
try testing.expectEqualSlices(u8, rust_bytes[0..rust_bytes.len], bytes);
}

Expand Down
30 changes: 12 additions & 18 deletions src/gossip/protocol.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test "gossip.protocol: ping message matches rust bytes" {
}

test "gossip.protocol: pull request serializes and deserializes" {
var rust_bytes = [_]u8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 190, 193, 13, 216, 175, 227, 117, 168, 246, 219, 213, 39, 67, 249, 88, 3, 238, 151, 144, 15, 23, 142, 153, 198, 47, 221, 117, 132, 218, 28, 29, 115, 248, 253, 211, 101, 137, 19, 174, 112, 43, 57, 251, 110, 173, 14, 71, 0, 186, 24, 36, 61, 75, 241, 119, 73, 86, 93, 136, 249, 167, 40, 134, 14, 0, 0, 0, 0, 25, 117, 21, 11, 61, 170, 38, 18, 67, 196, 242, 219, 50, 154, 4, 254, 79, 227, 253, 229, 188, 230, 121, 12, 227, 248, 199, 156, 253, 144, 175, 67, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
var rust_bytes = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 190, 193, 13, 216, 175, 227, 117, 168, 246, 219, 213, 39, 67, 249, 88, 3, 238, 151, 144, 15, 23, 142, 153, 198, 47, 221, 117, 132, 218, 28, 29, 115, 248, 253, 211, 101, 137, 19, 174, 112, 43, 57, 251, 110, 173, 14, 71, 0, 186, 24, 36, 61, 75, 241, 119, 73, 86, 93, 136, 249, 167, 40, 134, 14, 0, 0, 0, 0, 25, 117, 21, 11, 61, 170, 38, 18, 67, 196, 242, 219, 50, 154, 4, 254, 79, 227, 253, 229, 188, 230, 121, 12, 227, 248, 199, 156, 253, 144, 175, 67, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var keypair = try KeyPair.fromSecretKey(try std.crypto.sign.Ed25519.SecretKey.fromBytes([_]u8{
125, 52, 162, 97, 231, 139, 58, 13, 185, 212, 57, 142, 136, 12, 21, 127, 228, 71,
115, 126, 138, 52, 102, 69, 103, 185, 45, 255, 132, 222, 243, 138, 25, 117, 21, 11,
Expand All @@ -142,9 +142,9 @@ test "gossip.protocol: pull request serializes and deserializes" {
var pubkey = Pubkey.fromPublicKey(&keypair.public_key, true);

// pull requests only use ContactInfo CRDS data
const gossip_addr = SocketAddr.init_ipv4(.{127, 0, 0, 1}, 1234);
const gossip_addr = SocketAddr.init_ipv4(.{ 127, 0, 0, 1 }, 1234);
const unspecified_addr = SocketAddr.unspecified();
var legacy_contact_info = LegacyContactInfo {
var legacy_contact_info = LegacyContactInfo{
.id = pubkey,
.gossip = gossip_addr,
.tvu = unspecified_addr,
Expand All @@ -159,7 +159,7 @@ test "gossip.protocol: pull request serializes and deserializes" {
.wallclock = 0,
.shred_version = 0,
};
var crds_data = crds.CrdsData {
var crds_data = crds.CrdsData{
.LegacyContactInfo = legacy_contact_info,
};
var crds_value = try crds.CrdsValue.initSigned(crds_data, keypair);
Expand All @@ -170,7 +170,7 @@ test "gossip.protocol: pull request serializes and deserializes" {
var pull = Protocol{ .PullRequest = .{
filter,
crds_value,
}};
} };

var buf = [_]u8{0} ** 1232;
var serialized = try bincode.writeToSlice(buf[0..], pull, bincode.Params.standard);
Expand All @@ -180,19 +180,18 @@ test "gossip.protocol: pull request serializes and deserializes" {
try testing.expect(std.meta.eql(pull, deserialized));
}


test "gossip.protocol: push message serializes and deserializes correctly" {
var kp_bytes = [_]u8{1} ** 32;
const kp = try KeyPair.create(kp_bytes);
const pk = kp.public_key;
const id = Pubkey.fromPublicKey(&pk, true);

const gossip_addr = SocketAddr.init_ipv4(.{127, 0, 0, 1}, 1234);
const gossip_addr = SocketAddr.init_ipv4(.{ 127, 0, 0, 1 }, 1234);
const unspecified_addr = SocketAddr.unspecified();

var buf = [_]u8{0} ** 1024;

var legacy_contact_info = LegacyContactInfo {
var legacy_contact_info = LegacyContactInfo{
.id = id,
.gossip = gossip_addr,
.tvu = unspecified_addr,
Expand All @@ -208,19 +207,14 @@ test "gossip.protocol: push message serializes and deserializes correctly" {
.shred_version = 0,
};

var crds_data = crds.CrdsData {
var crds_data = crds.CrdsData{
.LegacyContactInfo = legacy_contact_info,
};

var rust_bytes = [_]u8{2, 0, 0, 0, 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 1, 0, 0, 0, 0, 0, 0, 0, 247, 119, 8, 235, 122, 255, 148, 105, 239, 205, 20, 32, 112, 227, 208, 92, 37, 18, 5, 71, 105, 58, 203, 18, 69, 196, 217, 80, 56, 47, 2, 45, 166, 139, 244, 114, 132, 206, 156, 187, 206, 205, 0, 176, 167, 196, 11, 17, 22, 77, 142, 176, 215, 8, 110, 221, 30, 206, 219, 80, 196, 217, 118, 13, 0, 0, 0, 0, 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
var rust_bytes = [_]u8{ 2, 0, 0, 0, 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 1, 0, 0, 0, 0, 0, 0, 0, 247, 119, 8, 235, 122, 255, 148, 105, 239, 205, 20, 32, 112, 227, 208, 92, 37, 18, 5, 71, 105, 58, 203, 18, 69, 196, 217, 80, 56, 47, 2, 45, 166, 139, 244, 114, 132, 206, 156, 187, 206, 205, 0, 176, 167, 196, 11, 17, 22, 77, 142, 176, 215, 8, 110, 221, 30, 206, 219, 80, 196, 217, 118, 13, 0, 0, 0, 0, 138, 136, 227, 221, 116, 9, 241, 149, 253, 82, 219, 45, 60, 186, 93, 114, 202, 103, 9, 191, 29, 148, 18, 27, 243, 116, 136, 1, 180, 15, 111, 92, 0, 0, 0, 0, 127, 0, 0, 1, 210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var crds_value = try crds.CrdsValue.initSigned(crds_data, kp);
var values = [_]crds.CrdsValue{ crds_value };
var pushmsg = Protocol {
.PushMessage = .{
id,
&values
}
};
var values = [_]crds.CrdsValue{crds_value};
var pushmsg = Protocol{ .PushMessage = .{ id, &values } };
var bytes = try bincode.writeToSlice(buf[0..], pushmsg, bincode.Params.standard);
try testing.expectEqualSlices(u8, bytes[0..bytes.len], &rust_bytes);
}
}

0 comments on commit c6dd232

Please sign in to comment.