def publisher(): SLEEP_TIME = 1 MAX_TIME = 10 from cilantro.logger import get_logger, overwrite_logger_level from cilantro.utils.test import MPComposer from cilantro.messages.transaction.standard import StandardTransactionBuilder import time, os log = get_logger("Publisher") sub_info = delegates[1] sub_info['ip'] = os.getenv('HOST_IP') d_info = delegates[0] d_info['ip'] = os.getenv('HOST_IP') pub = MPComposer(sk=d_info['sk']) # Publish on this node's own IP pub.add_pub(os.getenv('HOST_IP')) log.critical( "Starting experiment, sending messages every {} seconds for a total of {} seconds" .format(SLEEP_TIME, MAX_TIME)) elapsed_time = 0 while elapsed_time < MAX_TIME: log.info("Sending pub") msg = StandardTransactionBuilder.random_tx() pub.send_pub_msg(filter='0', message=msg) time.sleep(SLEEP_TIME) elapsed_time += SLEEP_TIME pub.teardown() log.critical("Done with experiment!")
def publisher(): from cilantro.logger import get_logger from cilantro.utils.test import MPComposer from cilantro.messages.transaction.standard import StandardTransactionBuilder import time, os, sys log = get_logger("Publisher") sub_info = delegates[1] sub_info['ip'] = os.getenv('HOST_IP') d_info = delegates[0] d_info['ip'] = os.getenv('HOST_IP') pub = MPComposer(sk=d_info['sk']) # Publish on this node's own IP pub.add_pub(os.getenv('HOST_IP')) for i in range(100): log.critical("Sending pub") msg = StandardTransactionBuilder.random_tx() time.sleep(0.1) pub.send_pub_msg(filter='0', message=msg) log.critical("Pub Done") sys.exit(0) exit
def random_envelope(): sk, vk = wallet.new() tx = StandardTransactionBuilder.random_tx() sender = 'me' return Envelope.create_from_message(message=tx, signing_key=sk, sender_id=sender)
def test_builder_serializiation(self): """ Tests serialization/deserialization using the StandardTransactionBuilder object """ tx = StandardTransactionBuilder.random_tx() clone = StandardTransaction.from_bytes(tx.serialize()) self.assertTrue(True)
def test_builder_reserialization(self): """ Tests that a transaction object can be loaded from binary created using StandardTransactionBuilder, and then properly serialized again """ tx = StandardTransactionBuilder.random_tx() clone = StandardTransaction.from_bytes(tx.serialize()) clone.serialize() self.assertTrue(True)
def test_create_with_envelope(self): """ Tests creating a message with an envelope produces an object with the expected properties """ sk, vk = wallet.new() tx = StandardTransactionBuilder.random_tx() sender = 'me' env = Envelope.create_from_message(message=tx, signing_key=sk) cmd = ReactorCommand.create_cmd('some_cls', 'some_func', envelope=env) self.assertTrue(ReactorCommand.envelope, env)
def random_msg(): return StandardTransactionBuilder.random_tx()
def _default_msg(self): # TODO -- write default TestMessage class # We should really have a default TestMessage object that is a bare-minimum subclass of MessageBase # instead of using other live objects for these kinds of tests message = StandardTransactionBuilder.random_tx() return message