コード例 #1
0
ファイル: base.py プロジェクト: JeffWScott/cilantro
def build_test_transaction() -> TransactionBase:
    """
    Utility method to build a random transaction (an instance of a subclass of TransactionBase). Used exclusively for
    unit/integration tests.
    :return: An instance of a subclass of TransactionBase
    """
    from cilantro.messages.transaction.contract import ContractTransactionBuilder
    return ContractTransactionBuilder.random_currency_tx()
コード例 #2
0
ファイル: test_perf_pubsub.py プロジェクト: sanko61/cilantro
def publisher():
    SLEEP_TIME = 0.05
    MAX_TIME = 10
    from cilantro.logger import get_logger, overwrite_logger_level
    from cilantro.utils.test import MPComposer
    from cilantro.messages.transaction.contract import ContractTransactionBuilder
    from cilantro.constants.testnet import TESTNET_DELEGATES
    import time, os

    log = get_logger("Publisher")
    sub_info = TESTNET_DELEGATES[1]
    sub_info['ip'] = os.getenv('HOST_IP')

    d_info = TESTNET_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.important(
        "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.notice("Sending pub")
        msg = ContractTransactionBuilder.random_currency_tx()
        pub.send_pub_msg(filter='0', message=msg)

        time.sleep(SLEEP_TIME)
        elapsed_time += SLEEP_TIME

    pub.teardown()
    log.important("Done with experiment!")