eth-prototype 0.7.4__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/.github/workflows/test.yaml +6 -1
  2. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/.gitignore +6 -0
  3. eth-prototype-1.0.0/.isort.cfg +2 -0
  4. eth-prototype-1.0.0/.pre-commit-config.yaml +41 -0
  5. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/PKG-INFO +34 -39
  6. eth-prototype-1.0.0/README.md +34 -0
  7. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/pyproject.toml +3 -0
  8. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/setup.cfg +6 -10
  9. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/PKG-INFO +34 -39
  10. eth-prototype-1.0.0/src/eth_prototype.egg-info/SOURCES.txt +58 -0
  11. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/requires.txt +4 -10
  12. eth-prototype-1.0.0/src/ethproto/build_artifacts.py +152 -0
  13. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/ethproto/contracts.py +8 -6
  14. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/ethproto/w3wrappers.py +179 -74
  15. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/ethproto/wrappers.py +97 -46
  16. eth-prototype-1.0.0/tests/conftest.py +42 -0
  17. eth-prototype-1.0.0/tests/hardhat-project/README.md +13 -0
  18. eth-prototype-1.0.0/tests/hardhat-project/artifacts2/TestCurrency.sol/TestCurrency.json +376 -0
  19. eth-prototype-1.0.0/tests/hardhat-project/contracts/Count.sol +18 -0
  20. eth-prototype-1.0.0/tests/hardhat-project/contracts/Counter.sol +17 -0
  21. eth-prototype-1.0.0/tests/hardhat-project/contracts/CounterUpgradeable.sol +32 -0
  22. eth-prototype-1.0.0/tests/hardhat-project/contracts/CounterUpgradeableWithLibrary.sol +35 -0
  23. eth-prototype-1.0.0/tests/hardhat-project/contracts/CounterWithLibrary.sol +25 -0
  24. eth-prototype-1.0.0/tests/hardhat-project/contracts/Datatypes.sol +18 -0
  25. eth-prototype-1.0.0/tests/hardhat-project/hardhat.config.js +14 -0
  26. eth-prototype-1.0.0/tests/hardhat-project/package-lock.json +16622 -0
  27. eth-prototype-1.0.0/tests/hardhat-project/package.json +25 -0
  28. eth-prototype-1.0.0/tests/test_build_artifacts.py +124 -0
  29. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/tests/test_contracts.py +19 -32
  30. eth-prototype-1.0.0/tests/test_defender.py +9 -0
  31. eth-prototype-1.0.0/tests/test_time_control.py +19 -0
  32. eth-prototype-1.0.0/tests/test_w3.py +79 -0
  33. eth-prototype-1.0.0/tests/test_wadray.py +48 -0
  34. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/tox.ini +4 -19
  35. eth-prototype-0.7.4/README.rst +0 -55
  36. eth-prototype-0.7.4/src/eth_prototype.egg-info/SOURCES.txt +0 -48
  37. eth-prototype-0.7.4/src/ethproto/brwrappers.py +0 -221
  38. eth-prototype-0.7.4/tests/brownie-project/.gitattributes +0 -2
  39. eth-prototype-0.7.4/tests/brownie-project/.gitignore +0 -5
  40. eth-prototype-0.7.4/tests/brownie-project/brownie-config.yaml +0 -12
  41. eth-prototype-0.7.4/tests/conftest.py +0 -10
  42. eth-prototype-0.7.4/tests/json-project/TestCurrency.json +0 -338
  43. eth-prototype-0.7.4/tests/json-project/TestCurrencyUUPS.json +0 -340
  44. eth-prototype-0.7.4/tests/json-project/TestNFT.json +0 -388
  45. eth-prototype-0.7.4/tests/json-project/dependencies/ERC1967Proxy.json +0 -80
  46. eth-prototype-0.7.4/tests/test_wadray.py +0 -46
  47. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/.coveragerc +0 -0
  48. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/.github/workflows/publish.yaml +0 -0
  49. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/.readthedocs.yml +0 -0
  50. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/AUTHORS.rst +0 -0
  51. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/CHANGELOG.rst +0 -0
  52. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/LICENSE.txt +0 -0
  53. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/Makefile +0 -0
  54. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/_static/.gitignore +0 -0
  55. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/authors.rst +0 -0
  56. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/changelog.rst +0 -0
  57. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/conf.py +0 -0
  58. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/index.rst +0 -0
  59. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/license.rst +0 -0
  60. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/readme.rst +0 -0
  61. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/docs/requirements.txt +0 -0
  62. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/setup.py +0 -0
  63. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/dependency_links.txt +0 -0
  64. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/not-zip-safe +0 -0
  65. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/top_level.txt +0 -0
  66. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/ethproto/__init__.py +0 -0
  67. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/ethproto/defender_relay.py +0 -0
  68. {eth-prototype-0.7.4 → eth-prototype-1.0.0}/src/ethproto/wadray.py +0 -0
  69. {eth-prototype-0.7.4/tests/brownie-project → eth-prototype-1.0.0/tests/hardhat-project}/contracts/TestCurrency.sol +0 -0
  70. {eth-prototype-0.7.4/tests/brownie-project → eth-prototype-1.0.0/tests/hardhat-project}/contracts/TestCurrencyUUPS.sol +0 -0
  71. {eth-prototype-0.7.4/tests/brownie-project → eth-prototype-1.0.0/tests/hardhat-project}/contracts/TestNFT.sol +0 -0
