Example #1
0
    def test_run_currency(self):
        tables = build_tables(self.ex, should_drop=True)

        run_contract(self.ex,
                     tables.contracts,
                     code_str=USING_CURRENCY_CODE,
                     user_id='DAVIS')
Example #2
0
    def test_run_currency_with_template(self):
        tables = build_tables(self.ex, should_drop=True)
        code_str = ContractTemplate.interpolate_template('currency',
                                                         receiver='DAVIS',
                                                         amount=2 * (10**6))

        run_contract(self.ex,
                     tables.contracts,
                     code_str=code_str,
                     user_id='CARL')
Example #3
0
 def _run_contract(self, contract: ContractTransaction, rerun: bool = False):
     self.log.debug("Executing use_contracts from user {}".format(contract.sender))
     res = run_contract(self.ex, self.contracts_table, contract_id=None, user_id=contract.sender, code_str=contract.code)
     if not res:
         self.log.error("Error executing use_contracts from user {} with code:\n{}\nres:{}".format(contract.sender, contract.code, res))
         self._rerun_contracts()
     else:
         self.log.debug("Successfully executing use_contracts from sender {}".format(contract.sender))
         if rerun: return res
         else: self.queue.append(contract)
Example #4
0
def run_contracts_standalone(num_contracts=100):
    ex = Executer('root', '', DB_NAME, '127.0.0.1')
    with DB() as db:
        contracts_table = db.tables.contracts

    count = 0
    start = time.time()
    log.info("Running contracts...")
    for _ in range(num_contracts):
        run_contract(ex,
                     contracts_table,
                     contract_id=None,
                     user_id=SENDER_VK,
                     code_str=CODE_STR)
        count += 1
        if count % checkpoint_freq == 0:
            log.notice("{} contracts run so far.".format(count))

    total_time = time.time() - start
    cps = num_contracts / total_time
    log.important("Ran {} contracts in {} seconds".format(
        num_contracts, round(total_time, 4)))
    log.important("{} contracts per second.".format(round(cps, 2)))