From c5bed6e8c4e8a1b00c1eb362a3c9bd0ea577baee Mon Sep 17 00:00:00 2001 From: Frederic Fortier Date: Tue, 6 Feb 2018 21:15:30 -0500 Subject: [PATCH] BLD: made some adjustments during testing --- catalyst/examples/mean_reversion_simple.py | 2 +- catalyst/marketplace/marketplace.py | 46 +++++++++++++--------- tests/marketplace/test_marketplace.py | 7 ++-- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/catalyst/examples/mean_reversion_simple.py b/catalyst/examples/mean_reversion_simple.py index db787612e..3b94d925c 100644 --- a/catalyst/examples/mean_reversion_simple.py +++ b/catalyst/examples/mean_reversion_simple.py @@ -257,7 +257,7 @@ def analyze(context=None, perf=None): algo_namespace=NAMESPACE, base_currency='eth', live_graph=False, - simulate_orders=False, + simulate_orders=True, stats_output=None, # auth_aliases=dict(poloniex='auth2') ) diff --git a/catalyst/marketplace/marketplace.py b/catalyst/marketplace/marketplace.py index 61ed7fecd..8f03145c0 100644 --- a/catalyst/marketplace/marketplace.py +++ b/catalyst/marketplace/marketplace.py @@ -142,14 +142,14 @@ def sign_transaction(self, from_address, tx): 'Gas Limit:\t\t{gas}\n' 'Nonce:\t\t\t{nonce}\n' 'Data:\t\t\t{data}\n'.format( - _from=from_address, - to=tx['to'], - value=tx['value'], - gas=tx['gas'], - nonce=tx['nonce'], - data=tx['data'], - ) - ) + _from=from_address, + to=tx['to'], + value=tx['value'], + gas=tx['gas'], + nonce=tx['nonce'], + data=tx['data'], + ) + ) signed_tx = input('Copy and Paste the "Signed Transaction" ' 'field here:\n') @@ -197,6 +197,7 @@ def list(self): print(df) def subscribe(self, dataset): + # TODO: what happens if we are already subscribed? dataset = dataset.lower() address = self.choose_pubaddr()[0] @@ -217,11 +218,13 @@ def subscribe(self, dataset): print('Checking that the ENG balance in {} is greater than ' '{} ENG... '.format(address, price), end='') + wallet_address = address[2:] balance = self.web3.eth.call({ 'from': address, 'to': self.eng_contract_address, 'data': '0x70a08231000000000000000000000000{}'.format( - address[2:]) + wallet_address + ) }) try: balance = int(balance[2:], 16) // 10 ** 8 @@ -242,7 +245,7 @@ def subscribe(self, dataset): agree_pay = input('Please confirm that you agree to pay {} ENG ' 'for a monthly subscription to the dataset "{}" ' 'starting today. [default: Y] '.format( - price, dataset)) or 'y' + price, dataset)) or 'y' if agree_pay.lower() not in ('y', 'n'): print("Please answer Y or N.") else: @@ -259,22 +262,25 @@ def subscribe(self, dataset): '2. Second transaction is the actual subscription for the ' 'desired dataset'.format(price)) + grains = price * 10 ** 8 tx = self.eng_contract.functions.approve( self.mkt_contract_address, - price, + grains, ).buildTransaction( - {'nonce': self.web3.eth.getTransactionCount(address)}) + {'nonce': self.web3.eth.getTransactionCount(address)} + ) if 'ropsten' in ETH_REMOTE_NODE: tx['gas'] = min(int(tx['gas'] * 1.5), 4700000) signed_tx = self.sign_transaction(address, tx) - try: - tx_hash = '0x{}'.format(bin_hex( - self.web3.eth.sendRawTransaction(signed_tx))) - print('\nThis is the TxHash for this transaction: ' - '{}'.format(tx_hash)) + tx_hash = '0x{}'.format( + bin_hex(self.web3.eth.sendRawTransaction(signed_tx)) + ) + print( + '\nThis is the TxHash for this transaction: {}'.format(tx_hash) + ) except Exception as e: print('Unable to subscribe to data source: {}'.format(e)) @@ -350,7 +356,7 @@ def subscribe(self, dataset): 'You can now ingest this dataset anytime during the ' 'next month by running the following command:\n' 'catalyst marketplace ingest --dataset={}'.format( - dataset, address, dataset)) + dataset, address, dataset)) def process_temp_bundle(self, ds_name, path): """ @@ -381,6 +387,7 @@ def process_temp_bundle(self, ds_name, path): def ingest(self, ds_name, start=None, end=None, force_download=False): ds_name = ds_name.lower() + # TODO: catch error conditions provider_info = self.mkt_contract.functions.getDataProviderInfo( bytes32(ds_name) ).call() @@ -391,7 +398,8 @@ def ingest(self, ds_name, start=None, end=None, force_download=False): return address, address_i = self.choose_pubaddr() - check_sub = self.mkt_contract.functions.checkAddressSubscription( + fns = self.mkt_contract.functions + check_sub = fns.checkAddressSubscription( address, bytes32(ds_name) ).call() diff --git a/tests/marketplace/test_marketplace.py b/tests/marketplace/test_marketplace.py index d2511ce8a..c45a727d6 100644 --- a/tests/marketplace/test_marketplace.py +++ b/tests/marketplace/test_marketplace.py @@ -16,18 +16,19 @@ def test_register(self): def test_subscribe(self): marketplace = Marketplace() - marketplace.subscribe('marketcap1') + marketplace.subscribe('marketcap1234') pass def test_ingest(self): marketplace = Marketplace() - ds_def = marketplace.ingest('marketcap1') + ds_def = marketplace.ingest('marketcap1234') pass def test_publish(self): marketplace = Marketplace() datadir = '/Users/fredfortier/Downloads/marketcap_test_single' - marketplace.publish('marketcap1', datadir, False) + marketplace.publish('marketcap1234', datadir, False) + pass def test_clean(self): marketplace = Marketplace()