mirror of
https://github.com/basicswap/basicswap.git
synced 2026-06-10 04:51:41 +02:00
test: add test for underfunded itx
This commit is contained in:
+11
-5
@@ -6906,7 +6906,16 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
self.log.debug(
|
self.log.debug(
|
||||||
f"Create initiate txn for coin {ci.coin_name()} to {addr_to} for bid {self.log.id(bid_id)}"
|
f"Create initiate txn for coin {ci.coin_name()} to {addr_to} for bid {self.log.id(bid_id)}"
|
||||||
)
|
)
|
||||||
txn_signed = ci.createRawSignedTransaction(addr_to, bid.amount)
|
amount_from: int = bid.amount
|
||||||
|
if bid.debug_ind == DebugTypes.MAKE_INVALID_ITX:
|
||||||
|
amount_from -= 100
|
||||||
|
self.logBidEvent(
|
||||||
|
bid.bid_id,
|
||||||
|
EventLogTypes.DEBUG_TWEAK_APPLIED,
|
||||||
|
f"Make invalid ITx for testing: {bid.debug_ind}",
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
txn_signed = ci.createRawSignedTransaction(addr_to, amount_from)
|
||||||
|
|
||||||
txjs = ci.describeTx(txn_signed)
|
txjs = ci.describeTx(txn_signed)
|
||||||
vout = getVoutByAddress(txjs, addr_to)
|
vout = getVoutByAddress(txjs, addr_to)
|
||||||
@@ -6997,13 +7006,10 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
|
|
||||||
if bid.debug_ind == DebugTypes.MAKE_INVALID_PTX:
|
if bid.debug_ind == DebugTypes.MAKE_INVALID_PTX:
|
||||||
amount_to -= 1
|
amount_to -= 1
|
||||||
self.log.debug(
|
|
||||||
f"bid {self.log.id(bid_id)}: Make invalid PTx for testing: {bid.debug_ind}."
|
|
||||||
)
|
|
||||||
self.logBidEvent(
|
self.logBidEvent(
|
||||||
bid.bid_id,
|
bid.bid_id,
|
||||||
EventLogTypes.DEBUG_TWEAK_APPLIED,
|
EventLogTypes.DEBUG_TWEAK_APPLIED,
|
||||||
"ind {}".format(bid.debug_ind),
|
f"Make invalid PTx for testing: {bid.debug_ind}",
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ class DebugTypes(IntEnum):
|
|||||||
BID_DONT_SPEND_COIN_A_LOCK_REFUND2 = auto() # continues
|
BID_DONT_SPEND_COIN_A_LOCK_REFUND2 = auto() # continues
|
||||||
CREATE_INVALID_COIN_B_LOCK = auto()
|
CREATE_INVALID_COIN_B_LOCK = auto()
|
||||||
BUYER_STOP_AFTER_ITX = auto()
|
BUYER_STOP_AFTER_ITX = auto()
|
||||||
|
MAKE_INVALID_ITX = auto()
|
||||||
MAKE_INVALID_PTX = auto()
|
MAKE_INVALID_PTX = auto()
|
||||||
DONT_SPEND_ITX = auto()
|
DONT_SPEND_ITX = auto()
|
||||||
SKIP_LOCK_TX_REFUND = auto()
|
SKIP_LOCK_TX_REFUND = auto()
|
||||||
|
|||||||
+39
-23
@@ -26,11 +26,13 @@ from basicswap.basicswap import (
|
|||||||
TxStates,
|
TxStates,
|
||||||
)
|
)
|
||||||
from basicswap.basicswap_util import (
|
from basicswap.basicswap_util import (
|
||||||
|
EventLogTypes,
|
||||||
TxLockTypes,
|
TxLockTypes,
|
||||||
)
|
)
|
||||||
from basicswap.chainparams import (
|
from basicswap.chainparams import (
|
||||||
chainparams,
|
chainparams,
|
||||||
)
|
)
|
||||||
|
from basicswap.db import Concepts
|
||||||
from basicswap.util import (
|
from basicswap.util import (
|
||||||
COIN,
|
COIN,
|
||||||
make_int,
|
make_int,
|
||||||
@@ -47,6 +49,7 @@ from tests.basicswap.common import (
|
|||||||
wait_for_balance,
|
wait_for_balance,
|
||||||
wait_for_bid,
|
wait_for_bid,
|
||||||
wait_for_bid_tx_state,
|
wait_for_bid_tx_state,
|
||||||
|
wait_for_event,
|
||||||
wait_for_in_progress,
|
wait_for_in_progress,
|
||||||
wait_for_offer,
|
wait_for_offer,
|
||||||
wait_for_unspent,
|
wait_for_unspent,
|
||||||
@@ -850,7 +853,6 @@ class Test(BaseTest):
|
|||||||
swap_clients = self.swap_clients
|
swap_clients = self.swap_clients
|
||||||
|
|
||||||
swap_value = make_int(random.uniform(0.001, 10.0), scale=8, r=1)
|
swap_value = make_int(random.uniform(0.001, 10.0), scale=8, r=1)
|
||||||
logging.info("swap_value {}".format(format_amount(swap_value, 8)))
|
|
||||||
offer_id = swap_clients[0].postOffer(
|
offer_id = swap_clients[0].postOffer(
|
||||||
Coins.LTC,
|
Coins.LTC,
|
||||||
Coins.BTC,
|
Coins.BTC,
|
||||||
@@ -879,15 +881,15 @@ class Test(BaseTest):
|
|||||||
)
|
)
|
||||||
wait_for_bid(
|
wait_for_bid(
|
||||||
test_delay_event,
|
test_delay_event,
|
||||||
swap_clients[1],
|
swap_clients[0],
|
||||||
bid_id,
|
bid_id,
|
||||||
BidStates.SWAP_COMPLETED,
|
BidStates.SWAP_COMPLETED,
|
||||||
sent=True,
|
sent=True,
|
||||||
wait_for=30,
|
wait_for=30,
|
||||||
)
|
)
|
||||||
|
|
||||||
js_0_bid = read_json_api(1800, "bids/{}".format(bid_id.hex()))
|
js_0_bid = read_json_api(1800, f"bids/{bid_id.hex()}")
|
||||||
js_1_bid = read_json_api(1801, "bids/{}".format(bid_id.hex()))
|
js_1_bid = read_json_api(1801, f"bids/{bid_id.hex()}")
|
||||||
assert js_0_bid["itx_state"] == "Refunded"
|
assert js_0_bid["itx_state"] == "Refunded"
|
||||||
assert js_1_bid["ptx_state"] == "Refunded"
|
assert js_1_bid["ptx_state"] == "Refunded"
|
||||||
|
|
||||||
@@ -904,38 +906,52 @@ class Test(BaseTest):
|
|||||||
assert compare_bid_states(offerer_states, self.states_offerer_sh[1]) is True
|
assert compare_bid_states(offerer_states, self.states_offerer_sh[1]) is True
|
||||||
assert compare_bid_states(bidder_states, self.states_bidder_sh[1]) is True
|
assert compare_bid_states(bidder_states, self.states_bidder_sh[1]) is True
|
||||||
|
|
||||||
"""
|
def test_11_bad_itx(self):
|
||||||
def test_11_refund(self):
|
# Invalid ITx sent, PTx should not be sent
|
||||||
# Seller submits initiate txn, buyer doesn't respond, repeat of test 5 using debug_ind
|
logging.info("---------- Test bad ITx, LTC to BTC")
|
||||||
logging.info('---------- Test refund, LTC to BTC')
|
|
||||||
swap_clients = self.swap_clients
|
swap_clients = self.swap_clients
|
||||||
|
|
||||||
swap_value = make_int(random.uniform(0.001, 10.0), scale=8, r=1)
|
swap_value = make_int(random.uniform(0.001, 10.0), scale=8, r=1)
|
||||||
logging.info('swap_value {}'.format(format_amount(swap_value, 8)))
|
offer_id = swap_clients[0].postOffer(
|
||||||
offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, swap_value, 0.1 * COIN, swap_value, SwapTypes.SELLER_FIRST,
|
Coins.LTC,
|
||||||
TxLockTypes.SEQUENCE_LOCK_BLOCKS, 10)
|
Coins.BTC,
|
||||||
|
swap_value,
|
||||||
|
0.1 * COIN,
|
||||||
|
swap_value,
|
||||||
|
SwapTypes.SELLER_FIRST,
|
||||||
|
TxLockTypes.SEQUENCE_LOCK_BLOCKS,
|
||||||
|
18,
|
||||||
|
)
|
||||||
|
|
||||||
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
wait_for_offer(test_delay_event, swap_clients[1], offer_id)
|
||||||
offer = swap_clients[1].getOffer(offer_id)
|
offer = swap_clients[1].getOffer(offer_id)
|
||||||
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
|
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
|
||||||
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BUYER_STOP_AFTER_ITX)
|
|
||||||
|
|
||||||
wait_for_bid(test_delay_event, swap_clients[0], bid_id)
|
wait_for_bid(test_delay_event, swap_clients[0], bid_id)
|
||||||
|
swap_clients[0].setBidDebugInd(bid_id, DebugTypes.MAKE_INVALID_ITX)
|
||||||
swap_clients[0].acceptBid(bid_id)
|
swap_clients[0].acceptBid(bid_id)
|
||||||
|
|
||||||
wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=120)
|
event = wait_for_event(
|
||||||
wait_for_bid(test_delay_event, swap_clients[1], bid_id, BidStates.BID_ABANDONED, sent=True, wait_for=30)
|
test_delay_event,
|
||||||
|
swap_clients[1],
|
||||||
|
Concepts.BID,
|
||||||
|
bid_id,
|
||||||
|
event_type=EventLogTypes.ERROR,
|
||||||
|
wait_for=120,
|
||||||
|
)
|
||||||
|
assert "Incorrect output amount in initiate txn " in event.event_msg
|
||||||
|
|
||||||
js_0_bid = read_json_api(1800, 'bids/{}'.format(bid_id.hex()))
|
wait_for_bid(
|
||||||
js_1_bid = read_json_api(1801, 'bids/{}'.format(bid_id.hex()))
|
test_delay_event,
|
||||||
assert (js_0_bid['itx_state'] == 'Refunded')
|
swap_clients[1],
|
||||||
assert (js_1_bid['ptx_state'] == 'Unknown')
|
bid_id,
|
||||||
|
BidStates.BID_ERROR,
|
||||||
|
sent=True,
|
||||||
|
wait_for=30,
|
||||||
|
)
|
||||||
|
|
||||||
js_0 = read_json_api(1800)
|
js_1_bid = read_json_api(1801, f"bids/{bid_id.hex()}")
|
||||||
js_1 = read_json_api(1801)
|
assert js_1_bid["ptx_state"] == "Unknown"
|
||||||
assert (js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
|
|
||||||
assert (js_1['num_swapping'] == 0 and js_1['num_watched_outputs'] == 0)
|
|
||||||
"""
|
|
||||||
|
|
||||||
def test_12_withdrawal(self):
|
def test_12_withdrawal(self):
|
||||||
logging.info("---------- Test LTC withdrawals")
|
logging.info("---------- Test LTC withdrawals")
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ from copy import deepcopy
|
|||||||
from coincurve.keys import PrivateKey
|
from coincurve.keys import PrivateKey
|
||||||
|
|
||||||
import basicswap.config as cfg
|
import basicswap.config as cfg
|
||||||
from basicswap.db import (
|
from basicswap.db import Concepts
|
||||||
Concepts,
|
|
||||||
)
|
|
||||||
from basicswap.basicswap import (
|
from basicswap.basicswap import (
|
||||||
Coins,
|
Coins,
|
||||||
BasicSwap,
|
BasicSwap,
|
||||||
|
|||||||
Reference in New Issue
Block a user