From 24714231976dfb9843e18ff28e50161ec00494a0 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 12 Jan 2021 10:56:37 +0100 Subject: [PATCH] Added (failing) test for transferring file from one peer to another --- dagger.nim | 22 +++++++++++++++++++ dagger.nimble | 6 +++++- tests/nim.cfg | 1 + tests/testDagger.nim | 51 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 tests/nim.cfg diff --git a/dagger.nim b/dagger.nim index e69de29b..ff12850b 100644 --- a/dagger.nim +++ b/dagger.nim @@ -0,0 +1,22 @@ +import pkg/chronos + +type + DaggerPeer* = ref object + +proc newDaggerPeer*: DaggerPeer = + DaggerPeer() + +proc listen*(peer: DaggerPeer, address: TransportAddress) = + discard + +proc dial*(peer: DaggerPeer, address: TransportAddress) = + discard + +proc upload*(peer: DaggerPeer, input: File): Future[string] {.async.} = + discard + +proc download*(peer: DaggerPeer, identifier: string, output: File) {.async.} = + discard + +proc close*(peer: DaggerPeer) = + discard diff --git a/dagger.nimble b/dagger.nimble index abac3ece..6bea9c0c 100644 --- a/dagger.nimble +++ b/dagger.nimble @@ -1,4 +1,8 @@ version = "0.1.0" author = "Dagger Team" description = "Dagger Storage Network" -license = "MIT" \ No newline at end of file +license = "MIT" + +requires "nim >= 1.4.2 & < 2.0.0" +requires "chronos >= 2.5.2 & < 3.0.0" +requires "asynctest >= 0.2.1 & < 0.3.0" diff --git a/tests/nim.cfg b/tests/nim.cfg new file mode 100644 index 00000000..0f840a15 --- /dev/null +++ b/tests/nim.cfg @@ -0,0 +1 @@ +--path:".." diff --git a/tests/testDagger.nim b/tests/testDagger.nim index 0d497969..a87cff4e 100644 --- a/tests/testDagger.nim +++ b/tests/testDagger.nim @@ -1,6 +1,49 @@ -import unittest +import std/os +import pkg/asynctest +import pkg/chronos +import pkg/dagger -suite "example": +suite "integration": - test "unit testing works": - check 2 == 2 + let address = initTAddress("127.0.0.1:48952") + + var peer1, peer2: DaggerPeer + var input, output: File + + proc setupPeers = + peer1 = newDaggerPeer() + peer2 = newDaggerPeer() + peer1.listen(address) + peer2.dial(address) + + proc setupFiles = + input = open("tests/input.txt", fmReadWrite) + output = open("tests/output.txt", fmReadWrite) + input.write("foo") + input.setFilePos(0) + + proc teardownPeers = + peer1.close() + peer2.close() + + proc teardownFiles = + input.close() + output.close() + removeFile("tests/input.txt") + removeFile("tests/output.txt") + + setup: + setupPeers() + setupFiles() + + teardown: + teardownPeers() + teardownFiles() + + test "file can be transferred from one peer to another": + let identifier = await peer1.upload(input) + await peer2.download(identifier, output) + + input.setFilePos(0) + output.setFilePos(0) + check output.readAll() == input.readAll()