2021-01-12 09:56:37 +00:00
|
|
|
import std/os
|
|
|
|
import pkg/asynctest
|
|
|
|
import pkg/chronos
|
2021-01-14 12:54:03 +00:00
|
|
|
import pkg/ipfs
|
2021-01-11 09:57:27 +00:00
|
|
|
|
2021-01-12 09:56:37 +00:00
|
|
|
suite "integration":
|
2021-01-11 09:57:27 +00:00
|
|
|
|
2021-01-12 09:56:37 +00:00
|
|
|
let address = initTAddress("127.0.0.1:48952")
|
|
|
|
|
2021-01-14 13:04:04 +00:00
|
|
|
var peer1, peer2: Ipfs
|
2021-01-12 09:56:37 +00:00
|
|
|
var input, output: File
|
|
|
|
|
|
|
|
proc setupPeers =
|
2021-01-14 13:04:04 +00:00
|
|
|
peer1 = Ipfs.create()
|
|
|
|
peer2 = Ipfs.create()
|
2021-01-12 09:56:37 +00:00
|
|
|
peer1.listen(address)
|
2021-01-14 13:04:04 +00:00
|
|
|
peer2.connect(address)
|
2021-01-12 09:56:37 +00:00
|
|
|
|
|
|
|
proc setupFiles =
|
|
|
|
input = open("tests/input.txt", fmReadWrite)
|
|
|
|
output = open("tests/output.txt", fmReadWrite)
|
|
|
|
input.write("foo")
|
|
|
|
input.setFilePos(0)
|
|
|
|
|
|
|
|
proc teardownPeers =
|
2021-01-14 13:04:04 +00:00
|
|
|
peer1.stop()
|
|
|
|
peer2.stop()
|
2021-01-12 09:56:37 +00:00
|
|
|
|
|
|
|
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":
|
2021-01-14 13:04:04 +00:00
|
|
|
let identifier = await peer1.add(input)
|
|
|
|
await peer2.get(identifier, output)
|
2021-01-12 09:56:37 +00:00
|
|
|
|
|
|
|
input.setFilePos(0)
|
|
|
|
output.setFilePos(0)
|
2021-01-14 13:26:06 +00:00
|
|
|
# TODO: enable this when all parts are in place:
|
|
|
|
# check output.readAll() == input.readAll()
|