Esempio n. 1
0
def test_content():

    controller = Controller(config)
    number = controller.params.ela_params.number
    crc_number = controller.params.ela_params.crc_number
    later_start_number = controller.params.ela_params.later_start_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]
    test_case = "Pre connect before h2 and producers are not enough"

    will_register_count = random.randrange(2, 7)
    start = crc_number + 1
    end = crc_number + will_register_count + 1
    start2 = end
    end2 = number - later_start_number + 1
    Logger.debug("The number will be registered a producer are: {}".format(will_register_count))
    Logger.debug("start2 = {}, end2 = {}".format(start2, end2))
    controller.tx_manager.register_producers(start, end)
    controller.tx_manager.vote_producers(start, end)

    global result
    global re_register
    re_register = False

    crc_public_keys = controller.keystore_manager.crc_public_keys
    crc_public_keys.sort()

    arbiter_accounts = controller.keystore_manager.node_accounts[1:13]

    target_public_keys = list()
    for account in arbiter_accounts:
        target_public_keys.append(account.public_key())

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(current_height, times))
        if times >= 1000:
            result = False
            break

        if current_height > h1:
            controller.show_arbiter_info()

        if not re_register and current_height >= h2 + 1:

            current_arbiters = controller.get_current_arbiter_public_keys()
            current_arbiters.sort()
            Logger.debug("crc_public_keys:  {}".format(crc_public_keys))
            Logger.debug("current arbiters: {}".format(current_arbiters))
            result = set(current_arbiters) == set(crc_public_keys)
            Logger.debug("crc_public_keys is equal current arbiters: {}".format(result))
            controller.check_result("crc public key is equal current arbiter key", result)
            Logger.debug("will register producers number: {}".format(end2 - start2))
            time.sleep(3)

            ret = controller.tx_manager.register_producers(start2, end2, True)
            controller.check_result("register producers", ret)
            ret = controller.tx_manager.vote_producers(start2, end2)
            controller.check_result("vote producers", ret)
            controller.start_later_nodes()
            re_register = True

        if current_height >= h2 + 100:
            current_arbiter_keys = controller.get_current_arbiter_public_keys()
            controller.check_result("all nodes have the same height", controller.check_nodes_height())

            result = set(target_public_keys) == set(current_arbiter_keys)
            controller.check_result(test_case, result)
            break

        controller.discrete_mining_blocks(1)

        time.sleep(1)

    controller.terminate_all_process(result)
Esempio n. 2
0
def test_content():

    # test case title
    test_case = "Major producers inactive first rotation still failed but second rotation success"
    # init controller for deploy, start nodes and recharges some nodes for registered as producers
    controller = Controller(config)
    # register and vote producers ready for h2 phase
    controller.ready_for_dpos()

    # get some important parameters for later use
    number = controller.params.ela_params.number
    crc_number = controller.params.ela_params.crc_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    # prepare inactive producers [9, 10, 11, 12, 13, 14, 15, 16]
    inactive_producers = controller.tx_manager.register_producers_list[
        crc_number:crc_number * 3]
    inactive_nodes = list()
    for producer in inactive_producers:
        inactive_nodes.append(producer.node)
    # prepare replace candidate [17, 18, 19, 20]
    replace_cadidates = controller.tx_manager.register_producers_list[
        crc_number * 3:crc_number * 4]

    # get inactive node public key
    inactive_public_keys = list()
    for producer in inactive_producers:
        inactive_public_keys.append(producer.node_account().public_key())

    # get replace node public key
    replace_public_keys = list()
    for producer in replace_cadidates:
        replace_public_keys.append(producer.node_account().public_key())

    global result
    global activate
    global remaining_start
    activate = False
    remaining_start = False
    stop_height = 0

    # mining to the height h1 - pre_connect_offset - 1 (300 - 5 - 1 = 294)
    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    # get number of times of the same height
    height_times = dict()
    height_times[current_height] = 1

    while True:

        # get current height and the number of times it appears
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(
            current_height, times))

        # if times is more than 1000, that means 1000 times at a certain height, this is unreasonable and \
        # the process will exit
        if times >= 1000:
            result = False
            break

        # after h1, will show current and next current arbiters info
        if current_height >= h1:
            controller.show_arbiter_info()

        # when current height is equal h2 + 12(320), then will stop the inactive \
        # producer nodes[9, 10, 11, 12, 13, 14, 15, 16]
        if stop_height == 0 and current_height >= h2 + 12:
            for node in inactive_nodes:
                node.stop()

            # stop height is equal h2 + 12 (320)
            stop_height = current_height
            controller.check_result(
                "Ater H2,stop 1/3 producers and candidates", True)
            Logger.debug("stop_height: {}".format(stop_height))

        # when current is not equal stop height, that means replace candidate promoted to producer and consensus
        if not activate and stop_height != 0 and current_height > stop_height + 36:
            arbiters_set = set(rpc.get_arbiters_info()["arbiters"])
            result = not set(inactive_public_keys).issubset(arbiters_set) and \
                            set(replace_public_keys).issubset(arbiters_set)

            controller.check_result("rotation check", result)

            # activate producers [9,10,11,12]
            activate_producers = inactive_producers[:4]
            activate_nodes = inactive_nodes[:4]

            # first start activate producers nodes
            for node in activate_nodes:
                node.start()

            controller.discrete_mining_blocks(1)

            # second, activate producers
            for producer in activate_producers:
                result = controller.tx_manager.active_producer(producer)
                controller.check_result(
                    "activate producer {}".format(producer.info.nickname),
                    result)

            controller.start_later_nodes()
            activate = True

        if not remaining_start and stop_height != 0 and current_height > stop_height + 80:
            remaining_inactive_nodes = inactive_nodes[4:]
            for node in remaining_inactive_nodes:
                node.start()
            remaining_start = True

        if stop_height != 0 and current_height > stop_height + 100:
            current_pubkeys = controller.get_current_arbiter_public_keys()
            controller.check_result("check all nodes have the same height",
                                    controller.check_nodes_height())

            result = set(controller.node_manager.normal_dpos_pubkeys) == set(
                current_pubkeys)
            break

        # mining a block per second
        controller.discrete_mining_blocks(1)
        time.sleep(1)

    # Finally, output the test result and exit
    controller.check_result(test_case, result)
    if result:
        controller.terminate_all_process(result)
