BLD: made some adjustments during testing

This commit is contained in:
Frederic Fortier
2018-02-06 21:15:30 -05:00
parent 2320a1432a
commit c5bed6e8c4
3 changed files with 32 additions and 23 deletions
+1 -1
View File
@@ -257,7 +257,7 @@ if __name__ == '__main__':
algo_namespace=NAMESPACE, algo_namespace=NAMESPACE,
base_currency='eth', base_currency='eth',
live_graph=False, live_graph=False,
simulate_orders=False, simulate_orders=True,
stats_output=None, stats_output=None,
# auth_aliases=dict(poloniex='auth2') # auth_aliases=dict(poloniex='auth2')
) )
+27 -19
View File
@@ -142,14 +142,14 @@ class Marketplace:
'Gas Limit:\t\t{gas}\n' 'Gas Limit:\t\t{gas}\n'
'Nonce:\t\t\t{nonce}\n' 'Nonce:\t\t\t{nonce}\n'
'Data:\t\t\t{data}\n'.format( 'Data:\t\t\t{data}\n'.format(
_from=from_address, _from=from_address,
to=tx['to'], to=tx['to'],
value=tx['value'], value=tx['value'],
gas=tx['gas'], gas=tx['gas'],
nonce=tx['nonce'], nonce=tx['nonce'],
data=tx['data'], data=tx['data'],
) )
) )
signed_tx = input('Copy and Paste the "Signed Transaction" ' signed_tx = input('Copy and Paste the "Signed Transaction" '
'field here:\n') 'field here:\n')
@@ -197,6 +197,7 @@ class Marketplace:
print(df) print(df)
def subscribe(self, dataset): def subscribe(self, dataset):
# TODO: what happens if we are already subscribed?
dataset = dataset.lower() dataset = dataset.lower()
address = self.choose_pubaddr()[0] address = self.choose_pubaddr()[0]
@@ -217,11 +218,13 @@ class Marketplace:
print('Checking that the ENG balance in {} is greater than ' print('Checking that the ENG balance in {} is greater than '
'{} ENG... '.format(address, price), end='') '{} ENG... '.format(address, price), end='')
wallet_address = address[2:]
balance = self.web3.eth.call({ balance = self.web3.eth.call({
'from': address, 'from': address,
'to': self.eng_contract_address, 'to': self.eng_contract_address,
'data': '0x70a08231000000000000000000000000{}'.format( 'data': '0x70a08231000000000000000000000000{}'.format(
address[2:]) wallet_address
)
}) })
try: try:
balance = int(balance[2:], 16) // 10 ** 8 balance = int(balance[2:], 16) // 10 ** 8
@@ -242,7 +245,7 @@ class Marketplace:
agree_pay = input('Please confirm that you agree to pay {} ENG ' agree_pay = input('Please confirm that you agree to pay {} ENG '
'for a monthly subscription to the dataset "{}" ' 'for a monthly subscription to the dataset "{}" '
'starting today. [default: Y] '.format( 'starting today. [default: Y] '.format(
price, dataset)) or 'y' price, dataset)) or 'y'
if agree_pay.lower() not in ('y', 'n'): if agree_pay.lower() not in ('y', 'n'):
print("Please answer Y or N.") print("Please answer Y or N.")
else: else:
@@ -259,22 +262,25 @@ class Marketplace:
'2. Second transaction is the actual subscription for the ' '2. Second transaction is the actual subscription for the '
'desired dataset'.format(price)) 'desired dataset'.format(price))
grains = price * 10 ** 8
tx = self.eng_contract.functions.approve( tx = self.eng_contract.functions.approve(
self.mkt_contract_address, self.mkt_contract_address,
price, grains,
).buildTransaction( ).buildTransaction(
{'nonce': self.web3.eth.getTransactionCount(address)}) {'nonce': self.web3.eth.getTransactionCount(address)}
)
if 'ropsten' in ETH_REMOTE_NODE: if 'ropsten' in ETH_REMOTE_NODE:
tx['gas'] = min(int(tx['gas'] * 1.5), 4700000) tx['gas'] = min(int(tx['gas'] * 1.5), 4700000)
signed_tx = self.sign_transaction(address, tx) signed_tx = self.sign_transaction(address, tx)
try: try:
tx_hash = '0x{}'.format(bin_hex( tx_hash = '0x{}'.format(
self.web3.eth.sendRawTransaction(signed_tx))) bin_hex(self.web3.eth.sendRawTransaction(signed_tx))
print('\nThis is the TxHash for this transaction: ' )
'{}'.format(tx_hash)) print(
'\nThis is the TxHash for this transaction: {}'.format(tx_hash)
)
except Exception as e: except Exception as e:
print('Unable to subscribe to data source: {}'.format(e)) print('Unable to subscribe to data source: {}'.format(e))
@@ -350,7 +356,7 @@ class Marketplace:
'You can now ingest this dataset anytime during the ' 'You can now ingest this dataset anytime during the '
'next month by running the following command:\n' 'next month by running the following command:\n'
'catalyst marketplace ingest --dataset={}'.format( 'catalyst marketplace ingest --dataset={}'.format(
dataset, address, dataset)) dataset, address, dataset))
def process_temp_bundle(self, ds_name, path): def process_temp_bundle(self, ds_name, path):
""" """
@@ -381,6 +387,7 @@ class Marketplace:
def ingest(self, ds_name, start=None, end=None, force_download=False): def ingest(self, ds_name, start=None, end=None, force_download=False):
ds_name = ds_name.lower() ds_name = ds_name.lower()
# TODO: catch error conditions
provider_info = self.mkt_contract.functions.getDataProviderInfo( provider_info = self.mkt_contract.functions.getDataProviderInfo(
bytes32(ds_name) bytes32(ds_name)
).call() ).call()
@@ -391,7 +398,8 @@ class Marketplace:
return return
address, address_i = self.choose_pubaddr() 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) address, bytes32(ds_name)
).call() ).call()
+4 -3
View File
@@ -16,18 +16,19 @@ class TestMarketplace(WithLogger, ZiplineTestCase):
def test_subscribe(self): def test_subscribe(self):
marketplace = Marketplace() marketplace = Marketplace()
marketplace.subscribe('marketcap1') marketplace.subscribe('marketcap1234')
pass pass
def test_ingest(self): def test_ingest(self):
marketplace = Marketplace() marketplace = Marketplace()
ds_def = marketplace.ingest('marketcap1') ds_def = marketplace.ingest('marketcap1234')
pass pass
def test_publish(self): def test_publish(self):
marketplace = Marketplace() marketplace = Marketplace()
datadir = '/Users/fredfortier/Downloads/marketcap_test_single' datadir = '/Users/fredfortier/Downloads/marketcap_test_single'
marketplace.publish('marketcap1', datadir, False) marketplace.publish('marketcap1234', datadir, False)
pass
def test_clean(self): def test_clean(self):
marketplace = Marketplace() marketplace = Marketplace()