def ready_for_cr(self):
        ret = self.register_cr_candidates()
        self.get_current_height()
        self.check_result("register cr", ret)
        Logger.info("{} register cr on success!".format(self.tag))

        ret = self.tx_manager.vote_cr_candidates()
        self.get_current_height()
        self.check_result("vote cr", ret)
        Logger.info("{} vote cr on success!".format(self.tag))

        # transfer to CRFoundation
        # self.tx_manager.transfer_asset(self.tap_account.private_key(), [self.CR_Foundation_TEMP], 5000 * util.TO_SELA)
        # if ret:
        #     rpc.discrete_mining(1)
        #     value = rpc.get_balance_by_address(self.CR_Foundation_TEMP)
        #     Logger.debug("{} CRFoundation {} wallet balance: {}".format(self.tag, self.CR_Foundation_TEMP, value))
        # else:
        #     Logger.error("{} CRFoundation transfer failed".format(self.tag))
        self.tx_manager.transfer_asset(self.tap_account.private_key(),
                                       [self.CRC_COMMITTEE_ADDRESS],
                                       5000 * util.TO_SELA)
        if ret:
            rpc.discrete_mining(1)
            value = rpc.get_balance_by_address(self.CRC_COMMITTEE_ADDRESS)
            Logger.debug("{} CRFoundation {} wallet balance: {}".format(
                self.tag, self.CRC_COMMITTEE_ADDRESS, value))
        else:
            Logger.error("{} CRFoundation transfer failed".format(self.tag))
    def pressure_inputs(self, inputs_num: int):
        output_addresses = list()
        for i in range(inputs_num):
            output_addresses.append(self.pressure_account.address())
        ret = self.tx_manager.transfer_asset(self.tap_account.private_key(),
                                             output_addresses,
                                             1 * util.TO_SELA)
        if ret:
            self.wait_block()
            value = rpc.get_balance_by_address(self.pressure_account.address())
            Logger.debug("{} account {} wallet balance: {}".format(
                self.tag, self.pressure_account.address(), value))

            ret = self.tx_manager.transfer_asset(
                self.pressure_account.private_key(),
                [self.pressure_account.address()],
                int(Decimal(value) * util.TO_SELA - util.TX_FEE))
            if ret:
                self.wait_block()
                return True
            else:
                Logger.error("{} pressure inputs transfer failed".format(
                    self.tag))
                return False
        else:
            Logger.error("{} pressure outupts transfer failed".format(
                self.tag))

        return ret
