예제 #1
0
def test_persistence():
    """
    Test persistence:
    Bob's downloaded blockchain should persist between restarts. He should
    only download updates to his blockchain when his node starts.
    """
    test_settings = settings["test_persistence"]

    # prepare a dir to hold the config and DB files
    root_dir = tempfile.mkdtemp()
    p_m_conf = """\
---
chain:
    persist: true
    db_path: \"""" + root_dir + """\"

mining:
    autostart: true
    expected_mine_rate: 100
    cuckoo:
        miner:
            executable: mean16s-generic
            extra_args: "-t 5"
            node_bits: 16
"""
    p_conf = """\
---
chain:
    persist: true
    db_path: \"""" + root_dir + """\"
"""
    persistence_mining_user_config = common.install_user_config(root_dir, "p_m_epoch.yaml", p_m_conf)
    only_persistence_user_config = common.install_user_config(root_dir, "p_epoch.yaml", p_conf)

    bob_node = test_settings["nodes"]["bob"]
    common.start_node(bob_node, persistence_mining_user_config)
    bob_api = common.external_api(bob_node)

    # Insert some blocks in Bob's chain
    blocks_to_mine = test_settings["blocks_to_mine"]
    common.wait_until_height(bob_api, blocks_to_mine)
    bob_top = bob_api.get_top()
    assert_equals(bob_top.height >= blocks_to_mine, True)
    # Now Bob has at least blocks_to_mine blocks

    common.stop_node(bob_node)

    common.start_node(bob_node, only_persistence_user_config)
    bob_new_top = bob_api.get_top()
    if(bob_new_top.height > bob_top.height):
        # Bob's node had mined another block(s) before being stopped
        bob_block = bob_api.get_block_by_hash(bob_top.hash) # this block is presnet
        assert_equals(bob_block.height, bob_top.height)
    else:
        assert_equals(bob_new_top.height, bob_top.height)
        assert_equals(bob_top.hash, bob_new_top.hash)

    common.stop_node(bob_node)
    shutil.rmtree(root_dir)
예제 #2
0
def make_no_mining_user_config(root_dir, file_name):
    key_dir = copy_peer_keys(root_dir, "node2")
    conf = """\
---
peers:
    - "aenode://pp$HdcpgTX2C1aZ5sjGGysFEuup67K9XiFsWqSPJs4RahEcSyF7X@localhost:3015"

sync:
    port: 3025

keys:
    dir: \"""" + key_dir + """\"
    password: "******"

chain:
    hard_forks:
        "16": 0

mining:
    autostart: false
    expected_mine_rate: 100
    cuckoo:
        miner:
            executable: mean16s-generic
            extra_args: "-t 5"
            node_bits: 16
"""
    return common.install_user_config(root_dir, file_name, conf)
예제 #3
0
def make_fast_mining_user_config(root_dir, file_name):
    key_dir = copy_peer_keys(root_dir, "node1")
    conf = """\
---
peers:
    - "aenode://pp$28uQUgsPcsy7TQwnRxhF8GMKU4ykFLKsgf4TwDwPMNaSCXwWV8@localhost:3025"

sync:
    port: 3015

keys:
    dir: \"""" + key_dir + """\"
    password: "******"

chain:
    hard_forks:
        "16": 0

mining:
    autostart: true
    expected_mine_rate: 100
    cuckoo:
        miner:
            executable: mean16s-generic
            extra_args: "-t 5"
            node_bits: 16
"""
    return common.install_user_config(root_dir, file_name, conf)
예제 #4
0
def make_peers_user_config(root_dir, file_name, keys, sync_port, peers,
                           mining):
    key_dir = copy_peer_keys(root_dir, keys)
    conf = """\
---
""" + peers + """

sync:
    port: {}
    single_outbound_per_group: false

keys:
    dir: "{}"
    password: "******"

mining:
    autostart: {}
    expected_mine_rate: 100
    beneficiary: "ak$2QLChDdERfod9QajLkCTsJnYP3RNqZJmAFWQWQZWr99fSrC55h"
    cuckoo:
        miner:
            executable: mean16s-generic
            extra_args: "-t 5"
            node_bits: 16
""".format(sync_port, key_dir, mining)
    return common.install_user_config(root_dir, file_name, conf)
