mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-12 15:44:18 +00:00
7a0a48e4a5
* [build] disable XCannotRaiseY hint There are too many {.raises:[Defect].} in the libraries that we use, drowning out all other warnings and hints * [build] disable BareExcept warning Not yet enabled in a released version of Nim, so libraries that we depend on have not fixed this yet, drowning out our own hints and warnings * [build] disable DotLikeOps warning dot-like ops were an experiment that is not going land in Nim * [build] compile log statements in tests When running tests, all log statements are compiled. They are filtered out at runtime during a test run. * [build] do not build executable when running unit test It's already built in the integration test * [build] Fix warnings - remove unused code - remove unused imports - stop using deprecated stuff * [build] Put compiler flags behind nim version checks * [CI] remove Nim 1.2 compatibility
72 lines
1.6 KiB
Nim
72 lines
1.6 KiB
Nim
import std/os
|
|
import std/httpclient
|
|
|
|
import pkg/chronos
|
|
import ../ethertest
|
|
import ./nodes
|
|
|
|
ethersuite "Node block expiration tests":
|
|
|
|
var node: NodeProcess
|
|
var baseurl: string
|
|
|
|
let dataDir = getTempDir() / "Codex1"
|
|
let content = "test file content"
|
|
|
|
setup:
|
|
baseurl = "http://localhost:8080/api/codex/v1"
|
|
|
|
teardown:
|
|
node.stop()
|
|
|
|
dataDir.removeDir()
|
|
|
|
proc startTestNode(blockTtlSeconds: int) =
|
|
node = startNode([
|
|
"--api-port=8080",
|
|
"--data-dir=" & dataDir,
|
|
"--nat=127.0.0.1",
|
|
"--disc-ip=127.0.0.1",
|
|
"--disc-port=8090",
|
|
"--block-ttl=" & $blockTtlSeconds,
|
|
"--block-mi=3",
|
|
"--block-mn=10"
|
|
], debug = false)
|
|
|
|
proc uploadTestFile(): string =
|
|
let client = newHttpClient()
|
|
let uploadUrl = baseurl & "/upload"
|
|
let uploadResponse = client.post(uploadUrl, content)
|
|
check uploadResponse.status == "200 OK"
|
|
client.close()
|
|
uploadResponse.body
|
|
|
|
proc downloadTestFile(contentId: string): Response =
|
|
let client = newHttpClient(timeout=3000)
|
|
let downloadUrl = baseurl & "/download/" & contentId
|
|
let content = client.get(downloadUrl)
|
|
client.close()
|
|
content
|
|
|
|
test "node retains not-expired file":
|
|
startTestNode(blockTtlSeconds = 60 * 60 * 1)
|
|
|
|
let contentId = uploadTestFile()
|
|
|
|
await sleepAsync(10.seconds)
|
|
|
|
let response = downloadTestFile(contentId)
|
|
check:
|
|
response.status == "200 OK"
|
|
response.body == content
|
|
|
|
test "node deletes expired file":
|
|
startTestNode(blockTtlSeconds = 5)
|
|
|
|
let contentId = uploadTestFile()
|
|
|
|
await sleepAsync(10.seconds)
|
|
|
|
expect TimeoutError:
|
|
discard downloadTestFile(contentId)
|