Skip to content

Commit

Permalink
Merge pull request #73 from skalenetwork/fix-naming
Browse files Browse the repository at this point in the history
Fix naming in new web3
  • Loading branch information
yavrsky authored Mar 31, 2023
2 parents 90d52f4 + 24e349f commit b593242
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions src/predeployed_generator/contract_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ def get_meta(self) -> dict:

# private

def _generate(self, storage: Storage = None, 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'
Expand Down Expand Up @@ -197,14 +202,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/predeployed_generator/upgradeable_contract_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.to_checksum_address(w3.solidity_keccak(['address'], [contract_address])[:20]))

return {
contract_address: super().generate(
Expand All @@ -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()}
4 changes: 2 additions & 2 deletions test/test_access_control_enumerable_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/test_contract_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_proxy_admin_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_transparent_upgradeable_proxy_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/test_upgradeable_contract_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/tools/custom_contract_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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--------
Expand Down

0 comments on commit b593242

Please sign in to comment.