def test_content():
    test_case = "More than 1/3 producers inactive and degenerate to CRC"
    controller = Controller(config)
    controller.ready_for_dpos()

    crc_number = controller.params.ela_params.crc_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    # get inactive producers [9,10,11,12]
    inactive_producers = controller.tx_manager.register_producers_list[crc_number: crc_number * 2]

    # get inactive nodes related to inactive producers
    inactive_producers_nodes = list()
    for producer in inactive_producers:
        inactive_producers_nodes.append(producer.node)

    # get inactive public keys related to inactive nodes
    inactive_public_keys = list()
    for node in inactive_producers_nodes:
        inactive_public_keys.append(node.get_node_public_key())

    stop_height = 0

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global restart
    global activate
    result = False
    restart = False
    activate = False

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(current_height, times))
        if times >= 1000:
            result = False
            break

        # after h1, show the current and next arbiters info by sort
        if current_height >= h1:
            controller.show_arbiter_info()

        if stop_height == 0 and current_height >= h2 + 12:
            for node in inactive_producers_nodes:
                node.stop()
            controller.check_result("Ater H2,stop 1/3 producers", True)

            stop_height = current_height
            Logger.debug("stop height: {}".format(stop_height))

        if not restart and stop_height != 0 and current_height > stop_height + 20:
            crc_public_keys = controller.keystore_manager.crc_public_keys
            current_arbiter_public_keys = controller.get_current_arbiter_public_keys()
            result = set(crc_public_keys) == set(current_arbiter_public_keys)

            Logger.debug("set crc public keys is equal set current arbiter public keys ?: {}".format(result))
            time.sleep(2)

            for node in inactive_producers_nodes:
                node.start()

            restart = True

        if not activate and stop_height != 0 and current_height > stop_height + 30:
            for producer in inactive_producers:
                ret = controller.tx_manager.active_producer(producer)
                controller.check_result("activate producer {}".format(producer.info.nickname), ret)
            controller.start_later_nodes()
            activate = True

        if stop_height != 0 and current_height > stop_height + 100:
            current_arbiter_public_keys = controller.get_current_arbiter_public_keys()
            controller.check_result("check all nodes have the same height", controller.check_nodes_height())

            result = set(inactive_public_keys).issubset(set(current_arbiter_public_keys))
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result(test_case, result)
    controller.terminate_all_process(result)
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()

    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]
    side_port = controller.node_manager.neo_nodes[0].rpc_port

    # side account config
    side_account1 = controller.keystore_manager.special_accounts[10]
    side_account2 = controller.keystore_manager.special_accounts[11]

    global test_case
    test_case = "test neo deploy contract"
    current_height = controller.get_current_height()

    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global before_h1
    before_h1 = True

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("current height: {}, times: {}".format(
            current_height, times))

        if times >= 1000:
            result = False
            break

        if current_height > h2 + 2:

            test_case = "cross chain recharge neo side account1"
            Logger.info("### Testing {} ###".format(test_case))
            result = controller.tx_manager.cross_chain_transaction(
                "neo", True, side_account1.address())
            controller.check_result(test_case, result)

            controller.discrete_mining_blocks(1)
            time.sleep(2)
            #
            # test_case = "cross chain recharge neo side account2"
            # Logger.info("### Testing {} ###".format(test_case))
            # result = controller.tx_manager.cross_chain_transaction("neo", True, side_account2.address())
            # controller.check_result(test_case, result)
            #
            # controller.discrete_mining_blocks(1)
            # time.sleep(2)

            before_deploy_balance = controller.get_address_balance(
                side_account2.address(), side_port)
            # code = "5bc56b6c766b00527ac46c766b51527ac4616168164e656f2e52756e74696d652e47657454726967676572609c6c766b52527ac46c766b52c3647501616c766b00c3066465706c6f79876c766b53527ac46c766b53c36414006161e001007d016c766b54527ac4626a016c766b00c3046e616d65876c766b55527ac46c766b55c36414006161e0010049026c766b54527ac4623f016c766b00c30673796d626f6c876c766b56527ac46c766b56c36414006161e0010095026c766b54527ac46212016c766b00c30b746f74616c537570706c79876c766b57527ac46c766b57c36414006161e0010007026c766b54527ac462e0006c766b00c3087472616e73666572876c766b58527ac46c766b58c3642b00616c766b51c300c36c766b51c351c36c766b51c352c3615272e00103b0026c766b54527ac4629a006c766b00c30962616c616e63654f66876c766b59527ac46c766b59c3641b00616c766b51c300c361e00101ff016c766b54527ac46263006c766b00c307646563696d616c876c766b5a527ac46c766b5ac36414006161e0010033026c766b54527ac462350004747275656c766b54527ac4622600186e6f74206170706c69636174696f6e20636f6e74726163746c766b54527ac46203006c766b54c3616c756655c56b616115215d4ab7ebc27ed8c9d7a5f7e33b08b8ca93af07a66168184e656f2e52756e74696d652e436865636b5769746e657373009c6c766b53527ac46c766b53c3640f0061006c766b54527ac4629e000700c06e31d910016c766b00527ac46168164e656f2e53746f726167652e476574436f6e74657874056173736574617ce001020c036c766b51527ac403c0c62d6c766b52527ac46c766b51c30b746f74616c537570706c796c766b52c3615272e000030603616c766b51c36115215d4ab7ebc27ed8c9d7a5f7e33b08b8ca93af07a66c766b00c3615272e00003340361516c766b54527ac46203006c766b54c3616c756651c56b61057a636f696e6c766b00527ac46203006c766b00c3616c756652c56b616168164e656f2e53746f726167652e476574436f6e74657874056173736574617ce0010256026c766b00527ac46c766b00c30b746f74616c537570706c79617ce0010211036c766b51527ac46203006c766b51c3616c756651c56b61017a6c766b00527ac46203006c766b00c3616c756653c56b6c766b00527ac4616168164e656f2e53746f726167652e476574436f6e74657874056173736574617ce00102da016c766b51527ac46c766b51c36c766b00c3617ce00102e7020400e1f505966c766b52527ac46203006c766b52c3616c756651c56b61586c766b00527ac46203006c766b00c3616c75665ac56b6c766b00527ac46c766b51527ac46c766b52527ac4616c766b52c3009f6c766b56527ac46c766b56c3640f0061006c766b57527ac4624d016c766b00c36168184e656f2e52756e74696d652e436865636b5769746e657373009c6c766b58527ac46c766b58c3640f0061006c766b57527ac46210010400e1f5056c766b52c3956a52527ac46168164e656f2e53746f726167652e476574436f6e74657874056173736574617ce00102e3006c766b53527ac46c766b53c36c766b00c3617ce00102f0016c766b54527ac46c766b54c36c766b52c39f6c766b59527ac46c766b59c3640f0061006c766b57527ac46295006c766b53c36c766b00c36c766b54c36c766b52c394615272e000030301616c766b53c36c766b51c3617ce0010294016c766b55527ac46c766b53c36c766b51c36c766b55c36c766b52c393615272e00003cd0061616c766b00c36c766b51c36c766b52c3615272087472616e7366657254c168124e656f2e52756e74696d652e4e6f7469667961516c766b57527ac46203006c766b57c3616c756652c56b6c766b00527ac46c766b51527ac46152c5766c766b00c3007cc4766c766b51c3517cc4616c756654c56b6c766b00527ac46c766b51527ac46c766b52527ac46c766b00c351c301007e6c766b51c37e6c766b53527ac46c766b00c300c36c766b53c36c766b52c3615272680f4e656f2e53746f726167652e507574616c756654c56b6c766b00527ac46c766b51527ac46c766b52527ac46c766b00c351c301007e6c766b51c37e6c766b53527ac46c766b00c300c36c766b53c36c766b52c3615272680f4e656f2e53746f726167652e507574616c756653c56b6c766b00527ac46c766b51527ac46c766b00c351c301007e6c766b51c37e6c766b52527ac46c766b00c300c36c766b52c3617c680f4e656f2e53746f726167652e476574616c756653c56b6c766b00527ac46c766b51527ac46c766b00c351c301007e6c766b51c37e6c766b52527ac46c766b00c300c36c766b52c3617c680f4e656f2e53746f726167652e476574616c7566ab"
            code = util.read_avm_file("./datas/code.avm")
            Logger.info("code: {}".format(code))
            function_code = FunctionCode(
                code=code,
                params_type=[
                    FunctionCode.TYPE_STRING, FunctionCode.TYPE_ARRAY
                ],
                return_type=FunctionCode.TYPE_OBJECT,
            )

            payload = NeoDeployContract(
                function_code=function_code,
                name="xiaobin",
                code_version="v0.0.1",
                author="xiaobin",
                email="*****@*****.**",
                description="simple neo contract",
                program_hash=bytes.fromhex(side_account1.program_hash()),
                gas=int(500 * constant.TO_SELA),
            )

            ret = controller.tx_manager.deploy_neo_contract(
                input_private_key=side_account1.private_key(),
                output_addresses=[side_account2.address()],
                payload=payload,
                amount=1 * constant.TO_SELA,
                rpc_port=side_port,
            )

            controller.check_result("deploy neo contract test", ret)
            controller.mining_side_blocks(side_port, 6)

            after_deploy_balance = controller.get_address_balance(
                side_account2.address(), side_port)

            Logger.info(
                "before deploy contract side account2 balance: {}".format(
                    before_deploy_balance))
            Logger.info(
                "after deploy contract side account2 balance: {}".format(
                    after_deploy_balance))

            controller.discrete_mining_blocks(1)
            time.sleep(1)
            controller.discrete_mining_blocks(1)
            time.sleep(1)

            Logger.debug("current height: {}".format(
                controller.get_current_height()))
            test_case = "invoke neo contract function deploy test"
            Logger.info("begin {}".format(test_case))

            contract_params = {FunctionCode.TYPE_STRING: "deploy"}

            invoke_payload = NeoInvokeContract(
                params=contract_params,
                program_hash=bytes.fromhex(side_account1.program_hash()),
                gas=0,
            )

            ret = controller.tx_manager.invoke_neo_contract(
                input_private_key=side_account1.private_key(),
                output_addresses=[side_account2.address()],
                payload=invoke_payload,
                amount=int(1 * constant.TO_SELA),
                rpc_port=side_port,
            )

            controller.check_result(test_case, ret)
            controller.mining_side_blocks(side_port, 6)
            balance3 = controller.get_address_balance(side_account2.address(),
                                                      side_port)
            Logger.info(
                "after invoke transaction, side account2 balance is {}".format(
                    balance3))
            response = rpc.invoke_function(
                operation="balanceOf",
                param={
                    "type": "Hash160",
                    "value": "ab555802d53185891cc51bdac7bcc8e78c3053d7"
                },
                return_type="Integer",
                port=side_port,
            )

            Logger.info(
                "after invoke deploy function, result: {}".format(response))
            result = int(response["result"]) == 3000000
            controller.check_result("invoke deploy balance test", result)

            test_case = "invoke neo contract function transfer test"
            transfer_account = controller.keystore_manager.sub1_accounts[0]
            contract_params2 = {
                FunctionCode.TYPE_STRING:
                "transfer",
                FunctionCode.TYPE_ARRAY: [{
                    FunctionCode.TYPE_HASH160:
                    "ab555802d53185891cc51bdac7bcc8e78c3053d7",
                    FunctionCode.TYPE_HASH160_2:
                    transfer_account.program_hash(),
                    FunctionCode.TYPE_INTEGER:
                    1000000,
                }]
            }
            invoke_payload2 = NeoInvokeContract(
                params=contract_params2,
                program_hash=bytes.fromhex(side_account1.program_hash()),
                gas=0,
            )

            ret = controller.tx_manager.invoke_neo_contract(
                input_private_key=side_account1.private_key(),
                output_addresses=[side_account2.address()],
                payload=invoke_payload2,
                amount=int(1 * constant.TO_SELA),
                rpc_port=side_port,
            )

            controller.check_result(test_case, ret)
            controller.mining_side_blocks(side_port, 6)
            balance4 = controller.get_address_balance(side_account2.address(),
                                                      side_port)
            Logger.info(
                "after invoke transaction, side account2 balance is {}".format(
                    balance4))

            result = rpc.invoke_function(
                operation="balanceOf",
                param={
                    "type": "Hash160",
                    "value": transfer_account.program_hash()
                },
                return_type="Integer",
            )

            Logger.info("after transfer contract, result: {}".format(result))

            transfer_account_balance = result["result"]
            result = int(transfer_account_balance) == 1000000
            controller.check_result("invoke transfer balance test", result)
            Logger.debug("Start later nodes and check all nodes height")
            controller.start_later_nodes()
            result = controller.check_nodes_height()
            controller.check_result("check all nodes height", result)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result(test_case, result)
    controller.terminate_all_process(result)
