threefoldtecharchive / jumpscaleX_archived

Apache License 2.0
1 stars 6 forks source link

how to run a group of tests for a kind of base client #756

Open GlenDC opened 5 years ago

GlenDC commented 5 years ago

In the current version of JSX we have a single blockchain client, all available under j.clients.tfchain. As we'll have other Rivine-based chains as well (we already have 1, the goldchain, and will soon have 2 more on top of it), it is needed to easily provide different JSX blockchain clients, without copying that code around for all these clients, as that would result in an unmaintainable mess.

In order to achieve this I was planning to move the relevant code that is not tfchain-specific (most code) to /clients/blockchain/rivine and modify where needed.

first question: Given the rivine "client" codebase is meant as base clients as well as all types and transaction types and what not, all provided by rivine, in order to implement other chains (tfchain, goldchain, ...), and not directly by the user. Is it there appropriate that this lives in under the directory path /clients/blockchain/rivine? Or should it be moved to somewhere else, where perhaps libraries such as this belong? It does not require a j.clients.rivine namespace either, as that would be confusing for the user (remember: user should not ever need to use rivine stuff directly).

Now more importantly. For that code I also have a bunch of tests, probably grouped as a group of files where a file can have one or multiple tests related to a specific part of the rivine codebase. How do I run these tests? For now these tests live (on my computer, not a branch) under /clients/blockchain/rivine/tests. I cannot run them using j.clients.rivine.test() as that would require a FactoryBaseClass that registers that namespace and is meant for clients. But, as I said, none of this is required or desired.

second question: This is the important question and what it is really about. How do I run such a group of tests for a base client? The way I would know how to do it is by attaching something to a namespace j.whatever.rivine so I can run j.whatever.rivine.test() but then the question would be how would that body look for that test method? It cannot use the _run_test functionality as that is apparently meant for Factory classes only if I check https://github.com/threefoldtech/jumpscaleX/blob/development_jumpscale/Jumpscale/core/BASECLASSES/JSFactoryTools.py#L37 where apparently that _run_test functionality is coming from.

third question: while I do not think we require a j subnamespace, I think that somehow the design philosophy does want all my types and such anyhow attached to a namespace, such that chains such as tfchain and goldchain will use the base classes, types, and so on, using the properties found un that j subnamespace, instead of importing directly from Jumpscale. If so, than the first question will definitely require a proper answer as well.

0xIslamTaha commented 5 years ago

As I can see that there is a bug in clients.x.test() according to latest changs in baseClasses. Here is an example of the bug.

j.clients.tfchain.test()                                                                                                                                                                                                                                                     
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/sandbox/lib/jumpscale/Jumpscale/clients/blockchain/tfchain/TFChainClientFactory.py", line 50, in test
    self._test_run(name=name)
  File "/sandbox/lib/jumpscale/Jumpscale/core/BASECLASSES/JSConfigs.py", line 328, in __getattr__
    return self.__getattribute__(name)  # else see if we can from the factory find the child object
AttributeError: 'TFChainClientFactory' object has no attribute '_test_run'

I'm investigating to fix this bug as it is infecting all clients but for you can do this hack to make your test run

from .BASECLASSES.JSFactoryTools import JSFactoryTools

and make your TFRivineClientFactory.py inherit from it too.