Ejemplo n.º 1
0
    def test_05_refund(self):
        # Seller submits initiate txn, buyer doesn't respond
        logging.info('---------- Test refund, NMC to BTC')
        swap_clients = self.swap_clients

        offer_id = swap_clients[0].postOffer(Coins.NMC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST,
                                             ABS_LOCK_BLOCKS, 10)

        wait_for_offer(delay_event, swap_clients[1], offer_id)
        offers = swap_clients[1].listOffers()
        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[1].abandonBid(bid_id)
        swap_clients[0].acceptBid(bid_id)

        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)

        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)
Ejemplo n.º 2
0
    def test_02_part_ltc(self):
        logging.info('---------- Test PART to LTC')
        swap_clients = self.swap_clients

        offer_id = swap_clients[0].postOffer(Coins.PART, Coins.LTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.SELLER_FIRST)

        wait_for_offer(test_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(test_delay_event, swap_clients[0], bid_id)

        swap_clients[0].acceptBid(bid_id)

        wait_for_in_progress(test_delay_event, swap_clients[1], bid_id, sent=True)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
        wait_for_bid(test_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)
Ejemplo n.º 3
0
    def test_10_locked_refundtx(self):
        logging.info('---------- Test Refund tx is locked')
        swap_clients = self.swap_clients
        offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.XMR, 10 * COIN, 100 * XMR_COIN, 10 * COIN, SwapTypes.XMR_SWAP)
        wait_for_offer(delay_event, swap_clients[1], offer_id)
        offers = swap_clients[1].listOffers(filters={'offer_id': offer_id})
        offer = offers[0]

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert(xmr_swap)

        swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BID_STOP_AFTER_COIN_A_LOCK)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.XMR_SWAP_SCRIPT_COIN_LOCKED, wait_for=180)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert(xmr_swap)

        try:
            swap_clients[0].ci(Coins.BTC).publishTx(xmr_swap.a_lock_refund_tx)
            assert(False), 'Lock refund tx should be locked'
        except Exception as e:
            assert('non-BIP68-final' in str(e))
Ejemplo n.º 4
0
    def test_03_follower_recover_a_lock_tx(self):
        logging.info('---------- Test PART to XMR follower recovers coin a lock tx')
        swap_clients = self.swap_clients

        js_w0_before = json.loads(urlopen('http://localhost:1800/json/wallets').read())

        offer_id = swap_clients[0].postOffer(
            Coins.PART, Coins.XMR, 101 * COIN, 0.13 * XMR_COIN, 101 * COIN, SwapTypes.XMR_SWAP,
            lock_type=SEQUENCE_LOCK_BLOCKS, lock_value=12)
        wait_for_offer(delay_event, swap_clients[1], offer_id)
        offer = swap_clients[1].getOffer(offer_id)

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert(xmr_swap)

        swap_clients[1].setBidDebugInd(bid_id, DebugTypes.BID_STOP_AFTER_COIN_A_LOCK)
        swap_clients[0].setBidDebugInd(bid_id, DebugTypes.BID_DONT_SPEND_COIN_A_LOCK_REFUND)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_ABANDONED, wait_for=180)
        wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.XMR_SWAP_FAILED_SWIPED, wait_for=80, sent=True)

        js_w0_after = json.loads(urlopen('http://localhost:1800/json/wallets').read())

        wait_for_none_active(delay_event, 1800)
        wait_for_none_active(delay_event, 1801)
Ejemplo n.º 5
0
    def test_05_btc_xmr(self):
        logging.info('---------- Test BTC to XMR')
        swap_clients = self.swap_clients
        offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.XMR, 10 * COIN,
                                             100 * XMR_COIN, 10 * COIN,
                                             SwapTypes.XMR_SWAP)
        wait_for_offer(test_delay_event, swap_clients[1], offer_id)
        offers = swap_clients[1].listOffers(filters={'offer_id': offer_id})
        offer = offers[0]

        swap_clients[1].ci(Coins.XMR).setFeePriority(3)

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id,
                     BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert (xmr_swap)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid_id,
                     BidStates.SWAP_COMPLETED,
                     wait_for=180)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid_id,
                     BidStates.SWAP_COMPLETED,
                     sent=True)

        swap_clients[1].ci(Coins.XMR).setFeePriority(0)
