tests: Use debug_ind in non-xmr swaps.

This commit is contained in:
tecnovert 2021-01-30 16:29:07 +02:00
parent 2e0edef9da
commit df732713ac
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
8 changed files with 149 additions and 62 deletions

View file

@ -1,3 +1,3 @@
name = "basicswap" name = "basicswap"
__version__ = "0.0.14" __version__ = "0.0.15"

View file

@ -211,6 +211,8 @@ class DebugTypes(IntEnum):
BID_STOP_AFTER_COIN_A_LOCK = auto() BID_STOP_AFTER_COIN_A_LOCK = auto()
BID_DONT_SPEND_COIN_A_LOCK_REFUND = auto() BID_DONT_SPEND_COIN_A_LOCK_REFUND = auto()
CREATE_INVALID_COIN_B_LOCK = auto() CREATE_INVALID_COIN_B_LOCK = auto()
BUYER_STOP_AFTER_ITX = auto()
MAKE_INVALID_PTX = auto()
SEQUENCE_LOCK_BLOCKS = 1 SEQUENCE_LOCK_BLOCKS = 1
@ -754,11 +756,12 @@ class BasicSwap(BaseApp):
session.remove() session.remove()
self.log.info('Upgraded database to version {}'.format(self.db_version)) self.log.info('Upgraded database to version {}'.format(self.db_version))
continue continue
if db_version == 4: if db_version == 7:
session = scoped_session(self.session_factory) session = scoped_session(self.session_factory)
session.execute('ALTER TABLE bids ADD COLUMN withdraw_to_addr TEXT') session.execute('ALTER TABLE transactions ADD COLUMN block_hash BLOB')
session.execute('ALTER TABLE offers ADD COLUMN withdraw_to_addr TEXT') session.execute('ALTER TABLE transactions ADD COLUMN block_height INTEGER')
session.execute('ALTER TABLE transactions ADD COLUMN block_time INTEGER')
db_version += 1 db_version += 1
self.db_version = db_version self.db_version = db_version
@ -1181,7 +1184,7 @@ class BasicSwap(BaseApp):
offer = session.query(Offer).filter_by(offer_id=offer_id).first() offer = session.query(Offer).filter_by(offer_id=offer_id).first()
if len(offer.security_token > 0) and offer.security_token != security_token: if offer.security_token is not None and offer.security_token != security_token:
raise ValueError('Mismatched security token') raise ValueError('Mismatched security token')
msg_buf = OfferRevokeMessage() msg_buf = OfferRevokeMessage()
@ -1551,7 +1554,19 @@ class BasicSwap(BaseApp):
linked_id=bid.bid_id, linked_id=bid.bid_id,
event_type=int(event_type), event_type=int(event_type),
event_msg=event_msg) event_msg=event_msg)
if session is not None:
session.add(entry) session.add(entry)
return
self.mxDB.acquire()
try:
session = scoped_session(self.session_factory)
session.add(entry)
session.commit()
finally:
session.close()
session.remove()
self.mxDB.release()
def countBidEvents(self, bid, event_type, session): def countBidEvents(self, bid, event_type, session):
q = session.execute('SELECT COUNT(*) FROM eventlog WHERE linked_type = {} AND linked_id = x\'{}\' AND event_type = {}'.format(int(TableTypes.BID), bid.bid_id.hex(), int(event_type))).first() q = session.execute('SELECT COUNT(*) FROM eventlog WHERE linked_type = {} AND linked_id = x\'{}\' AND event_type = {}'.format(int(TableTypes.BID), bid.bid_id.hex(), int(event_type))).first()
@ -1748,11 +1763,11 @@ class BasicSwap(BaseApp):
xmr_swap = session.query(XmrSwap).filter_by(bid_id=bid.bid_id).first() xmr_swap = session.query(XmrSwap).filter_by(bid_id=bid.bid_id).first()
xmr_offer = session.query(XmrOffer).filter_by(offer_id=bid.offer_id).first() xmr_offer = session.query(XmrOffer).filter_by(offer_id=bid.offer_id).first()
self.loadBidTxns(bid, session) self.loadBidTxns(bid, session)
if list_events:
events = self.list_bid_events(bid.bid_id, session)
else: else:
bid.initiate_tx = session.query(SwapTx).filter(sa.and_(SwapTx.bid_id == bid_id, SwapTx.tx_type == TxTypes.ITX)).first() bid.initiate_tx = session.query(SwapTx).filter(sa.and_(SwapTx.bid_id == bid_id, SwapTx.tx_type == TxTypes.ITX)).first()
bid.participate_tx = session.query(SwapTx).filter(sa.and_(SwapTx.bid_id == bid_id, SwapTx.tx_type == TxTypes.PTX)).first() bid.participate_tx = session.query(SwapTx).filter(sa.and_(SwapTx.bid_id == bid_id, SwapTx.tx_type == TxTypes.PTX)).first()
if list_events:
events = self.list_bid_events(bid.bid_id, session)
return bid, xmr_swap, offer, xmr_offer, events return bid, xmr_swap, offer, xmr_offer, events
finally: finally:
@ -2198,7 +2213,6 @@ class BasicSwap(BaseApp):
cblock_height = blockchaininfo['blocks'] cblock_height = blockchaininfo['blocks']
max_tries = 1000 max_tries = 1000
for i in range(max_tries): for i in range(max_tries):
self.log.debug('wtf %d', i)
prev_block = self.callcoinrpc(coin_to, 'getblock', [cblock_hash, ]) prev_block = self.callcoinrpc(coin_to, 'getblock', [cblock_hash, ])
self.log.debug('prev_block %s', str(prev_block)) self.log.debug('prev_block %s', str(prev_block))
@ -2232,6 +2246,11 @@ class BasicSwap(BaseApp):
# Check required? # Check required?
assert(amount_to == (bid.amount * offer.rate) // self.ci(offer.coin_from).COIN()) assert(amount_to == (bid.amount * offer.rate) // self.ci(offer.coin_from).COIN())
if bid.debug_ind == DebugTypes.MAKE_INVALID_PTX:
amount_to -= 1
self.log.debug('bid %s: Make invalid PTx for testing: %d.', bid_id.hex(), bid.debug_ind)
self.logBidEvent(bid, EventLogTypes.DEBUG_TWEAK_APPLIED, 'ind {}'.format(bid.debug_ind), None)
if self.coin_clients[coin_to]['use_segwit']: if self.coin_clients[coin_to]['use_segwit']:
p2wsh = getP2WSH(participate_script) p2wsh = getP2WSH(participate_script)
addr_to = self.encodeSegwitP2WSH(coin_to, p2wsh) addr_to = self.encodeSegwitP2WSH(coin_to, p2wsh)
@ -2491,6 +2510,12 @@ class BasicSwap(BaseApp):
bid.setState(BidStates.SWAP_INITIATED) bid.setState(BidStates.SWAP_INITIATED)
bid.setITxState(TxStates.TX_CONFIRMED) bid.setITxState(TxStates.TX_CONFIRMED)
if bid.debug_ind == DebugTypes.BUYER_STOP_AFTER_ITX:
self.log.debug('bid %s: Abandoning bid for testing: %d.', bid_id.hex(), bid.debug_ind)
bid.setState(BidStates.BID_ABANDONED)
self.logBidEvent(bid, EventLogTypes.DEBUG_TWEAK_APPLIED, 'ind {}'.format(bid.debug_ind), None)
return # Bid saved in checkBidState
# Seller first mode, buyer participates # Seller first mode, buyer participates
participate_script = self.deriveParticipateScript(bid_id, bid, offer) participate_script = self.deriveParticipateScript(bid_id, bid, offer)
if bid.was_sent: if bid.was_sent:
@ -2511,7 +2536,7 @@ class BasicSwap(BaseApp):
script=participate_script, script=participate_script,
) )
# bid saved in checkBidState # Bid saved in checkBidState
def setLastHeightChecked(self, coin_type, tx_height): def setLastHeightChecked(self, coin_type, tx_height):
chain_name = chainparams[coin_type]['name'] chain_name = chainparams[coin_type]['name']
@ -2661,6 +2686,7 @@ class BasicSwap(BaseApp):
bid.setState(BidStates.BID_ABANDONED) bid.setState(BidStates.BID_ABANDONED)
rv = True rv = True
self.saveBidInSession(bid_id, bid, session, xmr_swap) self.saveBidInSession(bid_id, bid, session, xmr_swap)
self.logBidEvent(bid, EventLogTypes.DEBUG_TWEAK_APPLIED, 'ind {}'.format(bid.debug_ind), session)
session.commit() session.commit()
return rv return rv
@ -2872,6 +2898,9 @@ class BasicSwap(BaseApp):
coin_to = Coins(offer.coin_to) coin_to = Coins(offer.coin_to)
# TODO: Batch calls to scantxoutset # TODO: Batch calls to scantxoutset
# TODO: timeouts # TODO: timeouts
if state == BidStates.BID_ABANDONED:
self.log.info('Deactivating abandoned bid: %s', bid_id.hex())
return True # Mark bid for archiving
if state == BidStates.BID_ACCEPTED: if state == BidStates.BID_ACCEPTED:
# Waiting for initiate txn to be confirmed in 'from' chain # Waiting for initiate txn to be confirmed in 'from' chain
initiate_txnid_hex = bid.initiate_tx.txid.hex() initiate_txnid_hex = bid.initiate_tx.txid.hex()
@ -4089,6 +4118,7 @@ class BasicSwap(BaseApp):
if bid.debug_ind == DebugTypes.CREATE_INVALID_COIN_B_LOCK: if bid.debug_ind == DebugTypes.CREATE_INVALID_COIN_B_LOCK:
self.log.debug('XMR bid %s: Debug %d - Reducing lock b txn amount by 10%%.', bid_id.hex(), bid.debug_ind) self.log.debug('XMR bid %s: Debug %d - Reducing lock b txn amount by 10%%.', bid_id.hex(), bid.debug_ind)
bid.amount_to -= int(bid.amount_to * 0.1) bid.amount_to -= int(bid.amount_to * 0.1)
self.logBidEvent(bid, EventLogTypes.DEBUG_TWEAK_APPLIED, 'ind {}'.format(bid.debug_ind), session)
try: try:
b_lock_tx_id = ci_to.publishBLockTx(xmr_swap.pkbv, xmr_swap.pkbs, bid.amount_to, xmr_offer.b_fee_rate) b_lock_tx_id = ci_to.publishBLockTx(xmr_swap.pkbv, xmr_swap.pkbs, bid.amount_to, xmr_offer.b_fee_rate)
except Exception as ex: except Exception as ex:

