Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for models.rs and lib.rs; integration tests for clients #65

Merged
merged 46 commits into from
Jul 29, 2022

Conversation

LeoNero
Copy link
Member

@LeoNero LeoNero commented Jul 12, 2022

Closes #58
Closes #71

For #58, I decided to to a simple error handling: check if the request returns "000000..." when it should have returned an error, and then return anyhow::Error::new("msg").

In case another version of Monero handles it correctly, our tests will fail :) and in such case, we will be able to remove anyhow::Error::new("msg").

For proper error types, I think the issue #22 can handle that.

Also, although the files are big, it is relatively easy to follow what is hapenning, since the function names are descriptive.

The tests are structured as follows:

  • basic_wallet_tests: tests wallet functionality that does not interact with the daemon
  • empty_blockchain_test: tests daemon_json_rpc functionaly when the blockchain is empty, ie has only the genesis block
  • non_empty_blockchain_test: tests daemon_json_rpc functionality that changes the blockchain state, but such functionalities are not related to transactions, outputs, etc
  • basic_daemon_rpc_test: tests the daemon_rpc when there are no transactions between users in the blockchain
  • all_clients_interaction_test: tests the functionality of all clients (creates transactions, transfers, blocks, updates balances, etc)

A separate test, testing the code in the README, was added as well

Finally, you can see the changes made to the code in src/ at CHANGELOG.md.

@LeoNero LeoNero force-pushed the add/tests-for-lib branch 2 times, most recently from 05aca62 to 5fd9c4f Compare July 15, 2022 19:22
@LeoNero LeoNero force-pushed the add/tests-for-lib branch from ca26567 to 8c7c7e5 Compare July 27, 2022 16:43
LeoNero added 22 commits July 27, 2022 13:43
`PartialEq` was derived for the following types:
- BlockTemplate
- Transaction
- SubaddressBalanceData
- BalanceData
- TransferPriority
- SubaddressData
- SubaddressIndex
- Payment
- AddressData
- IncomingTransfers
- GotAccount
- GetAccountsData
- GotTransfer
- SignedKeyImage
- KeyImageImportResponse
Comment is about the possibility of GenerateFromKeysArgs's `password`
field being optional, even though Monero docs do not mention it.
@LeoNero LeoNero force-pushed the add/tests-for-lib branch from 8c7c7e5 to 05e2996 Compare July 27, 2022 16:56
@LeoNero LeoNero changed the title WIP: tests for lib Unit tests for models.rs and lib.rs; integration tests for clients Jul 27, 2022
tests/rpc.rs Outdated Show resolved Hide resolved
@LeoNero LeoNero force-pushed the add/tests-for-lib branch from 87ce9a7 to e71e4ef Compare July 27, 2022 20:46
tests/common/main_tests/all_clients_interaction.rs Outdated Show resolved Hide resolved
tests/common/main_tests/all_clients_interaction.rs Outdated Show resolved Hide resolved
tests/rpc.rs Outdated Show resolved Hide resolved
@LeoNero LeoNero marked this pull request as ready for review July 27, 2022 20:52
tests/rpc.rs Outdated Show resolved Hide resolved
@TheCharlatan TheCharlatan merged commit 8601bf9 into monero-rs:master Jul 29, 2022
refring pushed a commit to refring/monero-rpc-rs that referenced this pull request Oct 16, 2022
…onero-rs#65)

* docs(README): improve `Testing` section

* feat(models): derive `PartialEq` for some types in src/models.rs

`PartialEq` was derived for the following types:
- BlockTemplate
- Transaction
- SubaddressBalanceData
- BalanceData
- TransferPriority
- SubaddressData
- SubaddressIndex
- Payment
- AddressData
- IncomingTransfers
- GotAccount
- GetAccountsData
- GotTransfer
- SignedKeyImage
- KeyImageImportResponse

* feat(models): add GenerateBlocksResponseR struct

* feat(models): add GenerateBlocksResponse struct

* feat(models): add `From<GenerateBlocksResponseR>` for `GenerateBlocksResponse`

* fix(models): fix type of TransferData's `tx_key` field

* doc(models): add comment about possible optional field

Comment is about the possibility of GenerateFromKeysArgs's `password`
field being optional, even though Monero docs do not mention it.

* test(models): test conversion from GenerateBlocksResponseR to GenerateBlocksResponse

* docs(lib): fix small typos and improve wording a little

* fix(lib): fix parameter name passed to `get_balance` RPC call

* refactor(lib): remove unncessary full type path from `json_params` in `daemon_rpc_call` method

* feat(lib): add `all` parameter for `export_key_images` RPC call

* docs(lib): add comment about get_bulk_payments's parameter min_block_height possibly being optional

* feat(lib): `generate_blocks` method now returns `GenerateBlocksResponse`

* fix(lib): fix `submit_block` method and return type

* fix(lib): handle `on_get_block_hash` inconsistency on invalid height

* fix(lib): fix `get_payments` to make it return a vector of payments

* fix(lib): fix type of `check_tx_key` RPC call parameters and return type

* test(lib): add unit tests for RpcParams

* test(lib): add serialization test for TransferType

* test(lib): add serialization and deserialization test for TransferPriority

* test(rpc): remove old tests in tests/rpc.rs

* test(rpc): add helpers functions to test DaemonRpcClient

* test(rpc): add helpers functions to test RegtestDaemonJsonRpcClient

* test(rpc): add helpers functions to test WalletClient

* test(rpc): add `common::helpers` module

* test(rpc): add `basic_wallet` test

* test(rpc): add `empty_blockchain` test

* test(rpc): add `non_empty_blockchain` test

* test(rpc): add `basic_daemon_rpc` test

* test(rpc): add tests of interaction between all clients

* test(rpc): add `common::main_tests` module

* test(rpc): add `common` crate

* test(rpc): add code to run all tests in `common::main_tests`

* test(rpc): fix the tests

* test(rpc): bump to Monero v0.18.0.0

* docs(CHANGELOG): update CHANGELOG to reflect recent changes

* refactor(tests): remove `common` folder

* refactor(tests): allow a lint on `empty_blockchain`.rs and add explanation

* refactor(tests): remove `async` declaration from function that don't need it

* fix(lib): fix Rust 1.56.1 format error in on_get_block_hash

* docs(rpc): improve test documentation

* test(rpc): rename main_tests to clients_tests, and `fn test` to `fn run`

* refactor(tests/wallet): fix expected_ naming inconsistency

* refactor(rpc): make tests functions more explicit

* docs(rpc): fix typo in a comment on rpc.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support for Monero 0.18 Add new type error to deal with Daemon RPC inconsistencies
2 participants