PolySwarmPolySwarmPolySwarmPolySwarm
Help

Unit Testing

ここでリストしているコマンドではすべて、以下のように想定しています。

  1. 現行作業ディレクトリーが参加者のルート・ディレクトリーである。
  2. 参加者が、PolySwarm 参加者テンプレート participant-template に基づいて作成されている。

参加者の Docker イメージのビルド

You'll need to build a Docker image of your participant for unit and integration testing.

For Linux-based participants:

$ docker build -t `basename ${PWD}` -f docker/Dockerfile .

For Windows-based participants:

PS > docker build -t (Get-Item (get-location)).Basename -f .\docker\Dockerfile .

これにより、ディレクトリーの名前でタグ付けされた Docker イメージが生成されます (例えば、microengine-eicar)。


Run Unit Tests

Supplied unit tests are quite limited and only support microengines. Running unit tests on ambassadors and arbiters will fail unless you supply unit test functions.

Unit testing logic is housed in the tests/ folder. Customize the script(s) there to implement your unit tests.

For Linux-based participants:

$ docker-compose -f docker/test-unit.yml up

For Windows-based participants:

PS > docker run --isolation=process <YOUR PARTICIPANT'S DOCKER IMAGE> tox

Example unit test output ensuring that an EICAR-detecting microengine actually detects EICAR (Windows-based output will vary slightly):

Recreating docker_test_engine_eicar_1 ... done
Attaching to docker_test_engine_eicar_1
test_engine_eicar_1  | GLOB sdist-make: /usr/src/app/setup.py
test_engine_eicar_1  | py36 create: /usr/src/app/.tox/py36
test_engine_eicar_1  | py36 installdeps: -rrequirements.txt
test_engine_eicar_1  | py36 inst: /usr/src/app/.tox/dist/polyswarm_eicar-0.1.zip
test_engine_eicar_1  | py36 installed: aiodns==1.1.1,aiohttp==3.5.1,aioredis==1.2.0,aioresponses==0.6.0,aiorwlock==0.6.0,asn1crypto==0.24.0,async-timeout==3.0.1,asynctest==0.12.2,atomicwrites==1.3.0,attrdict==2.0.1,attrs==19.1.0,base58==0.2.5,certifi==2019.3.9,cffi==1.12.2,chardet==3.0.4,click==6.7,coincurve==11.0.0,coverage==4.5.1,cytoolz==0.9.0.1,eth-abi==1.3.0,eth-account==0.3.0,eth-hash==0.2.0,eth-keyfile==0.5.1,eth-keys==0.2.1,eth-rlp==0.1.2,eth-typing==2.1.0,eth-utils==1.4.1,ethereum==2.3.2,future==0.17.1,hexbytes==0.1.0,hiredis==1.0.0,hypothesis==3.82.1,idna==2.7,idna-ssl==1.1.0,lru-dict==1.1.6,malwarerepoclient==0.1,more-itertools==7.0.0,multidict==4.5.2,mypy-extensions==0.4.1,parsimonious==0.8.1,pbkdf2==1.3,pluggy==0.9.0,polyswarm-client==1.4.0,polyswarm-eicar==0.1,py==1.8.0,py-ecc==1.6.0,pycares==3.0.0,pycparser==2.19,pycryptodome==3.8.1,pyethash==0.1.27,pysha3==1.0.2,pytest==3.9.2,pytest-asyncio==0.9.0,pytest-cov==2.6.0,pytest-timeout==1.3.2,python-json-logger==0.1.9,python-magic==0.4.15,PyYAML==5.1,repoze.lru==0.7,requests==2.20.1,rlp==1.1.0,scrypt==0.8.13,six==1.12.0,toml==0.10.0,toolz==0.9.0,tox==3.4.0,typing-extensions==3.7.2,urllib3==1.24.1,virtualenv==16.4.3,web3==4.8.2,websockets==6.0,yara-python==3.7.0,yarl==1.3.0
test_engine_eicar_1  | py36 run-test-pre: PYTHONHASHSEED='1600969341'
test_engine_eicar_1  | py36 runtests: commands[0] | pytest -s
test_engine_eicar_1  | ============================= test session starts ==============================
test_engine_eicar_1  | platform linux -- Python 3.6.8, pytest-3.9.2, py-1.8.0, pluggy-0.9.0
test_engine_eicar_1  | hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/usr/src/app/.hypothesis/examples')
test_engine_eicar_1  | rootdir: /usr/src/app, inifile:
test_engine_eicar_1  | plugins: timeout-1.3.2, cov-2.6.0, asyncio-0.9.0, hypothesis-3.82.1
test_engine_eicar_1  | collected 1 item
test_engine_eicar_1  |
test_engine_eicar_1  | tests/test_eicar.py .
test_engine_eicar_1  |
test_engine_eicar_1  | =============================== warnings summary ===============================
test_engine_eicar_1  | /usr/src/app/.tox/py36/lib/python3.6/site-packages/eth_utils/applicators.py:32: DeprecationWarning: combine_argument_formatters(formatter1, formatter2)([item1, item2])has been deprecated and will be removed in a subsequent major version release of the eth-utils library. Update your calls to use apply_formatters_to_sequence([formatter1, formatter2], [item1, item2]) instead.
test_engine_eicar_1  |   "combine_argument_formatters(formatter1, formatter2)([item1, item2])"
test_engine_eicar_1  |
test_engine_eicar_1  | -- Docs: https://docs.pytest.org/en/latest/warnings.html
test_engine_eicar_1  | ===================== 1 passed, 1 warnings in 3.54 seconds =====================
test_engine_eicar_1  | ___________________________________ summary ____________________________________
test_engine_eicar_1  |   py36: commands succeeded
test_engine_eicar_1  |   congratulations :)
docker_test_engine_eicar_1 exited with code 0

Next Steps

With unit tests passing, it's time to move onto Integration Testing.

Integration Testing →