Browse Source

Revert "Python 3 style conversion"

This reverts commit c08b69ba75.
master
AdamISZ 7 years ago
parent
commit
2eb3a8737d
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 5
      conftest.py
  2. 4
      jmbase/jmbase/__init__.py
  3. 47
      jmbase/jmbase/bigstring.py
  4. 146
      jmbase/jmbase/commands.py
  5. 6
      jmbase/jmbase/support.py
  6. 2
      jmbase/setup.py
  7. 4
      jmbase/test/test_base_support.py
  8. 4
      jmbase/test/test_commands.py
  9. 2
      jmbitcoin/setup.py
  10. 2
      jmclient/setup.py
  11. 6
      jmdaemon/jmdaemon/__init__.py
  12. 6
      jmdaemon/jmdaemon/daemon_protocol.py
  13. 4
      jmdaemon/jmdaemon/enc_wrapper.py
  14. 4
      jmdaemon/jmdaemon/irc.py
  15. 6
      jmdaemon/jmdaemon/message_channel.py
  16. 6
      jmdaemon/jmdaemon/orderbookwatch.py
  17. 9
      jmdaemon/jmdaemon/protocol.py
  18. 4
      jmdaemon/jmdaemon/socks.py
  19. 2
      jmdaemon/setup.py
  20. 4
      jmdaemon/test/dummy_mc.py
  21. 3
      jmdaemon/test/msgdata.py
  22. 4
      jmdaemon/test/test_daemon_protocol.py
  23. 25
      jmdaemon/test/test_enc_wrapper.py
  24. 6
      jmdaemon/test/test_irc_messaging.py
  25. 8
      jmdaemon/test/test_message_channel.py
  26. 4
      jmdaemon/test/test_orderbookwatch.py

5
conftest.py

@ -1,6 +1,3 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
import pytest import pytest
import os import os
import time import time
@ -19,7 +16,7 @@ def local_command(command, bg=False, redirect=''):
elif OS == 'Linux': elif OS == 'Linux':
command.extend(['>', '/dev/null', '2>&1']) command.extend(['>', '/dev/null', '2>&1'])
else: else:
print("OS not recognised, quitting.") print "OS not recognised, quitting."
elif redirect: elif redirect:
command.extend(['>', redirect]) command.extend(['>', redirect])

4
jmbase/jmbase/__init__.py

