Ejemplo n.º 1
0
 def cancel_producers_candidates(self):
     global result
     for producer in self.register_producers_list:
         ret = self.cancel_producer(producer)
         if not ret:
             return False
         rpc.discrete_mining(1)
         status = rpc.producer_status(
             producer.node.owner_keystore.public_key.hex())
         result = status is "Cancelled"
     return result
 def wait_block(self):
     Logger.info("waiting for the block ... ")
     count_height = 0
     height = self.get_current_height()
     while True:
         if height + 1 >= count_height:
             rpc.discrete_mining(1)
             time.sleep(1)
             count_height = self.get_current_height()
         else:
             break
 def vote_crc_proposal_candidates(self, crc_proposal_hash: bytes):
     vote_amount = 1 * constant.TO_SELA
     ret = self.vote_proposal(
         input_private_key=self.tap_account.private_key(),
         amount=vote_amount,
         candidates=[crc_proposal_hash])
     if not ret:
         return False
     rpc.discrete_mining(1)
     Logger.info(
         "{} vote crc proposal:{} amount:{} on success!\n".format(self.tag, crc_proposal_hash.hex(), vote_amount))
     return True
def run_wrong_addr_case(acc: Account, with_draw_times=1):
    global output, fee, value, balance
    balances_start = get_mainchain_balances([output])
    for i in range(with_draw_times):
        log_print(
            "=================Withdraw for {} time===================".format(
                i))
        main_addr = output
        if i == 1:
            log_print(
                "This withdraw is use wrong mainchain address: {}".format(
                    output_wrong))
            main_addr = output_wrong
        txhash, err = get_receipt_hash(main_addr, balance, fee, value, acc)
        if not txhash:
            log_print_is_case_pass(False, case_name,
                                   "Call contract methon Fail!" + err)
            return

    log_print(
        "To make sure the address of main chain has received the money, We need to wait main chain mining 151 blocks! "
    )
    start_height = rpc.get_block_count()

    while True:
        current_height = rpc.get_block_count()
        Logger.info("current height: {}, dest height:{} ".format(
            current_height, (start_height + 151)))
        if current_height - start_height > 150:
            break

        # 调用主链出块,要求时间等待3秒,给主链共识
        rpc.discrete_mining(1)
        time.sleep(3)

    balances_end = get_mainchain_balances([output])
    addr = output
    if with_draw_times > 1:
        with_draw_times -= 1
    value_term = balance / 1e18 * with_draw_times
    fee_term = fee / 1e18 * with_draw_times
    if float(balances_start[addr]) + value_term - fee_term - float(
            balances_end[addr]) > 0.0:
        infostr = "address: " + addr + "balance_start: " + str(
            balances_start[addr]) + "balance_end: " + str(
                balances_end[addr]) + "withdraw_value: " + str(
                    value_term) + "fee: " + str(fee_term)
        log_print_is_case_pass(
            False, "wrong_addr_case",
            "Withdraw Fail in balance calc! detail:" + infostr)
        return
    log_print_is_case_pass(True, "wrong_addr_case")