Esempio n. 5
0
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]
    crc_number = controller.params.ela_params.crc_number

    first_group_nodes = controller.node_manager.ela_nodes[crc_number * 2 +
                                                          1:crc_number * 3 + 1]
    second_group_nodes = controller.node_manager.ela_nodes[crc_number +
                                                           1:crc_number * 2 +
                                                           1]
    third_group_nodes = controller.node_manager.ela_nodes[1:crc_number + 1]
    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global last_change_height
    global last_stop_list
    last_stop_list = list()
    last_change_height = h2

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("current height: {}, times: {}".format(
            current_height, times))
        Logger.debug("last change height: {}".format(last_change_height))

        if times >= 100:
            result = False
            break

        if current_height >= h1:
            controller.show_current_next_info()

        if current_height - last_change_height == 12:
            last_change_height = current_height

            if len(last_stop_list) != 0:
                for node in last_stop_list:
                    node.start()

            result = controller.check_nodes_height()
            controller.check_result("check all nodes height middle", result)

            random_number = random.randint(1, 3)
            last_stop_list.clear()

            if random_number == 1:
                for i in range(3):
                    node = first_group_nodes[i]
                    node.stop()
                    last_stop_list.append(node)

            elif random_number == 2:
                for i in range(3):
                    node = second_group_nodes[i]
                    node.stop()
                    last_stop_list.append(node)

            elif random_number == 3:
                for i in range(3):
                    node = third_group_nodes[i]
                    node.stop()
                    last_stop_list.append(node)

        if current_height >= 1000:
            controller.start_later_nodes()
            result = controller.check_nodes_height()
            controller.check_result("check all nodes height", result)
            break

        controller.discrete_mining_blocks(1)
        if last_change_height == h2:
            time.sleep(1)
        else:
            time.sleep(3)

    controller.check_result("Minor nodes stop test", result)
    controller.terminate_all_process()
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()
    crc_number = controller.params.ela_params.crc_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]
    test_case = "More than 1/3 crc inactive after 2 rotations restart crc can generate blocks"
    inactive_crc_nodes = controller.node_manager.ela_nodes[1:crc_number + 1]

    stop_height = 0
    global result
    global restart
    result = False
    restart = False

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(
            current_height, times))
        if times >= 1000:
            result = False
            break

        if current_height > h1:
            controller.show_current_next_info()

        if stop_height == 0 and current_height >= h2 + 12:
            controller.check_result("Ater H2,the first round of consensus",
                                    True)

            for node in inactive_crc_nodes:
                node.stop()

            stop_height = current_height
            print("stop_height : ", stop_height)

        if not restart and times >= 100:
            for node in inactive_crc_nodes:
                node.start()
                restart = True

        if stop_height != 0 and current_height > stop_height + 36:
            arbiters_list = rpc.get_arbiters_info()["arbiters"]
            result = set(controller.rpc_manager.normal_dpos_pubkeys) == set(
                arbiters_list)
            Logger.debug("normal arbiters dpos result: {}".format(result))
            controller.check_result("normal arbiters consensus", result)

        if stop_height != 0 and current_height > stop_height + 60:
            controller.start_later_nodes()
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes height", result)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result(test_case, result)
    controller.terminate_all_process()
