logos-messaging-nim/tests/waku_rln_relay/test_waku_rln_relay.nim

517 lines
17 KiB
Nim
Raw Normal View History

{.used.}
Test for the Rln relay/membership management contract deployment (#312) * enhancement/cleanup-warnings (#290) Accounting: Move flag to config and add basic test for accounting state (#284) * Accounting: Add config flag (default to false) Also fix bug where query function is called twice when flag is set. * Accounting: test state update after store req Refactor: waku_types separation of concern (trial with waku_swap) (#282) * waku_types refactor: Accounting types to waku_swap * waku_types refactor: Separate waku_swap_types file * Fix import path for waku_swap adds the test file for waku rln relay WIP: adds some initial code commented out the rln-relay test code refactor/db-message-store-split (#280) * fixes * fic * fix * fix * fix * fixed * fix * fixes * fixes, using sqlite lib fully * fix * Update sqlite.nim Waku v2 JSON-RPC REST API: Store protocol proof of concept (#263) * Waku V2 history query POC * Fix folder structure * Improve test clarity * Improve imports, returns and some naming * Changed naming conventions. Refactor & improve. Co-authored-by: Oskar Thorén <ot@oskarthoren.com> Refactor types store (#291) * Refactor: Move waku_store into its own folder * Refactor: Move waku store types to new home (WIP) * Refactor: Fix errors and recursive imports * Fix rebase errors * Refactor: More rebase import fixes Accounting credit receiving node (#292) * Accounting WIP: Swap access through Store * Fix order bug and comment scenario + typo * WIP * Accounting: Account for receiving store node - Turn accountFor function into credit and debit - Misc formatting * Accounting: Fix bugs related to mount and test * Accounting: Simplify query signature We already have a ref to wakuSwap through wakuStore now. * Resolve rebase issues enhancement/remove-flood (#295) * removes flood * rm Co-authored-by: Oskar Thorén <ot@oskarthoren.com> Updated submodules (#303) add Jenkinsfile and some Makefile targets for CI (#302) Signed-off-by: Jakub Sokołowski <jakub@status.im> Co-authored-by: Oskar Thorén <ot@oskarthoren.com> Accounting: End to end with Cheque PoC (#304) Added some basic debug and relay json-rpc calls (#305) Uncomment and call empty rln test adds the membership contract to the test file adds a test utils for contract deployment increases the gas limit for group management contract * removes some files * WIP: adds the interface of membership contract * uncomments the interface of getNumber contract * adds tests for interaction with the membership contract * send is replaced with call * replaces call with send * enhancement/cleanup-warnings (#290) Accounting: Move flag to config and add basic test for accounting state (#284) * Accounting: Add config flag (default to false) Also fix bug where query function is called twice when flag is set. * Accounting: test state update after store req Refactor: waku_types separation of concern (trial with waku_swap) (#282) * waku_types refactor: Accounting types to waku_swap * waku_types refactor: Separate waku_swap_types file * Fix import path for waku_swap adds the test file for waku rln relay WIP: adds some initial code commented out the rln-relay test code refactor/db-message-store-split (#280) * fixes * fic * fix * fix * fix * fixed * fix * fixes * fixes, using sqlite lib fully * fix * Update sqlite.nim Waku v2 JSON-RPC REST API: Store protocol proof of concept (#263) * Waku V2 history query POC * Fix folder structure * Improve test clarity * Improve imports, returns and some naming * Changed naming conventions. Refactor & improve. Co-authored-by: Oskar Thorén <ot@oskarthoren.com> Refactor types store (#291) * Refactor: Move waku_store into its own folder * Refactor: Move waku store types to new home (WIP) * Refactor: Fix errors and recursive imports * Fix rebase errors * Refactor: More rebase import fixes Accounting credit receiving node (#292) * Accounting WIP: Swap access through Store * Fix order bug and comment scenario + typo * WIP * Accounting: Account for receiving store node - Turn accountFor function into credit and debit - Misc formatting * Accounting: Fix bugs related to mount and test * Accounting: Simplify query signature We already have a ref to wakuSwap through wakuStore now. * Resolve rebase issues enhancement/remove-flood (#295) * removes flood * rm Co-authored-by: Oskar Thorén <ot@oskarthoren.com> Updated submodules (#303) add Jenkinsfile and some Makefile targets for CI (#302) Signed-off-by: Jakub Sokołowski <jakub@status.im> Co-authored-by: Oskar Thorén <ot@oskarthoren.com> Accounting: End to end with Cheque PoC (#304) Added some basic debug and relay json-rpc calls (#305) Uncomment and call empty rln test adds the membership contract to the test file adds a test utils for contract deployment increases the gas limit for group management contract * removes some files * WIP: adds the interface of membership contract * uncomments the interface of getNumber contract * adds tests for interaction with the membership contract * send is replaced with call * replaces call with send * adds a todo * removes empty lines * adds some comments * adds a todo * adds the solidity code of the NumberContract * fixes a bug: replaces call with send * removes store test comments * removes excess spaces
2021-01-07 12:34:24 -08:00
import
std/[options, os, sequtils, tempfiles, strutils, osproc],
stew/byteutils,
testutils/unittests,
chronos,
chronicles,
2022-11-04 10:52:08 +01:00
stint,
libp2p/crypto/crypto
import
waku/[
waku_core,
waku_rln_relay,
waku_rln_relay/rln,
waku_rln_relay/protocol_metrics,
waku_keystore,
],
./rln/waku_rln_relay_utils,
./utils_onchain,
../testlib/[wakucore, futures, wakunode, testutils]
from std/times import epochTime
suite "Waku rln relay":
var anvilProc {.threadVar.}: Process
var manager {.threadVar.}: OnchainGroupManager
setup:
anvilProc = runAnvil(stateFile = some(DEFAULT_ANVIL_STATE_PATH))
manager = waitFor setupOnchainGroupManager(deployContracts = false)
teardown:
stopAnvil(anvilProc)
test "key_gen Nim Wrappers":
let merkleDepth: csize_t = 20
# keysBufferPtr will hold the generated identity credential i.e., id trapdoor, nullifier, secret hash and commitment
var keysBuffer: Buffer
let
keysBufferPtr = addr(keysBuffer)
done = key_gen(keysBufferPtr, true)
require:
# check whether the keys are generated successfully
done
let generatedKeys = cast[ptr array[4 * 32, byte]](keysBufferPtr.`ptr`)[]
check:
# the id trapdoor, nullifier, secert hash and commitment together are 4*32 bytes
generatedKeys.len == 4 * 32
info "generated keys: ", generatedKeys
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
test "membership Key Generation":
let idCredentialsRes = membershipKeyGen()
require:
idCredentialsRes.isOk()
let idCredential = idCredentialsRes.get()
let empty = default(array[32, byte])
check:
idCredential.idTrapdoor.len == 32
idCredential.idNullifier.len == 32
idCredential.idSecretHash.len == 32
idCredential.idCommitment.len == 32
idCredential.idTrapdoor != empty
idCredential.idNullifier != empty
idCredential.idSecretHash != empty
idCredential.idCommitment != empty
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
info "the generated identity credential: ", idCredential
test "poseidon hash utils":
# create an RLN instance
let rlnInstance = createRLNInstanceWrapper()
require:
rlnInstance.isOk()
let rln = rlnInstance.get()
# prepare the input
let msg =
@[
"126f4c026cd731979365f79bd345a46d673c5a3f6f588bdc718e6356d02b6fdc".toBytes(),
"1f0e5db2b69d599166ab16219a97b82b662085c93220382b39f9f911d3b943b1".toBytes(),
]
let hashRes = poseidon(msg)
# Value taken from zerokit
check:
hashRes.isOk()
"28a15a991fe3d2a014485c7fa905074bfb55c0909112f865ded2be0a26a932c3" ==
hashRes.get().inHex()
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
test "RateLimitProof Protobuf encode/init test":
var
proof: ZKSNARK
merkleRoot: MerkleNode
epoch: Epoch
shareX: MerkleNode
shareY: MerkleNode
nullifier: Nullifier
rlnIdentifier: RlnIdentifier
# populate fields with dummy values
for x in proof.mitems:
x = 1
for x in merkleRoot.mitems:
x = 2
for x in epoch.mitems:
x = 3
for x in shareX.mitems:
x = 4
for x in shareY.mitems:
x = 5
for x in nullifier.mitems:
x = 6
for x in rlnIdentifier.mitems:
x = 7
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
let
rateLimitProof = RateLimitProof(
proof: proof,
merkleRoot: merkleRoot,
epoch: epoch,
shareX: shareX,
shareY: shareY,
nullifier: nullifier,
rlnIdentifier: rlnIdentifier,
)
protobuf = rateLimitProof.encode()
decodednsp = RateLimitProof.init(protobuf.buffer)
Integrates proof generation and verification into wakunode2 (#735) * WIP * WIP: fixes a bug * adds test for static group formation * adds static group creation when rln-relay is enabled * adds createStatic group * wip: adds group formation to mount rlnrelay * adds createMembershipList utility function * adds doc strings and todos * cleans up the code and add comments * defaults createRLNInstance depth argument to 32 * renames Depth * distinguishes between onchain and offchain modes * updates index boundaries * updates log levels * updates docstring * updates log level of displayed membership keys * relocates a todo * activates all the tests * fixes some comments and todos * extracts some utils procs for better debugging * adds todo * moves calculateMerkleRoot and toMembersipKeyPairs to the rln utils * makes calls to the utils functions * adds unit test for createMembershipList * adds unittest for toMembershipKeyPairs and calcMerkleRoot * cleans up the code and fixes tree root value * reverts an unwanted change * minor * adds comments and cleans up the code * updates config message * adds more comments * fixes a minor value mismatch * edits the size of group * minor rewording * defines a const var for the group keys * replaces the sequence literal with the StaticGroupKeys const * adds a rudimentary unittest * adds todos * adds more comment * replaces uint with MembeshipIndex type * fixes rln relay mem index config message * adds rln relay setup proc * decouples relay and rln-relay * uses MemIndexType instead of uint * brings back the rlnRelayEnabled flag to mountRlnRelay * deletes commented codes * adds rln relay topic validator inside updates rln relay mounting procedure * adds rln-relay-pubsub-topic cli option * adds a static rln-relay topic * deletes rlnrelayEnabled argument * adds pubsub topic for rln-relay * deletes static pubsub topic * mounts relay before rlnrelay in the tests * logs rln relay pubsub topic * cleans up the code * edits rlnrelay setup * uninitializes the input parameter of rlnrelay setup * adds comments * removes unused comments * compiles addRLNRelayValidtor when RLN compilation flag is set * adds comment about topic validator * minor * mode modifications on the description of add validator * adds pubsubtopic field to wakuRlnRelay type * WIP: shaping the test * Checks whether rln relay pubsub topic is within the supported topics of relay protocol * minor * WIP: unit test for actual proof * fixes a bug * removes a redundant proc * refines the test for actual proof * breaks lines to 80 chars * defines NonSpamProof type * adds a return * defines Epoch type * WIP: proof gen * implements actual proof gen * adds proto enc and init * adds notes about proof structure * adds NonSpamProof to wakumessage * adds proof gen * WIP: non working tests for protobuf * fixes the protobuf encoding issue * discards the output of copyFrom * WIP: hash unittest and proofVrfy and ProofGen * integrates proofVrfy * uses toBuffer inside the hash proc * adds comment * fixes a bug * removes proof field initialization * cleans up the test * generalizes input from byte seq to byte openArray * adds toBuffer * adds a bad test * cleans up unused tests * adds integration test * adds comments * cleans up * adds description to the integration test * adds test for unhappy path * tides up the tests * tides up hash unit test * renames a few var * uses a const for wku rln relay pubsub topic * minor refinement * deletes an obsolete comment * comment revision * adds comments * cleans up and adds docstrings * profGen returns proofRes instead of proof * removes extra sleepAsync * fixes two bugs * returns reject when proof is not verified\ * addresses comments * adds comments * links to rln doc * more comments * fixes space format * uncomments v2 tests * dnsclient branch update * undo branch update * minor spacing fix * makes proof field conditional
2021-10-19 17:37:29 -07:00
require:
decodednsp.isOk()
check:
decodednsp.value == rateLimitProof
Integrates proof generation and verification into wakunode2 (#735) * WIP * WIP: fixes a bug * adds test for static group formation * adds static group creation when rln-relay is enabled * adds createStatic group * wip: adds group formation to mount rlnrelay * adds createMembershipList utility function * adds doc strings and todos * cleans up the code and add comments * defaults createRLNInstance depth argument to 32 * renames Depth * distinguishes between onchain and offchain modes * updates index boundaries * updates log levels * updates docstring * updates log level of displayed membership keys * relocates a todo * activates all the tests * fixes some comments and todos * extracts some utils procs for better debugging * adds todo * moves calculateMerkleRoot and toMembersipKeyPairs to the rln utils * makes calls to the utils functions * adds unit test for createMembershipList * adds unittest for toMembershipKeyPairs and calcMerkleRoot * cleans up the code and fixes tree root value * reverts an unwanted change * minor * adds comments and cleans up the code * updates config message * adds more comments * fixes a minor value mismatch * edits the size of group * minor rewording * defines a const var for the group keys * replaces the sequence literal with the StaticGroupKeys const * adds a rudimentary unittest * adds todos * adds more comment * replaces uint with MembeshipIndex type * fixes rln relay mem index config message * adds rln relay setup proc * decouples relay and rln-relay * uses MemIndexType instead of uint * brings back the rlnRelayEnabled flag to mountRlnRelay * deletes commented codes * adds rln relay topic validator inside updates rln relay mounting procedure * adds rln-relay-pubsub-topic cli option * adds a static rln-relay topic * deletes rlnrelayEnabled argument * adds pubsub topic for rln-relay * deletes static pubsub topic * mounts relay before rlnrelay in the tests * logs rln relay pubsub topic * cleans up the code * edits rlnrelay setup * uninitializes the input parameter of rlnrelay setup * adds comments * removes unused comments * compiles addRLNRelayValidtor when RLN compilation flag is set * adds comment about topic validator * minor * mode modifications on the description of add validator * adds pubsubtopic field to wakuRlnRelay type * WIP: shaping the test * Checks whether rln relay pubsub topic is within the supported topics of relay protocol * minor * WIP: unit test for actual proof * fixes a bug * removes a redundant proc * refines the test for actual proof * breaks lines to 80 chars * defines NonSpamProof type * adds a return * defines Epoch type * WIP: proof gen * implements actual proof gen * adds proto enc and init * adds notes about proof structure * adds NonSpamProof to wakumessage * adds proof gen * WIP: non working tests for protobuf * fixes the protobuf encoding issue * discards the output of copyFrom * WIP: hash unittest and proofVrfy and ProofGen * integrates proofVrfy * uses toBuffer inside the hash proc * adds comment * fixes a bug * removes proof field initialization * cleans up the test * generalizes input from byte seq to byte openArray * adds toBuffer * adds a bad test * cleans up unused tests * adds integration test * adds comments * cleans up * adds description to the integration test * adds test for unhappy path * tides up the tests * tides up hash unit test * renames a few var * uses a const for wku rln relay pubsub topic * minor refinement * deletes an obsolete comment * comment revision * adds comments * cleans up and adds docstrings * profGen returns proofRes instead of proof * removes extra sleepAsync * fixes two bugs * returns reject when proof is not verified\ * addresses comments * adds comments * links to rln doc * more comments * fixes space format * uncomments v2 tests * dnsclient branch update * undo branch update * minor spacing fix * makes proof field conditional
2021-10-19 17:37:29 -07:00
test "toEpoch and fromEpoch consistency check":
# check edge cases
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
let
epoch = uint64.high # rln epoch
epochBytes = epoch.toEpoch()
decodedEpoch = epochBytes.fromEpoch()
check:
epoch == decodedEpoch
info "encoded and decode time",
epoch = epoch, epochBytes = epochBytes, decodedEpoch = decodedEpoch
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
test "Epoch comparison, epoch1 > epoch2":
# check edge cases
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
let
time1 = uint64.high
time2 = uint64.high - 1
epoch1 = time1.toEpoch()
epoch2 = time2.toEpoch()
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
check:
absDiff(epoch1, epoch2) == uint64(1)
absDiff(epoch2, epoch1) == uint64(1)
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
test "updateLog and hasDuplicate tests":
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
let
wakuRlnRelay = WakuRLNRelay()
epoch = wakuRlnRelay.getCurrentEpoch()
# create some dummy nullifiers and secret shares
var nullifier1: Nullifier
for index, x in nullifier1.mpairs:
nullifier1[index] = 1
var shareX1: MerkleNode
for index, x in shareX1.mpairs:
shareX1[index] = 1
let shareY1 = shareX1
var nullifier2: Nullifier
for index, x in nullifier2.mpairs:
nullifier2[index] = 2
var shareX2: MerkleNode
for index, x in shareX2.mpairs:
shareX2[index] = 2
let shareY2 = shareX2
let nullifier3 = nullifier1
var shareX3: MerkleNode
for index, x in shareX3.mpairs:
shareX3[index] = 3
let shareY3 = shareX3
proc encodeAndGetBuf(proof: RateLimitProof): seq[byte] =
return proof.encode().buffer
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
let
proof1 = RateLimitProof(
epoch: epoch, nullifier: nullifier1, shareX: shareX1, shareY: shareY1
)
wm1 = WakuMessage(proof: proof1.encodeAndGetBuf())
proof2 = RateLimitProof(
epoch: epoch, nullifier: nullifier2, shareX: shareX2, shareY: shareY2
)
wm2 = WakuMessage(proof: proof2.encodeAndGetBuf())
proof3 = RateLimitProof(
epoch: epoch, nullifier: nullifier3, shareX: shareX3, shareY: shareY3
)
wm3 = WakuMessage(proof: proof3.encodeAndGetBuf())
# check whether hasDuplicate correctly finds records with the same nullifiers but different secret shares
# no duplicate for proof1 should be found, since the log is empty
let proofMetadata1 = proof1.extractMetadata().tryGet()
let isDuplicate1 = wakuRlnRelay.hasDuplicate(epoch, proofMetadata1).valueOr:
raiseAssert $error
assert isDuplicate1 == false, "no duplicate should be found"
# add it to the log
discard wakuRlnRelay.updateLog(epoch, proofMetadata1)
# no duplicate for proof2 should be found, its nullifier differs from proof1
let proofMetadata2 = proof2.extractMetadata().tryGet()
let isDuplicate2 = wakuRlnRelay.hasDuplicate(epoch, proofMetadata2).valueOr:
raiseAssert $error
# no duplicate is found
assert isDuplicate2 == false, "no duplicate should be found"
# add it to the log
discard wakuRlnRelay.updateLog(epoch, proofMetadata2)
# proof3 has the same nullifier as proof1 but different secret shares, it should be detected as duplicate
let isDuplicate3 = wakuRlnRelay.hasDuplicate(
epoch, proof3.extractMetadata().tryGet()
).valueOr:
raiseAssert $error
# it is a duplicate
assert isDuplicate3, "duplicate should be found"
asyncTest "validateMessageAndUpdateLog: against epoch gap":
let index = MembershipIndex(5)
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = index)
let wakuRlnRelay = (await WakuRlnRelay.new(wakuRlnConfig)).valueOr:
raiseAssert $error
let manager = cast[OnchainGroupManager](wakuRlnRelay.groupManager)
let idCredentials = generateCredentials()
try:
waitFor manager.register(idCredentials, UserMessageLimit(20))
except Exception, CatchableError:
assert false,
"exception raised when calling register: " & getCurrentExceptionMsg()
let epoch1 = wakuRlnRelay.getCurrentEpoch()
# Create messages from the same peer and append RLN proof to them (except wm4)
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
var
wm1 = WakuMessage(payload: "Valid message".toBytes(), timestamp: now())
# Another message in the same epoch as wm1, expected to break the rate limit
wm2 = WakuMessage(payload: "Spam message".toBytes(), timestamp: now())
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
await sleepAsync(1.seconds)
let epoch2 = wakuRlnRelay.getCurrentEpoch()
var
# wm3 points to the next epoch due to the sleep
wm3 = WakuMessage(payload: "Valid message".toBytes(), timestamp: now())
wm4 = WakuMessage(payload: "Invalid message".toBytes(), timestamp: now())
# Append RLN proofs
wakuRlnRelay.unsafeAppendRLNProof(wm1, epoch1, MessageId(1)).isOkOr:
raiseAssert $error
wakuRlnRelay.unsafeAppendRLNProof(wm2, epoch1, MessageId(1)).isOkOr:
raiseAssert $error
wakuRlnRelay.unsafeAppendRLNProof(wm3, epoch2, MessageId(3)).isOkOr:
raiseAssert $error
# Validate messages
let
msgValidate1 = wakuRlnRelay.validateMessageAndUpdateLog(wm1)
# wm2 is within the same epoch as wm1 → should be spam
msgValidate2 = wakuRlnRelay.validateMessageAndUpdateLog(wm2)
# wm3 is in the next epoch → should be valid
msgValidate3 = wakuRlnRelay.validateMessageAndUpdateLog(wm3)
# wm4 has no RLN proof → should be invalid
msgValidate4 = wakuRlnRelay.validateMessageAndUpdateLog(wm4)
check:
msgValidate1 == MessageValidationResult.Valid
chore|feat (waku-rln-relay): modules reorganization|Initial test for capturing events using nim-web3 (#941) * first edition * adds the full test scenario * fixes typos * fixes a bug in the supplied command * further edits the description * displays the chat prompt after spam detection * updates changelog * minor wording fix * adds a new test file for onchain rln relay * adds the Event proc * adds one working example of event subscription * defines a new unitt test for event subscription * adds the new test file * cleans up the code * adds a working event subscription for faucet contract * wip * makes faucet test conditional * updates contract byte codes * adds a working test for event subscription and cleans up the tests * fixes case * adss toUInt256 unit function * enables the tests * fixes a bug * undo commented tests * cleans up the test * logs the pk * removes excess entry in the changelog * fixes spacing * comments * removes unused test codes * adds the conditional compilation for onchain tests * uncomments offchain tests * removes onchain tests * reorganizes the code and moves the rln contract data into a separate module * deletes txt files * beautifies the code * beautifies the code * removes an excess line * more formatting fixes * minor fix * updates the case of membership fee const * renames compare to diff * renames time to e * edits the number of arguments of the send proc * fixes a comment alignment * fixes indentation * fixed id style * splits check from condition * fixes a naming mismatch
2022-05-10 14:09:18 -07:00
msgValidate2 == MessageValidationResult.Spam
msgValidate3 == MessageValidationResult.Valid
msgValidate4 == MessageValidationResult.Invalid
asyncTest "validateMessageAndUpdateLog: against timestamp gap":
let index = MembershipIndex(5)
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = index)
let wakuRlnRelay = (await WakuRlnRelay.new(wakuRlnConfig)).valueOr:
raiseAssert $error
let manager = cast[OnchainGroupManager](wakuRlnRelay.groupManager)
let idCredentials = generateCredentials()
try:
waitFor manager.register(idCredentials, UserMessageLimit(20))
except Exception, CatchableError:
assert false,
"exception raised when calling register: " & getCurrentExceptionMsg()
# usually it's 20 seconds but we set it to 1 for testing purposes which make the test faster
wakuRlnRelay.rlnMaxTimestampGap = 1
var epoch = wakuRlnRelay.getCurrentEpoch()
var
wm1 = WakuMessage(
payload: "timestamp message".toBytes(),
contentTopic: DefaultPubsubTopic,
timestamp: now(),
)
wm2 = WakuMessage(
payload: "timestamp message".toBytes(),
contentTopic: DefaultPubsubTopic,
timestamp: now(),
)
wakuRlnRelay.unsafeAppendRLNProof(wm1, epoch, MessageId(1)).isOkOr:
raiseAssert $error
wakuRlnRelay.unsafeAppendRLNProof(wm2, epoch, MessageId(2)).isOkOr:
raiseAssert $error
# validate the first message because it's timestamp is the same as the generated timestamp
let msgValidate1 = wakuRlnRelay.validateMessageAndUpdateLog(wm1)
# wait for 2 seconds to make the timestamp different from generated timestamp
await sleepAsync(2.seconds)
let msgValidate2 = wakuRlnRelay.validateMessageAndUpdateLog(wm2)
check:
msgValidate1 == MessageValidationResult.Valid
msgValidate2 == MessageValidationResult.Invalid
asyncTest "multiple senders with same external nullifier":
let index1 = MembershipIndex(5)
let rlnConf1 = getWakuRlnConfig(manager = manager, index = index1)
let wakuRlnRelay1 = (await WakuRlnRelay.new(rlnConf1)).valueOr:
raiseAssert "failed to create waku rln relay: " & $error
let manager1 = cast[OnchainGroupManager](wakuRlnRelay1.groupManager)
let idCredentials1 = generateCredentials()
try:
waitFor manager1.register(idCredentials1, UserMessageLimit(20))
except Exception, CatchableError:
assert false,
"exception raised when calling register: " & getCurrentExceptionMsg()
let index2 = MembershipIndex(6)
let rlnConf2 = getWakuRlnConfig(manager = manager, index = index2)
let wakuRlnRelay2 = (await WakuRlnRelay.new(rlnConf2)).valueOr:
raiseAssert "failed to create waku rln relay: " & $error
let manager2 = cast[OnchainGroupManager](wakuRlnRelay2.groupManager)
let idCredentials2 = generateCredentials()
try:
waitFor manager2.register(idCredentials2, UserMessageLimit(20))
except Exception, CatchableError:
assert false,
"exception raised when calling register: " & getCurrentExceptionMsg()
# get the current epoch time
let epoch = wakuRlnRelay1.getCurrentEpoch()
# create messages from different peers and append rln proofs to them
var
wm1 =
WakuMessage(payload: "Valid message from sender 1".toBytes(), timestamp: now())
# another message in the same epoch as wm1, it will break the messaging rate limit
wm2 =
WakuMessage(payload: "Valid message from sender 2".toBytes(), timestamp: now())
wakuRlnRelay1.unsafeAppendRLNProof(wm1, epoch, MessageId(1)).isOkOr:
raiseAssert $error
wakuRlnRelay2.unsafeAppendRLNProof(wm2, epoch, MessageId(1)).isOkOr:
raiseAssert $error
let
msgValidate1 = wakuRlnRelay1.validateMessageAndUpdateLog(wm1)
msgValidate2 = wakuRlnRelay1.validateMessageAndUpdateLog(wm2)
check:
msgValidate1 == MessageValidationResult.Valid
msgValidate2 == MessageValidationResult.Valid
test "toIDCommitment and toUInt256":
let idCredentialRes = membershipKeyGen()
require:
idCredentialRes.isOk()
let idCredential = idCredentialRes.get()
# convert the idCommitment to UInt256
let idCUInt = idCredential.idCommitment.toUInt256()
# convert the UInt256 back to ICommitment
let idCommitment = toIDCommitment(idCUInt)
# check that the conversion has not distorted the original value
check:
idCredential.idCommitment == idCommitment
Persisting rln credentials (#1037) * Persisting Credentials implemented by writing json of keypair and rlnindex to files * Removing testing files and ignores * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Comments * Comments * Security warning in comments * Redundant echos. Omitting unused variables. * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Limit line lengths using line breaks and indents * Membership file paths declared as const * Const fix * Rln Credentials Merged. Reading credentials from file abstracted away. * Spaces * Spaces * Dangling constants removed. Comments position. * Import sequence. * Path as argument to readPersistentKeys. Spaces in comments * readPersistentKeys test * Debug and info * Index check in test * Update tests/v2/test_waku_rln_relay.nim Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com> * Abstracted writeRlnCredentials. Fix var name in test. * Usage of writeRlnCredentials in test * Dnsclient? * Test reverted to direct call to writeFile. Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials * Indentation * Revert "Dnsclient?" This reverts commit 3f4dba1a0b07591fe97c5d14ce2ebe692483f15b. * Reverting abstraction of writing.. ..persiting credential Co-authored-by: Daniel Kaiser <git@kais3r.de> Co-authored-by: Keshav Gupta <keshav.pg@hotmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com>
2022-08-05 12:48:01 +02:00
test "Read/Write RLN credentials":
let idCredentialRes = membershipKeyGen()
require:
idCredentialRes.isOk()
let idCredential = idCredentialRes.get()
let empty = default(array[32, byte])
require:
idCredential.idTrapdoor.len == 32
idCredential.idNullifier.len == 32
idCredential.idSecretHash.len == 32
idCredential.idCommitment.len == 32
idCredential.idTrapdoor != empty
idCredential.idNullifier != empty
idCredential.idSecretHash != empty
idCredential.idCommitment != empty
Persisting rln credentials (#1037) * Persisting Credentials implemented by writing json of keypair and rlnindex to files * Removing testing files and ignores * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Comments * Comments * Security warning in comments * Redundant echos. Omitting unused variables. * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Limit line lengths using line breaks and indents * Membership file paths declared as const * Const fix * Rln Credentials Merged. Reading credentials from file abstracted away. * Spaces * Spaces * Dangling constants removed. Comments position. * Import sequence. * Path as argument to readPersistentKeys. Spaces in comments * readPersistentKeys test * Debug and info * Index check in test * Update tests/v2/test_waku_rln_relay.nim Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com> * Abstracted writeRlnCredentials. Fix var name in test. * Usage of writeRlnCredentials in test * Dnsclient? * Test reverted to direct call to writeFile. Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials * Indentation * Revert "Dnsclient?" This reverts commit 3f4dba1a0b07591fe97c5d14ce2ebe692483f15b. * Reverting abstraction of writing.. ..persiting credential Co-authored-by: Daniel Kaiser <git@kais3r.de> Co-authored-by: Keshav Gupta <keshav.pg@hotmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com>
2022-08-05 12:48:01 +02:00
info "the generated identity credential: ", idCredential
Persisting rln credentials (#1037) * Persisting Credentials implemented by writing json of keypair and rlnindex to files * Removing testing files and ignores * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Comments * Comments * Security warning in comments * Redundant echos. Omitting unused variables. * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Limit line lengths using line breaks and indents * Membership file paths declared as const * Const fix * Rln Credentials Merged. Reading credentials from file abstracted away. * Spaces * Spaces * Dangling constants removed. Comments position. * Import sequence. * Path as argument to readPersistentKeys. Spaces in comments * readPersistentKeys test * Debug and info * Index check in test * Update tests/v2/test_waku_rln_relay.nim Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com> * Abstracted writeRlnCredentials. Fix var name in test. * Usage of writeRlnCredentials in test * Dnsclient? * Test reverted to direct call to writeFile. Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials * Indentation * Revert "Dnsclient?" This reverts commit 3f4dba1a0b07591fe97c5d14ce2ebe692483f15b. * Reverting abstraction of writing.. ..persiting credential Co-authored-by: Daniel Kaiser <git@kais3r.de> Co-authored-by: Keshav Gupta <keshav.pg@hotmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com>
2022-08-05 12:48:01 +02:00
let index = MembershipIndex(1)
Persisting rln credentials (#1037) * Persisting Credentials implemented by writing json of keypair and rlnindex to files * Removing testing files and ignores * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Comments * Comments * Security warning in comments * Redundant echos. Omitting unused variables. * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Limit line lengths using line breaks and indents * Membership file paths declared as const * Const fix * Rln Credentials Merged. Reading credentials from file abstracted away. * Spaces * Spaces * Dangling constants removed. Comments position. * Import sequence. * Path as argument to readPersistentKeys. Spaces in comments * readPersistentKeys test * Debug and info * Index check in test * Update tests/v2/test_waku_rln_relay.nim Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com> * Abstracted writeRlnCredentials. Fix var name in test. * Usage of writeRlnCredentials in test * Dnsclient? * Test reverted to direct call to writeFile. Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials * Indentation * Revert "Dnsclient?" This reverts commit 3f4dba1a0b07591fe97c5d14ce2ebe692483f15b. * Reverting abstraction of writing.. ..persiting credential Co-authored-by: Daniel Kaiser <git@kais3r.de> Co-authored-by: Keshav Gupta <keshav.pg@hotmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com>
2022-08-05 12:48:01 +02:00
let keystoreMembership = KeystoreMembership(
membershipContract: MembershipContract(
chainId: "5", address: "0x0123456789012345678901234567890123456789"
),
treeIndex: index,
identityCredential: idCredential,
)
let password = "%m0um0ucoW%"
let filepath = "./testRLNCredentials.txt"
defer:
removeFile(filepath)
Persisting rln credentials (#1037) * Persisting Credentials implemented by writing json of keypair and rlnindex to files * Removing testing files and ignores * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Comments * Comments * Security warning in comments * Redundant echos. Omitting unused variables. * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Limit line lengths using line breaks and indents * Membership file paths declared as const * Const fix * Rln Credentials Merged. Reading credentials from file abstracted away. * Spaces * Spaces * Dangling constants removed. Comments position. * Import sequence. * Path as argument to readPersistentKeys. Spaces in comments * readPersistentKeys test * Debug and info * Index check in test * Update tests/v2/test_waku_rln_relay.nim Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com> * Abstracted writeRlnCredentials. Fix var name in test. * Usage of writeRlnCredentials in test * Dnsclient? * Test reverted to direct call to writeFile. Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials * Indentation * Revert "Dnsclient?" This reverts commit 3f4dba1a0b07591fe97c5d14ce2ebe692483f15b. * Reverting abstraction of writing.. ..persiting credential Co-authored-by: Daniel Kaiser <git@kais3r.de> Co-authored-by: Keshav Gupta <keshav.pg@hotmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com>
2022-08-05 12:48:01 +02:00
# Write RLN credentials
require:
addMembershipCredentials(
path = filepath,
membership = keystoreMembership,
password = password,
appInfo = RLNAppInfo,
)
.isOk()
let readKeystoreRes = getMembershipCredentials(
path = filepath,
password = password,
# here the query would not include
# the identityCredential,
# since it is not part of the query
# but have used the same value
# to avoid re-declaration
query = keystoreMembership,
appInfo = RLNAppInfo,
)
assert readKeystoreRes.isOk(), $readKeystoreRes.error
# getMembershipCredentials returns the credential in the keystore which matches
# the query, in this case the query is =
# chainId = "5" and
# address = "0x0123456789012345678901234567890123456789" and
# treeIndex = 1
let readKeystoreMembership = readKeystoreRes.get()
check:
readKeystoreMembership == keystoreMembership
test "histogram static bucket generation":
let buckets = generateBucketsForHistogram(10)
Persisting rln credentials (#1037) * Persisting Credentials implemented by writing json of keypair and rlnindex to files * Removing testing files and ignores * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Daniel Kaiser <git@kais3r.de> * Comments * Comments * Security warning in comments * Redundant echos. Omitting unused variables. * Update waku/v2/protocol/waku_rln_relay/waku_rln_relay_utils.nim Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> * Limit line lengths using line breaks and indents * Membership file paths declared as const * Const fix * Rln Credentials Merged. Reading credentials from file abstracted away. * Spaces * Spaces * Dangling constants removed. Comments position. * Import sequence. * Path as argument to readPersistentKeys. Spaces in comments * readPersistentKeys test * Debug and info * Index check in test * Update tests/v2/test_waku_rln_relay.nim Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com> * Abstracted writeRlnCredentials. Fix var name in test. * Usage of writeRlnCredentials in test * Dnsclient? * Test reverted to direct call to writeFile. Abstrated writePersistentRlnCredentials usage causing error, with readPersistentRlnCredentials * Indentation * Revert "Dnsclient?" This reverts commit 3f4dba1a0b07591fe97c5d14ce2ebe692483f15b. * Reverting abstraction of writing.. ..persiting credential Co-authored-by: Daniel Kaiser <git@kais3r.de> Co-authored-by: Keshav Gupta <keshav.pg@hotmail.com> Co-authored-by: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Co-authored-by: G. <28568419+s1fr0@users.noreply.github.com>
2022-08-05 12:48:01 +02:00
check:
buckets.len == 5
buckets == [2.0, 4.0, 6.0, 8.0, 10.0]
asyncTest "nullifierLog clearing only after epoch has passed":
let index = MembershipIndex(0)
proc runTestForEpochSizeSec(rlnEpochSizeSec: uint) {.async.} =
let wakuRlnConfig = getWakuRlnConfig(
manager = manager, index = index, epochSizeSec = rlnEpochSizeSec.uint64
)
let wakuRlnRelay = (await WakuRlnRelay.new(wakuRlnConfig)).valueOr:
raiseAssert $error
let rlnMaxEpochGap = wakuRlnRelay.rlnMaxEpochGap
let testProofMetadata = default(ProofMetadata)
let testProofMetadataTable =
{testProofMetadata.nullifier: testProofMetadata}.toTable()
for i in 0 .. rlnMaxEpochGap:
# we add epochs to the nullifierLog
let testEpoch = wakuRlnRelay.calcEpoch(epochTime() + float(rlnEpochSizeSec * i))
wakuRlnRelay.nullifierLog[testEpoch] = testProofMetadataTable
check:
wakuRlnRelay.nullifierLog.len().uint == i + 1
check:
wakuRlnRelay.nullifierLog.len().uint == rlnMaxEpochGap + 1
# clearing it now will remove 1 epoch
wakuRlnRelay.clearNullifierLog()
check:
wakuRlnRelay.nullifierLog.len().uint == rlnMaxEpochGap
var testEpochSizes: seq[uint] = @[1, 5, 10, 30, 60, 600]
for i in testEpochSizes:
await runTestForEpochSizeSec(i)