Skip to content

Commit

Permalink
PAN-2405: Updating contracts (#64)
Browse files Browse the repository at this point in the history
* PAN-2405: Updating contracts
  • Loading branch information
jacekv authored Jan 29, 2025
1 parent 1fab8aa commit b6909af
Show file tree
Hide file tree
Showing 43 changed files with 23 additions and 41 deletions.
6 changes: 3 additions & 3 deletions pantos/common/blockchains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ def load_contract_abi(
f'{_BASE_CONTRACT_ABI_PACKAGE}.v'
f'{version.major}_{version.minor}_{version.patch}')
try:
with importlib.resources.open_text(
versioned_contract_abi_package,
contract_abi_file_name) as contract_abi_file:
contract_file = importlib.resources.files(
versioned_contract_abi_package) / contract_abi_file_name
with contract_file.open('r') as contract_abi_file:
loaded_contract_abi = json.load(contract_abi_file)
self.__loaded_contract_abis[contract_abi] = loaded_contract_abi
return loaded_contract_abi
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions pantos/common/blockchains/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ def is_protocol_version_supported_by_contract(
node_connections)
match versioned_contract_abi.contract_abi:
case ContractAbi.PANTOS_HUB:
if (versioned_contract_abi.version
< semantic_version.Version('0.2.0')):
raise self._create_error(
'contract function not available',
versioned_contract_abi=versioned_contract_abi)
protocol_version = \
contract.caller().getProtocolVersion().get()
assert isinstance(protocol_version, bytes)
Expand Down
2 changes: 1 addition & 1 deletion pantos/common/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def json_record(self, message: str, extra: typing.Dict[str | int,
"""
extra['levelname'] = record.levelname
if 'time' not in extra:
extra['time'] = datetime.datetime.utcnow()
extra['time'] = datetime.datetime.now(datetime.UTC)
extra['message'] = message
if record.exc_info:
extra['exc_info'] = self.formatException(record.exc_info)
Expand Down
4 changes: 2 additions & 2 deletions pantos/common/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import semantic_version # type: ignore

_SUPPORTED_PROTOCOL_VERSIONS: typing.Final[set[semantic_version.Version]] = {
semantic_version.Version('0.1.0'),
semantic_version.Version('0.2.0')
semantic_version.Version('0.2.0'),
semantic_version.Version('0.3.0')
}


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pantos-common"
version = "4.3.0"
version = "5.0.0"
description = "Common code for Pantos off-chain components."
authors = ["Pantos GmbH <[email protected]>"]
license = "GPL-3.0-only"
Expand Down
1 change: 1 addition & 0 deletions tests/blockchains/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def transaction_adaptable_fee_per_gas():

@pytest.fixture(scope='package', params=ContractAbi)
def versioned_contract_abi(request, protocol_version):
print(">>", protocol_version)
return VersionedContractAbi(request.param, protocol_version)


Expand Down
30 changes: 8 additions & 22 deletions tests/blockchains/test_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from pantos.common.blockchains.ethereum import EthereumUtilitiesError
from pantos.common.entities import TransactionStatus
from pantos.common.protocol import get_latest_protocol_version
from pantos.common.protocol import get_supported_protocol_versions

_CONTRACT_ABI_PACKAGE = 'tests.blockchains.contracts'
"""Package that contains the contract ABI files."""
Expand Down Expand Up @@ -69,12 +68,14 @@ def ethereum_utilities(mock_create_node_connections, blockchain_node_urls,
@pytest.fixture
def deployed_erc20(w3, node_connections):
default_account = w3.eth.accounts[0]
with importlib.resources.open_text(
_CONTRACT_ABI_PACKAGE, _ERC20_CONTRACT_BYTECODE) as bytecode_file:
bytecode = bytecode_file.read()
with importlib.resources.open_text(_CONTRACT_ABI_PACKAGE,
_ERC20_CONTRACT_ABI) as abi_file:
erc20_abi = abi_file.read()
bytecode_file = importlib.resources.files(
_CONTRACT_ABI_PACKAGE) / _ERC20_CONTRACT_BYTECODE
with bytecode_file.open('r') as bytecode_file_content:
bytecode = bytecode_file_content.read()
abi_file = importlib.resources.files(
_CONTRACT_ABI_PACKAGE) / _ERC20_CONTRACT_ABI
with abi_file.open('r') as abi_file_content:
erc20_abi = abi_file_content.read()
erc20_contract = node_connections.eth.contract(abi=erc20_abi,
bytecode=bytecode)
tx_hash = erc20_contract.constructor(1000, 'TOK', 2, 'TOK').transact(
Expand Down Expand Up @@ -270,21 +271,6 @@ def test_is_protocol_version_supported_by_contract_results_not_matching_error(
contract_address, versioned_contract_abi)


@unittest.mock.patch.object(EthereumUtilities, 'create_contract')
def test_is_protocol_version_supported_by_contract_not_available_error(
mock_create_contract, ethereum_utilities, contract_address):
versioned_contract_abi = VersionedContractAbi(
ContractAbi.PANTOS_HUB, min(get_supported_protocol_versions()))

with pytest.raises(EthereumUtilitiesError) as exception_info:
ethereum_utilities.is_protocol_version_supported_by_contract(
contract_address, versioned_contract_abi)

assert 'contract function not available' in str(exception_info.value)
assert (exception_info.value.details['versioned_contract_abi'] ==
versioned_contract_abi)


@unittest.mock.patch.object(EthereumUtilities, 'create_contract')
def test_is_protocol_version_supported_by_contract_not_tied_error(
mock_create_contract, ethereum_utilities, contract_address):
Expand Down

0 comments on commit b6909af

Please sign in to comment.