Esempio n. 7
0
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()

    number = controller.params.ela_params.number
    crc_number = controller.params.ela_params.crc_number
    later_start_number = controller.params.ela_params.later_start_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    test_case = "Majority inactive degradation to CRC"

    # init inactive producers [5,6,7,8, 9,10,11,12, 13,14,15,16]
    inactive_producers = controller.tx_manager.register_producers_list[4:16]

    stop_height = 0

    global result
    global activate
    global current_arbiter_public_keys
    result = False
    activate = False
    current_arbiter_public_keys = list()

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(
            current_height, times))
        if times >= 1000:
            result = False
            break

        # after h1, show the current and next arbiters info
        if current_height >= h1:
            controller.show_current_next_info()

        if stop_height == 0 and current_height >= h2 + 12:
            controller.check_result("Ater H2,the first round of consensus",
                                    True)

            for producer in inactive_producers:
                producer.node.stop()

            stop_height = current_height
            print("stop_height 1: ", stop_height)

        if not activate and stop_height != 0 and current_height > stop_height + 20:
            inactive_producers = inactive_producers[:4]
            for producer in inactive_producers:
                producer.node.start()

            for producer in inactive_producers:
                ret = controller.tx_manager.activate_producer(producer)
                controller.check_result(
                    "activate producer {}".format(producer.info.nickname), ret)

            # start stopped nodes again and look at their height are sync them
            controller.start_stop_nodes()
            activate = True

        if stop_height != 0 and current_height > stop_height + 100:
            current_arbiter_public_keys = controller.get_current_arbiter_public_keys(
            )
            controller.check_result("check all nodes have the same height",
                                    controller.check_nodes_height())
            result = set(controller.rpc_manager.normal_dpos_pubkeys).issubset(
                current_arbiter_public_keys)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result(test_case, result)
    controller.terminate_all_process()