@ -1,6 +1,4 @@
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import *
from .support import (get_log, chunks, debug_silence, debug_dump_object, from .support import (get_log, chunks, debug_silence, debug_dump_object,
joinmarket_alert, core_alert, get_password, _byteify, joinmarket_alert, core_alert, get_password, _byteify,

47
jmbase/jmbase/bigstring.py

@ -0,0 +1,47 @@
try:
from cStringIO import StringIO
except ImportError: #pragma: no cover
from StringIO import StringIO #pragma: no cover
from itertools import count
from twisted.protocols import amp
CHUNK_MAX = 0xffff
class BigString(amp.Argument):
"""
A byte-string amp.Argument with no 65,535 length limit.
Each value for a key/value pair in an AMP box may not
exceed 65,535 bytes in length. So if we *really* want to
send potentially larger values, this class will implicitly
encode/decode them to/from an arbitrary additional
number of key/value pairs that are given automatic key
names by prefixing this Argument's key name to a counter.
"""
def fromBox(self, name, strings, objects, proto):
value = StringIO()
value.write(strings.get(name))
for counter in count(2):
chunk = strings.get("%s.%d" % (name, counter))
if chunk is None:
break
value.write(chunk)
objects[name] = self.buildvalue(value.getvalue())
def buildvalue(self, value):
return value
def toBox(self, name, strings, objects, proto):
value = StringIO(self.fromvalue(objects[name]))
firstChunk = value.read(CHUNK_MAX)
strings[name] = firstChunk
counter = 2
while True:
nextChunk = value.read(CHUNK_MAX)
if not nextChunk:
break
strings["%s.%d" % (name, counter)] = nextChunk
counter += 1
def fromvalue(self, value):
return value

146
jmbase/jmbase/commands.py

@ -1,19 +1,18 @@
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
""" """
Commands defining client-server (daemon) Commands defining client-server (daemon)
messaging protocol (*not* Joinmarket p2p protocol). messaging protocol (*not* Joinmarket p2p protocol).
Used for AMP asynchronous messages. Used for AMP asynchronous messages.
""" """
from twisted.protocols.amp import Boolean, Command, Integer, Unicode from twisted.protocols.amp import Boolean, Command, Integer, String
from bigstring import BigString
class DaemonNotReady(Exception): class DaemonNotReady(Exception):
pass pass
class JMCommand(Command): class JMCommand(Command):
#a default response type #a default response type
response = [(b'accepted', Boolean())] response = [('accepted', Boolean())]
"""COMMANDS FROM CLIENT TO DAEMON """COMMANDS FROM CLIENT TO DAEMON
================================= =================================
@ -28,44 +27,44 @@ class JMInit(JMCommand):
Blockchain source is communicated only as a naming Blockchain source is communicated only as a naming
tag for messagechannels (currently IRC 'realname' field). tag for messagechannels (currently IRC 'realname' field).
""" """
arguments = [(b'bcsource', Unicode()), arguments = [('bcsource', String()),
(b'network', Unicode()), ('network', String()),
(b'irc_configs', Unicode()), ('irc_configs', String()),
(b'minmakers', Integer()), ('minmakers', Integer()),
(b'maker_timeout_sec', Integer())] ('maker_timeout_sec', Integer())]
errors = {DaemonNotReady: b'daemon is not ready'} errors = {DaemonNotReady: 'daemon is not ready'}
class JMStartMC(JMCommand): class JMStartMC(JMCommand):
"""Will restart message channel connections if config """Will restart message channel connections if config
has changed; otherwise will only change nym/nick on MCs. has changed; otherwise will only change nym/nick on MCs.
""" """
arguments = [(b'nick', Unicode())] arguments = [('nick', String())]
class JMSetup(JMCommand): class JMSetup(JMCommand):
"""Communicates which of "MAKER" or "TAKER" """Communicates which of "MAKER" or "TAKER"
roles are to be taken by this client; for MAKER roles are to be taken by this client; for MAKER
role, passes initial offers for announcement (for TAKER, this data is "none") role, passes initial offers for announcement (for TAKER, this data is "none")
""" """
arguments = [(b'role', Unicode()), arguments = [('role', String()),
(b'initdata', Unicode())] ('initdata', String())]
class JMMsgSignature(JMCommand): class JMMsgSignature(JMCommand):
"""A response to a request for a bitcoin signature """A response to a request for a bitcoin signature
on a message-channel layer message from the daemon on a message-channel layer message from the daemon
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'cmd', Unicode()), ('cmd', String()),
(b'msg_to_return', Unicode()), ('msg_to_return', String()),
(b'hostid', Unicode())] ('hostid', String())]
class JMMsgSignatureVerify(JMCommand): class JMMsgSignatureVerify(JMCommand):
"""A response to a request to verify the bitcoin signature """A response to a request to verify the bitcoin signature
of a message-channel layer message from the daemon of a message-channel layer message from the daemon
""" """
arguments = [(b'verif_result', Boolean()), arguments = [('verif_result', Boolean()),
(b'nick', Unicode()), ('nick', String()),
(b'fullmsg', Unicode()), ('fullmsg', String()),
(b'hostid', Unicode())] ('hostid', String())]
"""TAKER specific commands """TAKER specific commands
""" """
@ -78,24 +77,24 @@ class JMRequestOffers(JMCommand):
class JMFill(JMCommand): class JMFill(JMCommand):
"""Fill an offer/order """Fill an offer/order
""" """
arguments = [(b'amount', Integer()), arguments = [('amount', Integer()),
(b'commitment', Unicode()), ('commitment', String()),
(b'revelation', Unicode()), ('revelation', String()),
(b'filled_offers', Unicode())] ('filled_offers', String())]
class JMMakeTx(JMCommand): class JMMakeTx(JMCommand):
"""Send a hex encoded raw bitcoin transaction """Send a hex encoded raw bitcoin transaction
to a set of counterparties to a set of counterparties
""" """
arguments = [(b'nick_list', Unicode()), arguments = [('nick_list', String()),
(b'txhex', Unicode())] ('txhex', String())]
class JMPushTx(JMCommand): class JMPushTx(JMCommand):
"""Pass a raw hex transaction to a specific """Pass a raw hex transaction to a specific
counterparty (maker) for pushing (anonymity feature in JM) counterparty (maker) for pushing (anonymity feature in JM)
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'txhex', Unicode())] ('txhex', String())]
"""MAKER specific commands """MAKER specific commands
""" """
@ -105,27 +104,27 @@ class JMAnnounceOffers(JMCommand):
to the daemon, along with new announcement to the daemon, along with new announcement
and cancellation lists (deltas). and cancellation lists (deltas).
""" """
arguments = [(b'to_announce', Unicode()), arguments = [('to_announce', String()),
(b'to_cancel', Unicode()), ('to_cancel', String()),
(b'offerlist', Unicode())] ('offerlist', String())]
class JMIOAuth(JMCommand): class JMIOAuth(JMCommand):
"""Send contents of !ioauth message after """Send contents of !ioauth message after
verifying Taker's auth message verifying Taker's auth message
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'utxolist', Unicode()), ('utxolist', String()),
(b'pubkey', Unicode()), ('pubkey', String()),
(b'cjaddr', Unicode()), ('cjaddr', String()),
(b'changeaddr', Unicode()), ('changeaddr', String()),
(b'pubkeysig', Unicode())] ('pubkeysig', String())]
class JMTXSigs(JMCommand): class JMTXSigs(JMCommand):
"""Send signatures on the bitcoin transaction """Send signatures on the bitcoin transaction
sent by TAKER sent by TAKER
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'sigs', Unicode())] ('sigs', String())]
"""COMMANDS FROM DAEMON TO CLIENT """COMMANDS FROM DAEMON TO CLIENT
================================= =================================
@ -138,10 +137,10 @@ class JMInitProto(JMCommand):
(that key being controlled by the client; the daemon knows nothing (that key being controlled by the client; the daemon knows nothing
about bitcoin). about bitcoin).
""" """
arguments = [(b'nick_hash_length', Integer()), arguments = [('nick_hash_length', Integer()),
(b'nick_max_encoded', Integer()), ('nick_max_encoded', Integer()),
(b'joinmarket_nick_header', Unicode()), ('joinmarket_nick_header', String()),
(b'joinmarket_version', Integer())] ('joinmarket_version', Integer())]
class JMUp(JMCommand): class JMUp(JMCommand):
"""Used to signal readiness of message channels to client. """Used to signal readiness of message channels to client.
@ -158,46 +157,47 @@ class JMRequestMsgSig(JMCommand):
"""Request the client to sign a message-channel """Request the client to sign a message-channel
layer message with the bitcoin key for the nick layer message with the bitcoin key for the nick
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'cmd', Unicode()), ('cmd', String()),
(b'msg', Unicode()), ('msg', String()),
(b'msg_to_be_signed', Unicode()), ('msg_to_be_signed', String()),
(b'hostid', Unicode())] ('hostid', String())]
class JMRequestMsgSigVerify(JMCommand): class JMRequestMsgSigVerify(JMCommand):
"""Request the client to verify a counterparty's """Request the client to verify a counterparty's
message-channel layer message against the provided nick message-channel layer message against the provided nick
""" """
arguments = [(b'msg', Unicode()), arguments = [('msg', String()),
(b'fullmsg', Unicode()), ('fullmsg', String()),
(b'sig', Unicode()), ('sig', String()),
(b'pubkey', Unicode()), ('pubkey', String()),
(b'nick', Unicode()), ('nick', String()),
(b'hashlen', Integer()), ('hashlen', Integer()),
(b'max_encoded', Integer()), ('max_encoded', Integer()),
(b'hostid', Unicode())] ('hostid', String())]
""" TAKER-specific commands """ TAKER-specific commands
""" """
class JMOffers(JMCommand): class JMOffers(JMCommand):
"""Return the entire contents of the """Return the entire contents of the
orderbook to TAKER, as a json-ified dict. orderbook to TAKER, as a json-ified dict;
note uses BigString because can be very large
""" """
arguments = [(b'orderbook', Unicode())] arguments = [('orderbook', BigString())]
class JMFillResponse(JMCommand): class JMFillResponse(JMCommand):
"""Returns ioauth data from MAKER if successful. """Returns ioauth data from MAKER if successful.
""" """
arguments = [(b'success', Boolean()), arguments = [('success', Boolean()),
(b'ioauth_data', Unicode())] ('ioauth_data', String())]
class JMSigReceived(JMCommand): class JMSigReceived(JMCommand):
"""Returns an individual bitcoin transaction signature """Returns an individual bitcoin transaction signature
from a MAKER from a MAKER
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'sig', Unicode())] ('sig', String())]
"""MAKER-specific commands """MAKER-specific commands
""" """
@ -208,17 +208,17 @@ class JMAuthReceived(JMCommand):
allowing the MAKER to verify against btc library allowing the MAKER to verify against btc library
before setting up encryption and continuing. before setting up encryption and continuing.
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'offer', Unicode()), ('offer', String()),
(b'commitment', Unicode()), ('commitment', String()),
(b'revelation', Unicode()), ('revelation', String()),
(b'amount', Integer()), ('amount', Integer()),
(b'kphex', Unicode())] ('kphex', String())]
class JMTXReceived(JMCommand): class JMTXReceived(JMCommand):
"""Send back transaction template provided """Send back transaction template provided
by TAKER, along with offerdata to verify fees. by TAKER, along with offerdata to verify fees.
""" """
arguments = [(b'nick', Unicode()), arguments = [('nick', String()),
(b'txhex', Unicode()), ('txhex', String()),
(b'offer', Unicode())] ('offer', String())]

