tokenika / eosfactory

Python-based EOS smart-contract development & testing framework
http://eosfactory.io/
Other
243 stars 62 forks source link

Documentation Update #40

Closed sjkelleyjr closed 6 years ago

sjkelleyjr commented 6 years ago

I have two questions:

  1. I was looking to try and list the accounts in the sess.wallet object, but couldn't find any documentation on this.
  2. I tried finding this in the documentation, but maybe I missed it. What is the procedure for running unit tests against a smart contract?
jakub-zarembinski commented 6 years ago

In the context of the EOSFactory, listing accounts can be understood in two different ways.

If what you mean is the get_accounts command of the cleos tool, the EOSFactory counterpart is cleos.GetAccounts(), for example:

>>> import cleos
>>> cleos.GetAccounts(account_alice.owner_key)

...where account_alice is an account object. The response is like this:

{
  "account_names": [
    "cznzipxsl35s"
  ]
}

If what you mean is a list of account objects that are referenced in the wallet, the wallet object has the restore_accounts() method, typically used when the wallet starts.

>>> import eosf_account
>>> eosf_account.wallet_singleton.restore_accounts()

The response is:

Restored accounts as global variables:
account_carol (cznzipxsl35s)
account_tic_tac_toe (1ja5ifnilhsg)
account_alice (xdmmfyfcatqy)

NOTE: The above syntax comes from an unpublished EOSFactory release - it will be out in a couple of days.

sjkelleyjr commented 6 years ago

Perfect, thanks!

sjkelleyjr commented 6 years ago

Actually, just realized I didn't get question number 2 answered.

andresberrios commented 6 years ago

@sjkelleyjr I'm not sure since I haven't been able to play around with EOSFactory yet since the current release doesn't work with the version of eosio I have installed (the new release is supposed to come out soon), but I imagine you would simply write a python script that would load up the stuff you need and then run some tests however you want. It would make sense to use a python testing library, like https://docs.python.org/3/library/unittest.html

andresberrios commented 6 years ago

@sjkelleyjr btw thanks for your youtube videos, they've helped me and a lot of other people out there! 👍

sjkelleyjr commented 6 years ago

@andresberrios thanks man! The reason I created the issue was because I briefly cover EOSFactory the "dApp Ecosystem" section of the course and wanted to add these two topics as well. Maybe I'll add a second video after the docs get updated.

I imagine you would simply write a python script that would load up the stuff you need and then run some tests however you want

I guess my question wasn't really unit testing, but integration testing. I imagine it wouldn't be terribly different, but I didn't give it much time or thought.

At any rate, could either or both be added to the documentation at some point?

jakub-zarembinski commented 6 years ago

What is the procedure for running unit tests against a smart contract?

The following info refers to the latest 2.0 release.

This tutorial guides you how to write a unit test: http://eosfactory.io/build/html/tutorials/03.BuildingAndDeployingEOSContractsInEOSFactory.html

This one shows you how to run a unit test (it's done in VSC but it can be also be done in a simple bash console): http://eosfactory.io/build/html/tutorials/04.WorkingWithEOSContractsUsingEOSFactoryInVSC.html

Or you can take a look at demo examples: https://github.com/tokenika/eosfactory/blob/master/contracts/01_hello_world/test/unittest1.py https://github.com/tokenika/eosfactory/blob/master/contracts/02_eosio_token/test/unittest1.py

This one works both locally and remotely: https://github.com/tokenika/eosfactory/blob/master/contracts/03_tic_tac_toe/test/unittest1.py