desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Testing whether an anonymous download over our tunnels works'
| @deferred(timeout=60)
@inlineCallbacks
def test_anon_download(self):
| (yield self.setup_nodes())
def download_state_callback(ds):
download = ds.get_download()
if ((download.get_progress() == 1.0) and (ds.get_status() == DLSTATUS_SEEDING)):
self.test_deferred.callback(None)
return (0.0, False)
return (2.0, False)
download = self.... |
'Testing whether an anon download does not make progress without exit nodes'
| @deferred(timeout=60)
@inlineCallbacks
def test_anon_download_no_exitnodes(self):
| assert isInIOThread()
(yield self.setup_nodes(num_exitnodes=0))
def download_state_callback(ds):
download = ds.get_download()
if (download.get_progress() != 0.0):
self.test_deferred.errback(RuntimeError('Anonymous download should not make progress without exi... |
'Testing whether an anon download does not make progress without relay nodes'
| @deferred(timeout=60)
@inlineCallbacks
def test_anon_download_no_relays(self):
| (yield self.setup_nodes(num_relays=0, num_exitnodes=1))
def download_state_callback(ds):
download = ds.get_download()
if (download.get_progress() != 0.0):
self.test_deferred.errback(RuntimeError('Anonymous download should not make progress without relay nodes'... |
'This mocked method simply adds a peer to the DHT dictionary and invokes the callback.'
| def get_peers(self, lookup_id, _, callback_f, bt_port=0):
| if (bt_port != 0):
self.dht_dict[lookup_id] = (self.dht_dict.get(lookup_id, []) + [('127.0.0.1', bt_port)])
callback_f(lookup_id, self.dht_dict.get(lookup_id, None), None)
|
'Setup the hidden seeder. This includes setting the right circuit parameters, creating the download callback and
waiting for the creation of an introduction point for the download.'
| def configure_hidden_seeder(self):
| def download_states_callback(dslist):
self.tunnel_community_seeder.monitor_downloads(dslist)
return []
self.tunnel_community_seeder.settings.min_circuits = 0
self.tunnel_community_seeder.settings.max_circuits = 0
self.session2.config.set_anon_proxy_settings(2, ('127.0.0.1', self.session2... |
'Testing the hidden services'
| @deferred(timeout=50)
@inlineCallbacks
def test_hidden_services(self):
| (yield self.setup_nodes(num_relays=4, num_exitnodes=2, seed_hops=1))
self.setup_dht_bypass()
(yield self.configure_hidden_seeder())
def download_state_callback(ds):
self.tunnel_community.monitor_downloads([ds])
download = ds.get_download()
if ((download.get_progress() == 1.0) and... |
'Testing whether the TunnelCommunity does not reload itself after unloading'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_unload_receive(self):
| tunnel_community = self.session.lm.tunnel_community
dispersy = self.session.lm.dispersy
some_candidate = Candidate(('1.2.3.4', 1234), False)
some_packet = self.create_valid_packet(tunnel_community)
dispersy.on_incoming_packets([(some_candidate, some_packet)])
self.assertIn(tunnel_community, disp... |
'Testing whether we do not load two different tunnel communities in the same session'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_load_other_tunnel_community(self):
| dispersy = self.session.lm.dispersy
master_member = DummyTunnelCommunity.get_master_members(dispersy)[0]
keypair = self.session.trustchain_keypair
dispersy_member = dispersy.get_member(private_key=keypair.key_to_bin())
community = DummyTunnelCommunity.init_community(dispersy, master_member, dispersy... |
'Setup various variables and load the tunnel community in the main downloader session.'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def setUp(self, autoload_discovery=True):
| (yield TestAsServer.setUp(self, autoload_discovery=autoload_discovery))
self.seed_tdef = None
self.sessions = []
self.session2 = None
self.crypto_enabled = True
self.bypass_dht = False
self.seed_config = None
self.tunnel_community_seeder = None
self.eccrypto = ECCrypto()
ec = sel... |
'Setup all required nodes, including the relays, exit nodes and seeder.'
| @inlineCallbacks
def setup_nodes(self, num_relays=1, num_exitnodes=1, seed_hops=0):
| assert isInIOThread()
baseindex = 3
for i in xrange(baseindex, (baseindex + num_relays)):
proxy = (yield self.create_proxy(i))
self.tunnel_communities.append(proxy)
baseindex += (num_relays + 1)
for i in xrange(baseindex, (baseindex + num_exitnodes)):
proxy = (yield self.crea... |
'Load the tunnel community in a given session. We are using our own tunnel community here instead of the one
used in Tribler.'
| @blocking_call_on_reactor_thread
def load_tunnel_community_in_session(self, session, exitnode=False):
| dispersy = session.get_dispersy_instance()
keypair = dispersy.crypto.generate_key(u'curve25519')
dispersy_member = dispersy.get_member(private_key=dispersy.crypto.key_to_bin(keypair))
settings = TunnelSettings(tribler_session=session)
if (not self.crypto_enabled):
settings.crypto = NoCrypto(... |
'Create a single proxy and load the tunnel community in the session of that proxy.'
| @inlineCallbacks
def create_proxy(self, index, exitnode=False):
| from Tribler.Core.Session import Session
self.setUpPreSession()
config = self.config.copy()
config.set_libtorrent_enabled(True)
config.set_dispersy_enabled(True)
config.set_state_dir(self.getStateDir(index))
config.set_tunnel_community_socks5_listen_ports(self.get_socks5_ports())
session... |
'Setup the seeder.'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def setup_tunnel_seeder(self, hops):
| from Tribler.Core.Session import Session
self.seed_config = self.config.copy()
self.seed_config.set_state_dir(self.getStateDir(2))
self.seed_config.set_megacache_enabled(True)
self.seed_config.set_tunnel_community_socks5_listen_ports(self.get_socks5_ports())
if (self.session2 is None):
s... |
'The callback of the seeder download. For now, this only logs the state of the download that\'s seeder and is
useful for debugging purposes.'
| def seeder_state_callback(self, ds):
| if self.tunnel_community_seeder:
self.tunnel_community_seeder.monitor_downloads([ds])
d = ds.get_download()
self._logger.debug('seeder: %s %s %s', repr(d.get_def().get_name()), dlstatus_strings[ds.get_status()], ds.get_progress())
return (5.0, False)
|
'Start an anonymous download in the main Tribler session.'
| def start_anon_download(self, hops=1):
| dscfg = DownloadStartupConfig()
dscfg.set_dest_dir(self.getDestDir())
dscfg.set_hops(hops)
download = self.session.start_download_from_tdef(self.seed_tdef, dscfg)
download.add_peer(('127.0.0.1', self.session2.config.get_libtorrent_port()))
return download
|
'Test the decoding process of a request'
| def test_decode_request(self):
| self.assertIsNone(decode_request(0, struct.pack('!BBBB', 5, 0, 0, 5))[1])
self.assertRaises(IPV6AddrError, decode_request, 0, struct.pack('!BBBB', 5, 0, 0, 4))
|
'Test whether UDP ASSOCIATE requests are answered with a REP_SUCCEEDED'
| def test_associate(self):
| self.connection.on_udp_associate_request(self.connection, MockRequest())
self.assertGreater(len(self.connection.transport.out), 0)
self.assertEquals(self.connection.transport.out[0].frag, REP_SUCCEEDED)
|
'When a Socks5Connection connection is closed twice, it should just
return True'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_double_close(self):
| self.assertFalse(self.connection.transport.dead)
(yield self.connection.close())
self.assertTrue(self.connection.transport.dead)
self.assertTrue(self.connection.close())
|
'When a SocksUDPConnection connection is closed twice, it should just
return True'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_double_close(self):
| (yield self.connection.close())
self.assertIsNone(self.connection.listen_port)
self.assertTrue(self.connection.close())
|
'When on_data receives an invalid encryption, crypto_in() should throw a CryptoException.'
| def test_on_data_invalid_encoding(self):
| tunnel_crypto = object.__new__(TunnelCrypto)
self.tunnel_community.settings = TunnelSettings()
circuit = Circuit(42L)
hop = Hop(tunnel_crypto.generate_key(u'curve25519'))
hop.session_keys = tunnel_crypto.generate_session_keys('1234')
circuit.add_hop(hop)
self.tunnel_community.circuits[42] = ... |
'Notifications of NTFY_TUNNEL NTFY_REMOVE should report candidates with valid member associations'
| @blocking_call_on_reactor_thread
def test_valid_member_on_tunnel_remove(self):
| class MockNotifier(object, ):
def __init__(self):
self.candidate = None
self.called = False
def notify(self, subject, change_type, tunnel, candidate):
self.called = True
self.candidate = candidate
tunnel_crypto = object.__new__(TunnelCrypto)
se... |
'Notifications of NTFY_TUNNEL NTFY_REMOVE should report candidates even though they are no longer tracked
The notification should still have a valid Candidate object for the reference of third parties.
For example, Dispersy might determine a Candidate is no longer needed for the TunnelCommunity, but the
TrustChainCommu... | @blocking_call_on_reactor_thread
def test_reconstruct_candidate_on_tunnel_remove(self):
| class MockNotifier(object, ):
def __init__(self):
self.candidate = None
self.called = False
def notify(self, subject, change_type, tunnel, candidate):
self.called = True
self.candidate = candidate
tunnel_crypto = object.__new__(TunnelCrypto)
se... |
'Notifications of NTFY_TUNNEL NTFY_REMOVE should report candidates even though they are no longer tracked
The notification should still have a valid Candidate object for the reference of third parties.
For example, Dispersy might determine a Candidate is no longer needed for the TunnelCommunity, but the
TrustChainCommu... | @blocking_call_on_reactor_thread
def test_reconstruct_candidate_on_relay_remove(self):
| class MockNotifier(object, ):
def __init__(self):
self.candidate = None
self.called = False
def notify(self, subject, change_type, tunnel, candidate):
self.called = True
self.candidate = candidate
tunnel_crypto = object.__new__(TunnelCrypto)
se... |
'test whether a full transaction will be executed between two nodes.'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_e2e_transaction(self):
| bid_session = (yield self.create_session(1))
test_deferred = Deferred()
ask_community = self.market_communities[self.session]
bid_community = self.market_communities[bid_session]
@inlineCallbacks
def on_received_half_block(_):
on_received_half_block.num_called += 1
if (on_receive... |
'Test whether the order book of two nodes are being synchronized'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_orderbook_sync(self):
| def check_orderbook_size():
if ((len(ask_community.order_book.bids) == 1) and (len(bid_community.order_book.asks) == 1)):
check_lc.stop()
test_deferred.callback(None)
test_deferred = Deferred()
bid_session = (yield self.create_session(1))
ask_community = self.market_commu... |
'Test whether a trade is made between two nodes'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_accept_trade(self):
| deferred = Deferred()
def mocked_start_transaction(*_):
deferred.callback(None)
self.node_b.community.start_transaction = mocked_start_transaction
(yield self.introduce_nodes(self.node_a, self.node_b))
(yield self.create_send_ask(self.node_a, self.node_b))
self.node_b.community.create_bi... |
'Test whether a counter trade is made between two nodes'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_counter_trade(self):
| deferred = Deferred()
def mocked_start_transaction(*_):
deferred.callback(None)
self.node_a.community.matching_enabled = False
self.node_b.community.matching_enabled = False
self.node_a.community.start_transaction = mocked_start_transaction
(yield self.introduce_nodes(self.node_a, self.n... |
'Test whether a decline trade is sent between nodes if the price of a proposed trade is not right'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_decline_trade(self):
| (yield self.introduce_nodes(self.node_a, self.node_b))
(yield self.create_send_ask(self.node_a, self.node_b))
self.node_b.community.create_bid(9, 'DUM1', 10, 'DUM2', 3600)
(yield self.parse_assert_packets(self.node_a))
order_a = self.node_a.community.order_manager.order_repository.find_all()[0]
... |
'Test whether a cancel-order message is sent between nodes if we cancel an order'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def test_cancel_order(self):
| (yield self.introduce_nodes(self.node_a, self.node_b))
order = (yield self.create_send_ask(self.node_a, self.node_b))
self.node_a.community.cancel_order(order.order_id)
(yield self.parse_assert_packets(self.node_b))
self.assertEqual(len(self.node_b.community.order_book.asks), 0)
|
'Setup various variables.'
| @blocking_call_on_reactor_thread
@inlineCallbacks
def setUp(self, autoload_discovery=True):
| os.environ[BOOTSTRAP_FILE_ENVNAME] = os.path.join(TESTS_DATA_DIR, 'bootstrap_empty.txt')
(yield TestAsServer.setUp(self, autoload_discovery=autoload_discovery))
self.sessions = []
self.eccrypto = ECCrypto()
ec = self.eccrypto.generate_key(u'curve25519')
MarketCommunityTests.master_key = self.ecc... |
'Load the market community and tradechain community in a given session.'
| @blocking_call_on_reactor_thread
def load_market_community_in_session(self, session, market_member, mc_community):
| wallets = {'BTC': BitcoinWallet(os.path.join(session.config.get_state_dir(), 'wallet')), 'MC': TrustchainWallet(mc_community), 'DUM1': DummyWallet1(), 'DUM2': DummyWallet2()}
wallets['MC'].check_negative_balance = False
dispersy = session.get_dispersy_instance()
tradechain_community = dispersy.define_au... |
'Load a custom instance of the TriblerChain community in a given session.'
| @blocking_call_on_reactor_thread
def load_triblerchain_community_in_session(self, session):
| dispersy = session.get_dispersy_instance()
keypair = dispersy.crypto.generate_key(u'curve25519')
dispersy_member = dispersy.get_member(private_key=dispersy.crypto.key_to_bin(keypair))
triblerchain_kwargs = {'tribler_session': session}
return dispersy.define_auto_load(TriblerChainCommunityTests, disp... |
'Create a single session and load the tunnel community in the session of that proxy.'
| @inlineCallbacks
def create_session(self, index):
| from Tribler.Core.Session import Session
config = self.config.copy()
config.set_state_dir(self.getStateDir(index))
session = Session(config, ignore_singleton=True, autoload_discovery=False)
(yield session.start())
self.sessions.append(session)
market_member = self.generate_member(session)
... |
'Test signing a tick'
| def test_signature(self):
| eccrypto = ECCrypto()
keypair = eccrypto.generate_key(u'curve25519')
sign_member = MockObject()
sign_member.public_key = eccrypto.key_to_bin(keypair.pub())
sign_member.private_key = keypair
self.tick.sign(sign_member)
self.assertFalse(self.tick.has_valid_signature())
self.tick._order_id ... |
'Test the update_timestamp method of a Tick object'
| def test_update_timestamp(self):
| self.tick.update_timestamp()
self.assertGreater(float(self.tick.timestamp), float(self.timestamp_now))
|
'Test the to dictionary method of a tick'
| def test_to_dictionary(self):
| self.assertDictEqual(self.tick.to_dictionary(), {'trader_id': '0', 'message_id': '0.message_number', 'order_number': 1, 'price': 63400.0, 'price_type': 'BTC', 'quantity': 30.0, 'quantity_type': 'MC', 'timeout': 30.0, 'timestamp': float(self.timestamp_now)})
|
'Test whether two ticks with different price types are not matched'
| def test_match_order_other_price(self):
| self.order_book.insert_ask(self.ask5)
self.assertEqual([], self.price_time_strategy.match_order(self.bid_order))
|
'Test whether two ticks with different quantity types are not matched'
| def test_match_order_other_quantity(self):
| self.order_book.insert_ask(self.ask6)
self.assertEqual([], self.price_time_strategy.match_order(self.bid_order))
|
'Test partial matching of a bid order with the matching engine'
| def test_match_order_partial_ask(self):
| self.ask._quantity = Quantity(20, 'MC')
self.order_book.insert_ask(self.ask)
proposed_trades = self.price_time_strategy.match_order(self.bid_order2)
self.assertEquals(1, len(proposed_trades))
|
'Test partial matching of an ask order with the matching engine'
| def test_match_order_partial_bid(self):
| self.bid._quantity = Quantity(20, 'MC')
self.order_book.insert_bid(self.bid)
proposed_trades = self.price_time_strategy.match_order(self.ask_order2)
self.assertEquals(1, len(proposed_trades))
|
'Test searching within a price level'
| def test_search_for_quantity_in_price_level(self):
| self.bid_order._order_id = self.ask.order_id
self.order_book.insert_ask(self.ask)
self.order_book.insert_ask(self.ask2)
(_, trades) = self.price_time_strategy._search_for_quantity_in_price_level(None, Quantity(10, 'MC'), self.bid_order)
self.assertFalse(trades)
(_, trades) = self.price_time_stra... |
'Test the initialization of a quantity'
| def test_init(self):
| with self.assertRaises(ValueError):
Quantity('1', 'MC')
with self.assertRaises(ValueError):
Quantity(1, 2)
|
'Test retrieval of the master members of the Market community'
| @blocking_call_on_reactor_thread
def test_get_master_members(self):
| self.assertTrue(MarketCommunity.get_master_members(self.dispersy))
|
'Test the timeout method of a proposed trade request in the cache'
| @blocking_call_on_reactor_thread
def test_proposed_trade_cache_timeout(self):
| ask = Ask(MessageId(TraderId('0'), MessageNumber('message_number')), OrderId(TraderId(self.market_community.mid), OrderNumber(24)), Price(63400, 'DUM1'), Quantity(30, 'DUM2'), Timeout(3600), Timestamp.now())
order = Order(OrderId(TraderId('0'), OrderNumber(23)), Price(20, 'DUM1'), Quantity(30, 'DUM2'), Timeout(... |
'Test creation of an offer in the community'
| @blocking_call_on_reactor_thread
def test_verify_offer_creation(self):
| self.assertRaises(RuntimeError, self.market_community.verify_offer_creation, Price(3, 'MC'), 'ABC', Quantity(4, 'BTC'), 'ABC')
self.assertRaises(RuntimeError, self.market_community.verify_offer_creation, Price(3, 'MC'), 'ABC', Quantity(4, 'BTC'), 'MC')
self.assertRaises(RuntimeError, self.market_community.v... |
'Test the general check of the validity of a message in the market community'
| @blocking_call_on_reactor_thread
def test_check_message(self):
| self.market_community.update_ip(TraderId(self.market_community.mid), ('2.2.2.2', 2))
proposed_trade_msg = self.get_proposed_trade_msg()
self.market_community.timeline.check = (lambda _: (True, None))
[self.assertIsInstance(msg, Message.Implementation) for msg in self.market_community.check_message([prop... |
'Test the general check of the validity of a tick message in the market community'
| @blocking_call_on_reactor_thread
def test_check_tick_message(self):
| self.ask._signature = EMPTY_SIG
[self.assertIsInstance(msg, DropMessage) for msg in self.market_community.check_tick_message([self.get_tick_message(self.ask)])]
self.market_community.timeline.check = (lambda _: (False, None))
[self.assertIsInstance(msg, DelayMessageByProof) for msg in self.market_commun... |
'Test the general check of the validity of a trade message in the market community'
| @blocking_call_on_reactor_thread
def test_check_trade_message(self):
| self.proposed_trade.recipient_order_id._trader_id = TraderId('abcdef')
self.market_community.update_ip(TraderId(self.market_community.mid), ('2.2.2.2', 2))
self.market_community.update_ip(TraderId('abcdef'), ('2.2.2.2', 2))
self.market_community.timeline.check = (lambda _: (False, None))
[self.asser... |
'Test sending an offer sync'
| @blocking_call_on_reactor_thread
def test_send_offer_sync(self):
| self.market_community.update_ip(TraderId('0'), ('127.0.0.1', 1234))
self.market_community.update_ip(TraderId('1'), ('127.0.0.1', 1234))
self.market_community.update_ip(self.ask.order_id.trader_id, ('127.0.0.1', 1234))
candidate = WalkCandidate(('127.0.0.1', 1234), False, ('127.0.0.1', 1234), ('127.0.0.1... |
'Test sending a proposed trade'
| @blocking_call_on_reactor_thread
def test_send_proposed_trade(self):
| self.market_community.update_ip(TraderId(self.market_community.mid), ('127.0.0.1', 1234))
self.assertEqual(self.market_community.send_proposed_trade_messages([self.proposed_trade]), [True])
|
'Test sending a counter trade'
| @blocking_call_on_reactor_thread
def test_send_counter_trade(self):
| self.market_community.update_ip(TraderId('b'), ('127.0.0.1', 1234))
counter_trade = CounterTrade(MessageId(TraderId('a'), MessageNumber('2')), self.order.order_id, OrderId(TraderId('b'), OrderNumber(3)), 1235, Price(3, 'MC'), Quantity(4, 'BTC'), Timestamp.now())
self.market_community.send_counter_trade(coun... |
'Test the start transaction method'
| @blocking_call_on_reactor_thread
def test_start_transaction(self):
| self.market_community.order_manager.order_repository.add(self.order)
self.market_community.update_ip(TraderId('0'), ('127.0.0.1', 1234))
self.market_community.start_transaction(self.proposed_trade)
self.assertEqual(len(self.market_community.transaction_manager.find_all()), 1)
|
'Test the creation of an introduction request'
| @blocking_call_on_reactor_thread
def test_create_intro_request(self):
| self.market_community.order_book.insert_ask(self.ask)
self.market_community.order_book.insert_bid(self.bid)
candidate = WalkCandidate(('127.0.0.1', 1234), False, ('127.0.0.1', 1234), ('127.0.0.1', 1234), u'public')
request = self.market_community.create_introduction_request(candidate, True)
self.ass... |
'Test that when we receive an intro request with a orders bloom filter, we send an order sync back'
| @blocking_call_on_reactor_thread
def test_on_introduction_request(self):
| def on_send_offer_sync(_, tick):
self.assertIsInstance(tick, Tick)
on_send_offer_sync.called = True
on_send_offer_sync.called = False
candidate = WalkCandidate(('127.0.0.1', 1234), False, ('127.0.0.1', 1234), ('127.0.0.1', 1234), u'public')
candidate.associate(self.market_community.my_me... |
'Test the retrieval of a wallet address'
| @blocking_call_on_reactor_thread
def test_get_wallet_address(self):
| self.assertRaises(ValueError, self.market_community.get_wallet_address, 'ABCD')
self.assertTrue(self.market_community.get_wallet_address('DUM1'))
|
'Test whether a tick is inserted in the order book when we receive one'
| @blocking_call_on_reactor_thread
def test_on_tick(self):
| self.market_community.on_tick([self.get_tick_message(self.ask), self.get_tick_message(self.bid)])
self.assertEquals(1, len(self.market_community.order_book.asks))
self.assertEquals(1, len(self.market_community.order_book.bids))
ask_timestamp = float(self.ask.timestamp)
self.ask.update_timestamp()
... |
'Test whether we accept a trade when we receive a correct proposed trade message'
| @blocking_call_on_reactor_thread
def test_on_proposed_trade_accept(self):
| def mocked_start_transaction(*_):
mocked_start_transaction.called = True
mocked_start_transaction.called = False
self.market_community.update_ip(TraderId(self.market_community.mid), ('2.2.2.2', 2))
self.market_community.start_transaction = mocked_start_transaction
self.market_community.order... |
'Test whether we decline a trade when we receive an invalid proposed trade message'
| @blocking_call_on_reactor_thread
def test_on_proposed_trade_decline(self):
| def mocked_send_decline_trade(*_):
mocked_send_decline_trade.called = True
mocked_send_decline_trade.called = False
self.market_community.update_ip(TraderId(self.market_community.mid), ('2.2.2.2', 2))
self.market_community.send_declined_trade = mocked_send_decline_trade
self.market_community... |
'Test whether we send a counter trade when we receive a proposed trade message'
| @blocking_call_on_reactor_thread
def test_on_proposed_trade_counter(self):
| def mocked_send_counter_trade(*_):
mocked_send_counter_trade.called = True
mocked_send_counter_trade.called = False
self.market_community.update_ip(TraderId(self.market_community.mid), ('2.2.2.2', 2))
self.market_community.send_counter_trade = mocked_send_counter_trade
self.market_community.... |
'Test whether the right operations happen when we receive an offer sync'
| @blocking_call_on_reactor_thread
def test_on_offer_sync(self):
| self.assertEqual(len(self.market_community.order_book.asks), 0)
self.assertEqual(len(self.market_community.order_book.bids), 0)
self.market_community.update_ip(TraderId(self.market_community.mid), ('2.2.2.2', 2))
self.market_community.on_offer_sync([self.get_offer_sync(self.ask)])
self.assertEqual(l... |
'Test the compute_reputation method'
| @blocking_call_on_reactor_thread
def test_compute_reputation(self):
| self.market_community.tradechain_community = MockObject()
self.market_community.tradechain_community.persistence = MockObject()
self.market_community.tradechain_community.persistence.get_all_blocks = (lambda : [])
self.market_community.compute_reputation()
self.assertFalse(self.market_community.repu... |
'Test aborting a transaction'
| @blocking_call_on_reactor_thread
def test_abort_transaction(self):
| self.order.reserve_quantity_for_tick(OrderId(TraderId('0'), OrderNumber(23)), Quantity(30, 'DUM2'))
self.market_community.order_manager.order_repository.add(self.order)
self.market_community.update_ip(TraderId('0'), ('127.0.0.1', 1234))
self.market_community.start_transaction(self.proposed_trade)
tr... |
'Test the initialization of a price'
| def test_init(self):
| with self.assertRaises(ValueError):
Price('1', 'MC')
with self.assertRaises(ValueError):
Price(1, 2)
|
'Test the add trade method of an order'
| def test_add_trade(self):
| self.order.reserve_quantity_for_tick(OrderId(TraderId('5'), OrderNumber(1)), Quantity(10, 'MC'))
self.assertEquals(self.order.traded_quantity, Quantity(0, 'MC'))
self.order.add_trade(OrderId(TraderId('5'), OrderNumber(1)), Quantity(10, 'MC'))
self.assertEquals(self.order.traded_quantity, Quantity(10, 'M... |
'Test the status of an order'
| def test_status(self):
| self.assertEqual(self.order.status, 'open')
self.order._timeout = Timeout(0)
self.assertEqual(self.order.status, 'expired')
self.order._traded_quantity = self.order.total_quantity
self.assertEqual(self.order.status, 'completed')
self.order._cancelled = True
self.assertEqual(self.order.status... |
'Test the base compute method of the reputation manager'
| def test_compute(self):
| rep_mgr = ReputationManager(None)
self.assertRaises(NotImplementedError, rep_mgr.compute, 'a')
|
'Test the price level lists of wallets of a side'
| def test_get_price_level_list_wallets(self):
| self.assertFalse(self.side.get_price_level_list_wallets())
self.side.insert_tick(self.tick)
self.assertTrue(self.side.get_price_level_list_wallets())
|
'Testing the list representation of a side'
| def test_get_list_representation(self):
| self.assertFalse(self.side.get_list_representation())
self.side.insert_tick(self.tick)
list_rep = self.side.get_list_representation()
self.assertTrue(list_rep)
|
'Test the market intro payload'
| def test_properties(self):
| self.assertEqual(self.market_intro_payload.orders_bloom_filter, 'f')
self.market_intro_payload.set_orders_bloom_filter('g')
self.assertEqual(self.market_intro_payload.orders_bloom_filter, 'g')
|
'Test the start transaction payload'
| def test_properties(self):
| self.assertEquals(MessageNumber('1'), self.start_transaction_payload.message_number)
self.assertEquals(TransactionNumber(2), self.start_transaction_payload.transaction_number)
self.assertEquals(Timestamp(0.0), self.start_transaction_payload.timestamp)
self.assertEquals(TraderId('2'), self.start_transact... |
'Test the payment payload'
| def test_properties(self):
| self.assertEquals(MessageNumber('1'), self.payment_payload.message_number)
self.assertEquals(TransactionNumber(2), self.payment_payload.transaction_number)
self.assertEquals(Price(10, 'BTC'), self.payment_payload.transferee_price)
self.assertEquals(Quantity(20, 'MC'), self.payment_payload.transferee_qua... |
'Test the wallet info payload'
| def test_properties(self):
| self.assertEquals(WalletAddress('a'), self.wallet_info_payload.incoming_address)
self.assertEquals(WalletAddress('b'), self.wallet_info_payload.outgoing_address)
|
'Test the dictionary representation of a payment'
| def test_to_dictionary(self):
| self.assertDictEqual(self.payment.to_dictionary(), {'trader_id': '2', 'transaction_number': 2, 'price': 2.0, 'price_type': 'BTC', 'quantity': 3.0, 'quantity_type': 'MC', 'payment_id': 'aaa', 'address_from': 'a', 'address_to': 'b', 'timestamp': 4.0, 'success': True})
|
'Test the initialization of a quantity'
| def test_init(self):
| with self.assertRaises(ValueError):
PaymentId(1)
|
'Test the string representation of a payment id'
| def test_str(self):
| self.assertEqual(str(self.payment_id1), '3')
|
'Test equality between payment ids'
| def test_equality(self):
| self.assertEqual(self.payment_id1, PaymentId('3'))
self.assertNotEqual(self.payment_id1, self.payment_id2)
self.assertEqual(NotImplemented, self.payment_id1.__eq__('3'))
|
'Test the hash creation of a payment id'
| def test_hash(self):
| self.assertEqual(self.payment_id1.__hash__(), '3'.__hash__())
self.assertNotEqual(self.payment_id1.__hash__(), self.payment_id2.__hash__())
|
'Test the timeout functions of asks/bids'
| def test_timeouts(self):
| self.order_book.insert_ask(self.ask)
self.assertEqual(self.order_book.timeout_ask(self.ask.order_id), self.ask)
self.order_book.insert_bid(self.bid)
self.assertEqual(self.order_book.timeout_bid(self.bid.order_id), self.bid)
self.order_book.on_invalid_tick_insert(None)
|
'Test the retrieval of a tick from the order book'
| def test_get_tick(self):
| self.order_book.insert_ask(self.ask)
self.order_book.insert_bid(self.bid)
self.assertTrue(self.order_book.get_tick(self.ask.order_id))
self.assertTrue(self.order_book.get_tick(self.bid.order_id))
|
'Test whether we get an error when we add an invalid ask to the order book'
| @deferred(timeout=10)
def test_ask_insertion_invalid(self):
| return self.order_book.insert_ask(self.invalid_ask)
|
'Test whether we get an error when we add an invalid bid to the order book'
| @deferred(timeout=10)
def test_bid_insertion_invalid(self):
| return self.order_book.insert_bid(self.invalid_bid)
|
'Test the trade tick method in an order book'
| def test_trade_tick(self):
| self.order_book.insert_ask(self.ask)
self.order_book.insert_bid(self.bid)
self.order_book.insert_ask(self.ask2)
self.order_book.insert_bid(self.bid2)
self.order_book.trade_tick(self.ask.order_id, self.bid.order_id, Quantity(20, 'MC'), Timestamp.now())
self.assertTrue(self.order_book.tick_exists(... |
'Test the get order IDs function in order book'
| def test_get_order_ids(self):
| self.assertFalse(self.order_book.get_order_ids())
self.order_book.insert_ask(self.ask)
self.order_book.insert_bid(self.bid)
self.assertEqual(len(self.order_book.get_order_ids()), 2)
|
'Test whether ticks from the order book are correctly saved to the database'
| @blocking_call_on_reactor_thread
def test_save_to_db(self):
| self.order_book.insert_ask(self.ask)
self.order_book.insert_bid(self.bid)
self.order_book.save_to_database()
self.assertEqual(len(self.database.get_ticks()), 2)
|
'Test whether ticks from the database are correctly restored to the order book'
| @blocking_call_on_reactor_thread
def test_restore_from_db(self):
| self.database.add_tick(self.ask)
self.database.add_tick(self.bid)
self.order_book.restore_from_database()
self.assertEqual(len(self.order_book.asks), 1)
self.assertEqual(len(self.order_book.bids), 1)
|
'Test the creating, opening, transactions and balance query of a Bitcoin wallet'
| @deferred(timeout=20)
def test_btc_wallet(self):
| wallet = BitcoinWallet(self.session_base_dir, testnet=True)
def on_wallet_transactions(transactions):
self.assertFalse(transactions)
wallet.get_transactions = (lambda : succeed([{'id': 'abc'}]))
return wallet.monitor_transaction('abc')
def on_wallet_balance(balance):
self.ass... |
'Test the name of a Bitcoin wallet'
| def test_btc_wallet_name(self):
| wallet = BitcoinWallet(self.session_base_dir)
self.assertEqual(wallet.get_name(), 'Bitcoin')
|
'Test the identifier of a Bitcoin wallet'
| def test_btc_wallet_identfier(self):
| wallet = BitcoinWallet(self.session_base_dir)
self.assertEqual(wallet.get_identifier(), 'BTC')
|
'Test the address of a Bitcoin wallet'
| def test_btc_wallet_address(self):
| wallet = BitcoinWallet(self.session_base_dir)
self.assertEqual(wallet.get_address(), '')
|
'Test the mininum unit of a Bitcoin wallet'
| def test_btc_wallet_unit(self):
| wallet = BitcoinWallet(self.session_base_dir)
self.assertEqual(wallet.min_unit(), 0.0001)
|
'Test the retrieval of the balance of a BTC wallet that is not created yet'
| def test_btc_balance_no_wallet(self):
| def on_wallet_balance(balance):
self.assertDictEqual(balance, {'available': 0, 'pending': 0, 'currency': 'BTC'})
wallet = BitcoinWallet(self.session_base_dir)
return wallet.get_balance().addCallback(on_wallet_balance)
|
'Test that the transfer method of a BTC wallet raises an error when we don\'t have enough funds'
| @deferred(timeout=10)
def test_btc_wallet_transfer_no_funds(self):
| test_deferred = Deferred()
wallet = BitcoinWallet(self.session_base_dir)
mock_daemon = MockObject()
wallet.get_daemon = (lambda : mock_daemon)
wallet.transfer(3, 'abacd').addErrback((lambda _: test_deferred.callback(None)))
return test_deferred
|
'Test that the transfer method of a BTC wallet'
| @deferred(timeout=10)
def test_btc_wallet_transfer(self):
| def mocked_run_cmdline(request):
if (request['cmd'] == 'payto'):
return {'hex': 'abcd'}
elif (request['cmd'] == 'broadcast'):
return (True, 'abcd')
wallet = BitcoinWallet(self.session_base_dir)
mock_daemon = MockObject()
mock_server = MockObject()
mock_server.... |
'Test that the transfer method of a BTC wallet'
| @deferred(timeout=10)
def test_btc_wallet_transfer_error(self):
| def mocked_run_cmdline(request):
if (request['cmd'] == 'payto'):
return {'hex': 'abcd'}
elif (request['cmd'] == 'broadcast'):
return (False, 'abcd')
test_deferred = Deferred()
wallet = BitcoinWallet(self.session_base_dir)
mock_daemon = MockObject()
mock_server... |
'Test the identifier of the Trustchain wallet'
| def test_get_mc_wallet_name(self):
| self.assertEqual(self.tc_wallet.get_name(), 'Reputation')
|
'Test the identifier of a Trustchain wallet'
| def test_get_mc_wallet_id(self):
| self.assertEqual(self.tc_wallet.get_identifier(), 'MC')
|
'Test the balance retrieval of a Trustchain wallet'
| @deferred(timeout=10)
def test_get_balance(self):
| def on_balance(balance):
self.assertEqual(balance['available'], 5)
return self.tc_wallet.get_balance().addCallback(on_balance)
|
'Test whether creating a Trustchain wallet raises an error'
| def test_create_wallet(self):
| self.assertRaises(RuntimeError, self.tc_wallet.create_wallet)
|
'Test the transfer method of a Trustchain wallet'
| @deferred(timeout=10)
def test_transfer_invalid(self):
| test_deferred = Deferred()
def on_error(failure):
self.assertIsInstance(failure.value, InsufficientFunds)
test_deferred.callback(None)
self.tc_wallet.transfer(200, None).addErrback(on_error)
return test_deferred
|
'Test the transfer method of a Trustchain wallet with a missing member'
| @deferred(timeout=10)
def test_transfer_missing_member(self):
| candidate = MockObject()
candidate.get_member = (lambda : None)
candidate.sock_addr = None
self.tc_wallet.check_negative_balance = False
self.tc_wallet.send_signature = (lambda *_: None)
return self.tc_wallet.transfer(200, candidate)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.