-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chen Kai <[email protected]>
- Loading branch information
Showing
10 changed files
with
432 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Zig Test and Benchmark | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
ZIG_VERSION: 0.13.0 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Cache Zig | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/zig | ||
key: ${{ runner.os }}-zig-${{ env.ZIG_VERSION }} | ||
|
||
- name: Install Zig | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: | | ||
wget https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz | ||
tar -xf zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz | ||
mv zig-linux-x86_64-${{ env.ZIG_VERSION }} ~/zig | ||
- name: Add Zig to PATH | ||
run: echo "${HOME}/zig" >> $GITHUB_PATH | ||
|
||
- name: Cache Zig build artifacts | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
zig-cache | ||
~/.cache/zig | ||
key: ${{ runner.os }}-zig-build-${{ hashFiles('**/*.zig') }} | ||
restore-keys: | | ||
${{ runner.os }}-zig-build- | ||
- name: Formatting | ||
run: zig fmt --check --color on . | ||
|
||
- name: Unit testing | ||
run: zig build test --summary all | ||
|
||
- name: Building | ||
run: zig build -Doptimize=ReleaseFast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const std = @import("std"); | ||
pub const primitives = @import("../../primitives/types.zig"); | ||
const preset = @import("../../presets/preset.zig"); | ||
|
||
pub fn ExecutionPayloadHeaderType(comptime T: preset.BeaconPreset) type { | ||
return struct { | ||
parent_hash: primitives.Hash32, | ||
fee_recipient: primitives.ExecutionAddress, | ||
state_root: primitives.Root, | ||
receipts_root: primitives.Root, | ||
logs_bloom: [T.BYTES_PER_LOGS_BLOOM]u8, | ||
prev_randao: primitives.Bytes32, | ||
block_number: u64, | ||
gas_used: u64, | ||
gas_limit: u64, | ||
timestamp: u64, | ||
extra_data: [T.MAX_EXTRA_DATA_BYTES]u8, | ||
base_fee_per_gas: u256, | ||
// Extra payload fields | ||
block_hash: primitives.Hash32, | ||
transactions_root: primitives.Root, | ||
withdrawals_root: primitives.Root, | ||
}; | ||
} | ||
|
||
pub const ExecutionPayloadHeaderMainnet = ExecutionPayloadHeaderType(preset.mainnet_preset); | ||
|
||
pub const ExecutionPayloadHeaderMinimal = ExecutionPayloadHeaderType(preset.minimal_preset); | ||
|
||
pub const ExecutionPayloadHeader = union(preset.Presets) { | ||
mainnet: ExecutionPayloadHeaderMainnet, | ||
minimal: ExecutionPayloadHeaderMinimal, | ||
}; | ||
|
||
test "test ExecutionPayloadHeaderMainnet" { | ||
const header = ExecutionPayloadHeaderMainnet{ | ||
.parent_hash = undefined, | ||
.fee_recipient = undefined, | ||
.state_root = undefined, | ||
.receipts_root = undefined, | ||
.logs_bloom = undefined, | ||
.prev_randao = undefined, | ||
.block_number = 21, | ||
.gas_used = 0, | ||
.gas_limit = 0, | ||
.timestamp = 0, | ||
.extra_data = undefined, | ||
.base_fee_per_gas = 0, | ||
.block_hash = undefined, | ||
.transactions_root = undefined, | ||
.withdrawals_root = undefined, | ||
}; | ||
|
||
try std.testing.expectEqual(header.parent_hash.len, 32); | ||
try std.testing.expectEqual(header.block_number, 21); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const std = @import("std"); | ||
pub const primitives = @import("../../primitives/types.zig"); | ||
const preset = @import("../../presets/preset.zig"); | ||
|
||
pub fn ExecutionPayloadHeaderType(comptime T: preset.BeaconPreset) type { | ||
return struct { | ||
parent_hash: primitives.Hash32, | ||
fee_recipient: primitives.ExecutionAddress, | ||
state_root: primitives.Root, | ||
receipts_root: primitives.Root, | ||
logs_bloom: [T.BYTES_PER_LOGS_BLOOM]u8, | ||
prev_randao: primitives.Bytes32, | ||
block_number: u64, | ||
gas_used: u64, | ||
gas_limit: u64, | ||
timestamp: u64, | ||
extra_data: [T.MAX_EXTRA_DATA_BYTES]u8, | ||
base_fee_per_gas: u256, | ||
// Extra payload fields | ||
block_hash: primitives.Hash32, | ||
transactions_root: primitives.Root, | ||
withdrawals_root: primitives.Root, | ||
blob_gas_used: u64, | ||
excess_blob_gas: u64, | ||
}; | ||
} | ||
|
||
pub const ExecutionPayloadHeaderMainnet = ExecutionPayloadHeaderType(preset.mainnet_preset); | ||
|
||
pub const ExecutionPayloadHeaderMinimal = ExecutionPayloadHeaderType(preset.minimal_preset); | ||
|
||
pub const ExecutionPayloadHeader = union(preset.Presets) { | ||
mainnet: ExecutionPayloadHeaderMainnet, | ||
minimal: ExecutionPayloadHeaderMinimal, | ||
}; | ||
|
||
test "test ExecutionPayloadHeaderMainnet" { | ||
const header = ExecutionPayloadHeaderMainnet{ | ||
.parent_hash = undefined, | ||
.fee_recipient = undefined, | ||
.state_root = undefined, | ||
.receipts_root = undefined, | ||
.logs_bloom = undefined, | ||
.prev_randao = undefined, | ||
.block_number = 21, | ||
.gas_used = 0, | ||
.gas_limit = 0, | ||
.timestamp = 0, | ||
.extra_data = undefined, | ||
.base_fee_per_gas = 0, | ||
.block_hash = undefined, | ||
.transactions_root = undefined, | ||
.withdrawals_root = undefined, | ||
.blob_gas_used = 0, | ||
.excess_blob_gas = 0, | ||
}; | ||
|
||
try std.testing.expectEqual(header.parent_hash.len, 32); | ||
try std.testing.expectEqual(header.block_number, 21); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const std = @import("std"); | ||
pub const primitives = @import("../../primitives/types.zig"); | ||
const preset = @import("../../presets/preset.zig"); | ||
|
||
pub fn ExecutionPayloadHeaderType(comptime T: preset.BeaconPreset) type { | ||
return struct { | ||
parent_hash: primitives.Hash32, | ||
fee_recipient: primitives.ExecutionAddress, | ||
state_root: primitives.Root, | ||
receipts_root: primitives.Root, | ||
logs_bloom: [T.BYTES_PER_LOGS_BLOOM]u8, | ||
prev_randao: primitives.Bytes32, | ||
block_number: u64, | ||
gas_used: u64, | ||
gas_limit: u64, | ||
timestamp: u64, | ||
extra_data: [T.MAX_EXTRA_DATA_BYTES]u8, | ||
base_fee_per_gas: u256, | ||
// Extra payload fields | ||
block_hash: primitives.Hash32, | ||
transactions_root: primitives.Root, | ||
withdrawals_root: primitives.Root, | ||
blob_gas_used: u64, | ||
excess_blob_gas: u64, | ||
deposit_requests_root: primitives.Root, | ||
withdrawal_requests_root: primitives.Root, | ||
consolidation_requests_root: primitives.Root, | ||
}; | ||
} | ||
|
||
pub const ExecutionPayloadHeaderMainnet = ExecutionPayloadHeaderType(preset.mainnet_preset); | ||
|
||
pub const ExecutionPayloadHeaderMinimal = ExecutionPayloadHeaderType(preset.minimal_preset); | ||
|
||
pub const ExecutionPayloadHeader = union(preset.Presets) { | ||
mainnet: ExecutionPayloadHeaderMainnet, | ||
minimal: ExecutionPayloadHeaderMinimal, | ||
}; | ||
|
||
test "test ExecutionPayloadHeaderMainnet" { | ||
const header = ExecutionPayloadHeaderMainnet{ | ||
.parent_hash = undefined, | ||
.fee_recipient = undefined, | ||
.state_root = undefined, | ||
.receipts_root = undefined, | ||
.logs_bloom = undefined, | ||
.prev_randao = undefined, | ||
.block_number = 21, | ||
.gas_used = 0, | ||
.gas_limit = 0, | ||
.timestamp = 0, | ||
.extra_data = undefined, | ||
.base_fee_per_gas = 0, | ||
.block_hash = undefined, | ||
.transactions_root = undefined, | ||
.withdrawals_root = undefined, | ||
.blob_gas_used = 0, | ||
.excess_blob_gas = 0, | ||
.deposit_requests_root = undefined, | ||
.withdrawal_requests_root = undefined, | ||
.consolidation_requests_root = undefined, | ||
}; | ||
|
||
try std.testing.expectEqual(header.parent_hash.len, 32); | ||
try std.testing.expectEqual(header.block_number, 21); | ||
} |
Oops, something went wrong.