Ejemplo n.º 5
0
 def vote_producers(self, start: int, end: int):
     for i in range(start, end):
         producer = self.register_producers_list
         vote_amount = constant.TO_SELA
         ret = self.vote_producer(input_private_key=self.private_key,
                                  amount=vote_amount,
                                  candidates=[producer])
         if not ret:
             return False
         Logger.info("{} vote node-{} {} Elas on success!\n".format(
             self.tag, i, vote_amount))
         rpc.discrete_mining(1)
     return True
 def vote_producers(self, start: int, end: int):
     for i in range(start, end):
         producer = self.register_producers_list[i - self.params.ela_params.crc_number - 1]
         vote_amount = (self.params.ela_params.number - i + 1) * constant.TO_SELA
         ret = self.vote_producer(
             input_private_key=producer.node_account().private_key(),
             amount=vote_amount,
             candidates=[producer]
         )
         if not ret:
             return False
         Logger.info("{} vote node-{} {} Elas on success!\n".format(self.tag, i, vote_amount))
         rpc.discrete_mining(1)
     return True
 def vote_cr_candidates(self):
     for i in range(1, self.params.ela_params.crc_number + 1):
         crs = self.register_cr_list[i - 1]
         vote_amount = (self.params.ela_params.crc_number - i + 1) * constant.TO_SELA
         ret = self.vote_cr(
             input_private_key=self.tap_account.private_key(),
             amount=vote_amount,
             candidates=[crs],
         )
         if not ret:
             return False
         rpc.discrete_mining(1)
         Logger.info("{} vote CR-{} {} Elas on success!\n".format(self.tag, i, vote_amount))
     return True
    def mining_side_blocks(self, side_port: int, num=1):
        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 > num:
                break

            rpc.discrete_mining(1)
            time.sleep(3)
Ejemplo n.º 9
0
 def vote_crc_proposal_candidates(self):
     for i in range(len(self.crc_proposal_list)):
         proposal = self.crc_proposal_list[i]
         vote_amount = (self.params.ela_params.crc_number - i +
                        1) * constant.TO_SELA
         ret = self.vote_proposal(
             input_private_key=self.tap_account.private_key(),
             amount=vote_amount,
             candidates=[proposal])
         if not ret:
             return False
         rpc.discrete_mining(1)
         Logger.info("{} vote crc proposal:{} on success!\n".format(
             self.tag, proposal.hash, vote_amount))
     return True
    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 vote_producers_candidates(self):
     for i in range(
             self.params.ela_params.crc_number + 1,
             self.params.ela_params.number - round(self.params.ela_params.later_start_number / 2) + 1
     ):
         producer = self.register_producers_list[i - self.params.ela_params.crc_number - 1]
         vote_amount = (self.params.ela_params.number - i + 1) * constant.TO_SELA
         ret = self.vote_producer(
             input_private_key=producer.node_private_key(),
             amount=vote_amount,
             candidates=[producer],
         )
         if not ret:
             return False
         rpc.discrete_mining(1)
         Logger.info("{} vote node-{} {} Elas on success!\n".format(self.tag, i, vote_amount))
     return True
    def register_producers(self, start: int, end: int, without_mining=False):
        for i in range(start, end):
            ela_node = self.node_manager.ela_nodes[i]
            ret = self.register_producer(ela_node)
            if not ret:
                return False

            current_height = rpc.get_block_count()
            last_height = current_height
            while True:
                rpc.discrete_mining(1)
                current_height = rpc.get_block_count()
                Logger.debug("{} current height: {}".format(self.tag, current_height))
                if current_height - 6 > last_height:
                    break
                time.sleep(1)

            Logger.info("{} register node-{} to be a producer on success!\n".format(self.tag, i))
        return True
    def register_producers_candidates(self):
        global result
        result = False
        for i in range(
                self.params.ela_params.crc_number + 1,
                self.params.ela_params.number - round(self.params.ela_params.later_start_number / 2) + 1
        ):
            ela_node = self.node_manager.ela_nodes[i]
            public_key = ela_node.node_account.public_key()
            ret = self.register_producer(ela_node)
            if not ret:
                return False
            rpc.discrete_mining(7)

            status = rpc.producer_status(public_key)
            Logger.debug("After mining 7 blocks, register status: {}".format(status))
            result = status == "Active"
            if not result:
                Logger.error("{} register producer {} failed".format(self.tag, ela_node.name))
                break

            Logger.info("{} register node-{} to be a producer on success!\n".format(self.tag, i))

        return result
Ejemplo n.º 14
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))
    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.º 16
0
 def discrete_mining_blocks(num: int):
     rpc.discrete_mining(num)
    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 discrete_miner(num: int):
     while num > 0:
         rpc.discrete_mining(1)
         num -= 1
         time.sleep(0.2)