undo xcatconf change, pull in old tests, create a older for unit tests
This commit is contained in:
parent
de8ec2df54
commit
917acd1efc
12
xcat/cli.py
12
xcat/cli.py
|
@ -215,14 +215,20 @@ def newtrade(tradeid, **kwargs):
|
|||
protocol = Protocol()
|
||||
print("Creating new XCAT trade...")
|
||||
utils.erase_trade()
|
||||
|
||||
conf = kwargs['conf'] if 'conf' in kwargs else 'regtest'
|
||||
network = kwargs['network'] if 'network' in kwargs else 'regtest'
|
||||
|
||||
tradeid, trade = protocol.initialize_trade(
|
||||
tradeid,
|
||||
conf=kwargs['conf'],
|
||||
network=kwargs['network'])
|
||||
conf=conf,
|
||||
network=network)
|
||||
print("New trade created: {0}".format(trade))
|
||||
trade = protocol.seller_init(tradeid, trade, network=kwargs['network'])
|
||||
|
||||
trade = protocol.seller_init(tradeid, trade, network=network)
|
||||
print("\nUse 'xcat exporttrade [tradeid]' to export the trade and sent "
|
||||
"to the buyer.\n")
|
||||
|
||||
save_state(trade, tradeid)
|
||||
return trade
|
||||
|
||||
|
|
|
@ -1,111 +1,59 @@
|
|||
import unittest
|
||||
import unittest.mock as mock
|
||||
import xcat.cli as cli
|
||||
# from xcat.tests.utils import test_trade
|
||||
# from xcat.trades import Trade
|
||||
import xcat.db as db
|
||||
from xcat.protocol import Protocol
|
||||
from xcat.tests.utils import mktrade
|
||||
from xcat.trades import Trade # , Contract
|
||||
|
||||
|
||||
class TestCLI(unittest.TestCase):
|
||||
|
||||
def test_save_state(self):
|
||||
pass
|
||||
|
||||
def test_checkSellStatus(self):
|
||||
pass
|
||||
|
||||
def test_buyer_check_status(self):
|
||||
pass
|
||||
|
||||
def test_seller_check_status(self):
|
||||
pass
|
||||
|
||||
def test_checkBuyStatus(self):
|
||||
pass
|
||||
|
||||
def test_importtrade(self):
|
||||
pass
|
||||
|
||||
def test_wormhole_importtrade(self):
|
||||
pass
|
||||
class SimpleTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.trade = mktrade()
|
||||
|
||||
def test_exporttrade(self):
|
||||
self.__class__.hexstr = cli.exporttrade('test')
|
||||
self.assertTrue(int(self.hexstr, 16))
|
||||
|
||||
def test_importtrade(self):
|
||||
# trade = cli.importtrade('test', self.__class__.hexstr)
|
||||
pass
|
||||
|
||||
|
||||
class CliTest(SimpleTestCase):
|
||||
def test_findtrade(self):
|
||||
pass
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_test(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'me'
|
||||
test_contract.fulfiller = 'me'
|
||||
|
||||
res = cli.find_role(test_contract)
|
||||
|
||||
self.assertEqual(res, 'test')
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_initiator(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'me'
|
||||
test_contract.fulfiller = 'you'
|
||||
|
||||
res = cli.find_role(test_contract)
|
||||
|
||||
self.assertEqual(res, 'initiator')
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_fulfiller(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'you'
|
||||
test_contract.fulfiller = 'me'
|
||||
|
||||
res = cli.find_role(test_contract)
|
||||
|
||||
self.assertEqual(res, 'fulfiller')
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_error(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'you'
|
||||
test_contract.fulfiller = 'you'
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
cli.find_role(test_contract)
|
||||
|
||||
self.assertTrue(
|
||||
'You are not a participant in this contract.'
|
||||
in str(context.exception))
|
||||
|
||||
def test_checktrade(self):
|
||||
# trade = cli.findtrade('test')
|
||||
pass
|
||||
|
||||
def test_newtrade(self):
|
||||
pass
|
||||
|
||||
def test_listtrades(self):
|
||||
pass
|
||||
trade = cli.newtrade('new', conf='regtest')
|
||||
self.assertTrue(isinstance(trade, Trade))
|
||||
|
||||
def test_fundsell(self):
|
||||
pass
|
||||
protocol = Protocol()
|
||||
|
||||
def test_fundbuy(self):
|
||||
pass
|
||||
trade = db.get('new')
|
||||
status = cli.seller_check_status(trade)
|
||||
print("Trade status: {0}\n".format(status))
|
||||
self.assertEqual(status, 'init')
|
||||
|
||||
def test_seller_redeem(self):
|
||||
pass
|
||||
|
||||
def test_buyer_redeem(self):
|
||||
pass
|
||||
fund_tx = protocol.fund_sell_contract(trade)
|
||||
print("Sent fund_tx", fund_tx)
|
||||
|
||||
# def test_fundbuy(self):
|
||||
# trade = db.get('new')
|
||||
# status = cli.buyer_check_status(trade)
|
||||
# self.assertEqual(status, 'sellerFunded')
|
||||
# fund_tx = cli.fund_contract(trade.buy)
|
||||
#
|
||||
# def test_seller_redeem(self):
|
||||
# trade = db.get('new')
|
||||
# status = cli.seller_check_status(trade)
|
||||
# self.assertEqual(status, 'buyerFunded')
|
||||
#
|
||||
# def test_buyer_redeem(self):
|
||||
# trade = db.get('new')
|
||||
# status = cli.buyer_check_status(trade)
|
||||
# self.assertEqual(status, 'sellerFunded')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
import unittest
|
||||
import unittest.mock as mock
|
||||
import xcat.cli as cli
|
||||
# from xcat.tests.utils import test_trade
|
||||
# from xcat.trades import Trade
|
||||
|
||||
|
||||
class TestCLI(unittest.TestCase):
|
||||
|
||||
def test_save_state(self):
|
||||
pass
|
||||
|
||||
def test_checkSellStatus(self):
|
||||
pass
|
||||
|
||||
def test_buyer_check_status(self):
|
||||
pass
|
||||
|
||||
def test_seller_check_status(self):
|
||||
pass
|
||||
|
||||
def test_checkBuyStatus(self):
|
||||
pass
|
||||
|
||||
def test_importtrade(self):
|
||||
pass
|
||||
|
||||
def test_wormhole_importtrade(self):
|
||||
pass
|
||||
|
||||
def test_exporttrade(self):
|
||||
pass
|
||||
|
||||
def test_findtrade(self):
|
||||
pass
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_test(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'me'
|
||||
test_contract.fulfiller = 'me'
|
||||
|
||||
res = cli.find_role(test_contract)
|
||||
|
||||
self.assertEqual(res, 'test')
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_initiator(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'me'
|
||||
test_contract.fulfiller = 'you'
|
||||
|
||||
res = cli.find_role(test_contract)
|
||||
|
||||
self.assertEqual(res, 'initiator')
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_fulfiller(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'you'
|
||||
test_contract.fulfiller = 'me'
|
||||
|
||||
res = cli.find_role(test_contract)
|
||||
|
||||
self.assertEqual(res, 'fulfiller')
|
||||
|
||||
@mock.patch('xcat.cli.Protocol')
|
||||
def test_find_role_error(self, mock_protocol):
|
||||
mock_protocol().is_myaddr = lambda k: k == 'me'
|
||||
|
||||
test_contract = mock.MagicMock()
|
||||
test_contract.initiator = 'you'
|
||||
test_contract.fulfiller = 'you'
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
cli.find_role(test_contract)
|
||||
|
||||
self.assertTrue(
|
||||
'You are not a participant in this contract.'
|
||||
in str(context.exception))
|
||||
|
||||
def test_checktrade(self):
|
||||
pass
|
||||
|
||||
def test_newtrade(self):
|
||||
pass
|
||||
|
||||
def test_listtrades(self):
|
||||
pass
|
||||
|
||||
def test_fundsell(self):
|
||||
pass
|
||||
|
||||
def test_fundbuy(self):
|
||||
pass
|
||||
|
||||
def test_seller_redeem(self):
|
||||
pass
|
||||
|
||||
def test_buyer_redeem(self):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -1,3 +1,5 @@
|
|||
from xcat import db
|
||||
|
||||
test_trade = {
|
||||
"sell": {
|
||||
"amount": 3.5,
|
||||
|
@ -18,3 +20,8 @@ test_trade = {
|
|||
"p2sh": "t2HP59RpfR34nBCWH4VVD497tkc2ikzgniP",
|
||||
"fulfiller": "tmTjZSg4pX2Us6V5HttiwFZwj464fD2ZgpY"},
|
||||
"commitment": "03d58daab37238604b3e57d4a8bdcffa401dc497a9c1aa4f08ffac81616c22b6"}
|
||||
|
||||
def mktrade():
|
||||
db.create(test_trade, 'test')
|
||||
trade = db.get('test')
|
||||
return trade
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
ADDRS = {
|
||||
'regtest': {
|
||||
"initiator": {
|
||||
"bitcoin": "moAccTjGt6nRCoLKhVLrDCAkqDt7fnsAgC",
|
||||
"zcash": "tmJBCsE4ZBcgi2LykoUyei5PDT1cQPkFxpf"
|
||||
"bitcoin": "mvc56qCEVj6p57xZ5URNC3v7qbatudHQ9b",
|
||||
"zcash": "tmTF7LMLjvEsGdcepWPUsh4vgJNrKMWwEyc"
|
||||
},
|
||||
"fulfiller": {
|
||||
"bitcoin": "mxdJ47MeEeqrBDjHj7SrSLFoDuSP3G37t5",
|
||||
"zcash": "tmBbe7hWtexP94638H1QUD9Z92BM4ZiXXgA"
|
||||
"bitcoin": "moRt56gJQGDNK46Y6fYy2HbooKnQXrTGDN",
|
||||
"zcash": "tmK3rGzHDqa78MCwEicx9VcY9ZWX9gCF2nd"
|
||||
},
|
||||
"amounts": {'buy': {'currency': 'zcash', 'amount': 0.02}, 'sell': {'currency': 'bitcoin', 'amount': 0.01}}
|
||||
},
|
||||
|
@ -17,11 +17,9 @@ ADDRS = {
|
|||
"zcash": "tmTF7LMLjvEsGdcepWPUsh4vgJNrKMWwEyc"
|
||||
},
|
||||
"fulfiller": {
|
||||
"bitcoin": "mn2boR7rYq9DaAWWrVN5MazHKFyf7UhdyU",
|
||||
"zcash": "tmErB22A1G74aq32aAh5AoqgQSJsAAAdT2p"
|
||||
"bitcoin": "mm2smEJjRN4xoijEfpb5XvYd8e3EYWezom",
|
||||
"zcash": "tmPwPdceaJAHQn7UiRCVnJ5tXBXHVqWMkis"
|
||||
},
|
||||
"amounts": {'buy': {'currency': 'zcash', 'amount': 0.02}, 'sell': {'currency': 'bitcoin', 'amount': 0.01}}
|
||||
}
|
||||
}
|
||||
|
||||
NETWORK = 'testnet'
|
||||
|
|
Loading…
Reference in New Issue