예제 #5
0
def make_no_mining_user_config(root_dir, file_name):
    key_dir = copy_peer_keys(root_dir, "node2")
    conf = """\
---
peers:
    - "aenode://pp_HdcpgTX2C1aZ5sjGGysFEuup67K9XiFsWqSPJs4RahEcSyF7X@localhost:3015"

sync:
    port: 3025

keys:
    dir: \"""" + key_dir + """\"
    peer_password: "******"

chain:
    hard_forks:
        "1": 0

mining:
    autostart: false
    expected_mine_rate: 100
    beneficiary: "ak_2QLChDdERfod9QajLkCTsJnYP3RNqZJmAFWQWQZWr99fSrC55h"
    cuckoo:
        miner:
            executable: mean15-generic
            extra_args: ""
            edge_bits: 15
"""
    return common.install_user_config(root_dir, file_name, conf)
예제 #6
0
def make_fast_mining_user_config(root_dir, file_name):
    key_dir = copy_peer_keys(root_dir, "node1")
    conf = """\
---
peers:
    - "aenode://pp_28uQUgsPcsy7TQwnRxhF8GMKU4ykFLKsgf4TwDwPMNaSCXwWV8@localhost:3025"

sync:
    port: 3015

keys:
    dir: \"""" + key_dir + """\"
    peer_password: "******"

chain:
    hard_forks:
        "1": 0

mining:
    autostart: true
    expected_mine_rate: 100
    beneficiary: "ak_2QLChDdERfod9QajLkCTsJnYP3RNqZJmAFWQWQZWr99fSrC55h"
    cuckoo:
        miner:
            executable: mean15-generic
            extra_args: ""
            edge_bits: 15
"""
    return common.install_user_config(root_dir, file_name, conf)
예제 #7
0
def make_peers_user_config(root_dir, file_name, keys, sync_port, peers, mining):
    key_dir = copy_peer_keys(root_dir, keys)
    conf = """\
---
""" + peers + """

sync:
    port: {}

keys:
    dir: "{}"
    password: "******"

mining:
    autostart: {}
    expected_mine_rate: 100
    cuckoo:
        miner:
            executable: mean16s-generic
            extra_args: "-t 5"
            node_bits: 16
""".format(sync_port, key_dir, mining)
    return common.install_user_config(root_dir, file_name, conf)
예제 #8
0
def test_persistence():
    """
    Test persistence:
    Bob's downloaded blockchain should persist between restarts. He should
    only download updates to his blockchain when his node starts.
    """
    test_settings = settings["test_persistence"]

    # prepare a dir to hold the config and DB files
    root_dir = tempfile.mkdtemp()
    p_m_conf = """\
---
chain:
    persist: true
    db_path: \"""" + root_dir + """\"

mining:
    autostart: true
    expected_mine_rate: 100
    beneficiary: "ak_2QLChDdERfod9QajLkCTsJnYP3RNqZJmAFWQWQZWr99fSrC55h"
    cuckoo:
        edge_bits: 15
        miners:
            - executable: mean15-generic
              extra_args: ""
"""
    p_conf = """\
---
chain:
    persist: true
    db_path: \"""" + root_dir + """\"

mining:
    beneficiary: "ak_2QLChDdERfod9QajLkCTsJnYP3RNqZJmAFWQWQZWr99fSrC55h"
"""
    persistence_mining_user_config = common.install_user_config(
        root_dir, "p_m_aeternity.yaml", p_m_conf)
    minimal_user_config_with_persistence = common.install_user_config(
        root_dir, "p_aeternity.yaml", p_conf)

    bob_node = test_settings["nodes"]["bob"]
    common.start_node(bob_node, persistence_mining_user_config)
    bob_api = common.external_api(bob_node)

    # Insert some blocks in Bob's chain
    blocks_to_mine = test_settings["blocks_to_mine"]
    common.wait_until_height(bob_api, blocks_to_mine)
    bob_top = bob_api.get_current_key_block()
    assert_equals(bob_top.height >= blocks_to_mine, True)
    # Now Bob has at least blocks_to_mine blocks

    common.stop_node(bob_node)

    common.start_node(bob_node, minimal_user_config_with_persistence)
    bob_new_top = bob_api.get_current_key_block()
    if (bob_new_top.height > bob_top.height):
        # Bob's node had mined another block(s) before being stopped
        bob_block = bob_api.get_key_block_by_hash(
            bob_top.hash)  # this block is presnet
        assert_equals(bob_block.height, bob_top.height)
    else:
        assert_equals(bob_new_top.height, bob_top.height)
        assert_equals(bob_top.hash, bob_new_top.hash)

    common.stop_node(bob_node)
    shutil.rmtree(root_dir)