nwaku/tests/waku_rln_relay/utils.nim

33 lines
1.1 KiB
Nim
Raw Normal View History

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 20:34:24 +00:00
import web3, chronos, options, stint
proc deployContract*(web3: Web3, code: string, gasPrice = 0, contractInput = ""): Future[ReceiptObject] {.async.} =
# the contract input is the encoded version of contract constructor's input
# use nim-web3/encoding.nim module to find the appropriate encoding procedure for different argument types
# e.g., consider the following contract constructor in solidity
# constructor(uint256 x, uint256 y)
#
# the contractInput can be calculated as follows
# let
# x = 1.u256
# y = 5.u256
# contractInput = encode(x).data & encode(y).data
# Note that the order of encoded inputs should match the order of the constructor inputs
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 20:34:24 +00:00
let provider = web3.provider
let accounts = await provider.eth_accounts()
var code = code
if code[1] notin {'x', 'X'}:
code = "0x" & code
var tr: EthSend
tr.source = web3.defaultAccount
tr.data = code & contractInput
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 20:34:24 +00:00
tr.gas = Quantity(3000000000000).some
if gasPrice != 0:
tr.gasPrice = some(gasPrice)
let r = await web3.send(tr)
return await web3.getMinedTransactionReceipt(r)
proc ethToWei*(eth: UInt256): UInt256 =
eth * 1000000000000000000.u256