diff --git a/.circleci/Dockerfile b/.circleci/Dockerfile new file mode 100644 index 0000000..8c54ec3 --- /dev/null +++ b/.circleci/Dockerfile @@ -0,0 +1,103 @@ +ARG eos_branch=v1.3.1 +ARG eos_symbol=SYS + +FROM tokenika/eosio:v1.5.0 + +############## PYTHON ############################################################################################# +## Based mostly on https://github.com/docker-library/python/blob/005dda958/3.5/jessie/Dockerfile +ARG python_version=3.5.6 + +ENV PATH /usr/local/bin:$PATH + +# http://bugs.python.org/issue19846 +# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. +ENV LANG C.UTF-8 +ENV TERM xterm + +RUN set -ex \ + \ + && wget -O python.tar.xz "https://www.python.org/ftp/python/${python_version%%[a-z]*}/Python-$python_version.tar.xz" \ + && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${python_version%%[a-z]*}/Python-$python_version.tar.xz.asc" \ + && mkdir -p /usr/src/python \ + && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ + && rm python.tar.xz \ + \ + && cd /usr/src/python \ + && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ + && ./configure \ + --build="$gnuArch" \ + --enable-loadable-sqlite-extensions \ + --enable-shared \ + --with-system-expat \ + --with-system-ffi \ + --without-ensurepip \ + && make -j "$(nproc)" \ + && make install \ + && ldconfig \ + \ + && find /usr/local -depth \ + \( \ + \( -type d -a \( -name test -o -name tests \) \) \ + -o \ + \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ + \) -exec rm -rf '{}' + \ + && rm -rf /usr/src/python \ + \ + && python3 --version + +# make some useful symlinks that are expected to exist +RUN cd /usr/local/bin \ + && ln -s idle3 idle \ + && ln -s pydoc3 pydoc \ + && ln -s python3 python \ + && ln -s python3-config python-config + +# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" +ENV PYTHON_PIP_VERSION 18.0 + +RUN set -ex; \ + \ + wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \ + \ + python get-pip.py \ + --disable-pip-version-check \ + --no-cache-dir \ + "pip==$PYTHON_PIP_VERSION" \ + ; \ + pip --version; \ + \ + find /usr/local -depth \ + \( \ + \( -type d -a \( -name test -o -name tests \) \) \ + -o \ + \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ + \) -exec rm -rf '{}' +; \ + rm -f get-pip.py + +RUN python -m pip install termcolor +############## EOS CDT ############################################################################################# + +RUN wget https://github.com/eosio/eosio.cdt/releases/download/v1.4.1/eosio.cdt-1.4.1.x86_64.deb && \ + apt install ./eosio.cdt-1.4.1.x86_64.deb \ + && rm ./eosio.cdt-1.4.1.x86_64.deb + +############## EOS FACTORY ############################################################################################# + +ARG eosfactory_branch=master +RUN git clone -b "$eosfactory_branch" https://github.com/tokenika/eosfactory.git /opt/eosfactory/ +WORKDIR /opt/eosfactory/ +RUN git branch +RUN git log -10 --oneline +RUN mkdir /opt/workspace +RUN apt-get update && apt-get install -y expect +RUN mkdir ~/eosio-wallet/ +RUN /opt/eosfactory/tests/integration/expect_script.sh + +# https://superuser.com/a/1253889/59009 +RUN sed -i 's/mesg n || true/tty -s \&\& mesg n || true/g' /root/.profile +RUN chmod +x ./tests/unittest.sh + +WORKDIR /opt/eosfactory/tests/ + +# bash loads .profile by default +ENTRYPOINT ["/bin/bash", "-l", "-c"] diff --git a/.circleci/config.yml b/.circleci/config.yml index e9deead..eb596de 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,52 +5,42 @@ version: 2 jobs: build: + working_directory: ~/ore-protocol docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: circleci/python:3.6.1 - - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/postgres:9.4 - - working_directory: ~/repo + - image: bcelebci/ore-protocol + environment: + PIPENV_VENV_IN_PROJECT: true steps: - checkout - - # Download and cache dependencies - - restore_cache: - keys: - - v1-dependencies-{{ checksum "requirements.txt" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - - run: - name: install dependencies - command: | - python3 -m venv venv - . venv/bin/activate - pip install -r requirements.txt - - - save_cache: - paths: - - ./venv - key: v1-dependencies-{{ checksum "requirements.txt" }} - + # - restore_cache: # restores saved dependency cache if the Branch key template or requirements.txt files have not changed since the previous run + # key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }} + # - run: + # name: install dependencies + # command: | + # ./expect_script.sh + # sudo -H python3 -m pip install -e eosfactory/ + # python3 eosfactory/eosfactory/install.py /opt/eos ~/testeos/contracts # run tests! # this example uses Django's built-in test-runner # other common Python testing frameworks include pytest and nose # https://pytest.org # https://nose.readthedocs.io + # - save_cache: # special step to save dependency cache + # key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }} + # paths: + # - "venv" - run: name: run tests command: | - . venv/bin/activate - python manage.py test + tests/build_and_test.sh + python3 tests/standard_token.py + python3 tests/rights_registry.py + python3 tests/instrument.py + python3 tests/usage_log.py - store_artifacts: path: test-reports - destination: test-reports - + destination: test-reports \ No newline at end of file diff --git a/tests/build_and_test.sh b/tests/build_and_test.sh new file mode 100755 index 0000000..c9fe1d7 --- /dev/null +++ b/tests/build_and_test.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +cd ~/ore-protocol/contracts + +cd ore.instrument && mkdir build +eosio-cpp ore.instrument.cpp -o build/ore.instrument.wast +eosio-abigen ore.instrument.cpp --contract=ore.instrument --output=build/ore.instrument.abi + +cd ../ore.rights_registry && mkdir build +eosio-cpp ore.rights_registry.cpp -o build/ore.rights_registry.wast +eosio-abigen ore.rights_registry.cpp --contract=ore.rights_registry --output=build/ore.rights_registry.abi + +cd ../ore.usage_log && mkdir build +eosio-cpp ore.usage_log.cpp -o build/ore.usage_log.wast +eosio-abigen ore.usage_log.cpp --contract=ore.usage_log --output=build/ore.usage_log.abi + +cd ../ore.standard_token && mkdir build +eosio-cpp ore.standard_token.cpp -o build/ore.standard_token.wast +eosio-abigen ore.standard_token.cpp --contract=ore.standard_token --output=build/ore.standard_token.abi diff --git a/tests/confirmation.py b/tests/confirmation.py deleted file mode 100644 index 1159227..0000000 --- a/tests/confirmation.py +++ /dev/null @@ -1,239 +0,0 @@ -# python3 ./tests/instrumenttest.py - -import time -import setup -import sys -import json -import eosf -import node -import unittest -from termcolor import cprint - -wallet_name = "" # Enter wallet name -wallet_pass = "" # Enter wallet password - -""" -This flag needs to be set to `True` only for the initial run -or after the contract is changed and re-built -""" -deployment = True - -setup.set_verbose(True) -setup.use_keosd(True) -setup.set_nodeos_URL("https://ore-staging.openrights.exchange:443") -setup.set_json(False) -#setup.set_command_line_mode(True) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - wallet = eosf.Wallet(wallet_name, wallet_pass) - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global test1 - test1 = eosf.account(account_master, name="test1") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(account_master, name="test2") - wallet.import_key(test2) - assert(not test2.error) - - global app_apim - app_apim = eosf.account(account_master, name="app.apim") - wallet.import_key(app_apim) - assert(not app_apim.error) - - token_deploy = eosf.account(account_master, name="ore.token") - wallet.import_key(token_deploy) - assert(not token_deploy.error) - - instr_deploy = eosf.account(account_master, name="instr.ore") - wallet.import_key(instr_deploy) - assert(not instr_deploy.error) - - rights_deploy = eosf.account(account_master, name="rights.ore") - wallet.import_key(rights_deploy) - assert(not rights_deploy.error) - - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global token_contract - token_contract = eosf.Contract(token_deploy, contractPath+"/ore.standard_token") - assert(not token_contract.error) - - global instr_ore - instr_ore = eosf.Contract(instr_deploy, contractPath+"/ore.instrument") - assert(not instr_ore.error) - - global rights_ore - rights_ore = eosf.Contract(rights_deploy, contractPath+"/ore.rights_registry") - assert(not rights_ore.error) - - - deployment = token_contract.deploy() - assert(not deployment.error) - - deployment = instr_ore.deploy() - assert(not deployment.error) - - deployment = rights_ore.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -OREINST TOKEN TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("OREINST create") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 OREINST"}').error) - - cprint(""" -INSTRUMENT CREATE FAIL TEST STARTED - """, 'yellow') - - cprint("instrument contract tries to create a symbol other than OREINST and fails", 'magenta') - self.assertTrue(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 TEST"}').error) - - cprint(""" -Action contract.push_action("OREINST issue") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "issue", - '{"to":"' + 'instr.ore' - + '", "quantity":"10000000.0000 OREINST", "memo": "OREINST token issued"}', - account_master).error) - - - - def test_02(self): - - cprint(""" -RIGHT SET ACTION TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'app.apim' - + '","right_name":"cloud.hadron.contest-2018-07","urls":[{"url":"https://contest-hadron-dot-partner-aikon.appspot.com/contest-1","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["app.apim"]}' - , app_apim).error) - - def test_03(self): - - cprint(""" -INSTRUMENT MINT TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("mint", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "mint", - '{"minter":"' + 'app.apim' - + '","owner":"' + 'app.apim' - +'","instrument":'+ '{"issuer":"app.apim", "instrument_class":"class", "description":"description", "instrument_template":"template", "security_type":"security",' - + '"rights":[], "parent_instrument_id":"0", "data":[],' - + '"start_time":"0", "end_time":"0"}' - + ',"instrumentId":' + '0' - + '}' - , app_apim).error) - cprint(""" -Assign t1 = instr_ore.table("tokens", "tokens") - """, 'green') - t1 = instr_ore.table("tokens", "instr.ore") - - cprint(""" -Get the OREINST balance as 1.0000 ORE from the accounts table for app.apim) - """,'green') - t2 = instr_ore.table("accounts","app.apim") - - def test_04(self): - - cprint(""" -INSTRUMENT TRANSFER TESTS STARTED - """, 'yellow') - - self.assertFalse(instr_ore.push_action( - "transfer", - '{"sender":"app.apim", "to":"test1", "token_id":0}', app_apim).error) - t3 = instr_ore.table("accounts","app.apim") - t4 = instr_ore.table("accounts","test1") - def test_05(self): - - cprint(""" -INSTRUMENT APPROVE TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("approve", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "approve", - '{"from":"' + 'test1' - + '","to":"' + 'test2' - +'","token_id":'+ '0' - + '}' - , test1).error) - - def test_06(self): - cprint(""" -INSTRUMENT TRANSFERFROM TESTS STARTED - """, 'yellow') - def test_07(self): - cprint(""" -INSTRUMENT BURN TESTS STARTED - """, 'yellow') - - def test_07(self): - cprint(""" -INSTRUMENT BURNFROM TESTS STARTED - """, 'yellow') - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - node.stop() - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/instrument.py b/tests/instrument.py new file mode 100644 index 0000000..b8f71f9 --- /dev/null +++ b/tests/instrument.py @@ -0,0 +1,592 @@ +import unittest +from eosfactory.eosf import * + +verbosity([Verbosity.INFO, Verbosity.OUT, Verbosity.TRACE, Verbosity.DEBUG]) + +class Test(unittest.TestCase): + + def run(self, result=None): + super().run(result) + + + @classmethod + def setUpClass(cls): + SCENARIO(''' + Create a contract from template, then build and deploy it. + ''') + reset() + create_wallet() + create_master_account("master") + + COMMENT(''' + Create test accounts: + ''') + create_account("app", master) + create_account("notminter", master) + + + def setUp(self): + pass + + + def test_01(self): + + create_account("right", master, account_name="rights.ore") + right_contract = Contract(right, "/root/ore-protocol/contracts/ore.rights_registry") + right_contract.build() + right_contract.deploy() + + create_account("instr", master, account_name="instr.ore") + instr_contract = Contract(instr, "/root/ore-protocol/contracts/ore.instrument") + instr_contract.build() + instr_contract.deploy() + + def test_02(self): + COMMENT(''' + Create and Issue OREINST: + ''') + + instr.push_action( + "create", + { + "issuer": instr, + "maximum_supply": "100000000.0000 OREINST" + }, + permission=(instr, Permission.ACTIVE)) + + instr.push_action( + "issue", + { + "to": instr, + "quantity": "10000000.0000 OREINST", + "memo": "" + }, + permission=(instr, Permission.ACTIVE)) + + def test_03(self): + COMMENT(''' + Register rights: + ''') + + right.push_action( + "upsertright", + { + "owner": app, + "right_name": "apimarket.manager.licenseApi", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": [app] + }, + permission=(app, Permission.ACTIVE)) + + right.push_action( + "upsertright", + { + "owner": app, + "right_name": "apimarket.manager.licenseApi2", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": [] + }, + permission=(app, Permission.ACTIVE)) + + right.push_action( + "upsertright", + { + "owner": app, + "right_name": "apimarket.manager.licenseApi3", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": [] + }, + permission=(app, Permission.ACTIVE)) + + def test_04(self): + COMMENT(''' + Mint: + ''') + + instr.push_action( + "mint", + { + "minter": app, + "owner": app, + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "sample_template", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }, + { + "right_name": "apimarket.manager.licenseApi2", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0, + "instrumentId": 0 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): # Instrument id exists + instr.push_action( + "mint", + { + "minter": app, + "owner": app, + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0, + "instrumentId": 1 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): # Owner account doesnt exists + instr.push_action( + "mint", + { + "minter": app, + "owner": "notexists", + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0, + "instrumentId": 0 + }, + permission=(app, Permission.ACTIVE)) + + def test_05(self): + COMMENT(''' + Create Instrument: + ''') + + instr.push_action( + "createinst", + { + "minter": app, + "owner": app, + "instrumentId": 2, + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0 + }, + permission=(instr, Permission.ACTIVE)) + + instr.push_action( + "createinst", + { + "minter": app, + "owner": app, + "instrumentId": 5, + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0 + }, + permission=(instr, Permission.ACTIVE)) + + + def test_06(self): + COMMENT(''' + Update Instrument: + ''') + + instr.push_action( + "createinst", + { + "minter": app, + "owner": app, + "instrumentId": 2, + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "different_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0 + }, + permission=(instr, Permission.ACTIVE)) + + + def test_07(self): + COMMENT(''' + Check Rights: + ''') + + instr.push_action( + "mint", + { + "minter": app, + "owner": app, + "instrument": { + "issuer": app, + "instrument_class": "class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi3", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0, + "instrumentId": 3 + }, + permission=(app, Permission.ACTIVE)) + + instr.push_action( + "checkright", + { + "minter": app, + "issuer": app, + "rightname": "apimarket.manager.licenseApi", + "deferred_transaction_id": 10 + }, + permission=(instr, Permission.ACTIVE)) + + with self.assertRaises(Error): # Right doesn't exist + instr.push_action( + "checkright", + { + "minter": app, + "issuer": app, + "rightname": "nonexistent.right", + "deferred_transaction_id": 0 + }, + permission=(instr, Permission.ACTIVE)) + + with self.assertRaises(Error): # minter neither owns the right nor whitelisted for the right + instr.push_action( + "checkright", + { + "minter": "ownerfails", + "issuer": app, + "rightname": "apimarket.manager.licenseApi", + "deferred_transaction_id": 0 + }, + permission=(instr, Permission.ACTIVE)) + + with self.assertRaises(Error): # instrument issuer neither holds the right nor whitelisted for the right + instr.push_action( + "checkright", + { + "minter": "minter", + "issuer": "issuerfails", + "rightname": "apimarket.manager.licenseApi", + "deferred_transaction_id": 0 + }, + permission=(instr, Permission.ACTIVE)) + + def test_08(self): + COMMENT(''' + Revoke: + ''') + + instr.push_action( + "mint", + { + "minter": app, + "owner": app, + "instrument": { + "issuer": app, + "instrument_class": "class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi3", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "start_time": 0, + "end_time": 0, + "instrumentId": 4 + }, + permission=(app, Permission.ACTIVE)) + + instr.push_action( + "revoke", + { + "revoker": app, + "token_id": 5 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #token doesn't exist + instr.push_action( + "revoke", + { + "revoker": app, + "token_id": 70 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): # The revoker account doesn't have authority to revoke the instrument + instr.push_action( + "revoke", + { + "revoker": right, + "token_id": 4 + }, + permission=(right, Permission.ACTIVE)) + + with self.assertRaises(Error): # token is already revoked + instr.push_action( + "revoke", + { + "revoker": app, + "token_id": 5 + }, + permission=(app, Permission.ACTIVE)) + + def test_09(self): + COMMENT(''' + Update: + ''') + + instr.push_action( + "update", + { + "updater": app, + "instrument_template": "", + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "instrument_id": 2, + "start_time": 0, + "end_time": 0 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Updater acccount doesn't have the authority to change start/edd time of the instrument + instr.push_action( + "update", + { + "updater": right, + "instrument_template": "", + "instrument": { + "issuer": app, + "instrument_class": "sample_class", + "description": "sample_description", + "instrument_template": "", + "security_type": "", + "parameter_rules": [], + "rights": [{ + "right_name": "apimarket.manager.licenseApi", + "description": "licenser", + "price_in_cpu": "10", + "additional_url_params": [] + }], + "parent_instrument_id": 0, + "data": [], + "encrypted_by": "", + "mutability": 2 + }, + "instrument_id": 1, + "start_time": 0, + "end_time": 0 + }, + permission=(right, Permission.ACTIVE)) + + def test_10(self): + COMMENT(''' + Transfer: + ''') + + instr.push_action( + "transfer", + { + "sender": app, + "to": right, + "token_id": 2 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Sender account is not allowed to transfer the instrument + instr.push_action( + "transfer", + { + "sender": app, + "to": right, + "token_id": 2 + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Token doesn't exists + instr.push_action( + "transfer", + { + "sender": app, + "to": right, + "token_id": 99 + }, + permission=(app, Permission.ACTIVE)) + + + # def test_06(self): + # def test_07(self): + # def test_08(self): + + + + + def tearDown(self): + pass + + + @classmethod + def tearDownClass(cls): + stop() + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/instrumenttest.py b/tests/instrumenttest.py deleted file mode 100755 index 6cbbea8..0000000 --- a/tests/instrumenttest.py +++ /dev/null @@ -1,232 +0,0 @@ -# python3 ./tests/instrumenttest.py - -import time -import setup -import sys -import json -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) -#setup.set_command_line_mode(True) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global test1 - test1 = eosf.account(account_master, name="test1") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(account_master, name="test2") - wallet.import_key(test2) - assert(not test2.error) - - global app_apim - app_apim = eosf.account(account_master, name="app.apim") - wallet.import_key(app_apim) - assert(not app_apim.error) - - token_deploy = eosf.account(account_master, name="ore.token") - wallet.import_key(token_deploy) - assert(not token_deploy.error) - - instr_deploy = eosf.account(account_master, name="instr.ore") - wallet.import_key(instr_deploy) - assert(not instr_deploy.error) - - rights_deploy = eosf.account(account_master, name="rights.ore") - wallet.import_key(rights_deploy) - assert(not rights_deploy.error) - - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global token_contract - token_contract = eosf.Contract(token_deploy, contractPath+"/ore.standard_token") - assert(not token_contract.error) - - global instr_ore - instr_ore = eosf.Contract(instr_deploy, contractPath+"/ore.instrument") - assert(not instr_ore.error) - - global rights_ore - rights_ore = eosf.Contract(rights_deploy, contractPath+"/ore.rights_registry") - assert(not rights_ore.error) - - - deployment = token_contract.deploy() - assert(not deployment.error) - - deployment = instr_ore.deploy() - assert(not deployment.error) - - deployment = rights_ore.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -OREINST TOKEN TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("OREINST create") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 OREINST"}').error) - - cprint(""" -INSTRUMENT CREATE FAIL TEST STARTED - """, 'yellow') - - cprint("instrument contract tries to create a symbol other than OREINST and fails", 'magenta') - self.assertTrue(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 TEST"}').error) - - cprint(""" -Action contract.push_action("OREINST issue") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "issue", - '{"to":"' + 'instr.ore' - + '", "quantity":"10000000.0000 OREINST", "memo": "OREINST token issued"}', - account_master).error) - - - - def test_02(self): - - cprint(""" -RIGHT SET ACTION TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'app.apim' - + '","right_name":"cloud.hadron.contest-2018-07","urls":[{"url":"https://contest-hadron-dot-partner-aikon.appspot.com/contest-1","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["app.apim"]}' - , app_apim).error) - - def test_03(self): - - cprint(""" -INSTRUMENT MINT TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("mint", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "mint", - '{"minter":"' + 'app.apim' - + '","owner":"' + 'app.apim' - +'","instrument":'+ '{"issuer":"app.apim", "instrument_class":"class", "description":"description", "instrument_template":"template", "security_type":"security",' - + '"rights":[], "parent_instrument_id":"0", "data":[],' - + '"start_time":"0", "end_time":"0"}' - + ',"instrumentId":' + '0' - + '}' - , app_apim).error) - cprint(""" -Assign t1 = instr_ore.table("tokens", "tokens") - """, 'green') - t1 = instr_ore.table("tokens", "instr.ore") - - cprint(""" -Get the OREINST balance as 1.0000 ORE from the accounts table for app.apim) - """,'green') - t2 = instr_ore.table("accounts","app.apim") - - def test_04(self): - - cprint(""" -INSTRUMENT TRANSFER TESTS STARTED - """, 'yellow') - - self.assertFalse(instr_ore.push_action( - "transfer", - '{"sender":"app.apim", "to":"test1", "token_id":0}', app_apim).error) - t3 = instr_ore.table("accounts","app.apim") - t4 = instr_ore.table("accounts","test1") - def test_05(self): - - cprint(""" -INSTRUMENT APPROVE TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("approve", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "approve", - '{"from":"' + 'test1' - + '","to":"' + 'test2' - +'","token_id":'+ '0' - + '}' - , test1).error) - - def test_06(self): - cprint(""" -INSTRUMENT TRANSFERFROM TESTS STARTED - """, 'yellow') - def test_07(self): - cprint(""" -INSTRUMENT BURN TESTS STARTED - """, 'yellow') - - def test_07(self): - cprint(""" -INSTRUMENT BURNFROM TESTS STARTED - """, 'yellow') - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - node.stop() - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/managertest.py b/tests/managertest.py deleted file mode 100644 index 8ebd1f2..0000000 --- a/tests/managertest.py +++ /dev/null @@ -1,236 +0,0 @@ -# python3 ./tests/instrumenttest.py - -import time -import setup -import sys -import json -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) -#setup.set_command_line_mode(True) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global test1 - test1 = eosf.account(account_master, name="test1") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(account_master, name="test2") - wallet.import_key(test2) - assert(not test2.error) - - global app_apim - app_apim = eosf.account(account_master, name="app.apim") - wallet.import_key(app_apim) - assert(not app_apim.error) - - token_deploy = eosf.account(account_master, name="ore.token") - wallet.import_key(token_deploy) - assert(not token_deploy.error) - - instr_deploy = eosf.account(account_master, name="instr.ore") - wallet.import_key(instr_deploy) - assert(not instr_deploy.error) - - rights_deploy = eosf.account(account_master, name="rights.ore") - wallet.import_key(rights_deploy) - assert(not rights_deploy.error) - - rights_deploy = eosf.account(account_master, name="rights.ore") - wallet.import_key(rights_deploy) - assert(not rights_deploy.error) - - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global token_contract - token_contract = eosf.Contract(token_deploy, contractPath+"/ore.standard_token") - assert(not token_contract.error) - - global instr_ore - instr_ore = eosf.Contract(instr_deploy, contractPath+"/ore.instrument") - assert(not instr_ore.error) - - global rights_ore - rights_ore = eosf.Contract(rights_deploy, contractPath+"/ore.rights_registry") - assert(not rights_ore.error) - - - deployment = token_contract.deploy() - assert(not deployment.error) - - deployment = instr_ore.deploy() - assert(not deployment.error) - - deployment = rights_ore.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -OREINST TOKEN TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("OREINST create") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 OREINST"}').error) - - cprint(""" -INSTRUMENT CREATE FAIL TEST STARTED - """, 'yellow') - - cprint("instrument contract tries to create a symbol other than OREINST and fails", 'magenta') - self.assertTrue(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 TEST"}').error) - - cprint(""" -Action contract.push_action("OREINST issue") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "issue", - '{"to":"' + 'instr.ore' - + '", "quantity":"10000000.0000 OREINST", "memo": "OREINST token issued"}', - account_master).error) - - - - def test_02(self): - - cprint(""" -RIGHT SET ACTION TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'app.apim' - + '","right_name":"cloud.hadron.contest-2018-07","urls":[{"url":"https://contest-hadron-dot-partner-aikon.appspot.com/contest-1","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["app.apim"]}' - , app_apim).error) - - def test_03(self): - - cprint(""" -INSTRUMENT MINT TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("mint", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "mint", - '{"minter":"' + 'app.apim' - + '","owner":"' + 'app.apim' - +'","instrument":'+ '{"issuer":"app.apim", "instrument_class":"class", "description":"description", "instrument_template":"template", "security_type":"security",' - + '"rights":[], "parent_instrument_id":"0", "data":[],' - + '"start_time":"0", "end_time":"0"}' - + ',"instrumentId":' + '0' - + '}' - , app_apim).error) - cprint(""" -Assign t1 = instr_ore.table("tokens", "tokens") - """, 'green') - t1 = instr_ore.table("tokens", "instr.ore") - - cprint(""" -Get the OREINST balance as 1.0000 ORE from the accounts table for app.apim) - """,'green') - t2 = instr_ore.table("accounts","app.apim") - - def test_04(self): - - cprint(""" -INSTRUMENT TRANSFER TESTS STARTED - """, 'yellow') - - self.assertFalse(instr_ore.push_action( - "transfer", - '{"sender":"app.apim", "to":"test1", "token_id":0}', app_apim).error) - t3 = instr_ore.table("accounts","app.apim") - t4 = instr_ore.table("accounts","test1") - def test_05(self): - - cprint(""" -INSTRUMENT APPROVE TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("approve", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "approve", - '{"from":"' + 'test1' - + '","to":"' + 'test2' - +'","token_id":'+ '0' - + '}' - , test1).error) - - def test_06(self): - cprint(""" -INSTRUMENT TRANSFERFROM TESTS STARTED - """, 'yellow') - def test_07(self): - cprint(""" -INSTRUMENT BURN TESTS STARTED - """, 'yellow') - - def test_07(self): - cprint(""" -INSTRUMENT BURNFROM TESTS STARTED - """, 'yellow') - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - node.stop() - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/migration.py b/tests/migration.py deleted file mode 100644 index f0362f0..0000000 --- a/tests/migration.py +++ /dev/null @@ -1,239 +0,0 @@ -# python3 ./tests/instrumenttest.py - -import time -import setup -import sys -import json -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) -#setup.set_command_line_mode(True) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global test1 - test1 = eosf.account(account_master, name="test1") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(account_master, name="test2") - wallet.import_key(test2) - assert(not test2.error) - - global app_apim - app_apim = eosf.account(account_master, name="app.apim") - wallet.import_key(app_apim) - assert(not app_apim.error) - - token_deploy = eosf.account(account_master, name="ore.token") - wallet.import_key(token_deploy) - assert(not token_deploy.error) - - instrold_deploy = eosf.account(account_master, name="instr.old") - wallet.import_key(instrold_deploy) - assert(not instrold_deploy.error) - - instr_deploy = eosf.account(account_master, name="instr.ore") - wallet.import_key(instr_deploy) - assert(not instr_deploy.error) - - rights_deploy = eosf.account(account_master, name="rights.ore") - wallet.import_key(rights_deploy) - assert(not rights_deploy.error) - - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global token_contract - token_contract = eosf.Contract(token_deploy, contractPath+"/ore.standard_token") - assert(not token_contract.error) - - global instr_ore - instr_ore = eosf.Contract(instr_deploy, contractPath+"/old.instrument") - assert(not instr_ore.error) - - instr_ore = eosf.Contract(instr_deploy, contractPath+"/ore.instrument") - assert(not instr_ore.error) - - global rights_ore - rights_ore = eosf.Contract(rights_deploy, contractPath+"/ore.rights_registry") - assert(not rights_ore.error) - - - deployment = token_contract.deploy() - assert(not deployment.error) - - deployment = instr_ore.deploy() - assert(not deployment.error) - - deployment = rights_ore.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -OREINST TOKEN TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("OREINST create") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 OREINST"}').error) - - cprint(""" -INSTRUMENT CREATE FAIL TEST STARTED - """, 'yellow') - - cprint("instrument contract tries to create a symbol other than OREINST and fails", 'magenta') - self.assertTrue(instr_ore.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 TEST"}').error) - - cprint(""" -Action contract.push_action("OREINST issue") - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "issue", - '{"to":"' + 'instr.ore' - + '", "quantity":"10000000.0000 OREINST", "memo": "OREINST token issued"}', - account_master).error) - - - - def test_02(self): - - cprint(""" -RIGHT SET ACTION TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'app.apim' - + '","right_name":"cloud.hadron.contest-2018-07","urls":[{"url":"https://contest-hadron-dot-partner-aikon.appspot.com/contest-1","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["app.apim"]}' - , app_apim).error) - - def test_03(self): - - cprint(""" -INSTRUMENT MINT TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("mint", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "mint", - '{"minter":"' + 'app.apim' - + '","owner":"' + 'app.apim' - +'","instrument":'+ '{"issuer":"app.apim", "instrument_class":"class", "description":"description", "instrument_template":"template", "security_type":"security",' - + '"rights":[], "parent_instrument_id":"0", "data":[],' - + '"start_time":"0", "end_time":"0"}' - + ',"instrumentId":' + '0' - + '}' - , app_apim).error) - cprint(""" -Assign t1 = instr_ore.table("tokens", "tokens") - """, 'green') - t1 = instr_ore.table("tokens", "instr.ore") - - cprint(""" -Get the OREINST balance as 1.0000 ORE from the accounts table for app.apim) - """,'green') - t2 = instr_ore.table("accounts","app.apim") - - def test_04(self): - - cprint(""" -INSTRUMENT TRANSFER TESTS STARTED - """, 'yellow') - - self.assertFalse(instr_ore.push_action( - "transfer", - '{"sender":"app.apim", "to":"test1", "token_id":0}', app_apim).error) - t3 = instr_ore.table("accounts","app.apim") - t4 = instr_ore.table("accounts","test1") - def test_05(self): - - cprint(""" -INSTRUMENT APPROVE TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("approve", app_apim) - """, 'magenta') - self.assertFalse(instr_ore.push_action( - "approve", - '{"from":"' + 'test1' - + '","to":"' + 'test2' - +'","token_id":'+ '0' - + '}' - , test1).error) - - def test_06(self): - cprint(""" -INSTRUMENT TRANSFERFROM TESTS STARTED - """, 'yellow') - def test_07(self): - cprint(""" -INSTRUMENT BURN TESTS STARTED - """, 'yellow') - - def test_07(self): - cprint(""" -INSTRUMENT BURNFROM TESTS STARTED - """, 'yellow') - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - node.stop() - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/mint.py b/tests/mint.py deleted file mode 100755 index 49d1db4..0000000 --- a/tests/mint.py +++ /dev/null @@ -1,233 +0,0 @@ -# python3 ./tests/mint.py - -import setup -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "" - - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global apim - apim = eosf.account(account_master, name="apim") - wallet.import_key(apim) - assert(not apim.error) - - global test1 - test1 = eosf.account(apim, name="test1.apim") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(apim, name="test2.apim") - wallet.import_key(test2) - assert(not test2.error) - - global manager_apim - manager_apim = eosf.account(apim, name="manager.apim") - wallet.import_key(manager_apim) - assert(not manager_apim.error) - - global app_apim - app_apim = eosf.account(apim, name="app.apim") - wallet.import_key(app_apim) - assert(not app_apim.error) - - global aikon_apim - aikon_apim = eosf.account(apim, name="aikon.apim") - wallet.import_key(aikon_apim) - assert(not aikon_apim.error) - - global ore - ore = eosf.account(account_master, name="ore") - wallet.import_key(ore) - assert(not ore.error) - - global token_ore - token_ore = eosf.account(ore, name="token.ore") - wallet.import_key(token_ore) - assert(not token_ore.error) - - global instr_ore - instr_ore = eosf.account(ore, name="instr.ore") - wallet.import_key(instr_ore) - assert(not instr_ore.error) - - global rights_ore - rights_ore = eosf.account(ore, name="rights.ore") - wallet.import_key(rights_ore) - assert(not rights_ore.error) - - global usage_log_ore - usage_log_ore = eosf.account(ore, name="usagelog.ore") - wallet.import_key(usage_log_ore) - assert(not usage_log_ore.error) - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global token_contract - token_contract = eosf.Contract(token_ore, contractPath+"/ore.standard_token") - assert(not token_contract.error) - - global instr_contract - instr_contract = eosf.Contract(instr_ore, contractPath+"/ore.instrument") - assert(not instr_contract.error) - - global rights_contract - rights_contract = eosf.Contract(rights_ore, contractPath+"/ore.rights_registry") - assert(not rights_contract.error) - - global usagelog_contract - usagelog_contract = eosf.Contract(usage_log_ore, contractPath+"/ore.usage_log") - assert(not usagelog_contract.error) - - global managerapim_contract - managerapim_contract = eosf.Contract(manager_apim, contractPath+"/apim.manager") - assert(not managerapim_contract.error) - - deployment = token_contract.deploy() - assert(not deployment.error) - - deployment = instr_contract.deploy() - assert(not deployment.error) - - deployment = rights_contract.deploy() - assert(not deployment.error) - - deployment = usagelog_contract.deploy() - assert(not deployment.error) - - deployment = managerapim_contract.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -TOKEN CONTRACT TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("CPU create") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 CPU"}').error) - - cprint(""" -Action contract.push_action("CPU issue") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "issue", - '{"to":"' + str(app_apim) - + '", "quantity":"10000000.0000 CPU", "memo": "CPU token issued"}', - account_master).error) - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 ORE"}').error) - - cprint(""" -Action contract.push_action("ORE issue") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "issue", - '{"to":"' + str(app_apim) - + '", "quantity":"10000000.0000 ORE", "memo": "ORE token issued"}', - account_master).error) - - cprint(""" -Action contract.push_action("OREINST create") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "create", - '{"issuer":"' - + str(account_master) - + '", "maximum_supply":"100000000.0000 OREINST"}').error) - - cprint(""" -Action contract.push_action("OREINST issue") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "issue", - '{"to":"' + str(app_apim) - + '", "quantity":"10000000.0000 OREINST", "memo": "OREINST token issued"}', - account_master, output=True).error) - - def test_02(self): - - cprint(""" -APP APIM ACTIONS TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_contract.push_action( - "upsertright", - '{"issuer":"' + str(app_apim) - + '","right_name":"cloud.hadron.contest-2018-07","urls":[{"url":"https://contest-hadron-dot-partner-aikon.appspot.com/contest-1","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["app.apim"]}' - , app_apim, output=True).error) - - - - cprint(""" -Assign t1 = rights_ore.table("rights.ore", "rights.ore") - """, 'green') - t2 = rights_contract.table("rights", "rights.ore") - - - - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - #node.stop() - pass - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/rights_registry.py b/tests/rights_registry.py new file mode 100644 index 0000000..d475b05 --- /dev/null +++ b/tests/rights_registry.py @@ -0,0 +1,117 @@ +import unittest +from eosfactory.eosf import * + +verbosity([Verbosity.INFO, Verbosity.OUT, Verbosity.TRACE, Verbosity.DEBUG]) + +class Test(unittest.TestCase): + + def run(self, result=None): + super().run(result) + + + @classmethod + def setUpClass(cls): + SCENARIO(''' + Create a contract from template, then build and deploy it. + ''') + reset() + create_wallet() + create_master_account("master") + + COMMENT(''' + Create test accounts: + ''') + create_account("app", master) + + + def setUp(self): + pass + + + def test_01(self): + COMMENT(''' + Create, build and deploy the contracts: + ''') + + create_account("right", master) + right_contract = Contract(right, "/root/ore-protocol/contracts/ore.rights_registry") + right_contract.build() + right_contract.deploy() + + def test_02(self): + COMMENT(''' + Register rights: + ''') + + right.push_action( + "upsertright", + { + "owner": app, + "right_name": "apimarket.manager.licenseApi", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": ["app.apim"] + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #You are not the issuer of the existing right. Update canceled. + right.push_action( + "upsertright", + { + "owner": right, + "right_name": "apimarket.manager.licenseApi", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": ["app.apim"] + }, + permission=(app, Permission.ACTIVE)) + + right.push_action( + "upsertright", + { + "owner": app, + "right_name": "apimarket.manager.licenseApi2", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": ["app.apim"] + }, + permission=(app, Permission.ACTIVE)) + + def tearDown(self): + pass + + + @classmethod + def tearDownClass(cls): + stop() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/rightstest.py b/tests/rightstest.py deleted file mode 100755 index 20c6f5c..0000000 --- a/tests/rightstest.py +++ /dev/null @@ -1,143 +0,0 @@ -# python3 ./tests/rightstest.py - -import time -import setup -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) -#setup.set_command_line_mode(True) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global test1 - test1 = eosf.account(account_master, name="test1") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(account_master, name="test2") - wallet.import_key(test2) - assert(not test2.error) - - global test3 - test3 = eosf.account(account_master, name="test3") - wallet.import_key(test3) - assert(not test3.error) - - rights_deploy = eosf.account(account_master, name="rights.ore") - wallet.import_key(rights_deploy) - assert(not rights_deploy.error) - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global rights_ore - rights_ore = eosf.Contract(rights_deploy, contractPath+"/ore.rights_registry") - assert(not rights_ore.error) - - - deployment = rights_ore.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -RIGHT REGISTRY TEST STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'test1' - + '","right_name":"TestRight1","urls":[{"url":"https://url/sample","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["test1"]}' - , test1, output=True).error) - - cprint(""" -Assign t1 = rights_ore.table("rights.ore", "rights.ore") - """, 'green') - t1 = rights_ore.table("rights", "rights.ore") - - - cprint(""" -RIGHT UDPDATE TEST STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("upsertright", app_apim) - """, 'magenta') - self.assertFalse(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'test1' - + '","right_name":"TestRight1","urls":[{"url":"https://url/edited1","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["test1", "test2"]}' - , test1, output=True).error) - - cprint(""" -Assign t1 = rights_ore.table("rights.ore", "rights.ore") - """, 'green') - t2 = rights_ore.table("rights", "rights.ore") - - - - cprint(""" -RIGHT UPDATE FAIL TEST STARTED - """, 'yellow') - - cprint("test2 account tries to update TestRight1, which is issued by test1", 'magenta') - self.assertTrue(rights_ore.push_action( - "upsertright", - '{"issuer":"' + 'test2' - + '","right_name":"TestRight1","urls":[{"url":"https://url/edited2","method":"get","matches_params":[],"token_life_span":100,"is_default":1}],"issuer_whitelist":["test1", "test2", "test3"]}' - , test2, output=True).error) - - cprint(""" -Assign t1 = rights_ore.table("rights.ore", "rights.ore") - """, 'green') - t3 = rights_ore.table("rights", "rights.ore") - - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - node.stop() - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/setup.py b/tests/setup.py new file mode 100644 index 0000000..e98a33f --- /dev/null +++ b/tests/setup.py @@ -0,0 +1,210 @@ +import unittest +from eosfactory.eosf import * + +verbosity([Verbosity.INFO, Verbosity.OUT, Verbosity.TRACE, Verbosity.DEBUG]) + +STANDARD_TOKEN = "~/Workspace/testeos/contracts/ore.standard_token/" +RIGHTS_REGISTRY = "~/Workspace/ore-protocol/contracts/ore.rights_registry/" +INSTRUMENT = "~/Workspace/ore-protocol/contracts/ore.instrument/" +USAGE_LOG = "~/Workspace/ore-protocol/contracts/ore.usage_log/" +APIM_MANAGER = "~/Workspace/ore-protocol/contracts/apim.manager/" + +class Test(unittest.TestCase): + + def run(self, result=None): + super().run(result) + + + @classmethod + def setUpClass(cls): + SCENARIO(''' + Create a contract from template, then build and deploy it. + ''') + reset() + create_wallet() + create_master_account("master") + + COMMENT(''' + Create test accounts: + ''') + create_account("app", master) + + + def setUp(self): + pass + + + def test_01(self): + COMMENT(''' + Create, build and deploy the contracts: + ''') + create_account("token", master) + token_contract = Contract(token, "ore.standard_token") + token_contract.build() + token_contract.deploy() + + create_account("right", master) + right_contract = Contract(right, "ore.rights_registry") + right_contract.build() + right_contract.deploy() + + create_account("instr", master) + instr_contract = Contract(instr, "ore.instrument") + instr_contract.build() + instr_contract.deploy() + + create_account("apim", master) + apim_contract = Contract(apim, "apim.manager") + apim_contract.build() + apim_contract.deploy() + + create_account("usage", master) + usage_contract = Contract(usage, "ore.usage_log") + usage_contract.build() + usage_contract.deploy() + + # token_contract.delete() + # right_contract.delete() + # instr_contract.delete() + # apim_contract.delete() + # usage_contract.delete() + + def test_02(self): + COMMENT(''' + Create and issue tokens: + ''') + + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "100000000.0000 CPU" + }, + permission=(token, Permission.ACTIVE)) + + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "100000000.0000 ORE" + }, + permission=(token, Permission.ACTIVE)) + + instr.push_action( + "create", + { + "issuer": instr, + "maximum_supply": "100000000.0000 OREINST" + }, + permission=(instr, Permission.ACTIVE)) + + token.push_action( + "issue", + { + "to": app, + "quantity": "10000000.0000 CPU", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + token.push_action( + "issue", + { + "to": app, + "quantity": "10000000.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + instr.push_action( + "issue", + { + "to": instr, + "quantity": "10000000.0000 OREINST", + "memo": "" + }, + permission=(instr, Permission.ACTIVE)) + + def test_03(self): + COMMENT(''' + Register rights: + ''') + + right.push_action( + "upsertright", + { + "owner": apim, + "right_name": "apimarket.manager.licenseApi", + "urls": [{ + "base_right": "", + "url": " ore://manager.apim/action/licenseapi", + "method": "post", + "matches_params": [{ + "name": "sla", + "value": "default" + }], + "token_life_span": 100, + "is_default": 1 + }], + "issuer_whitelist": ["app.apim"] + }, + permission=(apim, Permission.ACTIVE)) + + + + def test_04(self): + COMMENT(''' + Publish and license offers: + ''') + with self.assertRaises(Error): + apim.push_action( + "publishapi", + { + "creator":app, + "issuer":app, + "api_voucher_license_price_in_cpu":"0", + "api_voucher_lifetime_in_seconds": "10", + "api_voucher_start_date": "0", + "api_voucher_end_date": "0", + "api_voucher_mutability": "0", + "api_voucher_security_type":"pass", + "api_voucher_valid_forever": "0", + "right_params": [ + { + "right_name": "apimarket.manager.licenseApi", + "right_description":"description", + "right_price_in_cpu":"100", + "api_name":"apis", + "api_description":"desci", + "api_price_in_cpu":"10", + "api_payment_model":"pass", + "api_additional_url_params":"" + } + ], + "api_voucher_parameter_rules":[], + "offer_mutability": 2, + "offer_security_type": "sec", + "offer_template":"", + "offer_start_time": 0, + "offer_end_time":0, + "offer_override_id":0 + }, + permission=(app, Permission.ACTIVE)) + + + def test_05(self): + COMMENT(''' + Check tables: + ''') + + def tearDown(self): + pass + + + @classmethod + def tearDownClass(cls): + stop() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/standard_token.py b/tests/standard_token.py new file mode 100644 index 0000000..6ca6b6b --- /dev/null +++ b/tests/standard_token.py @@ -0,0 +1,380 @@ +import unittest +from eosfactory.eosf import * + +verbosity([Verbosity.INFO, Verbosity.OUT, Verbosity.TRACE, Verbosity.DEBUG]) + +class Test(unittest.TestCase): + + def run(self, result=None): + super().run(result) + + + @classmethod + def setUpClass(cls): + SCENARIO(''' + Create a contract from template, then build and deploy it. + ''') + reset() + create_wallet() + create_master_account("master") + + COMMENT(''' + Create test accounts: + ''') + create_account("app", master) + create_account("nonapp", master) + + + def setUp(self): + pass + + + def test_01(self): + COMMENT(''' + Create, build and deploy the contracts: + ''') + create_account("token", master) + token_contract = Contract(token, "/root/ore-protocol/contracts/ore.standard_token") + token_contract.build() + token_contract.deploy() + + def test_02(self): + COMMENT(''' + Create tokens: + ''') + + #Valid transaction + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "100000000.0000 ORE" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Invalid symbol name + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "100000000.0000 OREEEEEE" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Invalid supply + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "100000.000000000000000000000000000000 ORA" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Max supply must be positive + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "-100000000.0000 ORA" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Token symbol already exists + token.push_action( + "create", + { + "issuer": token, + "maximum_supply": "100000000.0000 ORE" + }, + permission=(token, Permission.ACTIVE)) + + + def test_03(self): + COMMENT(''' + Issue tokens: + ''') + #Valid transaction + token.push_action( + "issue", + { + "to": app, + "quantity": "10000000.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + token.push_action( + "issue", + { + "to": token, + "quantity": "100.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Invalid symbol name + token.push_action( + "issue", + { + "to": app, + "quantity": "100.0000 OREEEEEE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Token symbol does not exists + token.push_action( + "issue", + { + "to": app, + "quantity": "100.0000 ORU", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Memo has more than 256 bytes + token.push_action( + "issue", + { + "to": app, + "quantity": "100.0000 ORE", + "memo": "LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Quantity must be positive + token.push_action( + "issue", + { + "to": app, + "quantity": "-100.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Symbol precision mismatch + token.push_action( + "issue", + { + "to": app, + "quantity": "100.000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Quantity exceeds available supply + token.push_action( + "issue", + { + "to": app, + "quantity": "100000000.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + def test_04(self): + COMMENT(''' + Approve tokens: + ''') + #Valid transaction + token.push_action( + "approve", + { + "from": app, + "to": nonapp, + "quantity": "10.0000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Amount being approved is more than the balance of approver account + token.push_action( + "approve", + { + "from": app, + "to": nonapp, + "quantity": "10000001.0000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + def test_05(self): + COMMENT(''' + Retire tokens: + ''') + #Valid transaction + token.push_action( + "retire", + { + "quantity": "100.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Invalid symbol name + token.push_action( + "retire", + { + "quantity": "100.0000 OREEEEEE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Token symbol does not exists + token.push_action( + "retire", + { + "quantity": "100.0000 ORU", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Memo has more than 256 bytes + token.push_action( + "retire", + { + "quantity": "100.0000 ORE", + "memo": "LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Quantity must be positive + token.push_action( + "retire", + { + "quantity": "-100.0000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + with self.assertRaises(Error): #Symbol precision mismatch + token.push_action( + "retire", + { + "quantity": "100.000 ORE", + "memo": "" + }, + permission=(token, Permission.ACTIVE)) + + + def test_06(self): + COMMENT(''' + Transfer tokens: + ''') + #Valid Transaction + token.push_action( + "transfer", + { + "from":app, + "to": nonapp, + "quantity": "10.0000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Cannot transfer to self + token.push_action( + "transfer", + { + "from":app, + "to": app, + "quantity": "100.0000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #To account does not exist + token.push_action( + "transfer", + { + "from":app, + "to": "nonexist", + "quantity": "100.0000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Memo has more than 256 bytes + token.push_action( + "transfer", + { + "from":app, + "to": nonapp, + "quantity": "100.0000 ORE", + "memo": "LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Invalid quantity + token.push_action( + "transfer", + { + "from":app, + "to": nonapp, + "quantity": "A ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Quantity must be positive + + token.push_action( + "transfer", + { + "from":app, + "to": nonapp, + "quantity": "-100.0000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #Symbol precision mismatch + token.push_action( + "transfer", + { + "from":app, + "to": nonapp, + "quantity": "100.000 ORE", + "memo": "" + }, + permission=(app, Permission.ACTIVE)) + + + def test_07(self): + COMMENT(''' + Transfer From tokens: + ''') + token.push_action( + "transferfrom", + { + "sender": nonapp, + "from":app, + "to": token, + "quantity": "5.0000 ORE", + "memo": "" + }, + permission=(nonapp, Permission.ACTIVE)) + + with self.assertRaises(Error): #The amount being transferred is more than the approved account + token.push_action( + "transferfrom", + { + "sender": nonapp, + "from":app, + "to": token, + "quantity": "6.0000 ORE", + "memo": "" + }, + permission=(nonapp, Permission.ACTIVE)) + + def tearDown(self): + pass + + + @classmethod + def tearDownClass(cls): + stop() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/tokentest.py b/tests/tokentest.py deleted file mode 100755 index 2ade6b4..0000000 --- a/tests/tokentest.py +++ /dev/null @@ -1,239 +0,0 @@ -# python3 ./tests/mint.py - -import setup -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - global test1 - test1 = eosf.account(account_master, name="test1") - wallet.import_key(test1) - assert(not test1.error) - - global test2 - test2 = eosf.account(account_master, name="test2") - wallet.import_key(test2) - assert(not test2.error) - - global test3 - test3 = eosf.account(account_master, name="test3") - wallet.import_key(test3) - assert(not test3.error) - - contract_deploy = eosf.account(account_master, name="token.ore") - wallet.import_key(contract_deploy) - assert(not contract_deploy.error) - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global token_contract - token_contract = eosf.Contract(contract_deploy, contractPath+"/ore.standard_token") - assert(not token_contract.error) - - deployment = token_contract.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -TOKEN CREATE TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "create", - '{"issuer":"' - + 'test1' - + '", "maximum_supply":"100000000.0000 ORERERERERE"}').error) - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "create", - '{"issuer":"' - + 'test1' - + '", "maximum_supply":"-100000000.0000 OREE"}').error) - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "create", - '{"issuer":"' - + 'test1' - + '", "maximum_supply":"100000000.0000 ORE"}').error) - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "create", - '{"issuer":"' - + 'test1' - + '", "maximum_supply":"100000000.0000 ORE"}').error) - - cprint(""" -Action contract.push_action("ORE transfer") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "issue", - '{"to":"test1", "quantity":"10000000.0000 ORE", "memo": "ORE token issued"}', - test1).error) - - cprint(""" -Action contract.push_action("ORE transfer") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "issue", - '{"to":"test1", "quantity":"100000000000000.0000 ORE", "memo": "ORE token issued"}', - test1).error) - - cprint(""" -Action contract.push_action("ORE transfer") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "issue", - '{"to":"test2", "quantity":"1000000.0000 ORE", "memo": "ORE token issued"}', - test2).error) - - def test_02(self): - - cprint(""" -TOKEN TRANSFER TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("ORE transfer") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "transfer", - '{"from":"test1", "to":"test2", "quantity":"100.0000 ORE", "memo":"transfer1"}', test1).error) - - cprint(""" -Action contract.push_action("ORE transfer") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "transfer", - '{"from":"test2", "to":"test3", "quantity":"50.0000 ORE", "memo":"transfer1"}', test2).error) - - cprint(""" -Action contract.push_action("ORE transfer") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "transfer", - '{"from":"test2", "to":"test3", "quantity":"60.0000 ORE", "memo":"transfer1"}', test2).error) - - def test_03(self): - - cprint(""" -TOKEN APPROVAL TESTS STARTED - """, 'yellow') - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "approve", - '{"from":"test1", "to":"test3", "quantity":"100.0000 ORE", "memo":"transfer1"}', test1).error) - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "approve", - '{"from":"test2", "to":"test3", "quantity":"100.0000 ORE", "memo":"transfer1"}', test1).error) - - def test_04(self): - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertFalse(token_contract.push_action( - "transferfrom", - '{"sender":"test3", "from":"test1", "to":"test2", "quantity":"100.0000 ORE"}', test3).error) - - cprint(""" -Action contract.push_action("ORE create") - """, 'magenta') - self.assertTrue(token_contract.push_action( - "transferfrom", - '{"sender":"test3", "from":"test1", "to":"test2", "quantity":"100.0000 ORE"}', test3).error) - - def test_05(self): - - cprint(""" -TOKEN TABLE TESTS STARTED - """, 'yellow') - - cprint(""" -Assign t1 = token_contract.table("rights.ore", "rights.ore") - """, 'green') - t1 = token_contract.table("accounts", "test1") - - cprint(""" -Assign t1 = token_contract.table("rights.ore", "rights.ore") - """, 'green') - t2 = token_contract.table("accounts", "test2") - - cprint(""" -Assign t1 = token_contract.table("rights.ore", "rights.ore") - """, 'green') - t2 = token_contract.table("accounts", "test3") - - cprint(""" -Assign t1 = token_contract.table("rights.ore", "rights.ore") - """, 'green') - t3 = token_contract.table("allowances", "test1") - - - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - pass - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file diff --git a/tests/usage_log.py b/tests/usage_log.py new file mode 100644 index 0000000..35f0333 --- /dev/null +++ b/tests/usage_log.py @@ -0,0 +1,116 @@ +import unittest +from eosfactory.eosf import * + +verbosity([Verbosity.INFO, Verbosity.OUT, Verbosity.TRACE, Verbosity.DEBUG]) + +class Test(unittest.TestCase): + + def run(self, result=None): + super().run(result) + + + @classmethod + def setUpClass(cls): + SCENARIO(''' + Create a contract from template, then build and deploy it. + ''') + reset() + create_wallet() + create_master_account("master") + + COMMENT(''' + Create test accounts: + ''') + create_account("app", master) + + + def setUp(self): + pass + + + def test_01(self): + COMMENT(''' + Create, build and deploy the contracts: + ''') + + create_account("usage", master) + usage_contract = Contract(usage, "/root/ore-protocol/contracts/ore.usage_log") + usage_contract.build() + usage_contract.deploy() + + def test_02(self): + COMMENT(''' + Create Log: + ''') + + usage.push_action( + "createlog", + { + "instrument_id": 1, + "right_name": "right1", + "token_hash": "tokenhash1", + "timestamp": 100 + + }, + permission=(app, Permission.ACTIVE)) + + usage.push_action( + "createlog", + { + "instrument_id": 2, + "right_name": "right2", + "token_hash": "tokenhash2", + "timestamp": 100 + + }, + permission=(app, Permission.ACTIVE)) + + def test_03(self): + COMMENT(''' + Delete Log: + ''') + usage.push_action( + "deletelog", + { + "instrument_id": 2, + "token_hash": "tokenhash2" + + }, + permission=(app, Permission.ACTIVE)) + + with self.assertRaises(Error): #No log exist for the given pair or right and instrument + usage.push_action( + "deletelog", + { + "instrument_id": 2, + "token_hash": "tokenhash2" + + }, + permission=(app, Permission.ACTIVE)) + + def test_04(self): + COMMENT(''' + Update Count: + ''') + + usage.push_action( + "updatecount", + { + "instrument_id": 1, + "right_name": "right1", + "cpu": "1.0000 CPU" + + }, + permission=(app, Permission.ACTIVE)) + + def tearDown(self): + pass + + + @classmethod + def tearDownClass(cls): + stop() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/usagelogtest.py b/tests/usagelogtest.py deleted file mode 100755 index c8c053a..0000000 --- a/tests/usagelogtest.py +++ /dev/null @@ -1,146 +0,0 @@ -# python3 ./tests/mint.py - -import time -import setup -import eosf -import node -import unittest -from termcolor import cprint - -setup.set_verbose(True) -setup.set_json(False) -setup.use_keosd(False) -#setup.set_command_line_mode(True) - -class Test1(unittest.TestCase): - - def run(self, result=None): - """ Stop after first error """ - if not result.failures: - super().run(result) - - - @classmethod - def setUpClass(cls): - global contractPath - # set this variable to the local path for the contracts folder - contractPath = "/Users/basar/Workspace/ore-protocol/contracts" - - testnet = node.reset() - assert(not testnet.error) - - wallet = eosf.Wallet() - assert(not wallet.error) - - global account_master - account_master = eosf.AccountMaster() - wallet.import_key(account_master) - assert(not account_master.error) - - usage_deploy = eosf.account(account_master, name="usagelog") - wallet.import_key(usage_deploy) - assert(not usage_deploy.error) - - contract_eosio_bios = eosf.Contract( - account_master, "eosio.bios").deploy() - assert(not contract_eosio_bios.error) - - global usagelog_ore - usagelog_ore = eosf.Contract(usage_deploy, contractPath+"/ore.usage_log") - assert(not usagelog_ore.error) - - - deployment = usagelog_ore.deploy() - assert(not deployment.error) - - - def setUp(self): - pass - - - def test_01(self): - - cprint(""" -USAGE LOG TESTS STARTED - """, 'yellow') - - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertFalse(usagelog_ore.push_action( - "createlog", - '{"instrument_id": 0, "token_hash":"tokenhash", "timestamp":12345678 }').error) - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertFalse(usagelog_ore.push_action( - "createlog", - '{"instrument_id": 1, "token_hash":"tokenhash", "timestamp":12345678 }').error) - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertFalse(usagelog_ore.push_action( - "createlog", - '{"instrument_id": 2, "token_hash":"tokenhash", "timestamp":12345678 }').error) - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertTrue(usagelog_ore.push_action( - "createlog", - '{"instrument_id": 2, "token_hash":"tokenhash", "timestamp":12345678 }').error) - - cprint(""" -Assign t1 = usagelog_ore.table("logs", "usagelog") - """, 'green') - t1 = usagelog_ore.table("logs", "usagelog") - - def test_02(self): - - cprint(""" -USAGE COUNT TESTS STARTED - """, 'yellow') - - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertFalse(usagelog_ore.push_action( - "updatecount", - '{"instrument_id": 0, "right_name":"rightname", "cpu":"10.0000 CPU" }').error) - - time.sleep(1) - - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertFalse(usagelog_ore.push_action( - "updatecount", - '{"instrument_id": 0, "right_name":"rightname", "cpu":"10.0000 CPU" }').error) - - time.sleep(1) - - cprint(""" -Action usagelog_ore.push_action("LOG CREATE") - """, 'magenta') - self.assertFalse(usagelog_ore.push_action( - "updatecount", - '{"instrument_id": 0, "right_name":"rightname", "cpu":"10.0000 CPU" }').error) - - time.sleep(1) - - cprint(""" -Assign t1 = usagelog_ore.table("counts", "usagelog") - """, 'green') - t1 = usagelog_ore.table("counts", "0") - - - def tearDown(self): - pass - - - @classmethod - def tearDownClass(cls): - pass - - -if __name__ == "__main__": - unittest.main() \ No newline at end of file