@@ -23,6 +23,11 @@ jobs:
23
23
  run: |
24
24
  python -m pip install --upgrade pip
25
25
  python -m pip install tox tox-gh-actions
26
- npm install -g ganache@7.6.0
26
+ - name: Initialize hardhat
27
+ run: |
28
+ cd tests/hardhat-project
29
+ npm ci
30
+ npx hardhat compile
31
+ npx hardhat node &
27
32
  - name: Test with tox
28
33
  run: tox
@@ -51,3 +51,9 @@ MANIFEST
51
51
  # Per-project virtualenvs
52
52
  .venv*/
53
53
  .conda*/
54
+ .env
55
+
56
+ # Tests hardhat project
57
+ tests/hardhat-project/artifacts
58
+ tests/hardhat-project/cache
59
+ tests/hardhat-project/node_modules
@@ -0,0 +1,2 @@
1
+ [settings]
2
+ profile = black
@@ -0,0 +1,41 @@
1
+ exclude: "^docs/conf.py"
2
+
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v4.1.0
6
+ hooks:
7
+ - id: trailing-whitespace
8
+ - id: check-added-large-files
9
+ - id: check-ast
10
+ - id: check-json
11
+ - id: check-merge-conflict
12
+ - id: check-xml
13
+ - id: check-yaml
14
+ - id: debug-statements
15
+ - id: end-of-file-fixer
16
+ - id: requirements-txt-fixer
17
+ - id: mixed-line-ending
18
+ args: ["--fix=auto"] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
19
+
20
+ - repo: https://github.com/pycqa/isort
21
+ rev: 5.12.0
22
+ hooks:
23
+ - id: isort
24
+
25
+ - repo: https://github.com/psf/black
26
+ rev: stable
27
+ hooks:
28
+ - id: black
29
+ language_version: python3
30
+
31
+ - repo: https://github.com/PyCQA/flake8
32
+ rev: 4.0.1
33
+ hooks:
34
+ - id: flake8
35
+ ## You can add flake8 plugins via `additional_dependencies`:
36
+ # additional_dependencies: [flake8-bugbear]
37
+
38
+ - repo: https://github.com/zricethezav/gitleaks
39
+ rev: v8.12.0
40
+ hooks:
41
+ - id: gitleaks-docker
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eth-prototype
3
- Version: 0.7.4
3
+ Version: 1.0.0
4
4
  Summary: Prototype Ethereum Smart Contracts in Python
5
5
  Home-page: https://github.com/gnarvaja/eth-prototype
6
6
  Author: Guillermo M. Narvaja
@@ -11,68 +11,63 @@ Platform: any
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: Programming Language :: Python
13
13
  Requires-Python: >=3.7