Ejemplo n.º 6
0
    def test_01_part_xmr(self):
        logging.info('---------- Test PART to XMR')
        swap_clients = self.swap_clients

        js_1 = json.loads(urlopen('http://localhost:1801/json/wallets').read())
        assert(make_int(js_1[str(int(Coins.XMR))]['balance'], scale=12) > 0)
        assert(make_int(js_1[str(int(Coins.XMR))]['unconfirmed'], scale=12) > 0)

        offer_id = swap_clients[0].postOffer(Coins.PART, Coins.XMR, 100 * COIN, 0.11 * XMR_COIN, 100 * COIN, SwapTypes.XMR_SWAP)
        wait_for_offer(delay_event, swap_clients[1], offer_id)
        offers = swap_clients[1].listOffers(filters={'offer_id': offer_id})
        assert(len(offers) == 1)
        offer = offers[0]

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert(xmr_swap)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=180)
        wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True)

        js_0_end = json.loads(urlopen('http://localhost:1800/json/wallets').read())
        end_xmr = float(js_0_end['6']['balance']) + float(js_0_end['6']['unconfirmed'])
        assert(end_xmr > 10.9 and end_xmr < 11.0)
Ejemplo n.º 7
0
    def test_05_refund(self):
        # Seller submits initiate txn, buyer doesn't respond
        logging.info('---------- Test refund, LTC to BTC')
        swap_clients = self.swap_clients

        offer_id = swap_clients[0].postOffer(Coins.LTC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST,
                                             SEQUENCE_LOCK_BLOCKS, 10)

        wait_for_offer(test_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)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id)
        swap_clients[1].abandonBid(bid_id)
        swap_clients[0].acceptBid(bid_id)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
        wait_for_bid(test_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_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)
Ejemplo n.º 8
0
    def test_07_error(self):
        logging.info(
            '---------- Test error, BTC to NMC, set fee above bid value')
        swap_clients = self.swap_clients

        js_0_before = json.loads(urlopen('http://localhost:1800/json').read())

        offer_id = swap_clients[0].postOffer(Coins.NMC, Coins.BTC,
                                             0.001 * COIN, 1.0 * COIN,
                                             0.001 * COIN,
                                             SwapTypes.SELLER_FIRST,
                                             ABS_LOCK_TIME)

        wait_for_offer(delay_event, swap_clients[0], offer_id)
        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)

        wait_for_bid(delay_event, swap_clients[0], bid_id)
        swap_clients[0].acceptBid(bid_id)
        swap_clients[0].coin_clients[Coins.BTC]['override_feerate'] = 10.0
        swap_clients[0].coin_clients[Coins.NMC]['override_feerate'] = 10.0

        wait_for_bid(delay_event,
                     swap_clients[0],
                     bid_id,
                     BidStates.BID_ERROR,
                     wait_for=60)
Ejemplo n.º 9
0
    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(test_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(test_delay_event, swap_clients[0], 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)
        wait_for_bid(test_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)
Ejemplo n.º 10
0
    def test_04_nmc_btc(self):
        logging.info('---------- Test NMC to BTC')
        swap_clients = self.swap_clients

        offer_id = swap_clients[0].postOffer(Coins.NMC, Coins.BTC, 10 * COIN, 0.1 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST, ABS_LOCK_TIME)

        wait_for_offer(delay_event, swap_clients[1], offer_id)
        offers = swap_clients[1].listOffers()
        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_0bid = json.loads(urlopen('http://127.0.0.1:1800/json/bids/{}'.format(bid_id.hex())).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())

        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)
Ejemplo n.º 11
0
    def test_07_revoke_offer(self):
        logging.info('---------- Test offer revocaction')
        swap_clients = self.swap_clients
        offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.XMR, 10 * COIN, 100 * XMR_COIN, 10 * COIN, SwapTypes.XMR_SWAP)
        wait_for_offer(delay_event, swap_clients[1], offer_id)

        swap_clients[0].revokeOffer(offer_id)

        wait_for_no_offer(delay_event, swap_clients[1], offer_id)
