research/remote_log/tests/castest.nim

61 lines
1.5 KiB
Nim
Raw Normal View History

2019-09-21 12:16:38 +00:00
import cas_service_pb
import cas_service_twirp
import strutils
import byteutils
import strformat
# XXX: Hacky tests
# Can retrieve and post node
# CAS util
proc createContent*(s: string): vac_cas_Content =
var content = newvac_cas_Content()
try:
content.data = hexToSeqByte(s.toHex())
except:
echo("Unable to create Content data")
quit(QuitFailure)
return content
2019-09-25 08:25:15 +00:00
proc createAddress*(s: string): vac_cas_Address =
var address = newvac_cas_Address()
try:
setid(address, hexToSeqByte(s))
except:
echo("Unable to create Address data")
quit(QuitFailure)
return address
2019-09-21 12:16:38 +00:00
let casClient = newCASClient("http://localhost:8001")
2019-09-21 12:31:16 +00:00
proc postContent(s: string): string =
var content = createContent(s)
try:
let resp = Add(casClient, content)
let str = parseHexStr(toHex(resp.id))
echo(&"I got a new post: {str}")
return str
except Exception as e:
echo(&"Exception: {e.msg}")
2019-09-21 12:16:38 +00:00
2019-09-25 08:25:15 +00:00
proc getContent(s: string): string =
echo("getContent s: <", s, ">")
var address = createAddress(s)
echo("getContent address: <", toHex(address.id), ">")
try:
let resp = Get(casClient, address)
let str = parseHexStr(toHex(resp.data))
echo(&"I got a new post: {str}")
return str
except Exception as e:
echo(&"Exception: {e.msg}")
2019-09-21 12:16:38 +00:00
when isMainModule:
echo("Running CAS tests")
doAssert 1 == 1
2019-09-21 12:31:16 +00:00
let id = postContent("hello")
echo("ID:", id)
2019-09-25 08:25:15 +00:00
let res = getContent(id)
echo("getContent res:", res)
2019-09-21 12:31:16 +00:00
# TODO: Run retrieve test on this ID