Skip to content

Commit

Permalink
Merge branch 'beta' into merge-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
badrogger committed Oct 18, 2023
2 parents 129630f + f66a4e0 commit 374da86
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.4
2.1.5
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
skale.py==5.8dev4
skale.py==6.0dev0
4 changes: 2 additions & 2 deletions tests/docker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
4 changes: 2 additions & 2 deletions tests/processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
31 changes: 21 additions & 10 deletions tests/transaction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions transaction_manager/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions transaction_manager/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 374da86

Please sign in to comment.