Esempio n. 8
0
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()

    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]
    did_enable = config["did"]["enable"]
    neo_enable = config["neo"]["enable"]

    global test_case
    current_height = controller.get_current_height()

    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global before_h1
    before_h1 = True

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("current height: {}, times: {}".format(
            current_height, times))

        if times >= 100:
            result = False
            break

        # if before_h1 and current_height > h1 + 1:
        #     before_h1 = False
        #
        #     if did_enable:
        #         test_case = "cross chain recharge did between H1 and H2"
        #         Logger.info("### Testing {} ###".format(test_case))
        #         result = controller.tx_manager.cross_chain_transaction("did", True)
        #         controller.check_result(test_case, result)
        #
        #         controller.discrete_mining_blocks(1)
        #         time.sleep(2)
        #         controller.discrete_mining_blocks(1)
        #
        #         test_case = "cross chain withdraw did between H1 and H2"
        #         Logger.info("### Testing {} ###".format(test_case))
        #         result = controller.tx_manager.cross_chain_transaction("did", False)
        #         controller.check_result(test_case, result)
        #
        #         controller.discrete_mining_blocks(1)
        #         time.sleep(2)
        #         controller.discrete_mining_blocks(1)
        #         time.sleep(2)
        #
        #     if neo_enable:
        #         test_case = "cross chain recharge neo between H1 and H2"
        #         Logger.info("### Testing {} ###".format(test_case))
        #         result = controller.tx_manager.cross_chain_transaction("neo", True)
        #         controller.check_result(test_case, result)
        #
        #         controller.discrete_mining_blocks(1)
        #         time.sleep(2)
        #         controller.discrete_mining_blocks(1)
        #         time.sleep(2)
        #
        #         test_case = "cross chain withdraw neo between H1 and H2"
        #         Logger.info("### Testing {} ###".format(test_case))
        #         result = controller.tx_manager.cross_chain_transaction("neo", False)
        #         controller.check_result(test_case, result)

        if current_height > h2 + 20:

            if did_enable:
                test_case = "cross chain recharge did after H2"
                Logger.info("### Testing {} ###".format(test_case))
                result = controller.tx_manager.cross_chain_transaction(
                    "did", True)
                controller.check_result(test_case, result)

                controller.discrete_mining_blocks(1)
                time.sleep(2)
                controller.discrete_mining_blocks(1)
                time.sleep(2)

                test_case = "cross chain withdraw did after H2"
                Logger.info("### Testing {} ###".format(test_case))
                result = controller.tx_manager.cross_chain_transaction(
                    "did", False)
                controller.check_result(test_case, result)

                controller.discrete_mining_blocks(1)
                time.sleep(2)
                controller.discrete_mining_blocks(1)
                time.sleep(2)

            if neo_enable:
                test_case = "cross chain recharge noe after H2"
                Logger.info("### Testing {} ###".format(test_case))
                result = controller.tx_manager.cross_chain_transaction(
                    "neo", True)
                controller.check_result(test_case, result)

                controller.discrete_mining_blocks(1)
                time.sleep(2)
                controller.discrete_mining_blocks(1)
                time.sleep(2)

                test_case = "cross chain withdraw neo after H2"
                Logger.info("### Testing {} ###".format(test_case))
                result = controller.tx_manager.cross_chain_transaction(
                    "neo", False)
                controller.check_result(test_case, result)

            Logger.debug("Start later nodes and check all nodes height")
            controller.start_later_nodes()
            result = controller.check_nodes_height()
            controller.check_result("check all nodes height", result)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result(test_case, result)
    controller.terminate_all_process()
