From a041864d1808914e9bcd1f710fd7b0e55a5e0979 Mon Sep 17 00:00:00 2001 From: badrogger Date: Thu, 12 Jan 2023 18:38:16 +0000 Subject: [PATCH 1/3] Add meta and method fields --- tests/transaction_test.py | 31 +++++++++++++++++++++---------- transaction_manager/structures.py | 2 ++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/transaction_test.py b/tests/transaction_test.py index d8a67b4..3c9bff4 100644 --- a/tests/transaction_test.py +++ b/tests/transaction_test.py @@ -13,6 +13,7 @@ def test_sample_tx(): fee={'gas_price': 1000000000}, gas=22000, nonce=3, + method='createNode', source=None, tx_hash=None, data={'test': 1} @@ -23,7 +24,7 @@ def test_sample_tx(): assert not tx.is_sent() dumped_tx = tx.to_bytes() - expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "1232321332132131331321", "value": 1}' # noqa + expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": null, "method": "createNode", "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "1232321332132131331321", "value": 1}' # noqa assert dumped_tx == expected loaded_tx = Tx.from_bytes(tx.tx_id.encode('utf-8'), dumped_tx) @@ -99,38 +100,48 @@ def test_tx_from_bytes(): with pytest.raises(InvalidFormatError): Tx.from_bytes(tx_id, b'') - before_eip_1559 = b'{"attempts": 0, "status": "PROPOSED", "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "nonce": 3, "score": 1, "sent_ts": null, "to": "0x1", "tx_hash": null, "value": 1}' # noqa + before_eip_1559 = b'{"attempts": 0, "status": "PROPOSED", "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "meta": null, "method": null, "nonce": 3, "score": 1, "sent_ts": null, "to": "0x1", "tx_hash": null, "value": 1}' # noqa tx = Tx.from_bytes(tx_id, before_eip_1559) # sorted before_eip_1559 incuding eip_1559 fields - expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa + expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": null, "method": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa assert tx.to_bytes() == expected - missing_field_tx_id = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "value": 1}' # noqa + missing_field_tx_id = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": null, "method": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "value": 1}' # noqa tx = Tx.from_bytes(tx_id, missing_field_tx_id) # Same as missing_field_tx_id but with tx id - expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa + expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": null, "method": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa assert tx.to_bytes() == expected - missing_field_status = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "maxFeePerGas": 1000000000, "maxPriorityFeePerGas": 1000000000, "hashes": [], "nonce": 3, "score": 1, "sent_ts": null, "to": "0x1", "tx_hash": null, "value": 1}' # noqa + missing_field_status = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "maxFeePerGas": 1000000000, "maxPriorityFeePerGas": 1000000000, "hashes": [], "meta": null, "method": null, "nonce": 3, "score": 1, "sent_ts": null, "to": "0x1", "tx_hash": null, "value": 1}' # noqa with pytest.raises(InvalidFormatError): Tx.from_bytes(tx_id, missing_field_status) - missing_field_to = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "maxFeePerGas": 1000000000, "maxPriorityFeePerGas": 1000000000, "from": null, "gas": 22000, "hashes": [], "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "tx_hash": null, "value": 1}' # noqa + missing_field_to = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "maxFeePerGas": 1000000000, "maxPriorityFeePerGas": 1000000000, "from": null, "gas": 22000, "hashes": [], "meta": null, "method": null, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "tx_hash": null, "value": 1}' # noqa with pytest.raises(InvalidFormatError): Tx.from_bytes(tx_id, missing_field_to) - missing_field_hash = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "maxFeePerGas": 1000000000, "maxPriorityFeePerGas": 1000000000, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "value": 1}' # noqa + missing_field_hash = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "maxFeePerGas": 1000000000, "maxPriorityFeePerGas": 1000000000, "meta": null, "method": null, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "value": 1}' # noqa tx = Tx.from_bytes(tx_id, missing_field_hash) assert tx.hashes == [] - with_type = b'{"attempts": 0, "type": "0x0", "status": "PROPOSED", "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "nonce": 3, "score": 1, "sent_ts": null, "to": "0x1", "tx_hash": null, "value": 1}' # noqa + with_type = b'{"attempts": 0, "type": "0x0", "status": "PROPOSED", "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "meta": null, "method": null, "nonce": 3, "score": 1, "sent_ts": null, "to": "0x1", "tx_hash": null, "value": 1}' # noqa tx = Tx.from_bytes(tx_id, with_type) - expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa + expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": null, "method": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa tx.to_bytes() == expected + with_method_and_meta = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": {"chain": "test"}, "method": "createNode", "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa + tx = Tx.from_bytes(tx_id, with_method_and_meta) + assert tx.to_bytes() == with_method_and_meta + + missing_method_and_meta = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa + expected = b'{"attempts": 0, "chainId": null, "data": {"test": 1}, "from": null, "gas": 22000, "gasPrice": 1000000000, "hashes": [], "maxFeePerGas": null, "maxPriorityFeePerGas": null, "meta": null, "method": null, "multiplier": 1.2, "nonce": 3, "score": 1, "sent_ts": null, "status": "PROPOSED", "to": "0x1", "tx_hash": null, "tx_id": "tx-1232321332132131331321", "value": 1}' # noqa + tx = Tx.from_bytes(tx_id, missing_method_and_meta) + actual = tx.to_bytes() + assert actual == expected + def test_is_sent_by_ima(): tx = Tx( diff --git a/transaction_manager/structures.py b/transaction_manager/structures.py index 3750be3..09c9ecc 100644 --- a/transaction_manager/structures.py +++ b/transaction_manager/structures.py @@ -76,6 +76,8 @@ class Tx: data: Optional[Dict] = None tx_hash: Optional[str] = None sent_ts: Optional[int] = None + method: Optional[str] = None + meta: Optional[Dict] = None MAPPED_ATTR = { 'chainId': 'chain_id', From cc6f93b4b8571780a4047decd6532544c8da771d Mon Sep 17 00:00:00 2001 From: badrogger Date: Fri, 16 Jun 2023 16:12:05 +0000 Subject: [PATCH 2/3] Bump version to 2.1.5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7d2ed7c..cd57a8b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.4 +2.1.5 From 9b3c100e8b729f34f7f02557edbba40a4a9bdc40 Mon Sep 17 00:00:00 2001 From: badrogger Date: Sun, 18 Jun 2023 15:50:17 +0000 Subject: [PATCH 3/3] Update skale.py to 6.0dev0 --- requirements.txt | 2 +- tests/docker_test.py | 4 ++-- tests/processor_test.py | 4 ++-- tests/utils/account.py | 6 +++--- transaction_manager/eth.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index 05c9b8e..f748eb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -skale.py==5.8dev4 +skale.py==6.0dev0 diff --git a/tests/docker_test.py b/tests/docker_test.py index 412301f..4ce6ff8 100644 --- a/tests/docker_test.py +++ b/tests/docker_test.py @@ -51,8 +51,8 @@ def make_tx(w3, wallet, failed=False): number = 3 if failed else 4 return tester.functions.setOnlyEven( number - ).buildTransaction({ - 'gasPrice': w3.eth.gasPrice, + ).build_transaction({ + 'gasPrice': w3.eth.gas_price, 'gas': DEFAULT_GAS, 'from': wallet.address }) diff --git a/tests/processor_test.py b/tests/processor_test.py index af6f48c..48be47a 100644 --- a/tests/processor_test.py +++ b/tests/processor_test.py @@ -31,8 +31,8 @@ def make_tx(w3, wallet, failed=False): number = 3 if failed else 4 return tester.functions.setOnlyEven( number - ).buildTransaction({ - 'gasPrice': w3.eth.gasPrice, + ).build_transaction({ + 'gasPrice': w3.eth.gas_price, 'gas': DEFAULT_GAS, 'from': wallet.address }) diff --git a/tests/utils/account.py b/tests/utils/account.py index 8894fe3..2c16746 100644 --- a/tests/utils/account.py +++ b/tests/utils/account.py @@ -19,11 +19,11 @@ def send_eth( 'to': address, 'value': amount, 'gas': 8000000, - 'gasPrice': w3.eth.gasPrice + 'gasPrice': w3.eth.gas_price } signed_txn = wallet.sign(tx) - h = w3.eth.sendRawTransaction(signed_txn.rawTransaction) - w3.eth.waitForTransactionReceipt(h, timeout=60) + h = w3.eth.send_raw_transaction(signed_txn.rawTransaction) + w3.eth.wait_for_transaction_receipt(h, timeout=60) def generate_address(w3: Web3) -> str: diff --git a/transaction_manager/eth.py b/transaction_manager/eth.py index b7d1e0e..54d493c 100644 --- a/transaction_manager/eth.py +++ b/transaction_manager/eth.py @@ -86,7 +86,7 @@ def chain_id(self) -> int: return self.w3.eth.chain_id def get_balance(self, address: str) -> int: - checksum_addres = self.w3.toChecksumAddress(address) + checksum_addres = self.w3.to_checksum_address(address) return self.w3.eth.get_balance(checksum_addres) TX_ATTRS = [ @@ -190,7 +190,7 @@ def send_tx(self, signed_tx: Dict) -> str: return tx_hash def get_nonce(self, address: str) -> int: - checksum_addres = self.w3.toChecksumAddress(address) + checksum_addres = self.w3.to_checksum_address(address) return self.w3.eth.get_transaction_count(checksum_addres) def wait_for_blocks(