eth-prototype 0.7.5__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 (70) hide show
  1. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/.github/workflows/test.yaml +6 -1
  2. {eth-prototype-0.7.5 → 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.5 → eth-prototype-1.0.0}/PKG-INFO +15 -44
  6. eth-prototype-1.0.0/README.md +34 -0
  7. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/pyproject.toml +3 -0
  8. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/setup.cfg +3 -10
  9. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/PKG-INFO +15 -44
  10. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/SOURCES.txt +21 -12
  11. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/requires.txt +1 -11
  12. eth-prototype-1.0.0/src/ethproto/build_artifacts.py +152 -0
  13. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/ethproto/contracts.py +8 -6
  14. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/ethproto/w3wrappers.py +177 -72
  15. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/ethproto/wrappers.py +95 -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.5 → eth-prototype-1.0.0}/tests/test_contracts.py +19 -32
  30. eth-prototype-1.0.0/tests/test_time_control.py +19 -0
  31. eth-prototype-1.0.0/tests/test_w3.py +79 -0
  32. eth-prototype-1.0.0/tests/test_wadray.py +48 -0
  33. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/tox.ini +4 -19
  34. eth-prototype-0.7.5/README.rst +0 -55
  35. eth-prototype-0.7.5/src/ethproto/brwrappers.py +0 -221
  36. eth-prototype-0.7.5/tests/brownie-project/.gitattributes +0 -2
  37. eth-prototype-0.7.5/tests/brownie-project/.gitignore +0 -5
  38. eth-prototype-0.7.5/tests/brownie-project/brownie-config.yaml +0 -12
  39. eth-prototype-0.7.5/tests/conftest.py +0 -10
  40. eth-prototype-0.7.5/tests/json-project/TestCurrency.json +0 -338
  41. eth-prototype-0.7.5/tests/json-project/TestCurrencyUUPS.json +0 -340
  42. eth-prototype-0.7.5/tests/json-project/TestNFT.json +0 -388
  43. eth-prototype-0.7.5/tests/json-project/dependencies/ERC1967Proxy.json +0 -80
  44. eth-prototype-0.7.5/tests/test_wadray.py +0 -46
  45. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/.coveragerc +0 -0
  46. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/.github/workflows/publish.yaml +0 -0
  47. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/.readthedocs.yml +0 -0
  48. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/AUTHORS.rst +0 -0
  49. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/CHANGELOG.rst +0 -0
  50. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/LICENSE.txt +0 -0
  51. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/Makefile +0 -0
  52. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/_static/.gitignore +0 -0
  53. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/authors.rst +0 -0
  54. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/changelog.rst +0 -0
  55. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/conf.py +0 -0
  56. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/index.rst +0 -0
  57. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/license.rst +0 -0
  58. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/readme.rst +0 -0
  59. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/docs/requirements.txt +0 -0
  60. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/setup.py +0 -0
  61. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/dependency_links.txt +0 -0
  62. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/not-zip-safe +0 -0
  63. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/eth_prototype.egg-info/top_level.txt +0 -0
  64. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/ethproto/__init__.py +0 -0
  65. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/ethproto/defender_relay.py +0 -0
  66. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/src/ethproto/wadray.py +0 -0
  67. {eth-prototype-0.7.5/tests/brownie-project → eth-prototype-1.0.0/tests/hardhat-project}/contracts/TestCurrency.sol +0 -0
  68. {eth-prototype-0.7.5/tests/brownie-project → eth-prototype-1.0.0/tests/hardhat-project}/contracts/TestCurrencyUUPS.sol +0 -0
  69. {eth-prototype-0.7.5/tests/brownie-project → eth-prototype-1.0.0/tests/hardhat-project}/contracts/TestNFT.sol +0 -0
  70. {eth-prototype-0.7.5 → eth-prototype-1.0.0}/tests/test_defender.py +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.5
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,18 +11,16 @@ 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
14
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
15
  License-File: LICENSE.txt
16
16
  License-File: AUTHORS.rst
17
17
  Requires-Dist: m9g
18
18
  Requires-Dist: environs
