def setup(): # overwrite_logger_level(0) with SenecaInterface(False) as interface: interface.r.flushall() # Store all smart contracts in CONTRACTS_TO_STORE import seneca test_contracts_path = seneca.__path__[0] + '/../test_contracts/' for contract_name, file_name in CONTRACTS_TO_STORE.items(): with open(test_contracts_path + file_name) as f: code_str = f.read() interface.publish_code_str(contract_name, GENESIS_AUTHOR, code_str) start = time.time() print("------ MINTING -------") print("Minting {} wallets...".format(NUM_WALLETS)) for i in range(NUM_WALLETS): interface.execute_function( module_path='seneca.contracts.currency.mint', sender=GENESIS_AUTHOR, to=str(i), amount=SEED_AMOUNT, stamps=1000) for w in (PERSON_A, PERSON_B): interface.execute_function( module_path='seneca.contracts.currency.mint', sender=GENESIS_AUTHOR, to=w, amount=SEED_AMOUNT, stamps=1000) print("Finished minting wallet in {} seconds".format( round(time.time() - start, 2))) print("----------------------")
class TestPublishTransfer(TestCase): def setUp(self): r.flushdb() SenecaInterpreter.setup() SenecaInterpreter.concurrent_mode = False self.si = SenecaInterface(False) self.author = 'stu' self.sender = 'stu' self.rt = {'rt': {'sender': self.sender, 'author': self.author, 'contract': 'test'}} print(''' ################################################################################ {} ################################################################################ '''.format(self.id)) self.publish_contract() self.mint_account() self.code_str = ''' from seneca.contracts.kv_currency import transfer transfer('ass', 1) ''' self.print_balance() self.code_obj = self.si.compile_code(self.code_str) self.start = time.time() def tearDown(self): elapsed = time.time() - self.start print('Finished {} contracts in {}s!'.format(CONTRACT_COUNT, elapsed)) print('Rate: {}tps'.format(CONTRACT_COUNT / elapsed)) self.print_balance() def publish_contract(self): with open(join(test_contracts_path, 'kv_currency.sen.py')) as f: self.si.publish_code_str('kv_currency', 'falcon', f.read()) def mint_account(self): self.si.execute_code_str(""" from seneca.contracts.kv_currency import mint mint('stu', {}) """.format(CONTRACT_COUNT), self.rt) def print_balance(self): self.si.execute_code_str(""" from seneca.contracts.kv_currency import balance_of print('stu has a balance of: ' + str(balance_of('stu'))) print('ass has a balance of: ' + str(balance_of('ass'))) """) def test_transfer_template_with_metering(self): for i in range(CONTRACT_COUNT): self.si.execute_function('test_contracts.kv_currency.transfer', self.sender, 100000, 'ass', amount=1)
def setUp(self): r.flushdb() self.si = SenecaInterface(False) print(''' ################################################################################ {} ################################################################################ '''.format(self.id)) for user in users: self.mint_account(user) self.code_str = ''' from test_contracts.kv_currency import transfer transfer('tej', 1) ''' self.print_balance() self.code_obj = self.si.compile_code(self.code_str) self.start = time.time()
def setUp(self): self.si = SenecaInterface(False, port=get_redis_port(), password=get_redis_password()) try: v = self.si.r.get('market:stamps_to_tau') except: v = 1 self.si.r.flushdb() self.si.r.set('market:stamps_to_tau', v) print('\n{}'.format('#' * 128)) print(self.id) print('{}\n'.format('#' * 128))
def setUp(self): r.flushdb() self.si = SenecaInterface(False) self.author = 'stu' self.sender = 'stu' self.rt = {'rt': {'sender': self.author, 'author': self.sender, 'contract': 'test'}} print(''' ################################################################################ {} ################################################################################ '''.format(self.id)) self.mint_account() self.code_str = ''' from test_contracts.kv_currency import transfer transfer('ass', 1) ''' self.print_balance() self.code_obj = self.si.compile_code(self.code_str, self.rt) self.start = time.time()
def test_store_float(self): with SenecaInterface(False) as interface: interface.execute_function( module_path='seneca.contracts.decimal_test.store_float', sender=GENESIS_AUTHOR, stamps=None, s='floaty', f=Decimal('0.01')) f = interface.execute_function( module_path='seneca.contracts.decimal_test.read_float', sender=GENESIS_AUTHOR, stamps=None, s='floaty') self.assertEqual(f['output'], Decimal('0.01'))
def setUp(self): # overwrite_logger_level(0) with SenecaInterface(False) as interface: interface.r.flushall() # Store all smart contracts in CONTRACTS_TO_STORE import seneca test_contracts_path = seneca.__path__[0] + '/../test_contracts/' for contract_name, file_name in self.CONTRACTS_TO_STORE.items(): with open(test_contracts_path + file_name) as f: code_str = f.read() interface.publish_code_str(contract_name, GENESIS_AUTHOR, code_str) rt = { 'author': GENESIS_AUTHOR, 'sender': GENESIS_AUTHOR, 'contract': 'minter' }
def test_baseline(num_contracts: int = 30000): start = time.time() print(" ----- BASELINE ------") print( "Running {} contracts with random addresses...".format(num_contracts)) with SenecaInterface(False) as interface: for i in range(num_contracts): amount = 1 sender, receiver = random.sample(range(NUM_WALLETS), 2) interface.execute_function( module_path='seneca.contracts.currency.transfer', sender=str(sender), to=str(receiver), amount=amount, stamps=1000) dur = time.time() - start print("Finished running baseline contracts in {} seconds ".format( round(dur, 2))) print("Baseline TPS: {}".format(num_contracts / dur)) print("----------------------")
def setUp(self): # overwrite_logger_level(0) with SenecaInterface(False) as interface: interface.r.flushall() # Store all smart contracts in CONTRACTS_TO_STORE import seneca test_contracts_path = seneca.__path__[0] + '/../test_contracts/' for contract_name, file_name in self.CONTRACTS_TO_STORE.items(): with open(test_contracts_path + file_name) as f: code_str = f.read() interface.publish_code_str(contract_name, GENESIS_AUTHOR, code_str) rt = {'sender': GENESIS_AUTHOR, 'contract': 'minter'} # tooling.execute_code_str(MINT_CODE_STR, scope={'rt': rt}) for wallet, amount in MINT_WALLETS.items(): interface.execute_function( module_path='seneca.contracts.currency.mint', sender=GENESIS_AUTHOR, stamps=STAMP_AMOUNT, to=wallet, amount=amount)
def test_add_floats(self): with SenecaInterface(False) as interface: interface.execute_function( module_path='seneca.contracts.decimal_test.store_float', sender=GENESIS_AUTHOR, stamps=None, s='floaty', f=Decimal('1.1')) interface.execute_function( module_path='seneca.contracts.decimal_test.store_float', sender=GENESIS_AUTHOR, stamps=None, s='floaty2', f=Decimal('2.2')) f = interface.execute_function( module_path='seneca.contracts.decimal_test.add_floats', sender=GENESIS_AUTHOR, stamps=None, s1='floaty', s2='floaty2') self.assertEqual(f['output'], Decimal('3.3'))
def run_code_obj(user): si = SenecaInterface(False) SenecaInterpreter.setup(False) for i in range(CONTRACT_COUNT): si.execute_function('test_contracts.kv_currency.transfer', user, 10000, 'tej', 1)
class TestMultiProc(TestCase): def setUp(self): r.flushdb() self.si = SenecaInterface(False) print(''' ################################################################################ {} ################################################################################ '''.format(self.id)) for user in users: self.mint_account(user) self.code_str = ''' from test_contracts.kv_currency import transfer transfer('tej', 1) ''' self.print_balance() self.code_obj = self.si.compile_code(self.code_str) self.start = time.time() def tearDown(self): elapsed = time.time() - self.start print('Finished {} contracts in {}s!'.format(TOTAL_COUNT, elapsed)) print('Rate: {}tps'.format(TOTAL_COUNT / elapsed)) self.print_balance() def mint_account(self, user): self.si.execute_code_str( """ from test_contracts.kv_currency import mint mint('{}', {}) """.format(user, CONTRACT_COUNT), {'rt': { 'sender': user, 'author': user, 'contract': 'test' }}) def print_balance(self): self.si.execute_code_str( """ from test_contracts.kv_currency import balance_of print('stu has a balance of: ' + str(balance_of('stu'))) print('dav has a balance of: ' + str(balance_of('dav'))) print('fal has a balance of: ' + str(balance_of('fal'))) print('rag has a balance of: ' + str(balance_of('rag'))) print('tej has a balance of: ' + str(balance_of('tej'))) """, {'rt': { 'sender': 'stu', 'author': 'stu' }}) def test_transfer_template(self): def run_code_obj(user): si = SenecaInterface(False) SenecaInterpreter.setup(False) for i in range(CONTRACT_COUNT): si.execute_function('test_contracts.kv_currency.transfer', user, 10000, 'tej', 1) processes = [ Process(target=run_code_obj, args=(user,)) \ for user in users ] [p.start() for p in processes] [p.join() for p in processes]
def default_driver(): return SenecaInterface(concurrent_mode=False, port=6379, password='')