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_active_quit(self): checker_service_process = Process( target=vchain_system_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) with open("pub_priv.txt", "r+") as f: [_, node_priv_str] = f.readlines() f.close() node_priv_str = node_priv_str.strip() node_priv = petlib.bn.Bn.from_decimal(node_priv_str) (_, g, _, _) = setup() node_pub = node_priv * g with open("balance.txt", "r+") as f: balance = int(f.readline().strip()) f.close() init_transaction = vchain_system.init()['transaction'] token = init_transaction['outputs'][0] create_node_account_transaction = vchain_system.create_account( (token, ), None, [dumps(balance)], pack(node_pub))['transaction'] node_account = create_node_account_transaction['outputs'][1] # pack transaction transaction_dict = vchain_system.active_quit( [node_account, vchain_account], None, None, pack(node_priv)) ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + vchain_system_contract.contract_name + '/active_quit', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def init(vchain_pub): init_transaction = bank_authenticated.init()['transaction'] token = init_transaction['outputs'][0] create_vchain_account_transaction = bank_authenticated.create_account( (token,), None, [dumps(10)], pack(vchain_pub) )['transaction'] vchain_account = create_vchain_account_transaction['outputs'][1] return vchain_account
def test_create_account(self): ## ## run service ## checker_service_process = Process( target=vchain_system_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## (priv, pub) = key_gen(setup()) with open("pub_priv.txt", "w+") as f: f.write(str(pub) + "\n" + str(priv) + "\n") f.close() # init init_transaction = vchain_system.init()['transaction'] token = init_transaction['outputs'][0] # create bank account transaction_dict = vchain_system.create_account((token, ), None, [dumps(100)], pack(pub)) ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + vchain_system_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 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()