mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 06:03:09 +00:00
Enable Tests (#22)
* Enable make tests * Fix stale tests * Set test logging level to ERROR * Update readme * Formatting changes
This commit is contained in:
parent
127d16641c
commit
26c41313d4
6
Makefile
6
Makefile
@ -71,6 +71,12 @@ build-waku-nat:
|
|||||||
@echo "Start building waku nat-libs"
|
@echo "Start building waku nat-libs"
|
||||||
$(MAKE) -C vendor/nwaku nat-libs
|
$(MAKE) -C vendor/nwaku nat-libs
|
||||||
@echo "Completed building 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 ##
|
## Example ##
|
||||||
|
|||||||
@ -14,6 +14,9 @@ make update
|
|||||||
# Build executables
|
# Build executables
|
||||||
make all
|
make all
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
make tests
|
||||||
|
|
||||||
# Run the Text Interface
|
# Run the Text Interface
|
||||||
./build/tui --name=<unique_id>
|
./build/tui --name=<unique_id>
|
||||||
```
|
```
|
||||||
|
|||||||
@ -33,6 +33,13 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
|
|||||||
|
|
||||||
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
|
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
|
||||||
srcDir & name & ".nim"
|
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":
|
task waku_example, "Build Waku based simple example":
|
||||||
let name = "waku_example"
|
let name = "waku_example"
|
||||||
|
|||||||
@ -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) =
|
proc encrypt(self: var Doubleratchet, plaintext: var seq[byte], associatedData: openArray[byte]): (DrHeader, CipherText) =
|
||||||
|
|
||||||
let (msgKey, chainKey) = self.kdfChain(self.chainKeySend)
|
let (msgKey, chainKey) = self.kdfChain(self.chainKeySend)
|
||||||
|
self.chainKeySend = chainKey
|
||||||
let header = DrHeader(
|
let header = DrHeader(
|
||||||
dhPublic: self.dhSelf.public, #TODO Serialize
|
dhPublic: self.dhSelf.public, #TODO Serialize
|
||||||
msgNumber: self.msgCountSend,
|
msgNumber: self.msgCountSend,
|
||||||
|
|||||||
4
tests/all_tests.nim
Normal file
4
tests/all_tests.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# import individual test suites
|
||||||
|
|
||||||
|
import ./test_curve25519
|
||||||
|
import ./test_naxolotl
|
||||||
@ -1,8 +1,8 @@
|
|||||||
# test_example.nim
|
|
||||||
import unittest
|
|
||||||
import ../src/crypto/ecdh # TODO use config.nims
|
|
||||||
import results
|
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:
|
# Key share test from RFC-7748:
|
||||||
const ks7748_a_priv = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"
|
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:
|
if parseHex(hexStr[i*2..i*2+1], result[i]) == 0:
|
||||||
raise newException(ValueError, "Invalid hex pair: " & hexStr[i*2..i*2+1])
|
raise newException(ValueError, "Invalid hex pair: " & hexStr[i*2..i*2+1])
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
suite "X25519":
|
suite "X25519":
|
||||||
test "Key Loading":
|
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()
|
let a_pub = a_priv.getPublicKey()
|
||||||
|
|
||||||
check bytesToHex(a_pub.bytes, lowercase = true) == ks7748_a_pub
|
check bytesToHex(a_pub.bytes, lowercase = true) == ks7748_a_pub
|
||||||
check bytesToHex(a_pub.bytes, lowercase = true) != ks7748_b_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()
|
let b_pub = b_priv.getPublicKey()
|
||||||
|
|
||||||
check bytesToHex(b_pub.bytes, lowercase = true) != ks7748_a_pub
|
check bytesToHex(b_pub.bytes, lowercase = true) != ks7748_a_pub
|
||||||
@ -45,10 +44,10 @@ suite "X25519":
|
|||||||
|
|
||||||
test "ECDH":
|
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 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()
|
let b_pub = b_priv.getPublicKey()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import naxolotl
|
|
||||||
import results
|
import results
|
||||||
import random
|
import random
|
||||||
import sequtils
|
import sequtils
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
import naxolotl/utils
|
import ../src/naxolotl
|
||||||
|
import ../src/naxolotl/utils
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Key share test from RFC-7748:
|
# Key share test from RFC-7748:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user