Esempio n. 9
0
def test_content():

    test_case = "Arbiter Whole Rotation Test"
    controller = Controller(config)
    controller.ready_for_dpos()

    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height

    pre_offset = config["ela"]["pre_connect_offset"]
    number = controller.params.ela_params.number
    crc_number = controller.params.ela_params.crc_number

    global tap_keystore
    global result
    global check
    check = False
    result = False
    tap_keystore = controller.keystore_manager.tap_key_store
    register_producers = controller.tx_manager.register_producers_list

    vote_height = 0

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("current height: {}, times: {}".format(current_height, times))
        if times >= 100:
            controller.check_result(test_case, False)
            break

        global before_rotation_nicknames

        if current_height > h1:
            controller.show_current_info()

        if vote_height == 0 and current_height > h2 + 12:
            before_rotation_nicknames = controller.get_arbiter_names("arbiters")
            before_rotation_nicknames.sort()
            tap_balance = rpc.get_balance_by_address(tap_keystore.address)
            Logger.info("tap_balance: {}".format(tap_balance))

            ret = controller.tx_manager.vote_producer(
                keystore=tap_keystore,
                amount=number * constant.TO_SELA,
                candidates=register_producers[crc_number * 2: crc_number * 4]
            )
            controller.check_result("vote the candidates result", ret)
            vote_height = current_height

        if not check and vote_height > 0 and current_height > vote_height + crc_number * 3 * 2:
            after_rotation_nicknames = controller.get_arbiter_names("arbiters")
            after_rotation_nicknames.sort()
            arbiter_set = set(controller.get_current_arbiter_public_keys())
            Logger.info("before rotation register producers: {}".format(before_rotation_nicknames))
            Logger.info("after  rotation register producers: {}".format(after_rotation_nicknames))
            result = set(controller.get_node_public_keys(13, 21)).issubset(arbiter_set)
            controller.check_result(test_case, result)
            check = True

        if vote_height > 0 and current_height > vote_height + crc_number * 3 * 3:
            controller.start_later_nodes()
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes have the same height", result)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    time.sleep(2)
    controller.check_result(test_case, result)
    controller.terminate_all_process()
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global vote_height
    global after_h2_transactions
    global last_income_height
    global dpos_votes
    dpos_votes = dict()
    last_income_height = h2
    vote_height = 0
    after_h2_transactions = list()

    register_producers = controller.tx_manager.register_producers_list
    later_vote_producer = register_producers[len(register_producers) - 1]

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("current height: {}, times: {}".format(
            current_height, times))

        if times >= 100:
            result = False
            break

        if current_height >= h1:
            controller.show_current_next_info()

        if current_height == h2:
            dpos_votes = controller.get_dpos_votes()

        if current_height > h2 and controller.has_dpos_reward(current_height):
            tx_fee = controller.get_total_tx_fee(after_h2_transactions)
            real_income = controller.get_dpos_real_income(current_height)
            theory_income = controller.get_dpos_theory_income(
                current_height - last_income_height, tx_fee, dpos_votes)
            result = controller.check_dpos_income(real_income, theory_income)
            controller.check_result("check dpos income", result)
            after_h2_transactions.clear()
            last_income_height = current_height
            dpos_votes = controller.get_dpos_votes()

        if vote_height == 0 and current_height > vote_height + h2 + 20:
            votes = 100
            result = controller.tx_manager.vote_producer(
                keystore=controller.keystore_manager.tap_key_store,
                amount=votes * constant.TO_SELA,
                candidates=[later_vote_producer])

            controller.check_result(
                "vote producer {}".format(later_vote_producer.node.name),
                result)
            vote_height = current_height

            ti = TxIncome(10000, True)
            after_h2_transactions.append(ti)

        if vote_height != 0 and current_height > vote_height + 500000:
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes height", result)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result("Dpos Normal Test", result)
    controller.terminate_all_process()
def one_by_one_rotation_test():
    test_case = "Arbiter One by One Rotation Test"
    controller = Controller(config)
    controller.ready_for_dpos()
    pre_offset = config["ela"]["pre_connect_offset"]
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    number = controller.params.ela_params.number
    crc_number = controller.params.ela_params.crc_number
    later_start_number = controller.params.ela_params.later_start_number

    tap_account = controller.tx_manager.tap_account
    candidate_producers = controller.tx_manager.register_producers_list[
        crc_number * 2:(number - crc_number - later_start_number)]
    voted = False
    global current_vote_height
    global result
    result = False

    current_vote_height = 0
    index = 0
    candidate = None

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("[test] current height: {}, times: {}".format(
            current_height, times))
        controller.discrete_mining_blocks(1)

        if current_height > h1:
            controller.show_arbiter_info()

        if current_height > h2 + current_vote_height + 1:
            if not voted:
                candidate = candidate_producers[index]
                vote_amount = (len(candidate_producers) -
                               index) * constant.TO_SELA * 100
                ret = controller.tx_manager.vote_producer(
                    tap_account.private_key(), vote_amount, [candidate])
                controller.check_result(
                    "vote {} ELAs to {}".format(vote_amount / constant.TO_SELA,
                                                candidate.node.name), ret)

                current_vote_height = current_height - h2
                voted = True
        if current_vote_height > 0:
            Logger.debug(
                "last vote candidate height: {}".format(current_vote_height +
                                                        h2))

        if current_height > h2 + current_vote_height + crc_number * 3 * 2:
            arbiters_list = rpc.get_arbiters_info()["arbiters"]
            ret = candidate.node.get_node_public_key() in arbiters_list
            controller.check_result(
                "{} has rotated a producer!".format(candidate.info.nickname),
                ret)
            if ret:
                voted = False
                index += 1
        if index == 8:
            controller.start_later_nodes()
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes have the same height",
                                    result)
            break
        time.sleep(1)

    controller.check_result(test_case, True)
    controller.terminate_all_process(result)
