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 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=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()