View file

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2019-2020 tecnovert # Copyright (c) 2019-2021 tecnovert
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
from enum import IntEnum from enum import IntEnum
from .util import ( from .util import (
COIN, COIN,
make_int,
format_amount, format_amount,
make_int
) )
XMR_COIN = 10 ** 12 XMR_COIN = 10 ** 12

View file

@ -12,7 +12,7 @@ from sqlalchemy.ext.declarative import declarative_base
from enum import IntEnum, auto from enum import IntEnum, auto
CURRENT_DB_VERSION = 7 CURRENT_DB_VERSION = 8
Base = declarative_base() Base = declarative_base()
@ -178,6 +178,10 @@ class SwapTx(Base):
spend_txid = sa.Column(sa.LargeBinary) spend_txid = sa.Column(sa.LargeBinary)
spend_n = sa.Column(sa.Integer) spend_n = sa.Column(sa.Integer)
block_hash = sa.Column(sa.LargeBinary)
block_height = sa.Column(sa.Integer)
block_time = sa.Column(sa.BigInteger)
state = sa.Column(sa.Integer) state = sa.Column(sa.Integer)
states = sa.Column(sa.LargeBinary) # Packed states and times states = sa.Column(sa.LargeBinary) # Packed states and times

View file

@ -736,6 +736,9 @@ class HttpHandler(BaseHTTPRequestHandler):
data = describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, events, edit_bid, show_txns, view_tx_ind) data = describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, events, edit_bid, show_txns, view_tx_ind)
if bid.debug_ind is not None and bid.debug_ind > 0:
messages.append('Debug flag set: {}'.format(bid.debug_ind))
old_states = [] old_states = []
num_states = len(bid.states) // 12 num_states = len(bid.states) // 12
for i in range(num_states): for i in range(num_states):

