Skip to content

Commit 3b51220

Browse files
committed
Added CI
1 parent a7b3975 commit 3b51220

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

ssz_serialization/digest.nim

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,32 @@ else:
3838
{.hint: "nimcrypto SHA256 backend enabled".}
3939
type DigestCtx* = sha2.sha256
4040

41-
when PREFER_HASHTREE_SHA256 and (defined(arm64) or defined(amd64)) and (
41+
const HASHTREE_SUPPORTED* = (defined(arm64) or defined(amd64)) and (
4242
(defined(linux) and defined(gcc)) or
4343
# llvm-mingw doesn't support hashtree well even with "-fno-integrated-as"
4444
# this is true with clang-17(19th June 2024).
4545
(defined(windows) and defined(gcc) and "clang" notin staticExec("gcc --version")) or
4646
(defined(linux) and defined(clang)) or
4747
(defined(macosx) and defined(clang) and defined(arm64))
48-
):
48+
)
49+
when PREFER_HASHTREE_SHA256 and HASHTREE_SUPPORTED:
4950
{.hint: "Hashtree SHA256 backend enabled".}
5051
when tryImport ../vendor/hashtree/hashtree_abi:
5152
{.hint: "hashtree_abi found in vendor".}
52-
const USE_HASHTREE_SHA256 = true
53-
# import hashtree_abi from vendor
53+
const HASHTREE_ABI_FOUND = true
5454
elif tryImport hashtree_abi:
5555
{.hint: "hashtree_abi package found".}
56-
const USE_HASHTREE_SHA256 = true
57-
# import hashtree_abi as a package
56+
const HASHTREE_ABI_FOUND = true
5857
else:
5958
{.hint: "hashtree_abi not found, disabling hashtree backend".}
60-
const USE_HASHTREE_SHA256 = false
59+
const HASHTREE_ABI_FOUND = false
6160
else:
62-
const USE_HASHTREE_SHA256 = false
61+
const HASHTREE_ABI_FOUND = false
62+
63+
const USE_HASHTREE_SHA256* =
64+
PREFER_HASHTREE_SHA256 and HASHTREE_SUPPORTED and HASHTREE_ABI_FOUND
65+
66+
6367

6468
template computeDigest*(body: untyped): Digest =
6569
## This little helper will init the hash function and return the sliced

tests/test_all.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ import
1313
./test_ssz_union,
1414
./test_merkleization,
1515
./test_merkleization_types,
16-
./test_hash_tree_root
16+
./test_hash_tree_root,
17+
./test_backend_inclusion,

tests/test_backend_inclusion.nim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest2
2+
import ../ssz_serialization/digest
3+
4+
suite "Hashtree backend":
5+
6+
test "preference + support implies USE == ABI_FOUND":
7+
when PREFER_HASHTREE_SHA256 and HASHTREE_SUPPORTED:
8+
check USE_HASHTREE_SHA256 == HASHTREE_ABI_FOUND
9+
10+
test "constants are consistent":
11+
when USE_HASHTREE_SHA256:
12+
check PREFER_HASHTREE_SHA256
13+
check HASHTREE_SUPPORTED
14+
check HASHTREE_ABI_FOUND

0 commit comments

Comments
 (0)