def test_create_account(self): ## create transaction transaction = bank_authenticated.init() ## submit transaction response = requests.post('http://127.0.0.1:' +port+ '/api/' +version+ '/transaction/process', json=transaction) #print response.json() self.assertTrue(response.json()['success']) ## create transaction transaction = bank_authenticated.init() ## submit transaction response = requests.post( 'http://127.0.0.1:' +port+ '/api/' +version+ '/transaction/process', json=transaction ) #print response.json() self.assertTrue(response.json()['success']) ## ## create transaction ## # create alice's public key (_, alice_pub) = key_gen(setup()) # init init_transaction = bank_authenticated.init()['transaction'] token = init_transaction['outputs'][0] # create bank account transaction = bank_authenticated.create_account( (token,), None, None, pack(alice_pub) ) ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:' +port+ '/api/' +version+ '/transaction/process', json=transaction ) #print response.json() self.assertTrue(response.json()['success'])
def test_init(self): ## ## run service ## checker_service_process = Process( target=bank_authenticated_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## transaction_dict = bank_authenticated.init() ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + bank_authenticated_contract.contract_name + '/init', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_many_auth_transfer(self): ## ## run service ## checker_service_process = Process( target=bank_authenticated_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # create alice's and bob public key num_transfers = 7 transfer_amount = 1 params = setup() (alice_priv, alice_pub) = key_gen(params) (bob_priv, bob_pub) = key_gen(params) # init init_transaction = bank_authenticated.init()['transaction'] token = init_transaction['outputs'][0] # create alice's account create_alice_account_transaction = bank_authenticated.create_account( (token, ), None, None, pack(alice_pub))['transaction'] token = create_alice_account_transaction['outputs'][0] alice_account = create_alice_account_transaction['outputs'][1] # create bob's account create_bob_account_transaction = bank_authenticated.create_account( (token, ), None, None, pack(bob_pub))['transaction'] bob_account = create_bob_account_transaction['outputs'][1] # pack transaction transaction = {} input_obj = [alice_account, bob_account] for i in range(0, num_transfers): transaction_dict = bank_authenticated.auth_transfer( input_obj, None, [dumps(transfer_amount)], pack(alice_priv)) input_obj = transaction_dict['transaction']['outputs'] ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + bank_authenticated_contract.contract_name + '/auth_transfer', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_create_account(self): ## ## run service ## checker_service_process = Process( target=bank_authenticated_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # create alice's public key (_, alice_pub) = key_gen(setup()) # init init_transaction = bank_authenticated.init()['transaction'] token = init_transaction['outputs'][0] # create bank account transaction_dict = bank_authenticated.create_account((token, ), None, None, pack(alice_pub)) ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + bank_authenticated_contract.contract_name + '/create_account', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def main(): ## get contract and init pint bank_authenticated.contract._populate_empty_checkers() print "operation\t\tmean (s)\t\tsd (s)\t\truns" # --------------------------------------------------------- # get functions # --------------------------------------------------------- # params params = setup() (alice_priv, alice_pub) = key_gen(params) (_, bob_pub) = key_gen(params) # init init_tx = bank_authenticated.init() token = init_tx['transaction']['outputs'][0] # create accounts create_alice_account_tx = bank_authenticated.create_account( (token, ), None, None, pack(alice_pub)) create_bob_account_tx = bank_authenticated.create_account((token, ), None, None, pack(bob_pub)) alice_account = create_alice_account_tx['transaction']['outputs'][1] bob_account = create_bob_account_tx['transaction']['outputs'][1] # make transfer auth_transfer_tx = bank_authenticated.auth_transfer( (alice_account, bob_account), None, ('3', ), pack(alice_priv)) # --------------------------------------------------------- # test create_account # --------------------------------------------------------- # [gen] tester(RUNS, "create_account [g]", bank_authenticated.create_account, (token, ), None, None, pack(alice_pub)) # [check] solution = transaction_to_solution(create_alice_account_tx) tester( RUNS, "create_account [c]", bank_authenticated.contract.checkers['create_account'], solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], ) # --------------------------------------------------------- # test transfer # --------------------------------------------------------- # [gen] tester(RUNS, "auth_transfer [g]", bank_authenticated.auth_transfer, (alice_account, bob_account), None, ('3', ), pack(alice_priv)) # [gen] solution = transaction_to_solution(auth_transfer_tx) tester( RUNS, "auth_transfer [c]", bank_authenticated.contract.checkers['auth_transfer'], solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], )
def main(): bank_authenticated.contract._populate_empty_checkers() print "operation\t\tmean (s)\t\tsd (s)\t\truns" # gen init tx times = [] for i in range(RUNS): start_time = time.time() bank_authenticated.init() end_time = time.time() times.append(end_time-start_time) mean = numpy.mean(times) sd = numpy.std(times) print "gen init tx\t\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # check init tx init_tx = bank_authenticated.init() solution = transaction_to_solution(init_tx) times = [] for i in range(RUNS): start_time = time.time() bank_authenticated.contract.checkers['init']( solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], ) end_time = time.time() times.append(end_time-start_time) mean = numpy.mean(times) sd = numpy.std(times) print "check init tx\t\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # gen create_account tx times = [] for i in range(RUNS): start_time = time.time() (_, alice_pub) = key_gen(setup()) bank_authenticated.create_account( (init_tx['transaction']['outputs'][0],), None, None, pack(alice_pub) ) end_time = time.time() times.append(end_time-start_time) mean = numpy.mean(times) sd = numpy.std(times) print "gen create_account tx\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # check create_account tx (a_priv, a_pub) = key_gen(setup()) create_account_tx = bank_authenticated.create_account( (init_tx['transaction']['outputs'][0],), None, None, pack(a_pub) ) solution = transaction_to_solution(create_account_tx) times = [] for i in range(RUNS): start_time = time.time() bank_authenticated.contract.checkers['create_account']( solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], ) end_time = time.time() times.append(end_time-start_time) mean = numpy.mean(times) sd = numpy.std(times) print "check create_account tx\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # gen auth_transfer tx create_account_a_tx = create_account_tx (b_priv, b_pub) = key_gen(setup()) create_account_b_tx = bank_authenticated.create_account( (create_account_a_tx['transaction']['outputs'][0],), None, None, pack(b_pub) ) a_account = create_account_a_tx['transaction']['outputs'][1] b_account = create_account_b_tx['transaction']['outputs'][1] times = [] for i in range(RUNS): start_time = time.time() bank_authenticated.auth_transfer( [a_account, b_account], None, ['3'], pack(a_priv) ) end_time = time.time() times.append(end_time-start_time) mean = numpy.mean(times) sd = numpy.std(times) print "gen auth_transfer tx\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS) # check auth_transfer tx auth_transfer_tx = bank_authenticated.auth_transfer( [a_account, b_account], None, ['3'], pack(a_priv) ) solution = transaction_to_solution(auth_transfer_tx) times = [] for i in range(RUNS): start_time = time.time() bank_authenticated.contract.checkers['auth_transfer']( solution['inputs'], solution['referenceInputs'], solution['parameters'], solution['outputs'], solution['returns'], solution['dependencies'], ) end_time = time.time() times.append(end_time-start_time) mean = numpy.mean(times) sd = numpy.std(times) print "check auth_transfer tx\t{:.10f}\t\t{:.10f}\t{}".format(mean, sd, RUNS)
def test(self): ## ## params ## params = setup() (alice_priv, alice_pub) = key_gen(params) (bob_priv, bob_pub) = key_gen(params) ## ## init ## transaction = bank_authenticated.init() response = requests.post('http://127.0.0.1:' + port + '/api/' + version + '/transaction/process', json=transaction) self.assertTrue(response.json()['success']) time.sleep(1) ## ## create alice's account ## token = transaction['transaction']['outputs'][0] create_alice_account_transaction = bank_authenticated.create_account( (token, ), None, None, pack(alice_pub)) response = requests.post('http://127.0.0.1:' + port + '/api/' + version + '/transaction/process', json=create_alice_account_transaction) self.assertTrue(response.json()['success']) time.sleep(1) ## ## create bob's account ## token = create_alice_account_transaction['transaction']['outputs'][0] create_bob_account_transaction = bank_authenticated.create_account( (token, ), None, None, pack(alice_pub)) response = requests.post('http://127.0.0.1:' + port + '/api/' + version + '/transaction/process', json=create_bob_account_transaction) self.assertTrue(response.json()['success']) time.sleep(1) ## ## make transfer ## alice_account = create_alice_account_transaction['transaction'][ 'outputs'][1] bob_account = create_bob_account_transaction['transaction']['outputs'][ 1] transfer_transaction = bank_authenticated.auth_transfer( [alice_account, bob_account], None, [dumps(3)], pack(alice_priv)) response = requests.post('http://127.0.0.1:' + port + '/api/' + version + '/transaction/process', json=transfer_transaction) self.assertTrue(response.json()['success'] == 'True') time.sleep(1) ## ## read alice's balance ## alice_account = transfer_transaction['transaction']['outputs'][0] transaction = bank_authenticated.read(None, (alice_account, ), None) response = requests.post('http://127.0.0.1:' + port + '/api/' + version + '/transaction/process', json=transaction) #print response.json() self.assertTrue(response.json()['success']) time.sleep(1) ## ## read bob's balance ## bob_account = transfer_transaction['transaction']['outputs'][1] transaction = bank_authenticated.read(None, (bob_account, ), None) response = requests.post('http://127.0.0.1:' + port + '/api/' + version + '/transaction/process', json=transaction) #print response.json() self.assertTrue(response.json()['success']) time.sleep(1)