Ejemplo n.º 12
0
    def test_09_auto_accept(self):
        logging.info('---------- Test BTC to XMR auto accept')
        swap_clients = self.swap_clients
        offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.XMR, 11 * COIN, 101 * XMR_COIN, 10 * COIN, SwapTypes.XMR_SWAP, auto_accept_bids=True)
        wait_for_offer(delay_event, swap_clients[1], offer_id)
        offer = swap_clients[1].listOffers(filters={'offer_id': offer_id})[0]

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)
        wait_for_bid(delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=180)
        wait_for_bid(delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True)
Ejemplo n.º 13
0
    def test_09_part_ltc_auto_accept(self):
        logging.info('---------- Test PART to LTC, auto accept bid')
        swap_clients = self.swap_clients

        offer_id = swap_clients[0].postOffer(Coins.PART, Coins.LTC, 100 * COIN, 0.1 * COIN, 100 * COIN, SwapTypes.SELLER_FIRST, auto_accept_bids=True)

        wait_for_offer(test_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(test_delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)
        wait_for_bid(test_delay_event, swap_clients[1], bid_id, BidStates.SWAP_COMPLETED, sent=True, wait_for=60)
Ejemplo n.º 14
0
    def test_02_leader_recover_a_lock_tx(self):
        logging.info(
            '---------- Test PART to XMR leader recovers coin a lock tx')
        swap_clients = self.swap_clients

        js_w0_before = json.loads(
            urlopen('http://127.0.0.1:1800/json/wallets').read())

        offer_id = swap_clients[0].postOffer(Coins.PART,
                                             Coins.XMR,
                                             101 * COIN,
                                             0.12 * XMR_COIN,
                                             101 * COIN,
                                             SwapTypes.XMR_SWAP,
                                             lock_type=SEQUENCE_LOCK_BLOCKS,
                                             lock_value=12)
        wait_for_offer(test_delay_event, swap_clients[1], offer_id)
        offer = swap_clients[1].getOffer(offer_id)

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id,
                     BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert (xmr_swap)

        swap_clients[1].setBidDebugInd(bid_id,
                                       DebugTypes.BID_STOP_AFTER_COIN_A_LOCK)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid_id,
                     BidStates.XMR_SWAP_FAILED_REFUNDED,
                     wait_for=180)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid_id,
                     BidStates.XMR_SWAP_FAILED_REFUNDED,
                     sent=True)

        js_w0_after = json.loads(
            urlopen('http://127.0.0.1:1800/json/wallets').read())
        print('[rm] js_w0_before', json.dumps(js_w0_before))
        print('[rm] js_w0_after', json.dumps(js_w0_after))
Ejemplo n.º 15
0
    def test_04_follower_recover_b_lock_tx(self):
        logging.info(
            '---------- Test PART to XMR follower recovers coin b lock tx')

        swap_clients = self.swap_clients

        offer_id = swap_clients[0].postOffer(Coins.PART,
                                             Coins.XMR,
                                             101 * COIN,
                                             0.14 * XMR_COIN,
                                             101 * COIN,
                                             SwapTypes.XMR_SWAP,
                                             lock_type=SEQUENCE_LOCK_BLOCKS,
                                             lock_value=18)
        wait_for_offer(test_delay_event, swap_clients[1], offer_id)
        offer = swap_clients[1].getOffer(offer_id)

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id,
                     BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert (xmr_swap)

        swap_clients[1].setBidDebugInd(bid_id,
                                       DebugTypes.CREATE_INVALID_COIN_B_LOCK)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid_id,
                     BidStates.XMR_SWAP_FAILED_REFUNDED,
                     wait_for=180)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid_id,
                     BidStates.XMR_SWAP_FAILED_REFUNDED,
                     sent=True)
