Open rkintzi opened 5 years ago
How far are you into this / what kind of work has already been done?
@drdgvhbh This is just a proposal. No code for now. We are waiting for community feedback. What do you thing? Is this right direction?
It seems fairily straightforward and intuitive, so I would say so. One thing that I think is fairly lacking in the current verson of eosfactory is the ability to include external contracts from other repositories. For instance, I need to use the eosio.token
contract in some of my tests but in order to do so, I need to clone the eosio.contracts repository and link it in each of my tests.
E.x.
EOSIO_TOKEN_CONTRACT = sys.path[0] + \
"/../../eosio.contracts/build/eosio.token"
With this new api you could have some like include_contracts
, which will clone the repository in a cache, build it, and make it readily avaliable. Of course this will require each repository to have a standard way of buidling the contracts (some repository may just use cmake directly, while others use a shell script); a eosfactory.cfg file could work
E.x.
import eosfactory as eosf
network = eosf.cleos_for_net(testnet_cfg).include_contracts(
"https://github.com/EOSIO/eosio.contracts")
eosio_token_contract = network.contracts.eosio_token
eosio_token_contract.deploy()
...
Some other interesting features could be
network = eosf.cleos_for_net(
testnet_cfg).deploy_contracts_automatically(True).always_unique(True)
As a EOS smart-contract developer I need plain and simple API to manage local testnets.
Below is an example and of how new API (let's call it EOS Factory 2.0 for the time being) could feel like. It should be considered a starting point for a discussion with the EOS community about how ideal API for testing smart-contract should look like and what features should it provide. Everyone is welcome to contribute proposition, opinion and - what would be most valuable - describe real-live use cases. Let's discuss the idea and try to specify the API in comments.
Testnet configuration
eosf.TestnetCfg
is a constructor of a testnet configuration.Options used in the above example were taken from a command line used by EOS Factory to spawn
nodeos
processes and should be considered only as an example and not an exhaustive list of all the options.All the options supported by EOS Factory should have reasonable default values. For example: 1) For network addresses - if not specified,
localhost
should be used 2) For port numbers - if not specified, an unused number from documented range should be taken 3) For paths - if not specified, random not existing folder under/tmp
should be used (e.g./tmp/eosf-XXXXX
where XXXXX is a random number)Why separate configuration from the actual command
The testnet on its own is of no use. It brings a value only if we can interact with it, for example, to create a user account and its keys or to deploy a smart-contract. To support those interactions, we will have separate APIs, and we need an easy way to configure them to work with a specified testnet.
Below is an example of how this other APIs could use testnet configuration (note: this is just an example and not specification - we will have a discussion on this in a separate issue):
The other example of configuration object usage is a
cfg.file_in_workspace
function from the first listing. It creates a path to file in a folder where other data related to given testnet reside.Why separate command from its execution
The
cmd
value returned fromnodeos_cmd
function in the first example above is a sequence ofnodeos
arguments (first item of which is a path to binary itself) suitable to be used as the first argument toPopen
constructor from Python standardsubprocess
module. This way developer can have full control over hownodeos
is executed.We should also provide convenient functions to execute and manage EOS binaries. One of such function is
eosf.run_cmd_async()
. It usesPopen
internally to hide some nasty details from smart-contract developers (like the need for pipelines creation). It could also wait fornodeos
to become responsive (i.e. ready to serve requests) before it returns execution.eosf.kill_and_wait()
is another one, that sends a TERM signal to a process, waits for it to stop and returns its status code.