Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions counterparty-core/counterpartycore/lib/messages/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
logger = logging.getLogger(config.LOGGER_NAME)

ID = 101
MAX_BTC_OUTPUT_VALUE = 21_000_000 * config.UNIT


def validate_asset_and_quantity(asset, quantity):
Expand Down Expand Up @@ -115,6 +116,8 @@ def compose(
value = int(utxo_value)
except ValueError as e:
raise exceptions.ComposeError(["utxo_value must be an integer"]) from e
if value < 0 or value > MAX_BTC_OUTPUT_VALUE:
raise exceptions.ComposeError(["utxo_value must be a valid bitcoin output amount"])
# else we use the source address as the destination
destinations.append((source, value))

Expand Down
4 changes: 4 additions & 0 deletions counterparty-core/counterpartycore/lib/messages/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

logger = logging.getLogger(config.LOGGER_NAME)

MAX_BTC_OUTPUT_VALUE = 21_000_000 * config.UNIT


def compose(db, source, destination, utxo_value=None, skip_validation=False):
if not skip_validation:
Expand All @@ -28,6 +30,8 @@ def compose(db, source, destination, utxo_value=None, skip_validation=False):
value = int(utxo_value)
except ValueError as e:
raise exceptions.ComposeError(["utxo_value must be an integer"]) from e
if value < 0 or value > MAX_BTC_OUTPUT_VALUE:
raise exceptions.ComposeError(["utxo_value must be a valid bitcoin output amount"])

return (source, [(destination, value)], None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def test_compose(ledger_db, defaults):
b"eXCP|100|",
)

with pytest.raises(
exceptions.ComposeError, match="utxo_value must be a valid bitcoin output amount"
):
attach.compose(ledger_db, address_0, "XCP", 100, -1)

with pytest.raises(
exceptions.ComposeError, match="utxo_value must be a valid bitcoin output amount"
):
attach.compose(ledger_db, address_0, "XCP", 100, 21_000_000 * config.UNIT + 1)

with pytest.raises(exceptions.ComposeError, match="invalid source address"):
attach.compose(ledger_db, DUMMY_UTXO, "XCP", 100)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from counterpartycore.lib import exceptions
from counterpartycore.lib import config, exceptions
from counterpartycore.lib.messages import move

DUMMY_UTXO = 64 * "0" + ":0"
Expand Down Expand Up @@ -223,3 +223,18 @@ def test_compose(ledger_db, defaults):

with pytest.raises(exceptions.ComposeError, match="utxo_value must be an integer"):
move.compose(ledger_db, utxo, defaults["addresses"][0], utxo_value="string")

with pytest.raises(
exceptions.ComposeError, match="utxo_value must be a valid bitcoin output amount"
):
move.compose(ledger_db, utxo, defaults["addresses"][0], utxo_value=-1)

with pytest.raises(
exceptions.ComposeError, match="utxo_value must be a valid bitcoin output amount"
):
move.compose(
ledger_db,
utxo,
defaults["addresses"][0],
utxo_value=21_000_000 * config.UNIT + 1,
)