def test_addr():
    path = config['path']
    port = config['rpc_port']
    data: list = read_csv(path)
    for i in range(1, len(data)):
        print(data[i])
        s_data = data[i].split(',')
        addr = s_data[0]
        v1 = int(s_data[1])
        value = rpc.get_balance_by_address(addr, port)
        if v1 != int(Decimal(value) * util.TO_SELA):
            print("addr:{}, v1:{} != v2:{}".format(addr, v1, value))

    '''
    def recharge_necessary_keystore(self, input_private_key: str, accounts: list, amount: int):
        addresses = list()
        for a in accounts:
            addresses.append(a.address())

        ret = self.transfer_asset(input_private_key, addresses, amount)

        if ret:
            rpc.discrete_mining(1)
        else:
            Logger.error("{} recharge necessary keystore failed".format(self.tag))
            return False

        for i in range(len(addresses)):
            value = rpc.get_balance_by_address(addresses[i])
            Logger.debug("{} arbiter {} wallet balance: {}".format(self.tag, i, value))
        return ret
    def cross_chain_transaction(self, side_node_type: str, recharge: bool, target_address=""):
        if side_node_type is None or side_node_type is "":
            return False

        global cross_address
        global side_port
        global result
        global balance_port
        global cross_input_key

        if side_node_type is "did":
            side_port = 10136
            cross_did_account = self.node_manager.keystore_manager.cross_did_account
            cross_address = cross_did_account.address()
            cross_input_key = cross_did_account.private_key()

        elif side_node_type is "token":
            side_port = 10146
            cross_token_account = self.node_manager.keystore_manager.cross_token_account
            cross_address = cross_token_account.address()
            cross_input_key = cross_token_account.private_key()

        elif side_node_type is "neo":
            side_port = 10156
            cross_neo_account = self.node_manager.keystore_manager.cross_neo_account
            if target_address == "":
                cross_address = cross_neo_account.address()
            else:
                cross_address = target_address
            cross_input_key = cross_neo_account.private_key()

        if recharge:
            port = self.rpc_port
            balance_port = side_port
            input_private_key = self.tap_account.private_key()
            lock_address = self.params.arbiter_params.side_info[side_node_type][constant.SIDE_RECHARGE_ADDRESS]
            amount = 1000 * constant.TO_SELA

        else:
            port = side_port
            balance_port = self.rpc_port
            input_private_key = cross_input_key
            lock_address = self.params.arbiter_params.side_info[side_node_type][constant.SIDE_WITHDRAW_ADDRESS]
            cross_address = self.tap_account.address()
            amount = 300 * constant.TO_SELA

        balance1 = rpc.get_balance_by_address(cross_address, balance_port)

        ret = self.transfer_cross_chain_asset(
            input_private_key=input_private_key,
            lock_address=lock_address,
            cross_address=cross_address,
            amount=amount,
            recharge=recharge,
            port=port
        )

        if not ret:
            Logger.error("{} transfer cross chain asset failed".format(self.tag))
            return False

        side_height_begin = rpc.get_block_count(side_port)
        while True:
            main_height = rpc.get_block_count()
            side_height = rpc.get_block_count(side_port)

            Logger.debug("{} main height: {}, side height: {}".format(self.tag, main_height, side_height))

            if side_height - side_height_begin > 10:
                break

            rpc.discrete_mining(1)
            time.sleep(3)

        balance2 = rpc.get_balance_by_address(cross_address, balance_port)
        Logger.debug("{} recharge balance1: {}".format(self.tag, balance1))
        Logger.debug("{} recharge balance2: {}".format(self.tag, balance2))

        if isinstance(balance1, dict):
            before_balance = list(balance1.values())[0]
        else:
            before_balance = balance1

        if isinstance(balance2, dict):
            after_balance = list(balance2.values())[0]
        else:
            after_balance = balance2

        result = (float(after_balance) - float(before_balance)) * constant.TO_SELA > float(amount - 3 * 10000)
        Logger.debug("{} recharge result: {}".format(self.tag, result))

        return result
Ejemplo n.º 6
0
 def get_address_balance(address: str):
     return rpc.get_balance_by_address(address)
Ejemplo n.º 7
0
 def mining_blocks_ready(self, foundation_address):
     time.sleep(3)
     rpc.discrete_mining(110)
     balance = rpc.get_balance_by_address(foundation_address)
     Logger.info("{} foundation address: {} value: {}".format(
         self.tag, foundation_address, balance))
Ejemplo n.º 8
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 get_address_balance(address: str, port=rpc.DEFAULT_PORT):
     return rpc.get_balance_by_address(address, port)
    def cross_chain_transaction(self, side_node_type: str, recharge: bool, input_account=None):
        if side_node_type is None or side_node_type is "":
            return False, None, None, None, None

        global cross_key_account
        global side_port
        global result
        global balance_port

        if not input_account:
            input_account = self.tap_account

        if side_node_type is "did":
            side_port = 10136
            cross_key_account = self.node_manager.keystore_manager.cross_did_account
        elif side_node_type is "token":
            side_port = 10146
            cross_key_account = self.node_manager.keystore_manager.cross_token_account
        elif side_node_type is "neo":
            side_port = 10156
            cross_key_account = self.node_manager.keystore_manager.cross_neo_account
        elif side_node_type is "geth":
            side_port = 1111
            from src.core.nodes.eth import Eth
            cross_key_account = Eth.get_random_eth_account()

        if recharge:
            port = self.rpc_port
            balance_port = side_port
            input_private_key = input_account.private_key()
            lock_address = self.params.arbiter_params.side_info[side_node_type][constant.SIDE_RECHARGE_ADDRESS]
            cross_address = cross_key_account.address()
            amount = 100 * constant.TO_SELA

        else:
            port = side_port
            balance_port = self.rpc_port
            input_private_key = cross_key_account.private_key()
            lock_address = self.params.arbiter_params.side_info[side_node_type][constant.SIDE_WITHDRAW_ADDRESS]
            cross_address = self.tap_account.address()
            amount = 100 * constant.TO_SELA

        cross_address = cross_address[2:]
        Logger.warn("{} cross address: {}".format(self.tag, cross_address))

        balance1 = rpc.get_balance_by_address(cross_address, balance_port, side_node_type)

        ret, tx_hash = self.transfer_cross_chain_asset(
            input_private_key=input_private_key,
            lock_address=lock_address,
            cross_address=cross_address,
            amount=amount,
            recharge=recharge,
            port=port
        )

        if not ret:
            Logger.error("{} transfer cross chain asset failed".format(self.tag))
            return False, None, None, None, None

        side_height_begin = rpc.get_block_count(side_port)
        main_height = rpc.get_block_count()
        Logger.info(
            "To make sure recharge tx be putted into main chain block, we need to wait main chain mining 16 blocks!")
        while True:
            current_height = rpc.get_block_count()
            side_height = rpc.get_block_count(side_port)

            Logger.info("{} Current height: {}, dest height: {}".format(self.tag, current_height, (main_height + 16)))

            if side_node_type == "geth":
                if current_height - main_height > 15:
                    break
            else:
                if side_height - side_height_begin > 10:
                    break
            rpc.discrete_mining(1)
            time.sleep(3)

        balance2 = rpc.get_balance_by_address(cross_address, balance_port, side_node_type)
        Logger.debug("{} recharge balance1: {}".format(self.tag, balance1))
        Logger.debug("{} recharge balance2: {}".format(self.tag, balance2))

        # result = (float(balance2) - float(balance1)) * constant.TO_SELA > float(amount - 3 * 10000)
        # Logger.debug("{} recharge result: {}".format(self.tag, result))
        #
        return True, tx_hash, cross_address, amount, TX_FEE
def get_mainchain_balances(addrs=[]):
    res = {}
    for addr in addrs:
        balance = rpc.get_balance_by_address(addr)
        res.setdefault(addr, balance)
    return res