teia-community / teia-smart-contracts

Teia Community smart contracts
MIT License
28 stars 10 forks source link

Contract error metadata collection and lint tool. #11

Closed pyglot closed 2 years ago

pyglot commented 2 years ago

This commit adds a teia_sc.error_collection module which allows an option to collect error metadata. The main use is to encapsulate tests and methods related to producing consistent and compliant TZIP-16 error metadata.

The first commit implements an example in daoToken only:

TARGET=daoToken make test

Results in output/tests/daoToken/Lint_FAILWITH_messages/log.html, and in contract metadata under "errors", e.g. see Metdata tab in output/tests/daoToken/Test_set_metadata/log.html

The code has not been linted yet, but might be ok to take a look at now, at a high level.

pyglot commented 2 years ago

I am thinking I might see if I can decorate some of the smartpy functions, such as sp.verify() rather than 'collecting' the errors with the ERR() helper function. If it is possible to do that update to smartpy from outside of the smartpy module, I think it's a better way of collecting the error messages.

pyglot commented 2 years ago

There is an issue that became obvious in more complex scenarios with multiple contracts. So this is not in a useable state yet.

pyglot commented 2 years ago

This is working for me now. Time for a quick review, @jagracar.

I am not sure if this should be taken in, or if it will cause a bit of clutter. I am fine with it being put on hold or directed elsewhere.

The end product is a way to track most smart contract errors (providing the error-generating methods get triggered during test execution). It will then check what metadata is pre-recorded and see if it matches up to execution and if it looks 'compliant'. I have no deep understanding of TZIP-16, so don't trust my code on what it says is compliant!

There are no requirements and I tested with Python 3.8.

My own thoughts include:

jagracar commented 2 years ago

Looks good! Let me know if you want to merge it.

jagracar commented 2 years ago

The main problem i see is that one cannot copy paste the contracts to the smartpy gui and compile them. One will need to remove the import and the couple of lines involved, but it's not a big issue.

pyglot commented 2 years ago

There's still an issue with reading/setting up metadata when the contract is initialized with the metadata from ipfs function. Basically the input doesn't make too much sense. I think it will be an easier fix to accept it, but I didn't have time to look at it in any detail, yet.

jagracar commented 2 years ago

Merged!