6
jmbase/jmbase/support.py

@ -1,6 +1,4 @@
from __future__ import (absolute_import, division, from __future__ import absolute_import, print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
import sys import sys
@ -50,7 +48,7 @@ def set_logging_level(level):
consoleHandler.setLevel(level) consoleHandler.setLevel(level)
def chunks(d, n): def chunks(d, n):
return [d[x:x + n] for x in range(0, len(d), n)] return [d[x:x + n] for x in xrange(0, len(d), n)]
def get_password(msg): #pragma: no cover def get_password(msg): #pragma: no cover
return getpass(msg) return getpass(msg)

2
jmbase/setup.py

@ -9,5 +9,5 @@ setup(name='joinmarketbase',
author_email='', author_email='',
license='GPL', license='GPL',
packages=['jmbase'], packages=['jmbase'],
install_requires=['future', 'twisted==18.9.0', 'service-identity'], install_requires=['twisted==18.9.0', 'service-identity'],
zip_safe=False) zip_safe=False)

4
jmbase/test/test_base_support.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
from jmbase.support import debug_dump_object, joinmarket_alert from jmbase.support import debug_dump_object, joinmarket_alert
def test_debug_dump_object(): def test_debug_dump_object():

4
jmbase/test/test_commands.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import *
from twisted.internet import protocol, reactor, task from twisted.internet import protocol, reactor, task
from twisted.internet.error import (ConnectionLost, ConnectionAborted, from twisted.internet.error import (ConnectionLost, ConnectionAborted,
ConnectionClosed, ConnectionDone) ConnectionClosed, ConnectionDone)

