def setup_movingto_canonical_to_onepercent():
  """
  <Purpose>
    Setup everything thats needed to run the 
    movingto_canonical_to_onepercent test.

  <Arguments>
    None.

  <Side Effects>
    None.

  <Return>
    None.
  """

  testuser = maindb.get_user(mockutil.testusername)

  # Retrieve the info about the donation we just made.
  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  # Delete all the vessel records from the database. Assume that the nodes were
  # joined back by this point.
  maindb.delete_all_vessels_of_node(node)

  # Do the setup for this test.
  vessels_dict[mockutil.extra_vessel_name]['userkeys'] = [node_transition_lib.transition_state_keys['movingto_canonical']]
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_backend_split_vessel()
  mockutil.mock_backend_set_vessel_user_keylist([mockutil._mock_pubkey_to_string(
                                                node_transition_lib.transition_state_keys['onepercentmanyevents'])])
def setup_movingto_canonical_to_onepercent():
  """
  <Purpose>
    Setup everything thats needed to run the 
    movingto_canonical_to_onepercent test.

  <Arguments>
    None.

  <Side Effects>
    None.

  <Return>
    None.
  """

  testuser = maindb.get_user(mockutil.testusername)

  # Retrieve the info about the donation we just made.
  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  # Delete all the vessel records from the database. Assume that the nodes were
  # joined back by this point.
  maindb.delete_all_vessels_of_node(node)

  # Do the setup for this test.
  vessels_dict[mockutil.extra_vessel_name]['userkeys'] = [node_transition_lib.transition_state_keys['movingto_canonical']]
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_backend_split_vessel()
  mockutil.mock_backend_set_vessel_user_keylist([mockutil._mock_pubkey_to_string(
                                                node_transition_lib.transition_state_keys['onepercentmanyevents'])])
def combine_vessels(node_string, node_info, database_nodeobject):
  """
  <Purpose>
    The purpose of this function is to combine all the vessels of 
    a node into the extra vessel.

  <Arguments>
    node_string - the name of the node. ip:port or NAT:port

    node_info - the information about the node including the vesseldict

    database_nodeobject - This is the nodeobject that was retrieved from our database

    node_state_pubkey - This is the state that the node should be in. After all the 
      vessels are combined, the final vessel should have this as its state

  <Exceptions>
    NodeError - raised if unable to combine the vessels together

    DatabaseError - raised if unable to delete vessel records from database

  <Side Effects>
    None

  <Return>
    None
  """

  log("Beginning combine_vessels for the node: "+node_string)

  node_pubkey_string = database_nodeobject.owner_pubkey
    
  #This is the extra vessel or the vessel that has the transition state
  extra_vessel = database_nodeobject.extra_vessel_name 

  #the list that will hold all the vesselnames of the node
  vessel_list = get_vessel_list(node_info, node_pubkey_string, extra_vessel, node_string)

  # Combine all the vessels into one vessel.
  log("Trying to combine all the vessels...")
  create_combined_vessel(database_nodeobject, extra_vessel, vessel_list)

  try:
    # Delete all the vessel recoreds from database. 
    maindb.delete_all_vessels_of_node(database_nodeobject)
    log("Removed all the vessel records from the database for node: "+node_string)
  except:
    raise DatabaseError("Unable to delete all vessel records from the database for node "+
                        node_string+". " + traceback.format_exc())