19
19
  Requires-Dist: requests
20
+ Requires-Dist: hexbytes
20
21
  Requires-Dist: importlib-metadata; python_version < "3.8"
21
- Provides-Extra: brownie
22
- Requires-Dist: eth-brownie; extra == "brownie"
23
22
  Provides-Extra: web3
24
23
  Requires-Dist: web3; extra == "web3"
25
- Requires-Dist: eth-event; extra == "web3"
26
24
  Provides-Extra: defender
27
25
  Requires-Dist: boto3; extra == "defender"
28
26
  Provides-Extra: gmpy2
@@ -32,71 +30,44 @@ Requires-Dist: setuptools; extra == "testing"
32
30
  Requires-Dist: pytest; extra == "testing"
33
31
  Requires-Dist: gmpy2; extra == "testing"
34
32
  Requires-Dist: pytest-cov; extra == "testing"
35
- Provides-Extra: testing-br
36
- Requires-Dist: eth-brownie; extra == "testing-br"
37
- Requires-Dist: setuptools; extra == "testing-br"
38
- Requires-Dist: pytest; extra == "testing-br"
39
- Requires-Dist: pytest-cov; extra == "testing-br"
40
33
  Provides-Extra: testing-w3
41
34
  Requires-Dist: web3[tester]; extra == "testing-w3"
42
35
  Requires-Dist: setuptools; extra == "testing-w3"
43
36
  Requires-Dist: pytest; extra == "testing-w3"
44
- Requires-Dist: eth-event; extra == "testing-w3"
45
37
  Requires-Dist: pytest-cov; extra == "testing-w3"
46
38
  Requires-Dist: boto3; extra == "testing-w3"
47
39
 
48
- =============
49
- eth-prototype
50
- =============
40
+ # eth-prototype
51
41
 
52
42
 
53
43
  Prototype Ethereum Smart Contracts in Python
54
44
 
55
45
 
56
- Description
57
- ===========
46
+ ## Description
58
47
 
59
48
  Library with base classes to prototype Ethereum Smart Contracts in Python. This includes:
60
49
 
61
50
  - wadray: classes for fixed number of decimals math implemented with integers.
62
51
  - contracts: classes to simulate contracts in Python with features like *rollback* on exception, external
63
52
  methods, views. Also classes for common contracts like ERC20 (tokens), ERC721 (NFTs) and AccessControl.