Ejemplo n.º 16
0
    def test_07_error(self):
        logging.info('---------- Test error, BTC to LTC, set fee above bid value')
        swap_clients = self.swap_clients

        js_0_before = json.loads(urlopen('http://127.0.0.1:1800/json').read())

        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(test_delay_event, swap_clients[0], offer_id)
        offer = swap_clients[0].getOffer(offer_id)
        bid_id = swap_clients[0].postBid(offer_id, offer.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id)
        swap_clients[0].acceptBid(bid_id)
        swap_clients[0].getChainClientSettings(Coins.BTC)['override_feerate'] = 10.0
        swap_clients[0].getChainClientSettings(Coins.LTC)['override_feerate'] = 10.0

        wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.BID_ERROR, wait_for=60)

        swap_clients[0].abandonBid(bid_id)
        del swap_clients[0].getChainClientSettings(Coins.BTC)['override_feerate']
        del swap_clients[0].getChainClientSettings(Coins.LTC)['override_feerate']
Ejemplo n.º 17
0
    def test_06_self_bid(self):
        logging.info('---------- Test same client, BTC to LTC')
        swap_clients = self.swap_clients

        js_0_before = json.loads(urlopen('http://127.0.0.1:1800/json').read())

        offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.LTC, 10 * COIN, 10 * COIN, 10 * COIN, SwapTypes.SELLER_FIRST)

        wait_for_offer(test_delay_event, swap_clients[0], offer_id)
        offer = swap_clients[0].getOffer(offer_id)
        offers = swap_clients[0].listOffers()
        bid_id = swap_clients[0].postBid(offer_id, offer.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id)
        swap_clients[0].acceptBid(bid_id)

        wait_for_bid_tx_state(test_delay_event, swap_clients[0], bid_id, TxStates.TX_REDEEMED, TxStates.TX_REDEEMED, wait_for=60)
        wait_for_bid(test_delay_event, swap_clients[0], bid_id, BidStates.SWAP_COMPLETED, wait_for=60)

        js_0 = json.loads(urlopen('http://127.0.0.1:1800/json').read())
        assert(js_0['num_swapping'] == 0 and js_0['num_watched_outputs'] == 0)
        assert(js_0['num_recv_bids'] == js_0_before['num_recv_bids'] + 1 and js_0['num_sent_bids'] == js_0_before['num_sent_bids'] + 1)
Ejemplo n.º 18
0
    def test_06_multiple_swaps(self):
        logging.info('---------- Test Multiple concurrent swaps')
        swap_clients = self.swap_clients
        offer1_id = swap_clients[0].postOffer(Coins.BTC, Coins.XMR, 10 * COIN, 100 * XMR_COIN, 10 * COIN, SwapTypes.XMR_SWAP)
        offer2_id = swap_clients[0].postOffer(Coins.PART, Coins.XMR, 10 * COIN, 0.14 * XMR_COIN, 10 * COIN, SwapTypes.XMR_SWAP)

        wait_for_offer(delay_event, swap_clients[1], offer1_id)
        offer1 = swap_clients[1].getOffer(offer1_id)
        wait_for_offer(delay_event, swap_clients[1], offer2_id)
        offer2 = swap_clients[1].getOffer(offer2_id)

        bid1_id = swap_clients[1].postXmrBid(offer1_id, offer1.amount_from)
        bid2_id = swap_clients[1].postXmrBid(offer2_id, offer2.amount_from)

        offer3_id = swap_clients[0].postOffer(Coins.PART, Coins.XMR, 11 * COIN, 0.15 * XMR_COIN, 11 * COIN, SwapTypes.XMR_SWAP)

        wait_for_bid(delay_event, swap_clients[0], bid1_id, BidStates.BID_RECEIVED)
        swap_clients[0].acceptXmrBid(bid1_id)

        wait_for_offer(delay_event, swap_clients[1], offer3_id)
        offer3 = swap_clients[1].getOffer(offer3_id)
        bid3_id = swap_clients[1].postXmrBid(offer3_id, offer3.amount_from)

        wait_for_bid(delay_event, swap_clients[0], bid2_id, BidStates.BID_RECEIVED)
        swap_clients[0].acceptXmrBid(bid2_id)

        wait_for_bid(delay_event, swap_clients[0], bid3_id, BidStates.BID_RECEIVED)
        swap_clients[0].acceptXmrBid(bid3_id)

        wait_for_bid(delay_event, swap_clients[0], bid1_id, BidStates.SWAP_COMPLETED, wait_for=180)
        wait_for_bid(delay_event, swap_clients[1], bid1_id, BidStates.SWAP_COMPLETED, sent=True)

        wait_for_bid(delay_event, swap_clients[0], bid2_id, BidStates.SWAP_COMPLETED, wait_for=120)
        wait_for_bid(delay_event, swap_clients[1], bid2_id, BidStates.SWAP_COMPLETED, sent=True)

        wait_for_bid(delay_event, swap_clients[0], bid3_id, BidStates.SWAP_COMPLETED, wait_for=120)
        wait_for_bid(delay_event, swap_clients[1], bid3_id, BidStates.SWAP_COMPLETED, sent=True)

        wait_for_none_active(delay_event, 1800)
        wait_for_none_active(delay_event, 1801)
