diff --git a/Makefile b/Makefile index 7894bed..e2e7b86 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,12 @@ build-waku-nat: @echo "Start building waku nat-libs" $(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 ## diff --git a/README.md b/README.md index 1a5fc88..f2f0cbb 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ make update # Build executables make all +# Run tests +make tests + # Run the Text Interface ./build/tui --name= ``` diff --git a/nim_chat_poc.nimble b/nim_chat_poc.nimble index 40ec79e..cc5537e 100644 --- a/nim_chat_poc.nimble +++ b/nim_chat_poc.nimble @@ -33,6 +33,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" diff --git a/src/naxolotl/naxolotl.nim b/src/naxolotl/naxolotl.nim index 0163558..15927b5 100644 --- a/src/naxolotl/naxolotl.nim +++ b/src/naxolotl/naxolotl.nim @@ -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, diff --git a/tests/all_tests.nim b/tests/all_tests.nim new file mode 100644 index 0000000..cb136ba --- /dev/null +++ b/tests/all_tests.nim @@ -0,0 +1,4 @@ +# import individual test suites + +import ./test_curve25519 +import ./test_naxolotl diff --git a/tests/test_curve25519.nim b/tests/test_curve25519.nim index 25a26a2..02051af 100644 --- a/tests/test_curve25519.nim +++ b/tests/test_curve25519.nim @@ -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() diff --git a/tests/test_naxolotl.nim b/tests/test_naxolotl.nim index 26ef5e2..acbd824 100644 --- a/tests/test_naxolotl.nim +++ b/tests/test_naxolotl.nim @@ -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: