From 90abb2323c741935aa747531ed628e4f72e0efb5 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Wed, 29 Mar 2023 20:49:45 +0300 Subject: [PATCH 1/7] Fix naming in new web3 --- src/predeployed_generator/contract_generator.py | 4 ++-- .../openzeppelin/transparent_upgradeable_proxy_generator.py | 6 +++--- src/predeployed_generator/upgradeable_contract_generator.py | 2 +- test/tools/custom_contract_generator.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/predeployed_generator/contract_generator.py b/src/predeployed_generator/contract_generator.py index c76db89..48b9ab5 100644 --- a/src/predeployed_generator/contract_generator.py +++ b/src/predeployed_generator/contract_generator.py @@ -197,14 +197,14 @@ def calculate_mapping_value_slot( else: raise TypeError(f'{key_type} is unknown key type') - return int.from_bytes(w3.solidityKeccak([key_type, 'uint256'], [key, slot]), 'big') + return int.from_bytes(w3.solidity_keccak([key_type, 'uint256'], [key, slot]), 'big') @staticmethod def calculate_array_value_slot(slot: int, index: int) -> int: """Calculate slot in smart contract storage where value of the array in the index is stored """ - return int.from_bytes(w3.solidityKeccak(['uint256'], [slot]), 'big') + index + return int.from_bytes(w3.solidity_keccak(['uint256'], [slot]), 'big') + index @staticmethod def next_slot(previous_slot: int) -> int: diff --git a/src/predeployed_generator/openzeppelin/transparent_upgradeable_proxy_generator.py b/src/predeployed_generator/openzeppelin/transparent_upgradeable_proxy_generator.py index d1d9b8d..b23d03b 100644 --- a/src/predeployed_generator/openzeppelin/transparent_upgradeable_proxy_generator.py +++ b/src/predeployed_generator/openzeppelin/transparent_upgradeable_proxy_generator.py @@ -19,13 +19,13 @@ class TransparentUpgradeableProxyGenerator(OpenzeppelinContractGenerator): ARTIFACT_FILENAME = 'TransparentUpgradeableProxy.json' META_FILENAME = 'TransparentUpgradeableProxy.meta.json' ROLLBACK_SLOT = int.from_bytes( - w3.solidityKeccak(['string'], ['eip1967.proxy.rollback']), + w3.solidity_keccak(['string'], ['eip1967.proxy.rollback']), byteorder='big') - 1 IMPLEMENTATION_SLOT = int.from_bytes( - w3.solidityKeccak(['string'], ['eip1967.proxy.implementation']), + w3.solidity_keccak(['string'], ['eip1967.proxy.implementation']), byteorder='big') - 1 ADMIN_SLOT = int.from_bytes( - w3.solidityKeccak(['string'], ['eip1967.proxy.admin']), + w3.solidity_keccak(['string'], ['eip1967.proxy.admin']), byteorder='big') - 1 @staticmethod diff --git a/src/predeployed_generator/upgradeable_contract_generator.py b/src/predeployed_generator/upgradeable_contract_generator.py index 1a153cb..c3a87fc 100644 --- a/src/predeployed_generator/upgradeable_contract_generator.py +++ b/src/predeployed_generator/upgradeable_contract_generator.py @@ -65,7 +65,7 @@ def generate_allocation( proxy_admin_address = kwargs.pop('proxy_admin_address') implementation_address = kwargs.pop( 'implementation_address', - w3.toChecksumAddress(w3.solidityKeccak(['address'], [contract_address])[:20])) + w3.toChecksumAddress(w3.solidity_keccak(['address'], [contract_address])[:20])) return { contract_address: super().generate( diff --git a/test/tools/custom_contract_generator.py b/test/tools/custom_contract_generator.py index 2074c4c..8184236 100644 --- a/test/tools/custom_contract_generator.py +++ b/test/tools/custom_contract_generator.py @@ -10,7 +10,7 @@ class CustomContractGenerator(AccessControlEnumerableGenerator): CONTRACT_NAME = 'TestContract' DEFAULT_ADMIN_ROLE = (0).to_bytes(32, 'big') - TESTER_ROLE = w3.solidityKeccak(['string'], ['TESTER_ROLE']) + TESTER_ROLE = w3.solidity_keccak(['string'], ['TESTER_ROLE']) # ---------- storage ---------- # --------Initializable-------- From 732c86baafc434562688bc79dda3937e2afd1dbc Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Wed, 29 Mar 2023 21:00:30 +0300 Subject: [PATCH 2/7] Fix mypy --- src/predeployed_generator/contract_generator.py | 2 +- src/predeployed_generator/upgradeable_contract_generator.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/predeployed_generator/contract_generator.py b/src/predeployed_generator/contract_generator.py index 48b9ab5..01fbde0 100644 --- a/src/predeployed_generator/contract_generator.py +++ b/src/predeployed_generator/contract_generator.py @@ -118,7 +118,7 @@ def get_meta(self) -> dict: # private - def _generate(self, storage: Storage = None, balance: int = 0, nonce: int = 0) -> Account: + def _generate(self, storage: Storage = {}, balance: int = 0, nonce: int = 0) -> Account: """Produce smart contract allocation object. It consists of fields 'code', 'balance', 'nonce' and 'storage' diff --git a/src/predeployed_generator/upgradeable_contract_generator.py b/src/predeployed_generator/upgradeable_contract_generator.py index c3a87fc..92aac5b 100644 --- a/src/predeployed_generator/upgradeable_contract_generator.py +++ b/src/predeployed_generator/upgradeable_contract_generator.py @@ -65,7 +65,7 @@ def generate_allocation( proxy_admin_address = kwargs.pop('proxy_admin_address') implementation_address = kwargs.pop( 'implementation_address', - w3.toChecksumAddress(w3.solidity_keccak(['address'], [contract_address])[:20])) + w3.to_checksum_address(w3.solidity_keccak(['address'], [contract_address])[:20])) return { contract_address: super().generate( @@ -75,4 +75,4 @@ def generate_allocation( balance=balance, nonce=nonce), # pylint: disable=W0212 - implementation_address: self.implementation_generator._generate(storage=None)} + implementation_address: self.implementation_generator._generate(storage={})} From 6385882ebf6e75057e3f740c8049d81ad06118e3 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Wed, 29 Mar 2023 21:19:12 +0300 Subject: [PATCH 3/7] Fix pylint --- src/predeployed_generator/contract_generator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/predeployed_generator/contract_generator.py b/src/predeployed_generator/contract_generator.py index 01fbde0..999927d 100644 --- a/src/predeployed_generator/contract_generator.py +++ b/src/predeployed_generator/contract_generator.py @@ -118,7 +118,12 @@ def get_meta(self) -> dict: # private - def _generate(self, storage: Storage = {}, balance: int = 0, nonce: int = 0) -> Account: + def _generate( + self, + storage: Optional[Storage] = None, + balance: int = 0, + nonce: int = 0 + ) -> Account: """Produce smart contract allocation object. It consists of fields 'code', 'balance', 'nonce' and 'storage' From 7c97755d1f450b8cb64c0eb5529688faf558e4b4 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Wed, 29 Mar 2023 21:57:51 +0300 Subject: [PATCH 4/7] Fix is_connected --- test/test_access_control_enumerable_generator.py | 4 ++-- test/test_contract_generator.py | 8 ++++---- test/test_proxy_admin_generator.py | 2 +- test/test_transparent_upgradeable_proxy_generator.py | 4 ++-- test/test_upgradeable_contract_generator.py | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/test_access_control_enumerable_generator.py b/test/test_access_control_enumerable_generator.py index 5335cbf..e93b93e 100644 --- a/test/test_access_control_enumerable_generator.py +++ b/test/test_access_control_enumerable_generator.py @@ -26,7 +26,7 @@ def test_default_admin_role(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() test_contract = w3.eth.contract(address=self.CONTRACT_ADDRESS, abi=self.get_test_contract_abi()) assert test_contract.functions.getRoleMemberCount(CustomContractGenerator.DEFAULT_ADMIN_ROLE).call() == 1 @@ -38,7 +38,7 @@ def test_tester_role(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() test_contract = w3.eth.contract(address=self.CONTRACT_ADDRESS, abi=self.get_test_contract_abi()) assert test_contract.functions.getRoleMemberCount(CustomContractGenerator.TESTER_ROLE).call() == 2 diff --git a/test/test_contract_generator.py b/test/test_contract_generator.py index 93abb8d..c19f882 100644 --- a/test/test_contract_generator.py +++ b/test/test_contract_generator.py @@ -29,7 +29,7 @@ def test_short_string(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() test_contract = w3.eth.contract(address=self.CONTRACT_ADDRESS, abi=self.get_test_contract_abi()) assert test_contract.functions.shortString().call() == 'short string' @@ -39,7 +39,7 @@ def test_long_string(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() test_contract = w3.eth.contract(address=self.CONTRACT_ADDRESS, abi=self.get_test_contract_abi()) assert test_contract.functions.longString().call() == ' '.join(['very'] * 32) + ' long string' @@ -49,7 +49,7 @@ def test_bytes32(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() test_contract = w3.eth.contract(address=self.CONTRACT_ADDRESS, abi=self.get_test_contract_abi()) assert test_contract.functions.bytes32Value().call() == CustomContractGenerator.TESTER_ROLE @@ -59,7 +59,7 @@ def test_addresses_array(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() test_contract = w3.eth.contract(address=self.CONTRACT_ADDRESS, abi=self.get_test_contract_abi()) assert test_contract.functions.testers(0).call() == self.TESTER_ADDRESS diff --git a/test/test_proxy_admin_generator.py b/test/test_proxy_admin_generator.py index 2f0d12c..da8854f 100644 --- a/test/test_proxy_admin_generator.py +++ b/test/test_proxy_admin_generator.py @@ -16,7 +16,7 @@ def test_owner(self, tmpdir): proxy_admin_address = '0xd200000000000000000000000000000000000001' generator = ProxyAdminGenerator() with self.run_geth(tmpdir, self.generate_genesis({proxy_admin_address: generator.generate(owner_address=owner_address)})): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=proxy_admin_address, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.owner().call() == owner_address diff --git a/test/test_transparent_upgradeable_proxy_generator.py b/test/test_transparent_upgradeable_proxy_generator.py index 77afe17..9c738e9 100644 --- a/test/test_transparent_upgradeable_proxy_generator.py +++ b/test/test_transparent_upgradeable_proxy_generator.py @@ -40,7 +40,7 @@ def test_admin(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=self.PROXY_ADMIN_ADDRESS, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.getProxyAdmin(self.PROXY_ADDRESS).call() == self.PROXY_ADMIN_ADDRESS @@ -50,7 +50,7 @@ def test_implementation(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=self.PROXY_ADMIN_ADDRESS, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.getProxyImplementation(self.PROXY_ADDRESS).call() == self.IMPLEMENTATION_ADDRESS diff --git a/test/test_upgradeable_contract_generator.py b/test/test_upgradeable_contract_generator.py index e3747f3..659cbef 100644 --- a/test/test_upgradeable_contract_generator.py +++ b/test/test_upgradeable_contract_generator.py @@ -41,7 +41,7 @@ def test_admin(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=self.PROXY_ADMIN_ADDRESS, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.getProxyAdmin(self.PROXY_ADDRESS).call() == self.PROXY_ADMIN_ADDRESS @@ -51,7 +51,7 @@ def test_implementation(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=self.PROXY_ADMIN_ADDRESS, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.getProxyImplementation(self.PROXY_ADDRESS).call() == self.IMPLEMENTATION_ADDRESS @@ -71,7 +71,7 @@ def test_default_implementation_address(self, tmpdir): }) with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=self.PROXY_ADMIN_ADDRESS, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.getProxyImplementation(self.PROXY_ADDRESS).call() == self.PROXY_ADDRESS_HASH @@ -81,7 +81,7 @@ def test_owner(self, tmpdir): genesis = self.prepare_genesis() with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() proxy_admin = w3.eth.contract(address=self.PROXY_ADDRESS, abi=self.get_proxy_admin_abi()) assert proxy_admin.functions.owner().call() == self.OWNER_ADDRESS @@ -112,7 +112,7 @@ def test_balance_and_nonce(self, tmpdir): }) with self.run_geth(tmpdir, genesis): - assert w3.isConnected() + assert w3.is_connected() assert w3.eth.get_balance(self.PROXY_ADDRESS) == balance assert w3.eth.get_transaction_count(self.PROXY_ADDRESS) == nonce From 0b373dba131bd7a12f907630b548c2550771d2d7 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Wed, 29 Mar 2023 22:09:59 +0300 Subject: [PATCH 5/7] Add new python versions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d893212..09419ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - python-version: ["3.7.x", "3.8.x", "3.9.x"] + python-version: ["3.7.x", "3.8.x", "3.9.x", "3.10.x", "3.11.x"] steps: - uses: actions/checkout@v2 From af9cc7c46780aa29e9d7a5b06c0d034b1c5ef497 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Fri, 31 Mar 2023 16:43:27 +0300 Subject: [PATCH 6/7] Add small improvements --- setup.cfg | 2 +- src/predeployed_generator/upgradeable_contract_generator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 5c21dd7..524d49a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,7 @@ packages = find: include_package_data = True python_requires = >=3.7 install_requires = - web3 + web3>=6.0.0 [options.packages.find] where = src diff --git a/src/predeployed_generator/upgradeable_contract_generator.py b/src/predeployed_generator/upgradeable_contract_generator.py index 92aac5b..6645062 100644 --- a/src/predeployed_generator/upgradeable_contract_generator.py +++ b/src/predeployed_generator/upgradeable_contract_generator.py @@ -75,4 +75,4 @@ def generate_allocation( balance=balance, nonce=nonce), # pylint: disable=W0212 - implementation_address: self.implementation_generator._generate(storage={})} + implementation_address: self.implementation_generator._generate()} From 24e349f7b8b13c5195d1be6698649429e3aee9fe Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Fri, 31 Mar 2023 16:53:24 +0300 Subject: [PATCH 7/7] Add small improvements --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 524d49a..69f5456 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,7 @@ packages = find: include_package_data = True python_requires = >=3.7 install_requires = - web3>=6.0.0 + web3 >= 6.0.0 [options.packages.find] where = src