14
- Description-Content-Type: text/x-rst; charset=UTF-8
15
- Provides-Extra: brownie
14
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
+ License-File: LICENSE.txt
16
+ License-File: AUTHORS.rst
17
+ Requires-Dist: m9g
18
+ Requires-Dist: environs
19
+ Requires-Dist: requests
20
+ Requires-Dist: hexbytes
21
+ Requires-Dist: importlib-metadata; python_version < "3.8"
16
22
  Provides-Extra: web3
23
+ Requires-Dist: web3; extra == "web3"
24
+ Provides-Extra: defender
25
+ Requires-Dist: boto3; extra == "defender"
17
26
  Provides-Extra: gmpy2
27
+ Requires-Dist: gmpy2; extra == "gmpy2"
18
28
  Provides-Extra: testing
19
- Provides-Extra: testing-br
29
+ Requires-Dist: setuptools; extra == "testing"
30
+ Requires-Dist: pytest; extra == "testing"
31
+ Requires-Dist: gmpy2; extra == "testing"
32
+ Requires-Dist: pytest-cov; extra == "testing"
20
33
  Provides-Extra: testing-w3
21
- License-File: LICENSE.txt
22
- License-File: AUTHORS.rst
34
+ Requires-Dist: web3[tester]; extra == "testing-w3"
35
+ Requires-Dist: setuptools; extra == "testing-w3"
36
+ Requires-Dist: pytest; extra == "testing-w3"
37
+ Requires-Dist: pytest-cov; extra == "testing-w3"
38
+ Requires-Dist: boto3; extra == "testing-w3"
23
39
 
24
- =============
25
- eth-prototype
26
- =============
40
+ # eth-prototype
27
41
 
28
42
 
29
43
  Prototype Ethereum Smart Contracts in Python
30
44
 
31
45
 
32
- Description
33
- ===========
46
+ ## Description
34
47
 
35
48
  Library with base classes to prototype Ethereum Smart Contracts in Python. This includes:
36
49
 
37
50
  - wadray: classes for fixed number of decimals math implemented with integers.
38
51
  - contracts: classes to simulate contracts in Python with features like *rollback* on exception, external
39
52
  methods, views. Also classes for common contracts like ERC20 (tokens), ERC721 (NFTs) and AccessControl.
