diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f89ef2c..013754fe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }} ENDPOINT: ${{ secrets.ENDPOINT }} CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - MANAGER_TAG: "1.2.0-develop.1" + MANAGER_TAG: "1.3.0-develop.0" steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/skale/contracts/manager.py b/skale/contracts/manager.py index f8696b7d..91fb69de 100644 --- a/skale/contracts/manager.py +++ b/skale/contracts/manager.py @@ -22,10 +22,11 @@ import logging import socket +from eth_abi import encode_abi from skale.contracts import BaseContract, transaction_method from skale.utils import helper -from skale.utils.constants import GAS, OP_TYPES +from skale.utils.constants import GAS logger = logging.getLogger(__name__) @@ -37,41 +38,24 @@ def create_node(self, ip, port, name, public_ip=None): logger.info( f'create_node: {ip}:{port}, public ip: {public_ip} name: {name}') skale_nonce = helper.generate_nonce() - pk = self.skale.wallet.public_key - if not public_ip: public_ip = ip + pk = self.skale.wallet.public_key - transaction_data = self.create_node_data_to_bytes( - ip, public_ip, port, name, pk, skale_nonce) - return self.contract.functions.createNode(transaction_data) - - def create_node_data_to_bytes(self, ip, public_ip, port, name, pk, nonce): - pk_fix = str(pk)[2:] - - type_bytes = OP_TYPES['create_node'].to_bytes(1, byteorder='big') - port_bytes = port.to_bytes(2, byteorder='big') - nonce_bytes = nonce.to_bytes(2, byteorder='big') # todo ip_bytes = socket.inet_aton(ip) public_ip_bytes = socket.inet_aton(public_ip) - pk_bytes = bytes.fromhex(pk_fix) - name_bytes = name.encode() - - data_bytes = ( - type_bytes - + port_bytes # noqa: W503 - + nonce_bytes # noqa: W503 - + ip_bytes # noqa: W503 - + public_ip_bytes # noqa: W503 - + pk_bytes # noqa: W503 - + name_bytes # noqa: W503 - ) - logger.info( - f'create_node_data_to_bytes bytes: {self.skale.web3.toHex(data_bytes)}' + # pk to bytes without 0x + pk_bytes = bytes.fromhex(str(pk)[2:]) + + return self.contract.functions.createNode( + port, + skale_nonce, + ip_bytes, + public_ip_bytes, + pk_bytes, + name ) - return data_bytes - def create_default_schain(self, name): lifetime = 3600 nodes_type = 4 @@ -87,28 +71,11 @@ def create_schain(self, lifetime, type_of_nodes, deposit, name): token = self.skale.get_contract_by_name('token') skale_nonce = helper.generate_nonce() - transaction_data = self.create_schain_data_to_bytes( - lifetime, type_of_nodes, name, skale_nonce) - - return token.contract.functions.send(self.address, deposit, - transaction_data) - - def create_schain_data_to_bytes(self, lifetime, type_of_nodes, name, - nonce): - type_bytes = OP_TYPES['create_schain'].to_bytes(1, byteorder='big') - - lifetime_hex = lifetime.to_bytes(32, byteorder='big') - type_of_nodes_hex = type_of_nodes.to_bytes(1, byteorder='big') - nonce_hex = nonce.to_bytes(2, byteorder='big') - name_hex = name.encode() - - data_bytes = (type_bytes + lifetime_hex + - type_of_nodes_hex + nonce_hex + name_hex) - logger.info( - f'create_schain_data_to_bytes bytes:' - f'{self.skale.web3.toHex(data_bytes)}' + tx_data = encode_abi( + ['uint', 'uint8', 'uint16', 'string'], + [lifetime, type_of_nodes, skale_nonce, name] ) - return data_bytes + return token.contract.functions.send(self.address, deposit, tx_data) @transaction_method(gas_limit=GAS['get_bounty']) def get_bounty(self, node_id): @@ -116,13 +83,17 @@ def get_bounty(self, node_id): @transaction_method(gas_limit=GAS['send_verdict']) def send_verdict(self, validator, node_id, downtime, latency): - return self.contract.functions.sendVerdict(validator, node_id, downtime, - latency) + return self.contract.functions.sendVerdict( + validator, + [node_id, downtime, latency] + ) @transaction_method(gas_limit=GAS['send_verdicts']) def send_verdicts(self, validator, nodes_ids, downtimes, latencies): - return self.contract.functions.sendVerdicts(validator, nodes_ids, - downtimes, latencies) + return self.contract.functions.sendVerdicts( + validator, + [nodes_ids, downtimes, latencies] + ) @transaction_method(gas_limit=GAS['delete_node']) def deregister(self, node_id): diff --git a/skale/utils/constants.py b/skale/utils/constants.py index 511968e4..ef06ab29 100644 --- a/skale/utils/constants.py +++ b/skale/utils/constants.py @@ -60,8 +60,6 @@ 'set_launch_timestamp': 200000, } -OP_TYPES = {'create_node': 0x1, 'create_schain': 0x10} - LONG_LINE = '=' * 100 SCHAIN_TYPES = { diff --git a/tests/contracts/manager_test.py b/tests/contracts/manager_test.py index 80ecf4c7..a9210fb5 100644 --- a/tests/contracts/manager_test.py +++ b/tests/contracts/manager_test.py @@ -6,45 +6,14 @@ from hexbytes import HexBytes from mock import Mock -import skale.utils.helper as helper from skale.dataclasses.tx_res import TransactionFailedError from skale.utils.constants import GAS -from skale.utils.web3_utils import private_key_to_public from skale.utils.contracts_provision.main import ( generate_random_node_data, generate_random_schain_data ) -def test_create_node_data_to_bytes(skale): - ip, public_ip, port, name = generate_random_node_data() - skale_nonce = helper.generate_nonce() - pk = private_key_to_public(skale.wallet._private_key) - - bytes_data = skale.manager.create_node_data_to_bytes( - ip, public_ip, port, name, pk, skale_nonce) - name_bytes = name.encode() - - assert type(bytes_data) is bytes - assert bytes_data.find(name_bytes) != -1 - - -def test_create_schain_data_to_bytes(skale): - type_of_nodes, lifetime_seconds, name = generate_random_schain_data() - skale_nonce = helper.generate_nonce() - - bytes_data = skale.manager.create_schain_data_to_bytes( - lifetime_seconds, - type_of_nodes, - name, - skale_nonce - ) - name_bytes = name.encode() - - assert type(bytes_data) is bytes - assert bytes_data.find(name_bytes) != -1 - - def test_get_bounty(skale): node_id = 0 nonce = skale.web3.eth.getTransactionCount(skale.wallet.address) @@ -78,7 +47,7 @@ def test_send_verdict(skale): 'gas': 200000, 'nonce': nonce, 'to': contract_address, 'data': ( - '0xd77de31c000000000000000000000000000000000000000' + '0x96a1ce46000000000000000000000000000000000000000' '0000000000000000000000000000000000000000000000000' '000000000000000000000000000000000000007b000000000' '0000000000000000000000000000000000000000000000000' @@ -110,26 +79,24 @@ def test_send_verdicts(skale): 'value': 0, 'gasPrice': skale.gas_price, 'chainId': chain_id, 'gas': 8000000, 'nonce': nonce, 'to': contract_address, - 'data': ('0x25b2114b000000000000000000000000000000000000000000' - '0000000000000000000000000000000000000000000000000000' - '0000000000000000000000000000000080000000000000000000' - '0000000000000000000000000000000000000000000100000000' - '0000000000000000000000000000000000000000000000000000' - '0001800000000000000000000000000000000000000000000000' - '0000000000000000030000000000000000000000000000000000' - '00000000000000000000000000007b0000000000000000000000' - '0000000000000000000000000000000000000000e70000000000' - '0000000000000000000000000000000000000000000000000001' - 'c300000000000000000000000000000000000000000000000000' - '0000000000000300000000000000000000000000000000000000' - '0000000000000000000000000100000000000000000000000000' - '0000000000000000000000000000000000000200000000000000' - '0000000000000000000000000000000000000000000000000300' - '0000000000000000000000000000000000000000000000000000' - '0000000003000000000000000000000000000000000000000000' - '000000000000000000000a000000000000000000000000000000' - '0000000000000000000000000000000014000000000000000000' - '000000000000000000000000000000000000000000001e') + + 'data': ( + '0x42c81d610000000000000000000000000000000000000000' + '00000000000000000000000000000000000000000000000000' + '0000000000000000000000000000000000004000000000000' + '00000000000000000000000000000000000000000000000000' + '00300000000000000000000000000000000000000000000000' + '0000000000000007b000000000000000000000000000000000' + '00000000000000000000000000000e70000000000000000000' + '0000000000000000000000000000000000000000001c300000' + '00000000000000000000000000000000000000000000000000' + '00000000100000000000000000000000000000000000000000' + '00000000000000000000002000000000000000000000000000' + '00000000000000000000000000000000000030000000000000' + '00000000000000000000000000000000000000000000000000' + 'a0000000000000000000000000000000000000000000000000' + '00000000000001400000000000000000000000000000000000' + '0000000000000000000000000001e') } exp = skale.web3.eth.account.signTransaction( expected_txn, skale.wallet._private_key).rawTransaction