Closed philoniare closed 2 months ago
@AltiMario and @philoniare
I have implemented unit tests for the following APIs in their respective service handlers in the web service:
Pre-requisite for UT to pass: Keep running the blockchain, use the sled db, and local keystore as they are.
If we need to mock the blockchain, sled db, and local keystore, then I believe it's a significant effort. We would need to mock all the APIs and inject the mock blockchain, mock db, and mock keystore as dependencies to the Axum server insted of realones when UT is executing. This approach need actual code modification and I think it is not recommanded at this point when we are trying to conclude the project.
So, I opted for the approach of the above pre-requisite.
The following APIs have UTs that are passing:
get_block mint_coins create_kitty
However, for the remaining APIs, I find it challenging to implement the UTs due to dependencies between APIs.
For example, if I want to list a kitty for sale, the following prerequisites are necessary:
I have been able to satisfy all the above prerequisites except the third one, i.e., syncing the db is not done immediately after the kitty is created. Hence, when the actual API, i.e., get_txn_and_inpututxolist_for_list_kitty_for_sale(), looks for the kitty to be listed for sale in the local db, it cannot find it and the test case fails. Even if I make the test case sleep for 5 to 10 seconds after the kitty is created and before syncing the db, the local db is still not able to add the newly created kitty, causing the test case to fail. Please see the code : https://github.com/mlabs-haskell/Tuxedo/blob/b8780da09bee6cf004cb12ed7c75bdb9b91fc034/webservice-wallet/src/service_handlers/kitty_handler/kitty_service_handler.rs#L1357-L1377
This situation is the same for all the remaining APIs.
Additionally, the prerequisites for the next APIs will be more extensive and will lead to more test code:
For example, the prerequisites for buying a kitty will be:
So, I think it is going to be a significant effort as we need to write pre-requisite code for all the above steps. Of course, we can reuse the pre-requisite functions if we divide them into functions. But the main blocking point is how to sync the db synchronously before proceeding to the next step.
Below is test result: