Skip to content

Commit

Permalink
feat(rln-relay): integrate get_leaf ffi api
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Jun 9, 2023
1 parent 9c04b59 commit 515a5fc
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 97 deletions.
192 changes: 96 additions & 96 deletions tests/all_tests_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,105 @@ import
./v2/waku_core/test_peers


# Waku archive test suite
import
./v2/waku_archive/test_driver_queue_index,
./v2/waku_archive/test_driver_queue_pagination,
./v2/waku_archive/test_driver_queue_query,
./v2/waku_archive/test_driver_queue,
./v2/waku_archive/test_driver_sqlite_query,
./v2/waku_archive/test_driver_sqlite,
./v2/waku_archive/test_retention_policy,
./v2/waku_archive/test_waku_archive

const os* {.strdefine.} = ""
when os == "Linux":
# GitHub only supports container actions on Linux
# and we need to start a postgress database in a docker container
import
./v2/waku_archive/test_driver_postgres

# Waku store test suite
import
./v2/waku_store/test_rpc_codec,
./v2/waku_store/test_waku_store,
./v2/waku_store/test_wakunode_store

when defined(waku_exp_store_resume):
# TODO: Review store resume test cases (#1282)
import ./v2/waku_store/test_resume


# Waku relay test suite
import
./v2/waku_relay/test_waku_relay,
./v2/waku_relay/test_wakunode_relay

# Waku filter test suite
import
./v2/waku_filter_v2/test_waku_filter,
./v2/waku_filter_v2/test_waku_filter_protocol

import
# Waku v2 tests
./v2/test_wakunode,
# Waku LightPush
./v2/test_waku_lightpush,
./v2/test_wakunode_lightpush,
# Waku Filter
./v2/test_waku_filter,
./v2/test_wakunode_filter,
./v2/test_waku_peer_exchange,
./v2/test_peer_store_extended,
./v2/test_message_cache,
./v2/test_peer_manager,
./v2/test_peer_storage,
./v2/test_waku_keepalive,
./v2/test_waku_enr,
./v2/test_waku_dnsdisc,
./v2/test_waku_discv5,
./v2/test_peer_exchange,
./v2/test_waku_noise,
./v2/test_waku_noise_sessions,
./v2/test_waku_switch,
./v2/test_waku_rendezvous,
# Utils
./v2/test_utils_compat

# Waku Keystore test suite
import
./v2/test_waku_keystore_keyfile,
./v2/test_waku_keystore

## Wakunode JSON-RPC API test suite
import
./v2/wakunode_jsonrpc/test_jsonrpc_admin,
./v2/wakunode_jsonrpc/test_jsonrpc_debug,
./v2/wakunode_jsonrpc/test_jsonrpc_filter,
./v2/wakunode_jsonrpc/test_jsonrpc_relay,
./v2/wakunode_jsonrpc/test_jsonrpc_store

## Wakunode Rest API test suite
import
./v2/wakunode_rest/test_rest_debug,
./v2/wakunode_rest/test_rest_debug_serdes,
./v2/wakunode_rest/test_rest_relay,
./v2/wakunode_rest/test_rest_relay_serdes,
./v2/wakunode_rest/test_rest_serdes,
./v2/wakunode_rest/test_rest_store


## Apps

# Wakubridge test suite
import ./all_tests_wakubridge
# # Waku archive test suite
# import
# ./v2/waku_archive/test_driver_queue_index,
# ./v2/waku_archive/test_driver_queue_pagination,
# ./v2/waku_archive/test_driver_queue_query,
# ./v2/waku_archive/test_driver_queue,
# ./v2/waku_archive/test_driver_sqlite_query,
# ./v2/waku_archive/test_driver_sqlite,
# ./v2/waku_archive/test_retention_policy,
# ./v2/waku_archive/test_waku_archive

# const os* {.strdefine.} = ""
# when os == "Linux":
# # GitHub only supports container actions on Linux
# # and we need to start a postgress database in a docker container
# import
# ./v2/waku_archive/test_driver_postgres

# # Waku store test suite
# import
# ./v2/waku_store/test_rpc_codec,
# ./v2/waku_store/test_waku_store,
# ./v2/waku_store/test_wakunode_store

# when defined(waku_exp_store_resume):
# # TODO: Review store resume test cases (#1282)
# import ./v2/waku_store/test_resume


# # Waku relay test suite
# import
# ./v2/waku_relay/test_waku_relay,
# ./v2/waku_relay/test_wakunode_relay

# # Waku filter test suite
# import
# ./v2/waku_filter_v2/test_waku_filter,
# ./v2/waku_filter_v2/test_waku_filter_protocol

# import
# # Waku v2 tests
# ./v2/test_wakunode,
# # Waku LightPush
# ./v2/test_waku_lightpush,
# ./v2/test_wakunode_lightpush,
# # Waku Filter
# ./v2/test_waku_filter,
# ./v2/test_wakunode_filter,
# ./v2/test_waku_peer_exchange,
# ./v2/test_peer_store_extended,
# ./v2/test_message_cache,
# ./v2/test_peer_manager,
# ./v2/test_peer_storage,
# ./v2/test_waku_keepalive,
# ./v2/test_waku_enr,
# ./v2/test_waku_dnsdisc,
# ./v2/test_waku_discv5,
# ./v2/test_peer_exchange,
# ./v2/test_waku_noise,
# ./v2/test_waku_noise_sessions,
# ./v2/test_waku_switch,
# ./v2/test_waku_rendezvous,
# # Utils
# ./v2/test_utils_compat