Esempio n. 12
0
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()

    crc_number = controller.params.ela_params.crc_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    stop_height = 0
    test_case = "Single inactive and arbiter rotation"
    inactive_producer_index = 0

    # producer[PRO-005]
    inactive_producer = controller.tx_manager.register_producers_list[
        inactive_producer_index]

    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global activate
    global check
    global later_start

    result = False
    activate = False
    check = False
    later_start = False

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("[main] current height: {}, times: {}".format(
            current_height, times))
        if times > 1000:
            result = False
            break

        if current_height > h1:
            controller.show_arbiter_info()

        if stop_height == 0 and current_height >= h2 + 12:
            controller.check_result("Ater H2", True)
            inactive_producer.node.stop()
            stop_height = current_height
            Logger.error(
                "[main] node {} stopped at height {} on success!".format(
                    inactive_producer_index + crc_number + 1, stop_height))

        if not activate and stop_height != 0 and current_height >= stop_height + 60:

            state = controller.get_producer_state(inactive_producer_index)
            result = state == controller.PRODUCER_STATE_INACTIVE
            Logger.debug("get producer state: {}".format(state))
            controller.check_result(
                "Before active producer, the stopped producer state is Inactive",
                result)

            inactive_producer.node.start()
            result = controller.tx_manager.activate_producer(inactive_producer)
            Logger.info("activate the producer result: {}".format(result))
            controller.check_result("send activate producer transaction",
                                    result)

            ret = controller.tx_manager.activate_producer(inactive_producer)
            controller.check_result(
                "1 same height and send activate producer again", not ret)

            while True:
                current_height2 = controller.get_current_height()
                if current_height2 - current_height < 6:
                    ret = controller.tx_manager.activate_producer(
                        inactive_producer)
                    controller.check_result(
                        "2 pending state and send activate producer again",
                        not ret)
                else:
                    break
                controller.discrete_mining_blocks(1)
                time.sleep(1)

            activate = True

        if not later_start and stop_height != 0 and current_height > stop_height + 80:
            state = controller.get_producer_state(inactive_producer_index)
            result = state == controller.PRODUCER_STATE_ACTIVE
            Logger.debug("activted producer state: {}".format(state))
            controller.check_result("activated producer state is activate",
                                    result)
            ret = controller.tx_manager.activate_producer(inactive_producer)
            controller.check_result(
                "3 state is activated send activate producer again", not ret)
            controller.start_later_nodes()
            later_start = True

        if stop_height != 0 and current_height > stop_height + 100:
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes height", result)
            break

        time.sleep(1)
        controller.discrete_mining_blocks(1)

    controller.check_result(test_case, result)
    controller.terminate_all_process()
def test_content():
    controller = Controller(config)
    controller.ready_for_dpos()
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]
    crc_number = controller.params.ela_params.crc_number

    current_height = controller.get_current_height()

    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    height_times = dict()
    height_times[current_height] = 1

    global result
    global start_height
    global after_h2_transactions
    global last_income_height
    global dpos_votes
    dpos_votes = dict()
    last_income_height = h2
    after_h2_transactions = list()
    start_height = 0

    while True:
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.debug("current height: {}, times: {}".format(
            current_height, times))

        if times >= 100:
            result = False
            break

        if current_height >= h1:
            controller.show_arbiter_info()

        if current_height == h1 + 1:
            Logger.info("H1 PASS!")
            Logger.info("H1 PASS!")

        if current_height == h2 + 2:
            Logger.info("H2 PASS!")
            Logger.info("H2 PASS!")
            dpos_votes = controller.get_dpos_votes()

        # if current_height > h2 and controller.has_dpos_reward(current_height):
        #     tx_fee = controller.get_total_tx_fee(after_h2_transactions)
        #     real_income = controller.get_dpos_real_income(current_height)
        #     theory_income = controller.get_dpos_theory_income(current_height - last_income_height, tx_fee, dpos_votes)
        #     result = controller.check_dpos_income(real_income, theory_income)
        #     controller.check_result("check dpos income", result)
        #     after_h2_transactions.clear()
        #     last_income_height = current_height
        #     dpos_votes = controller.get_dpos_votes()

        # current is equal 380, start the later nodes include two candidates and two normal nodes
        if start_height == 0 and current_height > h2 + crc_number * 3 * 6:
            controller.start_later_nodes()
            start_height = current_height

        if start_height != 0 and current_height > start_height + 100000:
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes height", result)
            break

        controller.discrete_mining_blocks(1)
        time.sleep(1)

    controller.check_result("Dpos Normal Test", result)
    controller.terminate_all_process()