64
- - brwrappers: classes to wrap ethereum contracts called thru [brownie](https://github.com/eth-brownie/brownie/) but with a pythonic interface
65
53
  - w3wrappers: classes to wrap ethereum contracts called thru [web3py](https://web3py.readthedocs.io/) but with a pythonic interface
66
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:
67
56
 
68
- Tox Tests
69
- =========
57
+ ```
58
+ warrant @ git+https://github.com/gnarvaja/warrant.git#egg=warrant
59
+ ```
70
60
 
71
- The tox tests run in three variants:
61
+ Note that using the `warrant` package from pypi will not work because of incompatibilities with newer python versions.
72
62
 
73
- - `default`: only uses and tests the prototype libraries, no blockchain.
74
- - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
75
- - `default-br`: users and tests two variants: prototype and brwrappers (wrappers using brownie).
76
-
77
- It's not possible for now running all the tests together because of incompatibilities between brownie and web3[tester].
78
-
79
-
80
- To run the tox `default-br` tests, you need an environment with Brownie, SOLC and other requirements.
63
+ ## Tox Tests
81
64
 
82
- You can do it using a Docker image an a few commands
65
+ The tox tests run in two variants:
83
66
 
84
- .. code-block:: bash
85
-
86
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:1.0.0 bash
87
- gnarvaja/eth-dev:eth-proto-brownie
88
- pip install tox
89
- brownie pm install OpenZeppelin/openzeppelin-contracts@4.3.2
90
- brownie pm install OpenZeppelin/openzeppelin-contracts-upgradeable@4.3.2
91
- tox -e py39-br
92
-
93
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:eth-proto-brownie bash
94
- tox -e py39-br
95
-
96
- .. _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).
97
69
 
98
- Note
99
- ====
70
+ # Note
100
71
 
101
72
  This project has been set up using PyScaffold 4.0.2. For details and usage
102
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,8 @@ exclude =
33
34
  tests
34
35
 
35
36
  [options.extras_require]
36
- brownie = eth-brownie
37
37
  web3 =
38
38
  web3
39
- eth-event
40
39
  defender =
41
40
  boto3
42
41
  gmpy2 =
@@ -46,16 +45,10 @@ testing =
46
45
  pytest
47
46
  gmpy2
48
47
  pytest-cov
49
- testing-br =
50
- eth-brownie
51
- setuptools
52
- pytest
53
- pytest-cov
54
48
  testing-w3 =
55
49
  web3[tester]
56
50
  setuptools
57
51
  pytest
58
- eth-event
59
52
  pytest-cov
60
53
  boto3
61
54
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eth-prototype
3
- Version: 0.7.5
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,18 +11,16 @@ 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
14
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
15
  License-File: LICENSE.txt
16
16
  License-File: AUTHORS.rst
17
17
  Requires-Dist: m9g
18
18
  Requires-Dist: environs
19
19
  Requires-Dist: requests
20
+ Requires-Dist: hexbytes
20
21
  Requires-Dist: importlib-metadata; python_version < "3.8"
21
- Provides-Extra: brownie
22
- Requires-Dist: eth-brownie; extra == "brownie"
23
22
  Provides-Extra: web3
24
23
  Requires-Dist: web3; extra == "web3"
25
- Requires-Dist: eth-event; extra == "web3"
26
24
  Provides-Extra: defender
27
25
  Requires-Dist: boto3; extra == "defender"
28
26
  Provides-Extra: gmpy2
@@ -32,71 +30,44 @@ Requires-Dist: setuptools; extra == "testing"
32
30
  Requires-Dist: pytest; extra == "testing"
33
31
  Requires-Dist: gmpy2; extra == "testing"
34
32
  Requires-Dist: pytest-cov; extra == "testing"
35
- Provides-Extra: testing-br
36
- Requires-Dist: eth-brownie; extra == "testing-br"
37
- Requires-Dist: setuptools; extra == "testing-br"
38
- Requires-Dist: pytest; extra == "testing-br"
39
- Requires-Dist: pytest-cov; extra == "testing-br"
40
33
  Provides-Extra: testing-w3
41
34
  Requires-Dist: web3[tester]; extra == "testing-w3"
42
35
  Requires-Dist: setuptools; extra == "testing-w3"
43
36
  Requires-Dist: pytest; extra == "testing-w3"
44
- Requires-Dist: eth-event; extra == "testing-w3"
45
37
  Requires-Dist: pytest-cov; extra == "testing-w3"
46
38
  Requires-Dist: boto3; extra == "testing-w3"
47
39
 
48
- =============
49
- eth-prototype
50
- =============
40
+ # eth-prototype
51
41
 
52
42
 
53
43
  Prototype Ethereum Smart Contracts in Python
54
44
 
55
45
 
56
- Description
57
- ===========
46
+ ## Description
58
47
 
59
48
  Library with base classes to prototype Ethereum Smart Contracts in Python. This includes:
60
49
 
61
50
  - wadray: classes for fixed number of decimals math implemented with integers.
62
51
  - contracts: classes to simulate contracts in Python with features like *rollback* on exception, external
63
52
  methods, views. Also classes for common contracts like ERC20 (tokens), ERC721 (NFTs) and AccessControl.
64
- - brwrappers: classes to wrap ethereum contracts called thru [brownie](https://github.com/eth-brownie/brownie/) but with a pythonic interface
65
53
  - w3wrappers: classes to wrap ethereum contracts called thru [web3py](https://web3py.readthedocs.io/) but with a pythonic interface
66
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:
67
56
 
68
- Tox Tests
69
- =========
57
+ ```
58
+ warrant @ git+https://github.com/gnarvaja/warrant.git#egg=warrant
59
+ ```
70
60
 
71
- The tox tests run in three variants:
61
+ Note that using the `warrant` package from pypi will not work because of incompatibilities with newer python versions.
72
62
 
73
- - `default`: only uses and tests the prototype libraries, no blockchain.
74
- - `default-w3`: users and tests two variants: prototype and w3wrappers (wrappers using web3py).
75
- - `default-br`: users and tests two variants: prototype and brwrappers (wrappers using brownie).
76
-
77
- It's not possible for now running all the tests together because of incompatibilities between brownie and web3[tester].
78
-
79
-
80
- To run the tox `default-br` tests, you need an environment with Brownie, SOLC and other requirements.
63
+ ## Tox Tests
81
64
 
82
- You can do it using a Docker image an a few commands
65
+ The tox tests run in two variants:
83
66
 
84
- .. code-block:: bash
85
-
86
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:1.0.0 bash
87
- gnarvaja/eth-dev:eth-proto-brownie
88
- pip install tox
89
- brownie pm install OpenZeppelin/openzeppelin-contracts@4.3.2
90
- brownie pm install OpenZeppelin/openzeppelin-contracts-upgradeable@4.3.2
91
- tox -e py39-br
92
-
93
- docker run -it -v $PWD:/code -w /code gnarvaja/eth-dev:eth-proto-brownie bash
94
- tox -e py39-br
95
-
96
- .. _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).
97
69
 
98
- Note
99
- ====
70
+ # Note
100
71
 
101
72
  This project has been set up using PyScaffold 4.0.2. For details and usage
102
73
  information on PyScaffold see https://pyscaffold.org/.
@@ -1,10 +1,12 @@
1
1
  .coveragerc
2
2
  .gitignore
3
+ .isort.cfg
4
+ .pre-commit-config.yaml
3
5
  .readthedocs.yml
4
6
  AUTHORS.rst
5
7
  CHANGELOG.rst
6
8
  LICENSE.txt
7
- README.rst
9
+ README.md
8
10
  pyproject.toml
9
11
  setup.cfg
10
12
  setup.py
@@ -27,23 +29,30 @@ src/eth_prototype.egg-info/not-zip-safe
27
29
  src/eth_prototype.egg-info/requires.txt
28
30
  src/eth_prototype.egg-info/top_level.txt
29
31
  src/ethproto/__init__.py
30
- src/ethproto/brwrappers.py
32
+ src/ethproto/build_artifacts.py
31
33
  src/ethproto/contracts.py
32
34
  src/ethproto/defender_relay.py
33
35
  src/ethproto/w3wrappers.py
34
36
  src/ethproto/wadray.py
35
37
  src/ethproto/wrappers.py
36
38
  tests/conftest.py
39
+ tests/test_build_artifacts.py
37
40
  tests/test_contracts.py
38
41
  tests/test_defender.py
42
+ tests/test_time_control.py
43
+ tests/test_w3.py
39
44
  tests/test_wadray.py
40
- tests/brownie-project/.gitattributes
41
- tests/brownie-project/.gitignore
42
- tests/brownie-project/brownie-config.yaml
43
- tests/brownie-project/contracts/TestCurrency.sol
44
- tests/brownie-project/contracts/TestCurrencyUUPS.sol
45
- tests/brownie-project/contracts/TestNFT.sol
46
- tests/json-project/TestCurrency.json
47
- tests/json-project/TestCurrencyUUPS.json
48
- tests/json-project/TestNFT.json
49
- tests/json-project/dependencies/ERC1967Proxy.json
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,13 +1,11 @@
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
10
-
11
9
  [defender]
12
10
  boto3
13
11
 
@@ -20,20 +18,12 @@ pytest
20
18
  gmpy2
21
19
  pytest-cov
22
20
 
23
- [testing-br]
24
- eth-brownie
25
- setuptools
26
- pytest
27
- pytest-cov
28
-
29
21
  [testing-w3]
30
22
  web3[tester]
31
23
  setuptools
32
24
  pytest
33
- eth-event
34
25
  pytest-cov
35
26
  boto3
36
27
 
37
28
  [web3]
38
29
  web3
39
- 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