Skip to content

Commit 27ec741

Browse files
authored
fuzz tests (#350)
* add tests and update jamduna * update tests * rename * fix * fix release
1 parent b57478e commit 27ec741

File tree

120 files changed

+9226
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+9226
-161
lines changed

.github/workflows/release.yml

Lines changed: 66 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Binaries
1+
name: Release
22

33
on:
44
push:
@@ -15,83 +15,6 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
build-linux-x64:
19-
name: Build Linux x64
20-
runs-on: [self-hosted, linux]
21-
timeout-minutes: 60
22-
steps:
23-
- name: Checkout Code
24-
uses: actions/checkout@v4
25-
with:
26-
submodules: recursive
27-
- run: sudo apt-get update
28-
- uses: awalsh128/cache-apt-pkgs-action@latest
29-
with:
30-
packages: curl build-essential cmake librocksdb-dev libzstd-dev libbz2-dev liblz4-dev
31-
- uses: aws-actions/configure-aws-credentials@v4
32-
with:
33-
aws-region: us-east-2
34-
- name: Cache SPM
35-
uses: runs-on/cache@v4
36-
with:
37-
path: '**/.build'
38-
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
39-
restore-keys: |
40-
${{ runner.os }}-spm-
41-
env:
42-
RUNS_ON_S3_BUCKET_CACHE: laminar-gh-action-cache
43-
- name: Cache Cargo
44-
uses: actions/cache@v4
45-
with:
46-
path: |
47-
~/.cargo/bin/
48-
~/.cargo/registry/index/
49-
~/.cargo/registry/cache/
50-
~/.cargo/git/db/
51-
target/
52-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
53-
- name: Cache bandersnatch_vrfs static lib
54-
uses: actions/cache@v4
55-
with:
56-
path: .lib/libbandersnatch_vrfs.a
57-
key: ${{ runner.os }}-libs-libbandersnatch-${{ hashFiles('Utils/Sources/bandersnatch/**') }}
58-
restore-keys: |
59-
${{ runner.os }}-libs-libbandersnatch
60-
- name: Cache bls static lib
61-
uses: actions/cache@v4
62-
with:
63-
path: .lib/libbls.a
64-
key: ${{ runner.os }}-libs-libbls-${{ hashFiles('Utils/Sources/bls/**') }}
65-
restore-keys: |
66-
${{ runner.os }}-libs-libbls
67-
- name: Cache erasure-coding static lib
68-
uses: actions/cache@v4
69-
with:
70-
path: .lib/libec.a
71-
key: ${{ runner.os }}-libs-libec-${{ hashFiles('Utils/Sources/erasure-coding/**') }}
72-
restore-keys: |
73-
${{ runner.os }}-libs-libec
74-
- name: Setup Swift
75-
uses: SwiftyLab/setup-swift@latest
76-
- name: Setup Rust
77-
uses: dtolnay/rust-toolchain@nightly
78-
- name: Build External Libraries
79-
run: ./scripts/build-external-libs.sh
80-
- name: Build Dependencies
81-
run: make deps
82-
- name: Build Release Binary
83-
run: |
84-
cd Boka
85-
swift build -c release
86-
cp $(swift build -c release --show-bin-path)/Boka boka-linux-x64
87-
strip boka-linux-x64
88-
- name: Upload Binary
89-
uses: actions/upload-artifact@v4
90-
with:
91-
name: boka-linux-x64
92-
path: Boka/boka-linux-x64
93-
retention-days: 7
94-
9518
build-macos-aarch64:
9619
name: Build macOS aarch64
9720
runs-on: macos-15
@@ -107,27 +30,79 @@ jobs:
10730
uses: dtolnay/rust-toolchain@nightly
10831
- name: Install Dependencies
10932
run: |
110-
brew install rocksdb openssl
33+
brew install openssl snappy
11134
- name: Build External Libraries
11235
run: ./scripts/build-external-libs.sh
11336
- name: Build Dependencies
11437
run: make deps
11538
- name: Build Release Binary
11639
run: |
11740
cd Boka
118-
swift build -c release
119-
cp $(swift build -c release --show-bin-path)/Boka boka-macos-aarch64
120-
strip boka-macos-aarch64
41+
export MACOSX_DEPLOYMENT_TARGET=15.0
42+
43+
# Create a local build directory for static libraries
44+
mkdir -p ../static-libs
45+
STATIC_LIB_DIR="$(pwd)/../static-libs"
46+
cd ../static-libs
47+
48+
# Build LZ4 static from source
49+
git clone --depth=1 https://github.com/lz4/lz4.git
50+
cd lz4/lib
51+
make clean
52+
make liblz4.a
53+
mkdir -p "$STATIC_LIB_DIR/lib" "$STATIC_LIB_DIR/include"
54+
cp liblz4.a "$STATIC_LIB_DIR/lib/"
55+
cp lz4.h lz4hc.h lz4frame.h "$STATIC_LIB_DIR/include/"
56+
cd ../..
57+
58+
# Build Zstd static from source
59+
git clone --depth=1 https://github.com/facebook/zstd.git
60+
cd zstd/lib
61+
make clean
62+
make libzstd.a
63+
mkdir -p "$STATIC_LIB_DIR/lib" "$STATIC_LIB_DIR/include"
64+
cp libzstd.a "$STATIC_LIB_DIR/lib/"
65+
cp zstd.h zdict.h zstd_errors.h "$STATIC_LIB_DIR/include/"
66+
cd ../..
67+
68+
# Build RocksDB static with our static compression libs
69+
git clone --depth=1 https://github.com/facebook/rocksdb.git
70+
cd rocksdb
71+
make clean
72+
PORTABLE=1 make static_lib \
73+
LDFLAGS="-L$STATIC_LIB_DIR/lib" \
74+
EXTRA_CXXFLAGS="-I$STATIC_LIB_DIR/include -Wno-unused-parameter" \
75+
USE_RTTI=1
76+
cp librocksdb.a "$STATIC_LIB_DIR/lib/"
77+
cp -r include/rocksdb "$STATIC_LIB_DIR/include/"
78+
cd ../../Boka
79+
80+
# Build Swift release binary with our static libraries
81+
swift build -c release \
82+
-Xlinker "$STATIC_LIB_DIR/lib/librocksdb.a" \
83+
-Xlinker "$STATIC_LIB_DIR/lib/liblz4.a" \
84+
-Xlinker "$STATIC_LIB_DIR/lib/libzstd.a" \
85+
-Xlinker $(brew --prefix snappy)/lib/libsnappy.a \
86+
-Xlinker $(brew --prefix openssl)/lib/libssl.a \
87+
-Xlinker $(brew --prefix openssl)/lib/libcrypto.a \
88+
-Xlinker -lc++ \
89+
-Xlinker -lz \
90+
-Xlinker -lbz2
91+
cp $(swift build -c release --show-bin-path)/Boka ../boka-macos-aarch64
92+
strip ../boka-macos-aarch64
93+
94+
# Verify dependencies
95+
otool -L ../boka-macos-aarch64
12196
- name: Upload Binary
12297
uses: actions/upload-artifact@v4
12398
with:
12499
name: boka-macos-aarch64
125-
path: Boka/boka-macos-aarch64
100+
path: ./boka-macos-aarch64
126101
retention-days: 7
127102

128103
create-release:
129104
name: Create GitHub Release
130-
needs: [build-linux-x64, build-macos-aarch64]
105+
needs: [build-macos-aarch64]
131106
runs-on: ubuntu-latest
132107
permissions:
133108
contents: write
@@ -158,35 +133,24 @@ jobs:
158133
body: |
159134
## Boka Binary Release ${{ steps.get_tag.outputs.tag }}
160135
161-
Standalone binaries for multiple platforms. Download the appropriate binary for your system:
162-
163-
### Linux
164-
- **x64**: `boka-linux-x64` - For Intel/AMD 64-bit Linux systems
165-
166-
### macOS
167-
- **aarch64**: `boka-macos-aarch64` - For Apple Silicon Macs (M1/M2/M3)
136+
Download binaries for your platform:
168137
169138
### Usage
170139
```bash
171-
# Download and make executable
172-
chmod +x boka-*
140+
# macOS: Download and make executable
141+
chmod +x boka-macos-aarch64
142+
./boka-macos-aarch64 --help
173143
174-
# Run the binary
175-
./boka-linux-x64 --help
176-
./boka-macos-aarch64 generate --help
177-
./boka-macos-aarch64 fuzz --help
144+
# Linux: Use Docker
145+
docker run --rm acala/boka:${{ steps.get_tag.outputs.tag }} fuzz target --help
178146
```
179147
180148
### Verification
181-
Verify binary integrity using the provided checksums:
149+
Verify macOS binary integrity:
182150
```bash
183151
sha256sum -c checksums-all.txt
184152
```
185-
186-
### Docker Alternative
187-
If you prefer Docker: `docker run --rm acala/boka:latest --help`
188153
files: |
189-
binaries/boka-linux-x64/boka-linux-x64
190154
binaries/boka-macos-aarch64/boka-macos-aarch64
191155
binaries/checksums-all.txt
192156
draft: false

Blockchain/Sources/Blockchain/VMInvocations/HostCall/HostCalls.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ public class Designate: HostCall {
884884
if validatorQueue == nil {
885885
throw VMInvocationsError.panic
886886
} else if x.serviceIndex != x.state.delegator {
887+
logger.debug("Designate HUH: \(x.serviceIndex) != \(x.state.delegator)")
887888
state.writeRegister(Registers.Index(raw: 7), HostCallResultCode.HUH.rawValue)
888889
} else {
889890
x.state.validatorQueue = try ConfigFixedSizeArray(config: config, array: validatorQueue!)

JAMTests/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let package = Package(
3535
.copy("../../jamtestvectors"),
3636
.copy("../../jamduna"),
3737
.copy("../../javajam"),
38-
.copy("../../other"),
38+
.copy("../../fuzz"),
3939
],
4040
swiftSettings: [
4141
.interoperabilityMode(.Cxx),

JAMTests/Sources/JAMTests/TestLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum TestsSource: String {
3232
case jamduna
3333
case javajam
3434
case jamixir
35-
case other
35+
case fuzz
3636
}
3737

3838
enum TestLoader {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Foundation
2+
import Testing
3+
import Utils
4+
5+
@testable import JAMTests
6+
7+
struct FuzzTests {
8+
// empty array means run all
9+
static let testFilters: [(String, String)] = [
10+
// example: ("0.6.7/1754982630", "00000004")
11+
]
12+
13+
// ignore tests
14+
static let ignore: [(String, String)] = [
15+
("0.6.7/1754725568", "00000004"), // many mismatch (from javajam reports)
16+
("0.6.7/1754754058", "00000004"), // many mismatch (from javajam reports)
17+
("0.6.7/1754982630", "00000008"), // seems this should fail on .invalidResultCodeHash
18+
("0.6.7/1755150526", "00000013"), // designate HUH
19+
("0.6.7/1755155383", "00000015"), // .invalidResultCodeHash
20+
("0.6.7/1755155383", "00000016"), // .invalidResultCodeHash
21+
("0.6.7/1755186771", "00000029"), // .invalidResultCodeHash
22+
("0.6.7/1755190301", "00000008"), // .invalidResultCodeHash
23+
]
24+
25+
static func loadTests(version: String) throws -> [Testcase] {
26+
let basePath = Bundle.module.resourcePath! + "/fuzz/" + version
27+
var allTestcases: [Testcase] = []
28+
29+
for timestamp in try FileManager.default.contentsOfDirectory(atPath: basePath).sorted() {
30+
guard !timestamp.starts(with: ".") else { continue }
31+
32+
let path = "\(version)/\(timestamp)"
33+
34+
let testcases = try JamTestnet.loadTests(path: path, src: .fuzz)
35+
36+
let testsExceptIgnore = testcases.filter { testcase in
37+
for (ignorePath, prefix) in ignore where path == ignorePath && testcase.description.starts(with: prefix) {
38+
return false
39+
}
40+
return true
41+
}
42+
43+
if testFilters.isEmpty {
44+
allTestcases.append(contentsOf: testsExceptIgnore)
45+
} else {
46+
for (filterPath, filterPrefix) in testFilters where filterPath == path {
47+
let filtered = testsExceptIgnore.filter { $0.description.starts(with: filterPrefix) }
48+
allTestcases.append(contentsOf: filtered)
49+
}
50+
}
51+
}
52+
53+
return allTestcases
54+
}
55+
56+
@Test(arguments: try loadTests(version: "0.6.7"))
57+
func fuzzTestsv067(_ testcase: Testcase) async throws {
58+
try await TraceTest.test(testcase)
59+
}
60+
}

JAMTests/Tests/JAMTests/jamtestnet/OtherTests.swift

Lines changed: 0 additions & 56 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)