2
jmbitcoin/setup.py

@ -9,5 +9,5 @@ setup(name='joinmarketbitcoin',
author_email='', author_email='',
license='GPL', license='GPL',
packages=['jmbitcoin'], packages=['jmbitcoin'],
install_requires=['future', 'secp256k1',], install_requires=['secp256k1',],
zip_safe=False) zip_safe=False)

2
jmclient/setup.py

@ -9,5 +9,5 @@ setup(name='joinmarketclient',
author_email='', author_email='',
license='GPL', license='GPL',
packages=['jmclient'], packages=['jmclient'],
install_requires=['future', 'joinmarketbase==0.4.1', 'mnemonic', 'qt4reactor', 'argon2_cffi', 'bencoder.pyx', 'pyaes'], install_requires=['joinmarketbase==0.4.1', 'mnemonic', 'qt4reactor', 'argon2_cffi', 'bencoder.pyx', 'pyaes'],
zip_safe=False) zip_safe=False)

6
jmdaemon/jmdaemon/__init__.py

@ -1,9 +1,7 @@
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import *
import logging import logging
from .protocol import * from protocol import *
from .enc_wrapper import as_init_encryption, decode_decrypt, \ from .enc_wrapper import as_init_encryption, decode_decrypt, \
encrypt_encode, init_keypair, init_pubkey, get_pubkey, NaclError encrypt_encode, init_keypair, init_pubkey, get_pubkey, NaclError
from .irc import IRCMessageChannel from .irc import IRCMessageChannel

