Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Oct 2, 2024
1 parent 2b47612 commit 0578634
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion counterparty-core/counterpartycore/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pycoin.coins.bitcoin import Tx # noqa: F401

from counterpartycore import server
from counterpartycore.lib import arc4, config, database, ledger, log, script, util
from counterpartycore.lib import arc4, config, database, exceptions, ledger, log, script, util
from counterpartycore.lib.api import api_server as api_v2
from counterpartycore.lib.api import api_v1 as api
from counterpartycore.test import util_test
Expand Down Expand Up @@ -595,6 +595,22 @@ def get_utxo_address_and_value(value):
def get_transaction_fee(db, transaction_type, block_index):
return 10

def determine_encoding(
data, desired_encoding="auto", op_return_max_size=config.OP_RETURN_MAX_SIZE
):
if desired_encoding == "auto":
if len(data) + len(config.PREFIX) <= op_return_max_size:
encoding = "opreturn"
else:
encoding = "multisig"
else:
encoding = desired_encoding

if encoding not in ("pubkeyhash", "multisig", "opreturn", "p2sh"):
raise exceptions.TransactionError("Unknown encoding‐scheme.")

return encoding

monkeypatch.setattr("counterpartycore.lib.transaction.arc4.init_arc4", init_arc4)
monkeypatch.setattr(
"counterpartycore.lib.backend.addrindexrs.get_unspent_txouts", get_unspent_txouts
Expand Down Expand Up @@ -637,3 +653,4 @@ def get_transaction_fee(db, transaction_type, block_index):
)

monkeypatch.setattr("counterpartycore.lib.gas.get_transaction_fee", get_transaction_fee)
monkeypatch.setattr("counterpartycore.lib.transaction.determine_encoding", determine_encoding)
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
None,
),
{"encoding": "singlesig", "regular_dust_size": DP["regular_dust_size"]},
{"encoding": "opreturn", "regular_dust_size": DP["regular_dust_size"]},
),
"error": (exceptions.TransactionError, "Destination output is dust."),
},
Expand Down

0 comments on commit 0578634

Please sign in to comment.