40
- - brwrappers: classes to wrap ethereum contracts called thru [brownie](https://github.com/eth-brownie/brownie/) but with a pythonic interface
41
53
  - w3wrappers: classes to wrap ethereum contracts called thru [web3py](https://web3py.readthedocs.io/) but with a pythonic interface
42
54
 
55
+ To use the `defender_relay` module you need to have the `warrant` package from this repo: https://github.com/gnarvaja/warrant. Add it to your requirements.txt as:
43
56
 
44
- Tox Tests
45
- =========
46
-
47
- The tox tests run in three variants:
48
-
49
- - `default`: only uses and tests the prototype libraries, no blockchain.
50
- - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
51
- - `default-br`: users and tests two variants: prototype and brwrappers (wrappers using brownie).
52
-
53
- It's not possible for now running all the tests together because of incompatibilities between brownie and web3[tester].
54
-
55
-
56
- To run the tox `default-br` tests, you need an environment with Brownie, SOLC and other requirements.
57
+ ```
58
+ warrant @ git+https://github.com/gnarvaja/warrant.git#egg=warrant
59
+ ```
57
60
 
58
- You can do it using a Docker image an a few commands
61
+ Note that using the `warrant` package from pypi will not work because of incompatibilities with newer python versions.
59
62
 
60
- .. code-block:: bash
63
+ ## Tox Tests
61
64
 
62
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:1.0.0 bash
63
- gnarvaja/eth-dev:eth-proto-brownie
64
- pip install tox
65
- brownie pm install OpenZeppelin/openzeppelin-contracts@4.3.2
66
- brownie pm install OpenZeppelin/openzeppelin-contracts-upgradeable@4.3.2
67
- tox -e py39-br
65
+ The tox tests run in two variants:
68
66
 
69
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:eth-proto-brownie bash
70
- tox -e py39-br
71
-
72
- .. _pyscaffold-notes:
67
+ - `default`: only uses and tests the prototype libraries, no blockchain.
68
+ - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
73
69
 
74
- Note
75
- ====
70
+ # Note
76
71
 
77
72
  This project has been set up using PyScaffold 4.0.2. For details and usage
78
73
  information on PyScaffold see https://pyscaffold.org/.
@@ -0,0 +1,34 @@
1
+ # eth-prototype
2
+
3
+
4
+ Prototype Ethereum Smart Contracts in Python
5
+
6
+
7
+ ## Description
8
+
9
+ Library with base classes to prototype Ethereum Smart Contracts in Python. This includes:
10
+
11
+ - wadray: classes for fixed number of decimals math implemented with integers.
12
+ - contracts: classes to simulate contracts in Python with features like *rollback* on exception, external
13
+ methods, views. Also classes for common contracts like ERC20 (tokens), ERC721 (NFTs) and AccessControl.
14
+ - w3wrappers: classes to wrap ethereum contracts called thru [web3py](https://web3py.readthedocs.io/) but with a pythonic interface
15
+
16
+ To use the `defender_relay` module you need to have the `warrant` package from this repo: https://github.com/gnarvaja/warrant. Add it to your requirements.txt as:
17
+
18
+ ```
19
+ warrant @ git+https://github.com/gnarvaja/warrant.git#egg=warrant
20
+ ```
21
+
22
+ Note that using the `warrant` package from pypi will not work because of incompatibilities with newer python versions.
23
+
24
+ ## Tox Tests
25
+
26
+ The tox tests run in two variants:
27
+
28
+ - `default`: only uses and tests the prototype libraries, no blockchain.
29
+ - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
30
+
31
+ # Note
32
+
33
+ This project has been set up using PyScaffold 4.0.2. For details and usage
34
+ information on PyScaffold see https://pyscaffold.org/.
@@ -6,3 +6,6 @@ build-backend = "setuptools.build_meta"
6
6
  [tool.setuptools_scm]
7
7
  # See configuration details in https://github.com/pypa/setuptools_scm
8
8
  version_scheme = "no-guess-dev"
9
+
10
+ [tool.black]
11
+ line-length = 110
@@ -4,8 +4,8 @@ description = Prototype Ethereum Smart Contracts in Python
4
4
  author = Guillermo M. Narvaja
5
5
  author_email = guillermo@ensuro.co
6
6
  license = MIT
7
- long_description = file: README.rst
8
- long_description_content_type = text/x-rst; charset=UTF-8
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown; charset=UTF-8; variant=GFM
9
9
  url = https://github.com/gnarvaja/eth-prototype
10
10
  project_urls =
11
11
  Documentation = https://pyscaffold.org/
@@ -25,6 +25,7 @@ install_requires =
25
25
  m9g
26
26
  environs
27
27
  requests
28
+ hexbytes
28
29
  importlib-metadata; python_version<"3.8"
29
30
 
30
31
  [options.packages.find]
@@ -33,10 +34,10 @@ exclude =
33
34
  tests
34
35
 
35
36
  [options.extras_require]
36
- brownie = eth-brownie
37
37
  web3 =
38
38
  web3
39
- eth-event
39
+ defender =
40
+ boto3
40
41
  gmpy2 =
41
42
  gmpy2
42
43
  testing =
@@ -44,17 +45,12 @@ testing =
44
45
  pytest
45
46
  gmpy2
46
47
  pytest-cov
47
- testing-br =
48
- eth-brownie
49
- setuptools
50
- pytest
51
- pytest-cov
52
48
  testing-w3 =
53
49
  web3[tester]
54
50
  setuptools
55
51
  pytest
56
- eth-event
57
52
  pytest-cov
53
+ boto3
58
54
 
59
55
  [options.entry_points]
60
56
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eth-prototype
3
- Version: 0.7.4
3
+ Version: 1.0.0
4
4
  Summary: Prototype Ethereum Smart Contracts in Python
5
5
  Home-page: https://github.com/gnarvaja/eth-prototype
6
6
  Author: Guillermo M. Narvaja
@@ -11,68 +11,63 @@ Platform: any
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: Programming Language :: Python
13
13
  Requires-Python: >=3.7
14
- Description-Content-Type: text/x-rst; charset=UTF-8
15
- Provides-Extra: brownie
14
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
+ License-File: LICENSE.txt
16
+ License-File: AUTHORS.rst
17
+ Requires-Dist: m9g
18
+ Requires-Dist: environs
19
+ Requires-Dist: requests
20
+ Requires-Dist: hexbytes
21
+ Requires-Dist: importlib-metadata; python_version < "3.8"
16
22
  Provides-Extra: web3
23
+ Requires-Dist: web3; extra == "web3"
24
+ Provides-Extra: defender
25
+ Requires-Dist: boto3; extra == "defender"
17
26
  Provides-Extra: gmpy2
27
+ Requires-Dist: gmpy2; extra == "gmpy2"
18
28
  Provides-Extra: testing
19
- Provides-Extra: testing-br
29
+ Requires-Dist: setuptools; extra == "testing"
30
+ Requires-Dist: pytest; extra == "testing"
31
+ Requires-Dist: gmpy2; extra == "testing"
32
+ Requires-Dist: pytest-cov; extra == "testing"
20
33
  Provides-Extra: testing-w3
21
- License-File: LICENSE.txt
22
- License-File: AUTHORS.rst
34
+ Requires-Dist: web3[tester]; extra == "testing-w3"
35
+ Requires-Dist: setuptools; extra == "testing-w3"
36
+ Requires-Dist: pytest; extra == "testing-w3"
37
+ Requires-Dist: pytest-cov; extra == "testing-w3"
38
+ Requires-Dist: boto3; extra == "testing-w3"
23
39
 
24
- =============
25
- eth-prototype
26
- =============
40
+ # eth-prototype
27
41
 
28
42
 
29
43
  Prototype Ethereum Smart Contracts in Python
30
44
 
31
45
 
32
- Description
33
- ===========
46
+ ## Description
34
47
 
35
48
  Library with base classes to prototype Ethereum Smart Contracts in Python. This includes:
36
49
 
37
50
  - wadray: classes for fixed number of decimals math implemented with integers.
38
51
  - contracts: classes to simulate contracts in Python with features like *rollback* on exception, external
39
52
  methods, views. Also classes for common contracts like ERC20 (tokens), ERC721 (NFTs) and AccessControl.
40
- - brwrappers: classes to wrap ethereum contracts called thru [brownie](https://github.com/eth-brownie/brownie/) but with a pythonic interface
41
53
  - w3wrappers: classes to wrap ethereum contracts called thru [web3py](https://web3py.readthedocs.io/) but with a pythonic interface
42
54
 
55
+ To use the `defender_relay` module you need to have the `warrant` package from this repo: https://github.com/gnarvaja/warrant. Add it to your requirements.txt as:
43
56
 
44
- Tox Tests
45
- =========
46
-
47
- The tox tests run in three variants:
48
-
49
- - `default`: only uses and tests the prototype libraries, no blockchain.
50
- - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
51
- - `default-br`: users and tests two variants: prototype and brwrappers (wrappers using brownie).
52
-
53
- It's not possible for now running all the tests together because of incompatibilities between brownie and web3[tester].
54
-
55
-
56
- To run the tox `default-br` tests, you need an environment with Brownie, SOLC and other requirements.
57
+ ```
58
+ warrant @ git+https://github.com/gnarvaja/warrant.git#egg=warrant
59
+ ```
57
60
 
58
- You can do it using a Docker image an a few commands
61
+ Note that using the `warrant` package from pypi will not work because of incompatibilities with newer python versions.
59
62
 
60
- .. code-block:: bash
63
+ ## Tox Tests
61
64
 
62
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:1.0.0 bash
63
- gnarvaja/eth-dev:eth-proto-brownie
64
- pip install tox
65
- brownie pm install OpenZeppelin/openzeppelin-contracts@4.3.2
66
- brownie pm install OpenZeppelin/openzeppelin-contracts-upgradeable@4.3.2
67
- tox -e py39-br
65
+ The tox tests run in two variants:
68
66
 
69
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:eth-proto-brownie bash
70
- tox -e py39-br
71
-
72
- .. _pyscaffold-notes:
67
+ - `default`: only uses and tests the prototype libraries, no blockchain.
68
+ - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
73
69
 
74
- Note
75
- ====
70
+ # Note
76
71
 
77
72
  This project has been set up using PyScaffold 4.0.2. For details and usage
78
73
  information on PyScaffold see https://pyscaffold.org/.
@@ -0,0 +1,58 @@
1
+ .coveragerc
2
+ .gitignore
3
+ .isort.cfg
4
+ .pre-commit-config.yaml
5
+ .readthedocs.yml
6
+ AUTHORS.rst
7
+ CHANGELOG.rst
8
+ LICENSE.txt
9
+ README.md
10
+ pyproject.toml
11
+ setup.cfg
12
+ setup.py
13
+ tox.ini
14
+ .github/workflows/publish.yaml
15
+ .github/workflows/test.yaml
16
+ docs/Makefile
17
+ docs/authors.rst
18
+ docs/changelog.rst
19
+ docs/conf.py
20
+ docs/index.rst
21
+ docs/license.rst
22
+ docs/readme.rst
23
+ docs/requirements.txt
24
+ docs/_static/.gitignore
25
+ src/eth_prototype.egg-info/PKG-INFO
26
+ src/eth_prototype.egg-info/SOURCES.txt
27
+ src/eth_prototype.egg-info/dependency_links.txt
28
+ src/eth_prototype.egg-info/not-zip-safe
29
+ src/eth_prototype.egg-info/requires.txt
30
+ src/eth_prototype.egg-info/top_level.txt
31
+ src/ethproto/__init__.py
32
+ src/ethproto/build_artifacts.py
33
+ src/ethproto/contracts.py
34
+ src/ethproto/defender_relay.py
35
+ src/ethproto/w3wrappers.py
36
+ src/ethproto/wadray.py
37
+ src/ethproto/wrappers.py
38
+ tests/conftest.py
39
+ tests/test_build_artifacts.py
40
+ tests/test_contracts.py
41
+ tests/test_defender.py
42
+ tests/test_time_control.py
43
+ tests/test_w3.py
44
+ tests/test_wadray.py
45
+ tests/hardhat-project/README.md
46
+ tests/hardhat-project/hardhat.config.js
47
+ tests/hardhat-project/package-lock.json
48
+ tests/hardhat-project/package.json
49
+ tests/hardhat-project/artifacts2/TestCurrency.sol/TestCurrency.json
50
+ tests/hardhat-project/contracts/Count.sol
51
+ tests/hardhat-project/contracts/Counter.sol
52
+ tests/hardhat-project/contracts/CounterUpgradeable.sol
53
+ tests/hardhat-project/contracts/CounterUpgradeableWithLibrary.sol
54
+ tests/hardhat-project/contracts/CounterWithLibrary.sol
55
+ tests/hardhat-project/contracts/Datatypes.sol
56
+ tests/hardhat-project/contracts/TestCurrency.sol
57
+ tests/hardhat-project/contracts/TestCurrencyUUPS.sol
58
+ tests/hardhat-project/contracts/TestNFT.sol
@@ -1,12 +1,13 @@
1
1
  m9g
2
2
  environs
3
3
  requests
4
+ hexbytes
4
5
 
5
6
  [:python_version < "3.8"]
6
7
  importlib-metadata
7
8
 
8
- [brownie]
9
- eth-brownie
9
+ [defender]
10
+ boto3
10
11
 
11
12
  [gmpy2]
12
13
  gmpy2
@@ -17,19 +18,12 @@ pytest
17
18
  gmpy2
18
19
  pytest-cov
19
20
 
20
- [testing-br]
21
- eth-brownie
22
- setuptools
23
- pytest
24
- pytest-cov
25
-
26
21
  [testing-w3]
27
22
  web3[tester]
28
23
  setuptools
29
24
  pytest
30
- eth-event
31
25
  pytest-cov
26
+ boto3
32
27
 
33
28
  [web3]
34
29
  web3
35
- eth-event
@@ -0,0 +1,152 @@
1
+ """Helper classes to use hardhat build artifacts from python"""
2
+
3
+
4
+ import json
5
+ import os
6
+ import os.path
7
+ import re
8
+ from dataclasses import dataclass
9
+ from pathlib import Path
10
+ from typing import Union, Tuple
11
+
12
+ LIBRARY_PLACEHOLDER_MATCHER = re.compile(r"__\$[0-9a-f]{34}\$__")
13
+
14
+
15
+ @dataclass
16
+ class Artifact:
17
+ contract_name: str
18
+ abi: list
19
+ bytecode: str
20
+ deployed_bytecode: str
21
+ link_references: dict
22
+ deployed_link_references: dict
23
+
24
+ def __init__(self, **kwargs):
25
+ self.contract_name = kwargs["contractName"]
26
+ self.abi = kwargs["abi"]
27
+ self.bytecode = kwargs["bytecode"]
28
+ self.deployed_bytecode = kwargs["deployedBytecode"]
29
+ self.link_references = kwargs["linkReferences"]
30
+ self.deployed_link_references = kwargs["deployedLinkReferences"]
31
+
32
+ def link(self, libraries: dict) -> "Artifact":
33
+ """Returns a new artifact with the external libraries linked
34
+
35
+ Libraries is a dictionary of the form {library_name: address}
36
+ """
37
+ bytecode = self._replace_link_references(
38
+ self.bytecode, self.link_references, libraries
39
+ )
40
+ deployed_bytecode = self._replace_link_references(
41
+ self.deployed_bytecode, self.deployed_link_references, libraries
42
+ )
43
+ return Artifact(
44
+ contractName=self.contract_name,
45
+ abi=self.abi,
46
+ bytecode=bytecode,
47
+ deployedBytecode=deployed_bytecode,
48
+ linkReferences=self.link_references,
49
+ deployedLinkReferences=self.deployed_link_references,
50
+ )
51
+
52
+ def libraries(self) -> Tuple[str, str]:
53
+ """Generates a tuple of (library, source) for each library reference in the artifact"""
54
+ for source, libs in self.link_references.items():
55
+ for lib in libs.keys():
56
+ yield lib, source
57
+
58
+ def _replace_link_references(
59
+ self, bytecode: str, link_references: dict, libraries: dict
60
+ ) -> str:
61
+ # remove 0x prefix if present
62
+ bytecode = bytecode[2:] if bytecode.startswith("0x") else bytecode
63
+
64
+ for libs in link_references.values():
65
+ for lib, lib_refs in libs.items():
66
+ try:
67
+ address = libraries[lib]
68
+ except KeyError:
69
+ raise ValueError(f"Missing library address for {lib}")
70
+ address = address[2:] if address.startswith("0x") else address
71
+
72
+ assert len(address) == 40 # Sanity check
73
+
74
+ for ref in lib_refs:
75
+ # 2 nibbles -> 1 byte
76
+ start = ref["start"] * 2
77
+ length = ref["length"] * 2
78
+
79
+ # Sanity check
80
+ assert LIBRARY_PLACEHOLDER_MATCHER.match(
81
+ bytecode[start : start + length]
82
+ ), f"Unexpected placeholder at position {start}: {bytecode[start:start + length]}"
83
+
84
+ # Replace the placeholder with the actual address
85
+ bytecode = bytecode[:start] + address + bytecode[start + length :]
86
+
87
+ # Return value always has 0x prefix
88
+ return "0x" + bytecode
89
+
90
+ def __str__(self):
91
+ return f"Artifact({self.contract_name})"
92
+
93
+ def __repr__(self):
94
+ return f"Artifact({self.contract_name})"
95
+
96
+
97
+ class ArtifactLibrary:
98
+ def __init__(self, *paths: Tuple[Union[str, Path]]):
99
+ self.lookup_paths = [Path(p).absolute() for p in paths]
100
+ self._fullpath_cache = {}
101
+ self._name_cache = {}
102
+
103
+ def get_artifact(self, contract: str) -> Artifact:
104
+ """Returns a build artifact by full contract path
105
+
106
+ This method is compatible with hardhat's artifact structure.
107
+
108
+ Examples:
109
+
110
+ >>> library = ArtifactLibrary("./artifacts")
111
+ >>> counter_build = library.get_artifact("contracts/Counter.sol")
112
+ >>> proxy_build = library.get_artifact("@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol")
113
+ """
114
+ contract = Path(os.path.normpath(contract))
115
+
116
+ if contract not in self._fullpath_cache:
117
+ for path in self.lookup_paths:
118
+ build_artifact_path = (
119
+ path / contract / contract.with_suffix(".json").name
120
+ )
121
+ if build_artifact_path.exists():
122
+ with open(build_artifact_path) as f:
123
+ self._fullpath_cache[contract] = Artifact(**json.load(f))
124
+
125
+ if contract not in self._fullpath_cache:
126
+ raise FileNotFoundError(
127
+ f"Could not find artifact for {contract} on {self.lookup_paths}"
128
+ )
129
+
130
+ return self._fullpath_cache[contract]
131
+
132
+ def get_artifact_by_name(self, contract_name: str) -> Artifact:
133
+ """Returns a build artifact by looking for a matching contract name
134
+
135
+ Example:
136
+
137
+ >>> library = ArtifactLibrary("./artifacts")
138
+ >>> counter_build = library.get_artifact_by_name("Counter")
139
+ """
140
+ if contract_name not in self._name_cache:
141
+ for path in self.lookup_paths:
142
+ for dirpath, _, filenames in os.walk(path):
143
+ if f"{contract_name}.json" in filenames:
144
+ with open(Path(dirpath) / f"{contract_name}.json") as f:
145
+ self._name_cache[contract_name] = Artifact(**json.load(f))
146
+
147
+ if contract_name not in self._name_cache:
148
+ raise FileNotFoundError(
149
+ f"Could not find artifact for {contract_name} on {self.lookup_paths}"
150
+ )
151
+
152
+ return self._name_cache[contract_name]
@@ -1,11 +1,13 @@
1
1
  import os
2
2
  import time
3
+ from contextlib import contextmanager
3
4
  from decimal import Decimal
4
5
  from functools import wraps
5
- from contextlib import contextmanager
6
+
6
7
  from m9g import Model
7
- from m9g.fields import IntField, DictField, StringField, TupleField, ListField
8
- from .wadray import Wad, Ray
8
+ from m9g.fields import DictField, IntField, ListField, StringField, TupleField
9
+
10
+ from .wadray import Ray, Wad
9
11
 
10
12
  __author__ = "Guillermo M. Narvaja"
11
13
  __copyright__ = "Guillermo M. Narvaja"
@@ -501,7 +503,7 @@ class ERC721Token(AccessControlContract): # NFT
501
503
  @view
502
504
  def owner_of(self, token_id):
503
505
  if token_id not in self.owners:
504
- raise RevertError("ERC721: owner query for nonexistent token")
506
+ raise RevertError("ERC721: invalid token ID")
505
507
  return self.owners[token_id]
506
508
 
507
509
  # def token_uri
@@ -536,7 +538,7 @@ class ERC721Token(AccessControlContract): # NFT
536
538
  owner = self.owners[token_id]
537
539
  if sender != owner and self.token_approvals.get(token_id, None) != sender and \
538
540
  sender not in self.operator_approvals.get(owner, []):
539
- raise RevertError("ERC721: transfer caller is not owner nor approved")
541
+ raise RevertError("ERC721: caller is not token owner or approved")
540
542
  return self._transfer(from_, to, token_id)
541
543
 
542
544
  @external
@@ -544,7 +546,7 @@ class ERC721Token(AccessControlContract): # NFT
544
546
  owner = self.owners[token_id]
545
547
  if sender != owner and self.token_approvals.get(token_id, None) != sender and \
546
548
  sender not in self.operator_approvals.get(owner, []):
547
- raise RevertError("ERC721: transfer caller is not owner nor approved")
549
+ raise RevertError("ERC721: caller is not token owner or approved")
548
550
  # TODO: if `to` is contract, call onERC721Received
549
551
  return self._transfer(from_, to, token_id)
550
552