Skip to content

Commit

Permalink
progress in fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Mar 4, 2025
1 parent b8d8ed6 commit b2cfcac
Show file tree
Hide file tree
Showing 8 changed files with 638 additions and 607 deletions.
5 changes: 4 additions & 1 deletion counterparty-core/counterpartycore/lib/api/apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,10 @@ def create_method(**kwargs):
exceptions.BalanceError,
) as error:
# TypeError happens when unexpected keyword arguments are passed in
error_msg = f"Error composing {tx} transaction via API: {str(error)}"
import traceback

Check warning

Code scanning / pylint

Import outside toplevel (traceback). Warning

Import outside toplevel (traceback).

Check warning on line 615 in counterparty-core/counterpartycore/lib/api/apiv1.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/apiv1.py#L615

Added line #L615 was not covered by tests

print(traceback.format_exc())
error_msg = f"Error composing {tx} transaction via API: {str(error)} {traceback.format_exc()}"

Check warning on line 618 in counterparty-core/counterpartycore/lib/api/apiv1.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/apiv1.py#L617-L618

Added lines #L617 - L618 were not covered by tests
logger.trace(error_msg)
raise JSONRPCDispatchException(
code=JSON_RPC_ERROR_API_COMPOSE, message=error_msg
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def compose(
memo_bytes = bytes.fromhex(memo)

Check warning on line 75 in counterparty-core/counterpartycore/lib/messages/sweep.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/sweep.py#L75

Added line #L75 was not covered by tests
else:
memo_bytes = memo.encode("utf-8")
memo_bytes = struct.pack(f">{len(memo)}s", memo)
memo_bytes = struct.pack(f">{len(memo_bytes)}s", memo_bytes)

Check warning on line 78 in counterparty-core/counterpartycore/lib/messages/sweep.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/sweep.py#L77-L78

Added lines #L77 - L78 were not covered by tests

block_index = CurrentState().current_block_index()
problems, _total_fee = validate(db, source, destination, flags, memo_bytes, block_index)

Check warning on line 81 in counterparty-core/counterpartycore/lib/messages/sweep.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/sweep.py#L81

Added line #L81 was not covered by tests
Expand All @@ -98,7 +98,7 @@ def compose(
else:
data = messagetype.pack(ID)
data += struct.pack(FORMAT, short_address_bytes, flags)
data += memo
data += memo_bytes

Check warning on line 101 in counterparty-core/counterpartycore/lib/messages/sweep.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/sweep.py#L99-L101

Added lines #L99 - L101 were not covered by tests

return (source, [], data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def compose(
memo_bytes = bytes.fromhex(memo)
else:
memo_bytes = memo.encode("utf-8")
memo_bytes = struct.pack(f">{len(memo_bytes)}s", memo_bytes)

problems = validate(db, destination, asset, quantity, memo_bytes)
if problems and not skip_validation:
Expand All @@ -195,13 +196,13 @@ def compose(
memo_bytes,
]
)
logger.warning(f"data_content: {data_content}")
data += struct.pack(f">{len(data_content)}s", data_content)
logger.warning(f"data1: {data}")

Check warning

Code scanning / pylint

Use lazy % formatting in logging functions. Warning

Use lazy % formatting in logging functions.
else:
memo_bytes = struct.pack(f">{len(memo)}s", memo)
data = messagetype.pack(ID)
data += struct.pack(FORMAT, asset_id, quantity, short_address_bytes)
data += memo_bytes
logger.warning(f"data2: {data}")

Check warning

Code scanning / pylint

Use lazy % formatting in logging functions. Warning

Use lazy % formatting in logging functions.

Check warning on line 205 in counterparty-core/counterpartycore/lib/messages/versions/enhancedsend.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/versions/enhancedsend.py#L202-L205

Added lines #L202 - L205 were not covered by tests

cursor.close()
# return an empty array as the second argument because we don't need to send BTC dust to the recipient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def compose(
skip_validation: bool = False,
no_dispense: bool = False,
):
logger.warning("compose_send1")
cursor = db.cursor()

# Just send BTC?
Expand Down
1 change: 1 addition & 0 deletions counterparty-core/counterpartycore/lib/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def pack(address):
try:
validate(address) # This will check if the address is valid
short_address_bytes = bitcoin.base58.decode(address)[:-4]
print("short_address_bytes", short_address_bytes)

Check warning on line 103 in counterparty-core/counterpartycore/lib/utils/address.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/utils/address.py#L103

Added line #L103 was not covered by tests
return short_address_bytes
except Exception as e: # pylint: disable=broad-except # noqa: F841
raise exceptions.AddressError( # noqa: B904
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ def test_all_routes(
tx,
b"\x00\x00\x00\x00\x05\xf5\xe1\x00\x00\x00\x00\xa2[\xe3Kf\x00\x00\x00\x00\x00\x00\x00\x01",
)

tx = blockchain_mock.dummy_tx(ledger_db, defaults["addresses"][0])
message = b"o\x9c\x8d\x1fT\x05E\x1d\xe6\x07\x0b\xf1\xdb\x86\xabj\xcc\xb4\x95\xb6%\x01"
_source, _destination, data = sweep.compose(
ledger_db, defaults["addresses"][0], defaults["addresses"][1], 1, None, False
)
message = data[1:]
sweep.parse(ledger_db, tx, message)
apiwatcher.catch_up(ledger_db, state_db)

Expand Down
884 changes: 445 additions & 439 deletions counterparty-core/counterpartycore/test/units/api/apiv1_test.py

Large diffs are not rendered by default.

Loading

0 comments on commit b2cfcac

Please sign in to comment.