nim-dagger/tests/integration/testblockexpiration.nim
Jaremy Creechley 7efa9177df
Bump deps take2 (#492)
* extra utilities and tweaks
* add atlas lock
* update ignores
* break build into it's own script
* update url rules
* base off codexdht's
* compile fixes for Nim 1.6.14
* update submodules
* convert mapFailure to procs to work around type resolution issues
* add toml parser for multiaddress
* change error type on keyutils
* bump nimbus build to use 1.6.14
* update gitignore
* adding new deps submodules
* bump nim ci version
* even more fixes
* more libp2p changes
* update keys
* fix eventually function
* adding coverage test file
* move coverage to build.nims
* use nimcache/coverage
* move libp2p import for tests into helper.nim
* remove named bin
* bug fixes for networkpeers (from Dmitriy)

---------

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
2023-08-01 16:47:57 -07:00

72 lines
1.7 KiB
Nim

import std/os
import std/httpclient
from std/net import TimeoutError
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=1",
"--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 = 10)
let contentId = uploadTestFile()
await sleepAsync(2.seconds)
let response = downloadTestFile(contentId)
check:
response.status == "200 OK"
response.body == content
test "node deletes expired file":
startTestNode(blockTtlSeconds = 1)
let contentId = uploadTestFile()
await sleepAsync(2.seconds)
expect TimeoutError:
discard downloadTestFile(contentId)