6
jmdaemon/jmdaemon/daemon_protocol.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import *
from .message_channel import MessageChannelCollection from .message_channel import MessageChannelCollection
from .orderbookwatch import OrderbookWatch from .orderbookwatch import OrderbookWatch
@ -294,7 +292,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
are stored in the active_orders dict keyed by the nick of the Taker. are stored in the active_orders dict keyed by the nick of the Taker.
""" """
nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig = [_byteify( nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig = [_byteify(
x) for x in (nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig)] x) for x in nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig]
if not self.role == "MAKER": if not self.role == "MAKER":
return return
if not nick in self.active_orders: if not nick in self.active_orders:

4
jmdaemon/jmdaemon/enc_wrapper.py

@ -1,6 +1,4 @@
from __future__ import (absolute_import, division, from __future__ import absolute_import, print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
# A wrapper for public key # A wrapper for public key
# authenticated encryption # authenticated encryption

4
jmdaemon/jmdaemon/irc.py

@ -1,6 +1,4 @@
from __future__ import (absolute_import, division, from __future__ import absolute_import, print_function
print_function, unicode_literals)
from builtins import *
#TODO: SSL support (can it be done without back-end openssl?) #TODO: SSL support (can it be done without back-end openssl?)
from twisted.internet import reactor, protocol from twisted.internet import reactor, protocol

6
jmdaemon/jmdaemon/message_channel.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
import abc import abc
import base64 import base64
import threading import threading
@ -14,7 +12,7 @@ from functools import wraps
log = get_log() log = get_log()
class CJPeerError(Exception): class CJPeerError(StandardError):
pass pass

6
jmdaemon/jmdaemon/orderbookwatch.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import absolute_import, print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
import sqlite3 import sqlite3
import sys import sys
@ -46,7 +44,7 @@ class OrderbookWatch(object):
min_version = int(params[0]) min_version = int(params[0])
max_version = int(params[1]) max_version = int(params[1])
alert = msg[msg.index(params[1]) + len(params[1]):].strip() alert = msg[msg.index(params[1]) + len(params[1]):].strip()
except (ValueError, IndexError): except ValueError, IndexError:
continue continue
if min_version < JM_VERSION < max_version: if min_version < JM_VERSION < max_version:
print('=' * 60) print('=' * 60)

9
jmdaemon/jmdaemon/protocol.py

@ -1,6 +1,3 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
#Protocol version #Protocol version
JM_VERSION = 5 JM_VERSION = 5
@ -19,8 +16,8 @@ offertypes = {"reloffer": [(int, "oid"), (int, "minsize"), (int, "maxsize"),
offername_list = offertypes.keys() offername_list = offertypes.keys()
ORDER_KEYS = [b'counterparty', b'oid', b'ordertype', b'minsize', b'maxsize', b'txfee', ORDER_KEYS = ['counterparty', 'oid', 'ordertype', 'minsize', 'maxsize', 'txfee',
b'cjfee'] 'cjfee']
COMMAND_PREFIX = '!' COMMAND_PREFIX = '!'
JOINMARKET_NICK_HEADER = 'J' JOINMARKET_NICK_HEADER = 'J'
@ -36,5 +33,5 @@ commitment_broadcast_list = ["hp2"]
plaintext_commands += offername_list plaintext_commands += offername_list
plaintext_commands += commitment_broadcast_list plaintext_commands += commitment_broadcast_list
public_commands = commitment_broadcast_list + ["orderbook", "cancel" public_commands = commitment_broadcast_list + ["orderbook", "cancel"
] + list(offername_list) ] + offername_list
private_commands = encrypted_commands + plaintext_commands private_commands = encrypted_commands + plaintext_commands

4
jmdaemon/jmdaemon/socks.py

@ -29,9 +29,7 @@ This module provides a standard socket-like interface for Python
for tunneling connections through SOCKS proxies. for tunneling connections through SOCKS proxies.
""" """
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
import socket import socket
import struct import struct
import random import random

2
jmdaemon/setup.py

@ -9,5 +9,5 @@ setup(name='joinmarketdaemon',
author_email='', author_email='',
license='GPL', license='GPL',
packages=['jmdaemon'], packages=['jmdaemon'],
install_requires=['future', 'txtorcon', 'pyopenssl', 'libnacl', 'joinmarketbase==0.4.1'], install_requires=['txtorcon', 'pyopenssl', 'libnacl', 'joinmarketbase==0.4.1'],
zip_safe=False) zip_safe=False)

4
jmdaemon/test/dummy_mc.py

@ -1,6 +1,4 @@
from __future__ import (absolute_import, division, from __future__ import absolute_import, print_function
print_function, unicode_literals)
from builtins import *
import time import time

3
jmdaemon/test/msgdata.py

@ -1,6 +1,3 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
#orderbook #orderbook
t_orderbook = [{u'counterparty': u'J5FA1Gj7Ln4vSGne', u'ordertype': u'reloffer', u'oid': 0, t_orderbook = [{u'counterparty': u'J5FA1Gj7Ln4vSGne', u'ordertype': u'reloffer', u'oid': 0,
u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'}, u'minsize': 7500000, u'txfee': 1000, u'maxsize': 599972700, u'cjfee': u'0.0002'},

4
jmdaemon/test/test_daemon_protocol.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import absolute_import
print_function, unicode_literals)
from builtins import *
'''test daemon-protocol interfacae.''' '''test daemon-protocol interfacae.'''
from jmdaemon import MessageChannelCollection from jmdaemon import MessageChannelCollection

25
jmdaemon/test/test_enc_wrapper.py

@ -1,6 +1,3 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
import base64 import base64
import string import string
import random import random
@ -14,37 +11,37 @@ from jmdaemon import (init_keypair, get_pubkey, init_pubkey, as_init_encryption,
@pytest.mark.parametrize("ab_message,ba_message,num_iterations", @pytest.mark.parametrize("ab_message,ba_message,num_iterations",
[ [
# short ascii # short ascii
(b"Attack at dawn", b"Not tonight Josephine!", 5), ("Attack at dawn", "Not tonight Josephine!", 5),
# long base64 encoded # long base64 encoded
(base64.b64encode(''.join(random.choice( (base64.b64encode(''.join(random.choice(
string.ascii_letters) for _ in range(5000))), string.ascii_letters) for _ in xrange(5000))),
base64.b64encode(''.join(random.choice( base64.b64encode(''.join(random.choice(
string.ascii_letters) for _ in range(5000))), string.ascii_letters) for _ in xrange(5000))),
5,), 5,),
# large number of messages on the same connection # large number of messages on the same connection
(b'rand', b'rand', 40000), ('rand', 'rand', 40000),
# 1 character # 1 character
(b'\x00', b'\x00', 5), ('\x00', '\x00', 5),
]) ])
def test_enc_wrapper(alice_bob_boxes, ab_message, ba_message, num_iterations): def test_enc_wrapper(alice_bob_boxes, ab_message, ba_message, num_iterations):
alice_box, bob_box = alice_bob_boxes alice_box, bob_box = alice_bob_boxes
for i in range(num_iterations): for i in range(num_iterations):
ab_message = (''.join( ab_message = ''.join(
random.choice(string.ascii_letters) random.choice(string.ascii_letters)
for x in range(100))).encode('ascii') if ab_message == b'rand' else ab_message for x in range(100)) if ab_message == 'rand' else ab_message
ba_message = (''.join( ba_message = ''.join(
random.choice(string.ascii_letters) random.choice(string.ascii_letters)
for x in range(100))).encode('ascii') if ba_message == b'rand' else ba_message for x in range(100)) if ba_message == 'rand' else ba_message
otw_amsg = alice_box.encrypt(ab_message) otw_amsg = alice_box.encrypt(ab_message)
bob_ptext = bob_box.decrypt(otw_amsg) bob_ptext = bob_box.decrypt(otw_amsg)
assert bob_ptext == ab_message, "Encryption test: FAILED. Alice sent: {}, Bob received: {}".format( assert bob_ptext == ab_message, "Encryption test: FAILED. Alice sent: %s, Bob received: " % (
ab_message, bob_ptext) ab_message, bob_ptext)
otw_bmsg = bob_box.encrypt(ba_message) otw_bmsg = bob_box.encrypt(ba_message)
alice_ptext = alice_box.decrypt(otw_bmsg) alice_ptext = alice_box.decrypt(otw_bmsg)
assert alice_ptext == ba_message, "Encryption test: FAILED. Bob sent: {}, Alice received: {}".format( assert alice_ptext == ba_message, "Encryption test: FAILED. Bob sent: %s, Alice received: " % (
ba_message, alice_ptext) ba_message, alice_ptext)
assert decode_decrypt(encrypt_encode(ab_message, bob_box), bob_box) == ab_message assert decode_decrypt(encrypt_encode(ab_message, bob_box), bob_box) == ab_message

6
jmdaemon/test/test_irc_messaging.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import absolute_import
print_function, unicode_literals)
from builtins import * # noqa: F401
'''Tests of joinmarket bots end-to-end (including IRC and bitcoin) ''' '''Tests of joinmarket bots end-to-end (including IRC and bitcoin) '''
import time import time
@ -43,7 +41,7 @@ def on_order_seen(dummy, counterparty, oid, ordertype, minsize,
yg_name = counterparty yg_name = counterparty
def on_pubkey(pubkey): def on_pubkey(pubkey):
print("received pubkey: " + pubkey) print "received pubkey: " + pubkey
def junk_pubmsgs(mc): def junk_pubmsgs(mc):
#start a raw IRCMessageChannel instance in a thread; #start a raw IRCMessageChannel instance in a thread;

8
jmdaemon/test/test_message_channel.py

@ -1,7 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import absolute_import
print_function, unicode_literals)
from builtins import *
'''test messagechannel management code.''' '''test messagechannel management code.'''
import pytest import pytest
@ -78,9 +76,9 @@ def don_error():
def don_ioauth(nick, utxo_list, auth_pub, cj_addr, def don_ioauth(nick, utxo_list, auth_pub, cj_addr,
change_addr, btc_sig): change_addr, btc_sig):
jlog.debug("onioauth callback") jlog.debug("onioauth callback")
jlog.debug("Args are: " + ",".join([str(x) for x in (nick, jlog.debug("Args are: " + ",".join([str(x) for x in nick,
utxo_list, auth_pub, cj_addr, utxo_list, auth_pub, cj_addr,
change_addr, btc_sig)])) change_addr, btc_sig]))
def don_sig(nick, sig): def don_sig(nick, sig):
jlog.debug("calledback on-sig") jlog.debug("calledback on-sig")

4
jmdaemon/test/test_orderbookwatch.py

@ -1,7 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import (absolute_import, division, from __future__ import print_function
print_function, unicode_literals)
from builtins import * # noqa: F401
import pytest import pytest

Loading…
Cancel
Save