mirror of https://github.com/vacp2p/research.git
Make getContent tests pass
This commit is contained in:
parent
737ab57294
commit
2712b3ed38
|
@ -17,6 +17,15 @@ proc createContent*(s: string): vac_cas_Content =
|
|||
quit(QuitFailure)
|
||||
return content
|
||||
|
||||
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
|
||||
|
||||
let casClient = newCASClient("http://localhost:8001")
|
||||
|
||||
proc postContent(s: string): string =
|
||||
|
@ -29,9 +38,23 @@ proc postContent(s: string): string =
|
|||
except Exception as e:
|
||||
echo(&"Exception: {e.msg}")
|
||||
|
||||
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}")
|
||||
|
||||
when isMainModule:
|
||||
echo("Running CAS tests")
|
||||
doAssert 1 == 1
|
||||
let id = postContent("hello")
|
||||
echo("ID:", id)
|
||||
let res = getContent(id)
|
||||
echo("getContent res:", res)
|
||||
# TODO: Run retrieve test on this ID
|
||||
|
|
Loading…
Reference in New Issue