Ejemplo n.º 19
0
    def test_06_multiple_swaps(self):
        logging.info('---------- Test Multiple concurrent swaps')
        swap_clients = self.swap_clients

        js_w0_before = json.loads(
            urlopen('http://127.0.0.1:1800/json/wallets').read())
        js_w1_before = json.loads(
            urlopen('http://127.0.0.1:1801/json/wallets').read())

        amt_1 = make_int(random.uniform(0.001, 49.0), scale=8, r=1)
        amt_2 = make_int(random.uniform(0.001, 49.0), scale=8, r=1)

        rate_1 = make_int(random.uniform(80.0, 110.0), scale=12, r=1)
        rate_2 = make_int(random.uniform(0.01, 0.5), scale=12, r=1)

        logging.info('amt_1 {}, rate_1 {}'.format(amt_1, rate_1))
        logging.info('amt_2 {}, rate_2 {}'.format(amt_2, rate_2))
        offer1_id = swap_clients[0].postOffer(Coins.BTC, Coins.XMR, amt_1,
                                              rate_1, amt_1,
                                              SwapTypes.XMR_SWAP)
        offer2_id = swap_clients[0].postOffer(Coins.PART, Coins.XMR, amt_2,
                                              rate_2, amt_2,
                                              SwapTypes.XMR_SWAP)

        wait_for_offer(test_delay_event, swap_clients[1], offer1_id)
        offer1 = swap_clients[1].getOffer(offer1_id)
        wait_for_offer(test_delay_event, swap_clients[1], offer2_id)
        offer2 = swap_clients[1].getOffer(offer2_id)

        bid1_id = swap_clients[1].postXmrBid(offer1_id, offer1.amount_from)
        bid2_id = swap_clients[1].postXmrBid(offer2_id, offer2.amount_from)

        offer3_id = swap_clients[0].postOffer(Coins.PART, Coins.XMR, 11 * COIN,
                                              0.15 * XMR_COIN, 11 * COIN,
                                              SwapTypes.XMR_SWAP)

        wait_for_bid(test_delay_event, swap_clients[0], bid1_id,
                     BidStates.BID_RECEIVED)
        swap_clients[0].acceptXmrBid(bid1_id)

        wait_for_offer(test_delay_event, swap_clients[1], offer3_id)
        offer3 = swap_clients[1].getOffer(offer3_id)
        bid3_id = swap_clients[1].postXmrBid(offer3_id, offer3.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid2_id,
                     BidStates.BID_RECEIVED)
        swap_clients[0].acceptXmrBid(bid2_id)

        wait_for_bid(test_delay_event, swap_clients[0], bid3_id,
                     BidStates.BID_RECEIVED)
        swap_clients[0].acceptXmrBid(bid3_id)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid1_id,
                     BidStates.SWAP_COMPLETED,
                     wait_for=180)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid1_id,
                     BidStates.SWAP_COMPLETED,
                     sent=True)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid2_id,
                     BidStates.SWAP_COMPLETED,
                     wait_for=120)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid2_id,
                     BidStates.SWAP_COMPLETED,
                     sent=True)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid3_id,
                     BidStates.SWAP_COMPLETED,
                     wait_for=120)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid3_id,
                     BidStates.SWAP_COMPLETED,
                     sent=True)

        wait_for_none_active(test_delay_event, 1800)
        wait_for_none_active(test_delay_event, 1801)

        js_w0_after = json.loads(
            urlopen('http://127.0.0.1:1800/json/wallets').read())
        js_w1_after = json.loads(
            urlopen('http://127.0.0.1:1801/json/wallets').read())
        logging.info('[rm] js_w0_after {}'.format(
            json.dumps(js_w0_after, indent=4)))
        logging.info('[rm] js_w1_after {}'.format(
            json.dumps(js_w1_after, indent=4)))

        assert (make_int(js_w1_after['2']['balance'], scale=8, r=1) -
                (make_int(js_w1_before['2']['balance'], scale=8, r=1) + amt_1)
                < 1000)
