Ejemplo n.º 1
0
 def test_yield_event_plugin(self):
     # configure with adapter + plugin
     chainsync = ChainSync(adapter=SteemAdapter(),
                           plugins=[SamplePlugin1()])
     # sample 'what' and 'data' for the event
     what = 'block'
     data = {'timestamp': '2018-02-19T23:54:09'}
     # yield the data in an event
     tupled = chainsync.yield_event(what, data)
     eventType, eventData = tupled
     # they should still match
     self.assertEqual(eventType, what)
     self.assertEqual(eventData, data)
     # ensure a datetime is returned
     self.assertIsInstance(eventData['timestamp'], datetime)
 def test_txopdata_format(self):
     # Specify custom node since api.steemit.com doesn't have these endpoints enabled
     adapter = SteemAdapter(endpoints='https://steemd.pevo.science',
                            retry=False)
     chainsync = ChainSync(adapter=adapter, retry=False)
     # Load a transaction by ID
     transaction = chainsync.get_transaction(
         '04008551461adb9a48c5c9eac8be6f63f9c840d9')
     for opIndex, op in enumerate(transaction['operations']):
         formatted = adapter.format_op_from_get_transaction(transaction,
                                                            op,
                                                            opIndex=opIndex)
         self.assertEqual(formatted['block_num'], 4042653)
         self.assertTrue(formatted['op_in_trx'] >= 0)
         self.assertTrue(formatted['trx_in_block'] >= 0)
         self.assertTrue('operation_type' in formatted
                         and formatted['operation_type'] is not False)
         self.assertTrue('transaction_id' in formatted
                         and formatted['transaction_id'] is not False)
Ejemplo n.º 3
0
from chainsync import ChainSync
from chainsync.adapters.steem import SteemAdapter

from chainmodel import ChainModel
from chainmodel.models.steem.schema import Schema

# define endpoints
endpoints = [
    'https://api.steemit.com/',
    'https://rpc.buildteam.io/',
    'https://steemd.privex.io/',
]

# setup adapter + chainsync
adapter = SteemAdapter(endpoints=endpoints)
chainsync = ChainSync(adapter)

# establish models with schema
chainmodel = ChainModel(schema=Schema())

# connect to database
mongo = MongoClient('mongodb://localhost', connect=False)
db = mongo['steem']

# stream all operations
for dataType, opData in chainsync.stream(['ops']):

    # model data based on schema
    model = chainmodel.get(opData)

    # insert in database
Ejemplo n.º 4
0
 def setUp(self):
     adapter = SteemAdapter(endpoints='https://steemd.pevo.science',
                            retry=False)
     self.chainsync = ChainSync(adapter=adapter, retry=False)
Ejemplo n.º 5
0
 def test_main_debug_flag_set_true_from_main_false_for_adapter(self):
     adapter = SteemAdapter(debug=False)
     # main debug flag should override adapter
     custom = ChainSync(adapter, debug=True)
     self.assertEqual(custom.debug, True)
     self.assertEqual(custom.adapter.debug, True)
Ejemplo n.º 6
0
 def test_main_debug_flag_set_false_from_adapter(self):
     adapter = SteemAdapter(debug=True)
     custom = ChainSync(adapter)
     self.assertEqual(custom.debug, False)
Ejemplo n.º 7
0
 def test_main_debug_flag_set_true(self):
     adapter = SteemAdapter()
     custom = ChainSync(adapter, debug=True)
     self.assertEqual(custom.debug, True)
Ejemplo n.º 8
0
 def setUp(self):
     adapter = SteemAdapter(
         endpoints='https://rpc.buildteam.io',
         retry=False
     )
     self.chainsync = ChainSync(adapter=adapter, retry=False)
Ejemplo n.º 9
0
 def setUp(self):
     self.chainsync = ChainSync(adapter=SteemAdapter)
Ejemplo n.º 10
0
 def test_adapter_debug_flag_set_true(self):
     adapter = SteemAdapter(debug=True)
     custom = ChainSync(adapter)
     self.assertEqual(custom.adapter.debug, True)
Ejemplo n.º 11
0
 def test_adapter_init_custom_adapter_custom_endpoint_list(self):
     endpoints = ['http://localhost:8091', 'http://localhost:8090']
     adapter = SteemAdapter(endpoints=endpoints)
     custom = ChainSync(adapter)
     self.assertEqual(custom.adapter.endpoint, 'http://localhost:8091')
     self.assertEqual(custom.adapter.endpoints, endpoints)
Ejemplo n.º 12
0
 def test_adapter_init_custom_adapter_custom_endpoint_string(self):
     adapter = SteemAdapter(endpoints='http://localhost:8091')
     custom = ChainSync(adapter)
     self.assertEqual(custom.adapter.endpoint, 'http://localhost:8091')
Ejemplo n.º 13
0
 def setUp(self):
     self.chainsync = ChainSync(adapter=self.adapter, retry=False)