smart-contracts icon indicating copy to clipboard operation
smart-contracts copied to clipboard

Path issue when running tests

Open owen9825 opened this issue 4 years ago • 2 comments

Upon trying to run the tests in eg single_asset, there is an issue with the paths during the importing of different .mligo files:

ERROR: test_transfer_to_receiver (test_fa2.TestTransfer)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/test_fa2.py", line 181, in setUp
    super().setUp()
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/test_fa2.py", line 39, in setUp
    self.orig_contracts()
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/test_fa2.py", line 58, in orig_contracts
    self.fa2 = self.orig_fa2(ligo_fa2)
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/test_fa2.py", line 108, in orig_fa2
    ptz_storage = ligo_fa2.compile_storage(ligo_storage)
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/ligo.py", line 76, in compile_storage
    michelson = self._ligo_to_michelson_sanitized(command)
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/ligo.py", line 102, in _ligo_to_michelson_sanitized
    michelson = self._ligo_to_michelson(command)
  File "/home/owen/tezos/fa2-demo/smart-contracts/single_asset/tezos_fa2_single_tests/ligo.py", line 97, in _ligo_to_michelson
    raise Exception(msg)
Exception: in file "fa2_single_token.mligo", line 9, characters 9-37
Preprocessing error in file "fa2_single_token.mligo", line 9, characters 9-37:
File "../fa2/fa2_interface.mligo" to include not found.

Here I've installed the smart-contracts directory as a submodule within /home/owen/tezos/fa2-demo/.

I had first tried running the tests in smart-contracts/nft_assets, but had some Python errors there too, in tezos_fa2_nft_tests/test_fa2.py where the reference to pytezos.rpc.errors must've been out of date − happy to submit a PR for that once I can get these tests running :) (same LIGO path issue).

The errors occur as soon as relative paths are used, eg in fa2_single_token.mligo:

…
#include "../fa2/fa2_interface.mligo"

I was invoking the test from ~/tezos/fa2-demo/smart-contracts/single_asset

owen9825 avatar Jul 26 '21 15:07 owen9825

I noticed that the path issue can be resolved by replacing ligo_cmd in smart_contracts/shared/python/ligo.py with ligo (the locally installed program) instead of the Docker version.

I've installed it from source, so ligo --version prints a SHA hash of the commit, rather than the semantic version. I can implement a version consistency check by running ligo changelog and searching for the strings like *** 0.7.1 ***.

This might not be to everyone's tastes:

ligo_cmd = "ligo"
with Popen(f"{ligo_cmd} changelog", stdout=PIPE, stderr=PIPE, shell=True) as changelog_command:
    changelog = changelog_command.stdout.read().decode()
    assert " 0.7.1 " in changelog

I haven't imposed a maximum version.

Anyway, after that, I see there are failures in the tests, eg:

FAILED [ 25%]loading ligo contracts...
originating contracts...

tezos_fa2_nft_tests/test_fa2.py:164 (TestMintBurn.test_mint_burn_implicit)
args = ({},), kwargs = {'lazy_diff': False, 'try_unpack': False}

    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
>           return func(*args, **kwargs)

venv/lib/python3.8/site-packages/pytezos/michelson/micheline.py:27: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = {}, try_unpack = False, lazy_diff = False, comparable = False

    def to_python_object(self, try_unpack=False, lazy_diff=False, comparable=False):
        if lazy_diff:
            assert not comparable, f'big_map is not comparable'
            res = super(BigMapType, self).to_python_object(try_unpack=try_unpack)
            removals = {key.to_python_object(try_unpack=try_unpack, comparable=True): None
                        for key in self.removed_keys}
            return {**res, **removals}
        else:
>           assert self.ptr is not None, f'Big_map id is not defined'
E           AssertionError: ('big_map', 'Big_map id is not defined')

owen9825 avatar Jul 29 '21 20:07 owen9825

This repo uses symlinks to bring reusable files into example projects. When running Ligo as a docker container, its PWD should be a parent directory not only for the example code directory, but for all linked directories as well.

emishur avatar Nov 03 '21 15:11 emishur