Enable Tests (#22)

* Enable make tests

* Fix stale tests

* Set test logging level to ERROR

* Update readme

* Formatting changes
This commit is contained in:
Jazz Turner-Baggs 2025-11-25 08:14:59 -08:00 committed by GitHub
parent 127d16641c
commit 26c41313d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 32 additions and 12 deletions

View File

@ -72,6 +72,12 @@ build-waku-nat:
$(MAKE) -C vendor/nwaku nat-libs
@echo "Completed building nat-libs"
.PHONY: tests
tests: | build-waku-librln build-waku-nat nim_chat_poc.nims
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) nim_chat_poc.nims
##########
## Example ##
##########

View File

@ -14,6 +14,9 @@ make update
# Build executables
make all
# Run tests
make tests
# Run the Text Interface
./build/tui --name=<unique_id>
```

View File

@ -34,6 +34,13 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
srcDir & name & ".nim"
proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") =
buildBinary name, "tests/", params
exec "build/" & name
task tests, "Build & run tests":
test "all_tests", "-d:chronicles_log_level=ERROR -d:chronosStrictException"
task waku_example, "Build Waku based simple example":
let name = "waku_example"
buildBinary name, "examples/", " -d:chronicles_log_level='TRACE' "

View File

@ -114,7 +114,7 @@ proc skipMessageKeys(self: var Doubleratchet, until: MsgCount): Result[(), strin
proc encrypt(self: var Doubleratchet, plaintext: var seq[byte], associatedData: openArray[byte]): (DrHeader, CipherText) =
let (msgKey, chainKey) = self.kdfChain(self.chainKeySend)
self.chainKeySend = chainKey
let header = DrHeader(
dhPublic: self.dhSelf.public, #TODO Serialize
msgNumber: self.msgCountSend,

4
tests/all_tests.nim Normal file
View File

@ -0,0 +1,4 @@
# import individual test suites
import ./test_curve25519
import ./test_naxolotl

View File

@ -1,8 +1,8 @@
# test_example.nim
import unittest
import ../src/crypto/ecdh # TODO use config.nims
import results
import ../src/utils
import unittest
import ../src/chat_sdk/crypto/ecdh # TODO use config.nims
import ../src/chat_sdk/utils
# Key share test from RFC-7748:
const ks7748_a_priv = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"
@ -26,18 +26,17 @@ proc hexToArray*[N: static[int]](hexStr: string): array[N, byte] =
if parseHex(hexStr[i*2..i*2+1], result[i]) == 0:
raise newException(ValueError, "Invalid hex pair: " & hexStr[i*2..i*2+1])
# Usage
suite "X25519":
test "Key Loading":
let a_priv = loadKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_pub = a_priv.getPublicKey()
check bytesToHex(a_pub.bytes, lowercase = true) == ks7748_a_pub
check bytesToHex(a_pub.bytes, lowercase = true) != ks7748_b_pub
let b_priv = loadKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_pub = b_priv.getPublicKey()
check bytesToHex(b_pub.bytes, lowercase = true) != ks7748_a_pub
@ -45,10 +44,10 @@ suite "X25519":
test "ECDH":
let a_priv = loadKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_pub = a_priv.getPublicKey()
let b_priv = loadKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_pub = b_priv.getPublicKey()

View File

@ -1,13 +1,14 @@
import unittest
import naxolotl
import results
import random
import sequtils
import strutils
import naxolotl/utils
import ../src/naxolotl
import ../src/naxolotl/utils
# Key share test from RFC-7748: