Skip to content

Commit 26c4131

Browse files
authored
Enable Tests (#22)
* Enable make tests * Fix stale tests * Set test logging level to ERROR * Update readme * Formatting changes
1 parent 127d166 commit 26c4131

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ build-waku-nat:
7171
@echo "Start building waku nat-libs"
7272
$(MAKE) -C vendor/nwaku nat-libs
7373
@echo "Completed building nat-libs"
74+
75+
.PHONY: tests
76+
tests: | build-waku-librln build-waku-nat nim_chat_poc.nims
77+
echo -e $(BUILD_MSG) "build/$@" && \
78+
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) nim_chat_poc.nims
79+
7480

7581
##########
7682
## Example ##

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ make update
1414
# Build executables
1515
make all
1616
17+
# Run tests
18+
make tests
19+
1720
# Run the Text Interface
1821
./build/tui --name=<unique_id>
1922
```

nim_chat_poc.nimble

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
3333

3434
exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
3535
srcDir & name & ".nim"
36+
37+
proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") =
38+
buildBinary name, "tests/", params
39+
exec "build/" & name
40+
41+
task tests, "Build & run tests":
42+
test "all_tests", "-d:chronicles_log_level=ERROR -d:chronosStrictException"
3643

3744
task waku_example, "Build Waku based simple example":
3845
let name = "waku_example"

src/naxolotl/naxolotl.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ proc skipMessageKeys(self: var Doubleratchet, until: MsgCount): Result[(), strin
114114
proc encrypt(self: var Doubleratchet, plaintext: var seq[byte], associatedData: openArray[byte]): (DrHeader, CipherText) =
115115

116116
let (msgKey, chainKey) = self.kdfChain(self.chainKeySend)
117-
117+
self.chainKeySend = chainKey
118118
let header = DrHeader(
119119
dhPublic: self.dhSelf.public, #TODO Serialize
120120
msgNumber: self.msgCountSend,

tests/all_tests.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# import individual test suites
2+
3+
import ./test_curve25519
4+
import ./test_naxolotl

tests/test_curve25519.nim

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# test_example.nim
2-
import unittest
3-
import ../src/crypto/ecdh # TODO use config.nims
41
import results
5-
import ../src/utils
2+
import unittest
3+
4+
import ../src/chat_sdk/crypto/ecdh # TODO use config.nims
5+
import ../src/chat_sdk/utils
66

77
# Key share test from RFC-7748:
88
const ks7748_a_priv = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"
@@ -26,29 +26,28 @@ proc hexToArray*[N: static[int]](hexStr: string): array[N, byte] =
2626
if parseHex(hexStr[i*2..i*2+1], result[i]) == 0:
2727
raise newException(ValueError, "Invalid hex pair: " & hexStr[i*2..i*2+1])
2828

29-
# Usage
3029

3130
suite "X25519":
3231
test "Key Loading":
3332

34-
let a_priv = loadKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
33+
let a_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
3534
let a_pub = a_priv.getPublicKey()
3635

3736
check bytesToHex(a_pub.bytes, lowercase = true) == ks7748_a_pub
3837
check bytesToHex(a_pub.bytes, lowercase = true) != ks7748_b_pub
3938

40-
let b_priv = loadKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
39+
let b_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
4140
let b_pub = b_priv.getPublicKey()
4241

4342
check bytesToHex(b_pub.bytes, lowercase = true) != ks7748_a_pub
4443
check bytesToHex(b_pub.bytes, lowercase = true) == ks7748_b_pub
4544

4645
test "ECDH":
4746

48-
let a_priv = loadKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
47+
let a_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
4948
let a_pub = a_priv.getPublicKey()
5049

51-
let b_priv = loadKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
50+
let b_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
5251
let b_pub = b_priv.getPublicKey()
5352

5453

tests/test_naxolotl.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11

22
import unittest
3-
import naxolotl
43
import results
54
import random
65
import sequtils
76

87
import strutils
98

10-
import naxolotl/utils
9+
import ../src/naxolotl
10+
import ../src/naxolotl/utils
11+
1112

1213

1314
# Key share test from RFC-7748:

0 commit comments

Comments
 (0)