# # Waku Keystore test suite
# import
# ./v2/test_waku_keystore_keyfile,
# ./v2/test_waku_keystore

# ## Wakunode JSON-RPC API test suite
# import
# ./v2/wakunode_jsonrpc/test_jsonrpc_admin,
# ./v2/wakunode_jsonrpc/test_jsonrpc_debug,
# ./v2/wakunode_jsonrpc/test_jsonrpc_filter,
# ./v2/wakunode_jsonrpc/test_jsonrpc_relay,
# ./v2/wakunode_jsonrpc/test_jsonrpc_store

# ## Wakunode Rest API test suite
# import
# ./v2/wakunode_rest/test_rest_debug,
# ./v2/wakunode_rest/test_rest_debug_serdes,
# ./v2/wakunode_rest/test_rest_relay,
# ./v2/wakunode_rest/test_rest_relay_serdes,
# ./v2/wakunode_rest/test_rest_serdes,
# ./v2/wakunode_rest/test_rest_store


# ## Apps

# # Wakubridge test suite
# import ./all_tests_wakubridge


## Experimental

when defined(rln):
import
./v2/waku_rln_relay/test_waku_rln_relay,
./v2/waku_rln_relay/test_wakunode_rln_relay,
./v2/waku_rln_relay/test_rln_group_manager_onchain,
./v2/waku_rln_relay/test_rln_group_manager_static
./v2/waku_rln_relay/test_waku_rln_relay
# ./v2/waku_rln_relay/test_wakunode_rln_relay,
# ./v2/waku_rln_relay/test_rln_group_manager_onchain,
# ./v2/waku_rln_relay/test_rln_group_manager_static
33 changes: 33 additions & 0 deletions tests/v2/waku_rln_relay/test_waku_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ suite "Waku rln relay":
check:
memberAdded

test "getMember Nim wrapper":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
# generate an identity credential
let idCredentialRes = membershipKeyGen(rln)
require:
idCredentialRes.isOk()

let idCredential = idCredentialRes.get()
let pkBuffer = toBuffer(idCredential.idCommitment)
let pkBufferPtr = unsafeAddr(pkBuffer)

let
root1 {.noinit.}: Buffer = Buffer()
rootPtr1 = unsafeAddr(root1)
getRootSuccessful1 = getRoot(rlnInstance.get(), rootPtr1)

# add the member to the tree
let memberAdded = updateNextMember(rln, pkBufferPtr)
require:
memberAdded

let leafRes = getMember(rln, 0)
require:
leafRes.isOk()
let leaf = leafRes.get()
let leafHex = leaf.inHex()
check:
leafHex == idCredential.idCommitment.inHex()

test "delete_member Nim wrapper":
# create an RLN instance which also includes an empty Merkle tree
let rlnInstance = createRLNInstance()
Expand Down
1 change: 0 additions & 1 deletion waku/v2/waku_rln_relay/constants.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import
std/json,
stint

import
Expand Down
5 changes: 5 additions & 0 deletions waku/v2/waku_rln_relay/rln/rln_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ proc set_leaf*(ctx: ptr RLN, index: uint, input_buffer: ptr Buffer): bool {.impo
## the input_buffer holds a serialized leaf of 32 bytes
## the return bool value indicates the success or failure of the operation

proc get_leaf*(ctx: ptr RLN, index: uint, output_buffer: ptr Buffer): bool {.importc: "get_leaf".}
## gets the leaf at position index in the tree stored by ctx
## the output_buffer holds a serialized leaf of 32 bytes
## the return bool value indicates the success or failure of the operation

proc init_tree_with_leaves*(ctx: ptr RLN, input_buffer: ptr Buffer): bool {.importc: "init_tree_with_leaves".}
## sets multiple leaves in the tree stored by ctx to the value passed by input_buffer
## the input_buffer holds a serialized vector of leaves (32 bytes each)
Expand Down
19 changes: 19 additions & 0 deletions waku/v2/waku_rln_relay/rln/wrappers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,25 @@ proc insertMember*(rlnInstance: ptr RLN, idComm: IDCommitment): bool =
let memberAdded = update_next_member(rlnInstance, pkBufferPtr)
return memberAdded

proc getMember*(rlnInstance: ptr RLN, index: MembershipIndex): RlnRelayResult[IDCommitment] =
## returns the member at the given index
## returns an error if the index is out of bounds
## returns the member if the index is valid
var
idCommitment {.noinit.}: Buffer = Buffer()
idCommitmentPtr = addr(idCommitment)
memberRetrieved = get_leaf(rlnInstance, index, idCommitmentPtr)

if not memberRetrieved:
return err("could not get the member")

if not idCommitment.len == 32:
return err("wrong output size")

let idCommitmentValue = (cast[ptr array[32, byte]](idCommitment.`ptr`))[]

return ok(@idCommitmentValue)

proc atomicWrite*(rlnInstance: ptr RLN,
index = none(MembershipIndex),
idComms = newSeq[IDCommitment](),
Expand Down

0 comments on commit 515a5fc

Please sign in to comment.