Esempio n. 14
0
def test_content():

    # test case title
    test_case = "Mojor producers inactive first rotation"
    # init controller for deploy, start nodes and recharges some nodes for registered as producers
    controller = Controller(config)
    # register and vote producers ready for h2 phase
    controller.ready_for_dpos()

    # get some important parameters for later use
    crc_number = controller.params.ela_params.crc_number
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    # prepare inactive nodes[9, 10, 11, 12]
    inactive_producers = controller.tx_manager.register_producers_list[4: 8]

    inactive_nodes = list()
    for producer in inactive_producers:
        inactive_nodes.append(producer.node)

    inactive_public_keys = list()
    for producer in inactive_producers:
        inactive_public_keys.append(producer.node_account().public_key())

    inactive_set = set(inactive_public_keys)

    # mining to the height h1 - pre_connect_offset - 1 (300 - 5 - 1 = 294)
    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    # get number of times of the same height
    height_times = dict()
    height_times[current_height] = 1

    stop_height = 0
    global result
    global activate
    activate = False
    result = False

    while True:
        # get current height and the number of times it appears
        current_height = controller.get_current_height()
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(current_height, times))

        # if times is more than 1000, that means 1000 times at a certain height, this is unreasonable and \
        # the process will exit
        if times >= 1000:
            result = False
            break

            # when current height is higher than h1,  will show current and next current arbiters info
        if current_height > h1:
            controller.show_arbiter_info()

        # when current height is equal h2 + 12(320), then will stop the inactive producer nodes[5,6,7,8]
        if stop_height == 0 and current_height >= h2 + 12:
            for node in inactive_nodes:
                node.stop()

            stop_height = current_height
            Logger.debug("stop height: {}".format(stop_height))

        if not activate and stop_height != 0 and current_height > stop_height + 36:
            arbiters_set = set(rpc.get_arbiters_info()["arbiters"])
            result = not inactive_set.issubset(arbiters_set) and \
                set(controller.get_node_public_keys(13, 17)).issubset(arbiters_set)

            controller.check_result("replace public key", result)

            for node in inactive_nodes:
                node.start()

            controller.discrete_mining_blocks(1)

            for producer in inactive_producers:
                ret = controller.tx_manager.active_producer(producer)
                controller.check_result("activate producer {}".format(producer.info.nickname), ret)
            controller.start_later_nodes()
            activate = True

        if stop_height != 0 and current_height > stop_height + 100:
            controller.check_result("check all nodes have the same height", controller.check_nodes_height())
            current_pubkeys = controller.get_current_arbiter_public_keys()
            current_pubkeys.sort()
            normal_dpos_pubkeys = controller.node_manager.normal_dpos_pubkeys
            normal_dpos_pubkeys.sort()
            Logger.debug("current public keys    : {}".format(current_pubkeys))
            Logger.debug("normal dpos public keys: {}".format(normal_dpos_pubkeys))
            result = set(controller.node_manager.normal_dpos_pubkeys) == set(current_pubkeys)
            break
        # mining a block per second
        controller.discrete_mining_blocks(1)
        time.sleep(1)

    # check the result and exit
    controller.check_result(test_case, result)
    controller.terminate_all_process(result)
Esempio n. 15
0
def test_content():

    # test case title
    test_case = "Insufficient producers degradation cancel and stop"
    # init for the controller that will deploy start nodes and recharge register vote producers before h1
    controller = Controller(config)
    controller.ready_for_dpos()

    # get some important params for later use
    h1 = controller.params.ela_params.crc_dpos_height
    h2 = controller.params.ela_params.public_dpos_height
    pre_offset = config["ela"]["pre_connect_offset"]

    # prepare  cancel producers, which number will be between 4 and 8
    cancel_height = 0
    cancel_count = random.randrange(4, 8)

    # get cancel producer node
    stop_nodes = list()
    cancel_producers = controller.tx_manager.register_producers_list[: cancel_count]
    for producer in cancel_producers:
        stop_nodes.append(producer.node)

    # mining the height to h1 - pre_connect_offset - 1
    current_height = controller.get_current_height()
    if current_height < h1 - pre_offset - 1:
        controller.discrete_mining_blocks(h1 - pre_offset - 1 - current_height)

    # height_times is for get the number of times of the same height
    height_times = dict()
    height_times[current_height] = 1

    global result
    global check
    result = False
    check = False

    while True:

        # get current height
        current_height = controller.get_current_height()

        # get number of times of the same height
        times = controller.get_height_times(height_times, current_height)
        Logger.info("current height: {}, times: {}".format(current_height, times))
        if times >= 1000:
            result = False
            break

        # after h1, show the current and next arbiters nicknames by sort
        if current_height >= h1:
            controller.show_current_next_info()

        # mining the height after h2 + 12(320), cancel producers and stop nodes \
        # which number is between 4 and 8 by random
        if cancel_height == 0 and current_height >= h2 + 12:
            Logger.info("will cancel {} producers:".format(cancel_count))
            time.sleep(2)

            # cancel producers
            for producer in cancel_producers:
                ret = controller.tx_manager.cancel_producer(producer)
                controller.check_result("Cancel Producer {}".format(producer.node.name), ret)

            cancel_height = current_height
            Logger.debug("cancel height: {}".format(cancel_height))

            time.sleep(4)
            # stop the nodes relative to the producers
            for node in stop_nodes:
                node.stop()

        # after the cancel_height + 36(356), will check the result and break to finish this test
        if not check and cancel_height != 0 and current_height > cancel_height + 36:
            crc_public_keys = controller.keystore_manager.crc_public_keys
            current_arbiter_public_keys = controller.get_current_arbiter_public_keys()
            result = set(crc_public_keys) == set(current_arbiter_public_keys)
            controller.check_result("degradation to only crc consensus", result)
            controller.check_result("degradation to only crc consensus", result)
            controller.start_later_nodes()
            check = True

        if cancel_height != 0 and current_height > cancel_height + 60:
            result = controller.check_nodes_height()
            controller.check_result("check all the nodes height", result)
            break
        controller.discrete_mining_blocks(1)
        time.sleep(1)

    # check result and terminate all the processes
    controller.check_result(test_case, result)
    controller.terminate_all_process()