View file

@ -79,6 +79,14 @@
{% endfor %} {% endfor %}
</table> </table>
<h4>Events</h4>
<table>
<tr><th>At</th><th>Event</th></tr>
{% for e in data.events %}
<tr><td>{{ e.at | formatts }}</td><td>{{ e.desc }}</td></tr>
{% endfor %}
</table>
<p><a href="/">home</a></p> <p><a href="/">home</a></p>
<script> <script>
function confirmPopup() { function confirmPopup() {

View file

@ -174,6 +174,7 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
'participate_conf': 'None' if (not bid.participate_tx or not bid.participate_tx.conf) else bid.participate_tx.conf, 'participate_conf': 'None' if (not bid.participate_tx or not bid.participate_tx.conf) else bid.participate_tx.conf,
'show_txns': show_txns, 'show_txns': show_txns,
'can_abandon': True if bid.state not in (BidStates.BID_ABANDONED, BidStates.SWAP_COMPLETED) else False, 'can_abandon': True if bid.state not in (BidStates.BID_ABANDONED, BidStates.SWAP_COMPLETED) else False,
'events': bid_events,
} }
if edit_bid: if edit_bid:
@ -225,6 +226,4 @@ def describeBid(swap_client, bid, xmr_swap, offer, xmr_offer, bid_events, edit_b
if view_tx_id == xmr_swap.a_lock_refund_spend_tx_id and xmr_swap.a_lock_refund_spend_tx: if view_tx_id == xmr_swap.a_lock_refund_spend_tx_id and xmr_swap.a_lock_refund_spend_tx:
data['view_tx_hex'] = xmr_swap.a_lock_refund_spend_tx.hex() data['view_tx_hex'] = xmr_swap.a_lock_refund_spend_tx.hex()
data['events'] = bid_events
return data return data

View file

@ -17,6 +17,7 @@ import os
import sys import sys
import json import json
import time import time
import random
import shutil import shutil
import signal import signal
import logging import logging
@ -31,12 +32,15 @@ from basicswap.basicswap import (
SwapTypes, SwapTypes,
BidStates, BidStates,
TxStates, TxStates,
DebugTypes,
SEQUENCE_LOCK_BLOCKS, SEQUENCE_LOCK_BLOCKS,
) )
from basicswap.util import ( from basicswap.util import (
COIN, COIN,
toWIF, toWIF,
dumpje, dumpje,
make_int,
format_amount,
) )
from basicswap.rpc import ( from basicswap.rpc import (
callrpc_cli, callrpc_cli,
@ -442,9 +446,7 @@ class Test(unittest.TestCase):
offer_id = swap_clients[1].postOffer(Coins.LTC, Coins.PART, 10 * COIN, 9.0 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST) offer_id = swap_clients[1].postOffer(Coins.LTC, Coins.PART, 10 * COIN, 9.0 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
wait_for_offer(delay_event, swap_clients[0], offer_id) wait_for_offer(delay_event, swap_clients[0], offer_id)
offers = swap_clients[0].listOffers() offer = swap_clients[0].getOffer(offer_id)
for offer in offers:
if offer.offer_id == offer_id:
bid_id = swap_clients[0].postBid(offer_id, offer.amount_from) bid_id = swap_clients[0].postBid(offer_id, offer.amount_from)
wait_for_bid(delay_event, swap_clients[1], bid_id) wait_for_bid(delay_event, swap_clients[1], bid_id)
@ -467,9 +469,7 @@ class Test(unittest.TestCase):
offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST) offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
wait_for_offer(delay_event, swap_clients[1], offer_id) wait_for_offer(delay_event, swap_clients[1], offer_id)
offers = swap_clients[1].listOffers() offer = swap_clients[1].getOffer(offer_id)
for offer in offers:
if offer.offer_id == offer_id:
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from) bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
wait_for_bid(delay_event, swap_clients[0], bid_id) wait_for_bid(delay_event, swap_clients[0], bid_id)
@ -497,9 +497,7 @@ class Test(unittest.TestCase):
SEQUENCE_LOCK_BLOCKS, 10) SEQUENCE_LOCK_BLOCKS, 10)
wait_for_offer(delay_event, swap_clients[1], offer_id) wait_for_offer(delay_event, swap_clients[1], offer_id)
offers = swap_clients[1].listOffers() offer = swap_clients[1].getOffer(offer_id)
for offer in offers:
if offer.offer_id == offer_id:
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from) bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
wait_for_bid(delay_event, swap_clients[0], bid_id) wait_for_bid(delay_event, swap_clients[0], bid_id)
@ -509,6 +507,11 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60) wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.BID_ABANDONED, sent=True, wait_for=60) wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.BID_ABANDONED, sent=True, wait_for=60)
js_0_bid = json.loads(urlopen('http://127.0.0.1:1800/json/bids/{}'.format(bid_id.hex())).read())
js_1_bid = json.loads(urlopen('http://127.0.0.1:1801/json/bids/{}'.format(bid_id.hex())).read())
assert(js_0_bid['itx_state'] == 'Refunded')
assert(js_1_bid['ptx_state'] == 'Unknown')
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read()) js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read()) js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0) assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
@ -523,9 +526,8 @@ class Test(unittest.TestCase):
offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST) offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)
wait_for_offer(delay_event, swap_clients[0], offer_id) wait_for_offer(delay_event, swap_clients[0], offer_id)
offer = swap_clients[0].getOffer(offer_id)
offers = swap_clients[0].listOffers() offers = swap_clients[0].listOffers()
for offer in offers:
if offer.offer_id == offer_id:
bid_id = swap_clients[0].postBid(offer_id, offer.amount_from) bid_id = swap_clients[0].postBid(offer_id, offer.amount_from)
wait_for_bid(delay_event, swap_clients[0], bid_id) wait_for_bid(delay_event, swap_clients[0], bid_id)
@ -547,9 +549,7 @@ class Test(unittest.TestCase):
offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 0.001 * COIN, 1.0 * COIN, 0.001 * COIN, SwapTypes.SELLER_FIRST) offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 0.001 * COIN, 1.0 * COIN, 0.001 * COIN, SwapTypes.SELLER_FIRST)
wait_for_offer(delay_event, swap_clients[0], offer_id) wait_for_offer(delay_event, swap_clients[0], offer_id)
offers = swap_clients[0].listOffers() offer = swap_clients[0].getOffer(offer_id)
for offer in offers:
if offer.offer_id == offer_id:
bid_id = swap_clients[0].postBid(offer_id, offer.amount_from) bid_id = swap_clients[0].postBid(offer_id, offer.amount_from)
wait_for_bid(delay_event, swap_clients[0], bid_id) wait_for_bid(delay_event, swap_clients[0], bid_id)
@ -569,28 +569,7 @@ class Test(unittest.TestCase):
offer_id = swap_clients[0].postOffer(Coins.PART, Coins.LTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.BUYER_FIRST) offer_id = swap_clients[0].postOffer(Coins.PART, Coins.LTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.BUYER_FIRST)
return # TODO logging.warning('TODO')
wait_for_offer(delay_event, swap_clients[1], offer_id)
offers = swap_clients[1].listOffers()
assert(len(offers) == 1)
for offer in offers:
if offer.offer_id == offer_id:
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
wait_for_bid(delay_event, swap_clients[0], bid_id)
swap_clients[0].acceptBid(bid_id)
wait_for_in_progress(delay_event, swap_clients[1], bid_id, sent=True)
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
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_09_part_ltc_auto_accept(self): def test_09_part_ltc_auto_accept(self):
logging.info('---------- Test PART to LTC, auto accept bid') logging.info('---------- Test PART to LTC, auto accept bid')
@ -608,6 +587,70 @@ class Test(unittest.TestCase):
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60) wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60) wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
def test_10_bad_ptx(self):
# Invalid PTX sent, swap should stall and ITx and PTx should be reclaimed by senders
logging.info('---------- Test bad PTx, LTC to BTC')
swap_clients = self.swap_clients
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(Coins.LTC, Coins.BTC, swap_value, 0.1 * COIN, swap_value, SwapTypes.SELLER_FIRST,
SEQUENCE_LOCK_BLOCKS, 10)
wait_for_offer(delay_event, swap_clients[1], offer_id)
offer = swap_clients[1].getOffer(offer_id)
bid_id = swap_clients[1].postBid(offer_id, offer.amount_from)
swap_clients[1].setBidDebugInd(bid_id, DebugTypes.MAKE_INVALID_PTX)
wait_for_bid(delay_event, swap_clients[0], bid_id)
swap_clients[0].acceptBid(bid_id)
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=120)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=120)
js_0_bid = json.loads(urlopen('http://127.0.0.1:1800/json/bids/{}'.format(bid_id.hex())).read())
js_1_bid = json.loads(urlopen('http://127.0.0.1:1801/json/bids/{}'.format(bid_id.hex())).read())
assert(js_0_bid['itx_state'] == 'Refunded')
assert(js_1_bid['ptx_state'] == 'Refunded')
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
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_11_refund(self):
# Seller submits initiate txn, buyer doesn't respond, repeat of test 5 using debug_ind
logging.info('---------- Test refund, LTC to BTC')
swap_clients = self.swap_clients
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(Coins.LTC, Coins.BTC, swap_value, 0.1 * COIN, swap_value, SwapTypes.SELLER_FIRST,
SEQUENCE_LOCK_BLOCKS, 10)
wait_for_offer(delay_event, swap_clients[1], offer_id)
offer = swap_clients[1].getOffer(offer_id)
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(delay_event, swap_clients[0], bid_id)
swap_clients[0].acceptBid(bid_id)
wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=120)
wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.BID_ABANDONED, sent=True, wait_for=120)
js_0_bid = json.loads(urlopen('http://127.0.0.1:1800/json/bids/{}'.format(bid_id.hex())).read())
js_1_bid = json.loads(urlopen('http://127.0.0.1:1801/json/bids/{}'.format(bid_id.hex())).read())
assert(js_0_bid['itx_state'] == 'Refunded')
assert(js_1_bid['ptx_state'] == 'Unknown')
js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
js_1 = json.loads(urlopen('http://127.0.0.1:1801/json').read())
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 pass_99_delay(self): def pass_99_delay(self):
global stop_test global stop_test
logging.info('Delay') logging.info('Delay')