Ejemplo n.º 20
0
    def test_11_particl_anon(self):
        logging.info('---------- Test Particl anon transactions')
        swap_clients = self.swap_clients

        js_0 = json.loads(
            urlopen('http://127.0.0.1:1800/json/wallets/part').read())
        assert (float(js_0['anon_balance']) == 0.0)

        js_1 = json.loads(
            urlopen('http://127.0.0.1:1801/json/wallets/part').read())
        assert (float(js_1['balance']) > 200.0)

        callnoderpc(
            1, 'reservebalance', [True, 1000000]
        )  # Stop staking to avoid conflicts (input used by tx->anon staked before tx gets in the chain)
        post_json = {
            'value': 100,
            'address': js_1['stealth_address'],
            'subfee': False,
            'type_to': 'anon',
        }
        json_rv = json.loads(
            post_json_req('http://127.0.0.1:1801/json/wallets/part/withdraw',
                          post_json))
        assert (len(json_rv['txid']) == 64)

        post_json['value'] = 0.5
        for i in range(22):
            json_rv = json.loads(
                post_json_req(
                    'http://127.0.0.1:1801/json/wallets/part/withdraw',
                    post_json))
            assert (len(json_rv['txid']) == 64)

        logging.info('Waiting for anon balance')
        try:
            wait_for_balance(test_delay_event,
                             'http://127.0.0.1:1801/json/wallets/part',
                             'anon_balance', 110.0)
        except Exception as e:
            ft = callnoderpc(0, 'filtertransactions', [{'count': 0}])
            raise e

        callnoderpc(1, 'reservebalance', [False])
        post_json = {
            'value': 10,
            'address': js_0['stealth_address'],
            'subfee': True,
            'type_from': 'anon',
            'type_to': 'blind',
        }
        json_rv = json.loads(
            post_json_req('http://127.0.0.1:1801/json/wallets/part/withdraw',
                          post_json))
        assert (len(json_rv['txid']) == 64)

        logging.info('Waiting for blind balance')
        wait_for_balance(test_delay_event,
                         'http://127.0.0.1:1800/json/wallets/part',
                         'blind_balance', 9.8)
        if float(js_0['blind_balance']) >= 10.0:
            raise ValueError('Expect blind balance < 10')

        return  # TODO

        amt_swap = make_int(random.uniform(0.1, 2.0), scale=8, r=1)
        rate_swap = make_int(random.uniform(2.0, 20.0), scale=8, r=1)
        offer_id = swap_clients[0].postOffer(Coins.BTC, Coins.PART_ANON,
                                             amt_swap, rate_swap, amt_swap,
                                             SwapTypes.XMR_SWAP)
        wait_for_offer(test_delay_event, swap_clients[1], offer_id)
        offers = swap_clients[0].listOffers(filters={'offer_id': offer_id})
        offer = offers[0]

        bid_id = swap_clients[1].postXmrBid(offer_id, offer.amount_from)

        wait_for_bid(test_delay_event, swap_clients[0], bid_id,
                     BidStates.BID_RECEIVED)

        bid, xmr_swap = swap_clients[0].getXmrBid(bid_id)
        assert (xmr_swap)

        swap_clients[0].acceptXmrBid(bid_id)

        wait_for_bid(test_delay_event,
                     swap_clients[0],
                     bid_id,
                     BidStates.SWAP_COMPLETED,
                     wait_for=180)
        wait_for_bid(test_delay_event,
                     swap_clients[1],
                     bid_id,
                     BidStates.SWAP_COMPLETED,
                     sent=True)

        js_1 = json.loads(
            urlopen('http://127.0.0.1:1801/json/wallets/part').read())
        print('[rm] js_1', js_1)