Skip to content

Commit

Permalink
Fixed market tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Jun 25, 2018
1 parent 9b2756d commit 195ef54
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Tribler/Test/Community/Market/test_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_info_message(self):
self.assertTrue(self.nodes[0].overlay.matchmakers)
self.assertTrue(self.nodes[1].overlay.matchmakers)

@twisted_wrapper
@twisted_wrapper(2)
def test_create_ask(self):
"""
Test creating an ask and sending it to others
Expand All @@ -66,15 +66,15 @@ def test_create_ask(self):

yield self.nodes[0].overlay.create_ask(1, 'DUM1', 2, 'DUM2', 3600)

yield self.deliver_messages()
yield self.sleep(0.5)

orders = self.nodes[0].overlay.order_manager.order_repository.find_all()
self.assertTrue(orders)
self.assertTrue(orders[0].verified)
self.assertTrue(orders[0].is_ask())
self.assertEqual(len(self.nodes[2].overlay.order_book.asks), 1)

@twisted_wrapper
@twisted_wrapper(2)
def test_create_bid(self):
"""
Test creating a bid and sending it to others
Expand All @@ -83,15 +83,15 @@ def test_create_bid(self):

yield self.nodes[0].overlay.create_bid(1, 'DUM1', 2, 'DUM2', 3600)

yield self.deliver_messages()
yield self.sleep(0.5)

orders = self.nodes[0].overlay.order_manager.order_repository.find_all()
self.assertTrue(orders)
self.assertTrue(orders[0].verified)
self.assertFalse(orders[0].is_ask())
self.assertEqual(len(self.nodes[2].overlay.order_book.bids), 1)

@twisted_wrapper
@twisted_wrapper(2)
def test_decline_trade(self):
"""
Test declining a trade
Expand All @@ -102,12 +102,12 @@ def test_decline_trade(self):
order = yield self.nodes[0].overlay.create_ask(1, 'DUM1', 1, 'DUM2', 3600)
order._traded_quantity._quantity = 1 # So it looks like this order has already been fulfilled

yield self.deliver_messages()
yield self.sleep(0.5)

self.assertEqual(len(self.nodes[2].overlay.order_book.asks), 1)
self.nodes[1].overlay.create_bid(1, 'DUM1', 1, 'DUM2', 3600)

yield self.deliver_messages()
yield self.sleep(0.5)

# The ask should be removed since this node thinks the order is already completed
self.assertEqual(len(self.nodes[2].overlay.order_book.asks), 0)
Expand All @@ -123,12 +123,12 @@ def test_counter_trade(self):
order = yield self.nodes[0].overlay.create_ask(2, 'DUM1', 2, 'DUM2', 3600)
order._traded_quantity._quantity = 1 # Partially fulfill this order

yield self.deliver_messages(timeout=.4)
yield self.sleep(0.5) # Give it some time to complete the trade

self.assertEqual(len(self.nodes[2].overlay.order_book.asks), 1)
self.nodes[1].overlay.create_bid(2, 'DUM1', 2, 'DUM2', 3600)

yield self.deliver_messages(timeout=.4)
yield self.sleep(0.5)

self.assertTrue(self.nodes[0].overlay.transaction_manager.find_all())
self.assertTrue(self.nodes[1].overlay.transaction_manager.find_all())
Expand Down

0 comments on commit 195ef54

Please sign in to comment.