Beispiel #1
0
    def get_no_candidate_list(self):
        '''
        获取未被质押的节点ID列表
        :return:
        '''
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        node_info = get_node_info(self.node_yml_path)
        self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
            'nocollusion')
        no_candidate_list = []
        for index in range(len(nodeid_list)):
            nodeid = nodeid_list[index]
            result = platon_ppos.getCandidateInfo(nodeid)
            flag = result['Status']

            if not flag:
                no_candidate_list.append(nodeid)
        if no_candidate_list:
            node_list_length = len(no_candidate_list)
            index = random.randint(0, node_list_length - 1)
            nodeId = no_candidate_list[index]
            return nodeId
        else:
            CommonMethod.start_init(self)
            # self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get ('nocollusion')
            return nodeid_list[0]
Beispiel #2
0
 def test_token_transactions(self):
     node_info = get_node_info(conf.TWENTY_FIVENODE_YML)
     self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
         'collusion')
     from_address = Web3.toChecksumAddress(conf.ADDRESS)
     to_address = Web3.toChecksumAddress(
         self.ppos_link(self.rpc_list).web3.personal.newAccount(self.pwd))
     send_data = self.transfer_parameters(to_address, from_address)
     self.platon_ppos.eth.sendTransaction(send_data)
     assert self.platon_dpos1.eth.getBalance(
         to_address) == self.w3_list[0].toWei(100000, 'ether')
Beispiel #3
0
 def test_token_loukup(self):
     #查看初始化时锁仓余额
     file = conf.GENESIS_TMP_OTHER
     genesis_dict = LoadFile(file).get_data()
     FOUNDATION = genesis_dict['alloc'][conf.FOUNDATIONADDRESS]
     FOUNDATIONLOCKUP = self.platon_dpos1.eth.getBalance(
         conf.FOUNDATIONLOCKUPADDRESS)
     node_info = get_node_info(conf.PPOS25NODE_YML)
     self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
         'collusion')
     FOUNDATIONTOTAL = conf.TOKENTOTAL * 0.01
     assert FOUNDATIONTOTAL == (FOUNDATION + FOUNDATIONLOCKUP)
Beispiel #4
0
 def read_out_nodeId(self, code):
     """
     读取节点id列表
     :param code: 共识节点或者非共识节点标识
     :return:
     """
     node_info = get_node_info(self.node_yml_path)
     self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
         code)
     node_list_length = len(nodeid_list)
     index = random.randint(0, node_list_length - 1)
     nodeId = nodeid_list[index]
     return nodeId
Beispiel #5
0
    def View_available_nodes(self):
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        node_info = get_node_info(self.node_yml_path)
        self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
            'nocollusion')
        candidateinfo = platon_ppos.getCandidateList()
        candidateinfo = candidateinfo.get('Data')
        candidate_list = []
        for nodeid in candidateinfo:
            candidate_list.append(nodeid.get('NodeId'))

        if set(nodeid_list) <= set(candidate_list):
            CommonMethod.start_init(self)
Beispiel #6
0
    def ppos_link(self,
                  url=None,
                  address=conf.ADDRESS,
                  privatekey=conf.PRIVATE_KEY):
        if url is None:
            node_info = get_node_info(conf.TWENTY_FIVENODE_YML)
            self.rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
                'collusion')
            rpc_list_length = len(self.rpc_list) - 1
            index = random.randint(0, rpc_list_length)
            url = self.rpc_list[index]

        self.platon_ppos = Ppos(url,
                                address=address,
                                chainid=101,
                                privatekey=privatekey)
        return self.platon_ppos
Beispiel #7
0
 def link_list(self):
     '''
     获取随机一个可以连接正常节点url
     :return:
     '''
     rpc_lastlist = []
     node_info = get_node_info(self.node_yml_path)
     self.rpc_list, enode_list, self.nodeid_list, ip_list, port_list = node_info.get(
         'collusion')
     for i in self.rpc_list:
         self.web3 = connect_web3(i)
         if self.web3.isConnected():
             rpc_lastlist.append(i)
     if rpc_lastlist:
         #log.info("目前可连接节点列表:{}".format(rpc_lastlist))
         index = random.randint(0, len(rpc_lastlist) - 1)
         url = rpc_lastlist[index]
         log.info("当前连接节点:{}".format(url))
         return url
     else:
         log.info("无可用节点")
Beispiel #8
0
class TestConsensus:
    node_yml = conf.NODE_YML
    consensus_list, _ = get_node_list(node_yml)
    f = get_f(consensus_list)
    n = len(consensus_list)
    url_list, enode_list, nodeid_list, ip_list, _ = get_node_info(
        node_yml)["collusion"]
    genesis_path = conf.GENESIS_TMP
    auto = AutoDeployPlaton()
    cbft_path = conf.CBFT_TMP
    cbft_template = conf.CBFT_TEMPLATE

    def teardown_class(self):
        self.auto.start_all_node(self.node_yml)

    def get_cbft_json_data(self, period, duration):
        with open(self.cbft_template, 'r', encoding='utf-8') as f:
            res = json.loads(f.read())
            res['period'] = period
            res['duration'] = duration
        with open(self.cbft_path, 'w', encoding='utf-8') as b:
            cbft_json = json.dumps(res)
            b.write(cbft_json)

    @allure.title("每个节点在窗口期正常出块")
    def test_block_out_of_each_node_window(self):
        """
        用例id:73
        测试 N 个节点每个窗口期都在出块
        """
        log.info("更新cbft文件")
        self.get_cbft_json_data(period=1, duration=10)
        auto = AutoDeployPlaton(cbft=self.cbft_path)
        auto.start_all_node(self.node_yml)
        log.info("跟所有节点建立连接")
        w3_list = [connect_web3(url) for url in self.url_list]
        w3 = w3_list[0]
        start_block = w3.eth.blockNumber
        time.sleep(self.n * 10 + 5)
        block_number = w3.eth.blockNumber
        if block_number > 0:
            log.info("正在出块,块高:{}".format(block_number))
        node_id_dict = {}
        log.info("获取1至{}块的nodeID".format(block_number))
        for block in range(start_block, block_number + 1):
            node_id = get_pub_key(self.url_list[0], block)
            if node_id not in node_id_dict.keys():
                node_id_dict[node_id] = 1
            else:
                node_id_dict[node_id] += 1
        log.info("nodeID对应的出块数{}".format(node_id_dict))
        assert self.n == len(node_id_dict), "出块节点数少于共识节点数"
        for k, v in node_id_dict.items():
            assert 0 <= v <= 20, "节点{}出块周期约为10个块,实际为{}".format(k, v)

    @allure.title("cbft.json配置period{period}-{duration}")
    @pytest.mark.parametrize('period,duration', [(1, 10), (3, 30), (5, 50),
                                                 (10, 100), (0, 10)])
    def test_block_time_period(self, period, duration):
        '''
        用例id 1,2,3,4,5
        测试period的不同值,观察查看时间
        根据5种场景,分别出块时间约为1,3,5,10,1s
        '''
        log.info("更新cbft.json")
        self.get_cbft_json_data(period, duration)
        auto = AutoDeployPlaton(cbft=self.cbft_path)
        auto.start_all_node(self.node_yml)
        time.sleep(duration + 5)
        log.info("跟所有节点建立连接")
        w3_list = [connect_web3(url) for url in self.url_list]
        w3 = w3_list[0]
        block_number = w3.eth.blockNumber
        assert block_number > 1, "没有正常出块"
        log.info(block_number)
        start_time = w3.eth.getBlock(1).get("timestamp")
        end_time = w3.eth.getBlock(block_number).get("timestamp")
        use_time = end_time - start_time
        average_time = int(use_time / (block_number - 1))
        log.info("平均出块时间{}".format(average_time))
        if period == 0:
            period = 1
        deviation = int(period * 1000 * 0.5)
        assert period * 1000 - deviation < average_time < period * \
            1000 + deviation, "出块间隔过大或过小"

    @allure.title("cbft.json配置period{period}-{duration}-{delay_time}--{number}"
                  )
    @pytest.mark.parametrize('period,duration,delay_time,number',
                             [(1, 10, 50, 30), (1, 20, 90, 70),
                              (1, 30, 130, 90), (1, 50, 180, 140),
                              (1, 100, 350, 250)])
    def test_block_cycle_duration(self, period, duration, delay_time, number):
        '''
        用例id 6,7,8,9,10
        测试duration的不同值,观察出块周期
        根据5种场景,出块周期约为10,20,30,50,100
        '''
        self.get_cbft_json_data(period, duration)
        auto = AutoDeployPlaton(cbft=self.cbft_path)
        log.info("上传cbft文件成功")
        auto.start_all_node(self.node_yml)
        time.sleep(delay_time)
        log.info("跟所有节点建立连接")
        w3_list = [connect_web3(url) for url in self.url_list]
        w3 = w3_list[0]
        block_number = w3.eth.blockNumber
        if block_number > 0:
            log.info("正在出块,块高:{}".format(block_number))
        if block_number < number:
            raise Exception("出块很慢,没达到预期{}".format(number))
        node_id_dict = {}
        log.info("获取1至{}块的nodeID".format(number))
        for block in range(1, number):
            node_id = get_pub_key(self.url_list[0], block)
            if node_id not in node_id_dict.keys():
                node_id_dict[node_id] = [block]
            else:
                node_id_dict[node_id].append(block)
        log.info("获取到全部的nodeID对应的出块".format(node_id_dict))
        log.info("由于第一组nodeID收集数据不全,从第二组开始收集统计,删除第一组")
        node_id_list = []
        for node_id in node_id_dict.keys():
            node_id_list.append(node_id)
        node_id_dict.pop(node_id_list[0])
        log.info("统计出nodeID对应的出块ID{}".format(node_id_dict))
        print(node_id_dict)
        print(node_id_list)
        if duration == 10:
            block_cycle_a = node_id_dict.get(node_id_list[1])
            log.info("出块人A出块周期数:%s" % block_cycle_a)
            assert 7 <= len(block_cycle_a) <= 12, "出块周期预期在7到12,实际{}".format(
                len(block_cycle_a))
            block_cycle_b = node_id_dict.get(node_id_list[2])
            log.info("出块人B出块周期数:%s" % block_cycle_b)
            assert 7 <= len(block_cycle_b) <= 12, "出块周期预期在7到12,实际{}".format(
                len(block_cycle_b))
            times_tamp_a = w3.eth.getBlock(block_cycle_a[-1]).get("timestamp")
            times_tamp_b = w3.eth.getBlock(block_cycle_b[-1]).get("timestamp")
            log.info("获取出块人B的最后一个块的时间戳%s" % times_tamp_b)
            assert 8000 < times_tamp_b - \
                times_tamp_a < 12000, "预期出块周期为8到12s,实际为{}".format(
                    times_tamp_b - times_tamp_a)
            log.info(
                "出块人B最后一个块出块时间-出块人A最后一个块出块时间 = 出块周期时间{}".format(times_tamp_b -
                                                                times_tamp_a))

        if duration == 20:
            block_cycle_a = node_id_dict.get(node_id_list[1])
            log.info("出块人A出块周期数:%s" % block_cycle_a)
            assert 16 <= len(block_cycle_a) <= 23, "出块周期预期在16到23,实际{}".format(
                len(block_cycle_a))
            block_cycle_b = node_id_dict.get(node_id_list[2])
            log.info("出块人B出块周期数:%s" % block_cycle_b)
            assert 16 <= len(block_cycle_b) <= 23, "出块周期预期在16到23,实际{}".format(
                len(block_cycle_b))
            times_tamp_a = w3.eth.getBlock(block_cycle_a[-1]).get("timestamp")
            times_tamp_b = w3.eth.getBlock(block_cycle_b[-1]).get("timestamp")
            log.info("获取出块人B的最后一个块的时间戳%s" % times_tamp_b)
            assert 16000 < times_tamp_b - times_tamp_a < 23000, "预期出块周期为16到23s,实际为{}".format(
                times_tamp_b - times_tamp_a)
            log.info(
                "出块人B最后一个块出块时间-出块人A最后一个块出块时间 = 出块周期时间{}".format(times_tamp_b -
                                                                times_tamp_a))

        if duration == 30:
            block_cycle_a = node_id_dict.get(node_id_list[1])
            log.info("出块人A出块周期数:%s" % block_cycle_a)
            assert 26 <= len(block_cycle_a) <= 33, "出块周期预期在26到33,实际{}".format(
                len(block_cycle_a))
            block_cycle_b = node_id_dict.get(node_id_list[2])
            log.info("出块人B出块周期数:%s" % block_cycle_b)
            assert 26 <= len(block_cycle_b) <= 33, "出块周期预期在26到33,实际{}".format(
                len(block_cycle_b))
            times_tamp_a = w3.eth.getBlock(block_cycle_a[-1]).get("timestamp")
            times_tamp_b = w3.eth.getBlock(block_cycle_b[-1]).get("timestamp")
            log.info("获取出块人B的最后一个块的时间戳%s" % times_tamp_b)
            assert 26000 < times_tamp_b - times_tamp_a < 33000, "预期出块周期为26到30s,实际为{}".format(
                times_tamp_b - times_tamp_a)
            log.info(
                "出块人B最后一个块出块时间-出块人A最后一个块出块时间 = 出块周期时间{}".format(times_tamp_b -
                                                                times_tamp_a))

        if duration == 50:
            block_cycle_a = node_id_dict.get(node_id_list[1])
            log.info("出块人A出块周期数:%s" % block_cycle_a)
            assert 40 <= len(block_cycle_a) <= 60, "出块周期预期在40到60,实际{}".format(
                len(block_cycle_a))
            block_cycle_b = node_id_dict.get(node_id_list[2])
            log.info("出块人B出块周期数:%s" % block_cycle_b)
            assert 40 <= len(block_cycle_b) <= 60, "出块周期预期在40到60,实际{}".format(
                len(block_cycle_b))
            times_tamp_a = w3.eth.getBlock(block_cycle_a[-1]).get("timestamp")
            times_tamp_b = w3.eth.getBlock(block_cycle_b[-1]).get("timestamp")
            log.info("获取出块人B的最后一个块的时间戳%s" % times_tamp_b)
            assert 4000 < times_tamp_b - times_tamp_a < 60000, "预期出块周期为40到60s,实际为{}".format(
                times_tamp_b - times_tamp_a)
            log.info(
                "出块人B最后一个块出块时间-出块人A最后一个块出块时间 = 出块周期时间{}".format(times_tamp_b -
                                                                times_tamp_a))

        if duration == 100:
            block_cycle_a = node_id_dict.get(node_id_list[1])
            log.info("出块人A出块周期数:%s" % block_cycle_a)
            assert 90 <= len(
                block_cycle_a) <= 110, "出块周期预期在90到110,实际{}".format(
                    len(block_cycle_a))
            block_cycle_b = node_id_dict.get(node_id_list[2])
            log.info("出块人B出块周期数:%s" % block_cycle_b)
            assert 90 <= len(
                block_cycle_b) <= 110, "出块周期预期在90到110,实际{}".format(
                    len(block_cycle_b))
            times_tamp_a = w3.eth.getBlock(block_cycle_a[-1]).get("timestamp")
            times_tamp_b = w3.eth.getBlock(block_cycle_b[-1]).get("timestamp")
            log.info("获取出块人B的最后一个块的时间戳%s" % times_tamp_b)
            assert 90000 < times_tamp_b - times_tamp_a < 110000, "预期出块周期为99到110s,实际为{}".format(
                times_tamp_b - times_tamp_a)
            log.info(
                "出块人B最后一个块出块时间-出块人A最后一个块出块时间 = 出块周期时间{}".format(times_tamp_b -
                                                                times_tamp_a))

    @allure.title("重启节点后查看旧块交易,钱包余额")
    def test_kill_process_observation_block_data(self):
        '''
       用例id 30,31,32,33
       测试kill进程后,重启查看块高持续增长
       测试kill进程后,重启查看旧块转账,合约信息不变
       测试kill进程后,钱包余额不变
        '''
        log.info("部署节点")
        self.auto.start_all_node(self.node_yml)
        log.info("启动会等待60s出块")
        time.sleep(10)
        log.info("跟所有节点建立连接")
        w3_list = [connect_web3(url) for url in self.url_list]
        w3 = w3_list[0]
        number_before = w3.eth.blockNumber
        if number_before == 0:
            raise Exception("起服务但未出块")
        log.info("块高为:{}".format(number_before))
        log.info("发起转账交易")
        t_hash = self.transaction(w3)
        result, number, result_block, hash_list = self.check_block_information(
            w3, t_hash)
        log.info("发起合约交易")
        contract_address, resp, contract_number = self.deploy_contract()
        log.info("kill 所有节点")
        self.auto.kill_of_yaml(self.node_yml)
        time.sleep(2)
        log.info("重启platon服务")
        self.auto.start_all_node(self.node_yml, is_need_init=False)
        log.info("重启25节点后,延迟30s")
        time.sleep(30)
        w3_list = [connect_web3(url) for url in self.url_list]
        w3 = w3_list[0]
        number_after = w3.eth.blockNumber
        assert number_after >= number_before, "块高未有增长"
        balance = w3.eth.getBalance(w3.eth.accounts[1])
        assert balance == 100000, "kill进程重启后余额发生变化,余额为:{}".format(balance)
        log.info("查看重启前的{}区块转账信息".format(number))
        t_hash_list = (w3.eth.getBlock(number).get("transactions"))
        log.info("查看重启前的{}区块合约信息".format(contract_number))
        c_hash_list = (w3.eth.getBlock(contract_number).get("transactions"))
        log.info("通过transactions字段得到的交易哈希列表:{}".format(hash_list))
        assert t_hash in t_hash_list, "kill进程重启后转账交易丢失"
        c_hash = HexBytes(resp)
        assert c_hash in c_hash_list, "kill进程重启后合约交易丢失"
        contract_address_after = w3.eth.waitForTransactionReceipt(resp).get(
            'contractAddress')
        assert contract_address == contract_address_after, "kill进程后,合约地址发生改变"

    def check_block_information(self, w3, hash):
        transaction_hash = HexBytes(hash).hex()
        result = w3.eth.waitForTransactionReceipt(transaction_hash)
        number = result.get("blockNumber")
        result_block = w3.eth.getBlock(number)
        hash_list = result_block.get("transactions")
        return result, number, result_block, hash_list

    def transaction(self, w3, value=100000):
        from_address = w3.toChecksumAddress(w3.eth.accounts[0])
        to_address = w3.toChecksumAddress(w3.personal.newAccount('88888888'))
        log.info("解锁账号")
        w3.personal.unlockAccount(from_address, '88888888', 666666)
        params = {
            'to': to_address,
            'from': from_address,
            'gas': 91000000,
            'gasPrice': 9000000000,
            'value': value
        }
        t_hash = w3.eth.sendTransaction(params)
        return t_hash

    def deploy_contract(self):
        consensus_list, _ = get_node_list(self.node_yml)
        url = consensus_list[0]['url']
        wt = PlatonContractTransaction(url)
        addrress = wt.w3.toChecksumAddress(conf.ADDRESS)
        wt.w3.personal.unlockAccount(addrress, conf.PASSWORD, 99999999)
        log.info("部署合约")
        resp = wt.contract_deploy(
            get_byte_code(abspath('./data/contract/sum.wasm')),
            get_abi_bytes(abspath('./data/contract/sum.cpp.abi.json')),
            addrress)
        log.info("获取合约交易信息")
        result = wt.eth.waitForTransactionReceipt(resp)
        contract_address = result['contractAddress']
        contract_number = result['blockNumber']
        return contract_address, resp, contract_number
class TestUndelegate():
    node_yml_path = conf.NODE_YML
    node_info = get_node_info(node_yml_path)
    rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
        'collusion')
    rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
        'nocollusion')

    address = Web3.toChecksumAddress(conf.ADDRESS)
    privatekey = conf.PRIVATE_KEY
    account_list = conf.account_list
    privatekey_list = conf.privatekey_list
    externalId = "1111111111"
    nodeName = "platon"
    website = "https://www.test.network"
    details = "supper node"
    programVersion = 1792
    illegal_nodeID = conf.illegal_nodeID

    genesis_path = conf.GENESIS_TMP
    """替换config.json"""
    get_config_data()
    config_json_path = conf.PLATON_CONFIG_PATH
    config_dict = LoadFile(config_json_path).get_data()
    amount_delegate = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['MinimumThreshold']),
        'ether')
    amount = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['StakeThreshold']),
        'ether')

    def setup_class(self):
        self.auto = AutoDeployPlaton()
        self.auto.start_all_node(self.node_yml_path)
        self.genesis_dict = LoadFile(self.genesis_path).get_data()
        self.chainid = int(self.genesis_dict["config"]["chainId"])
        self.ppos_link = Ppos(self.rpc_list[0], self.address, self.chainid)
        self.w3_list = [connect_web3(url) for url in self.rpc_list]
        """用新的钱包地址和未质押过的节点id封装对象"""
        self.ppos_noconsensus_1 = Ppos(self.rpc_list[0],
                                       self.account_list[0],
                                       self.chainid,
                                       privatekey=self.privatekey_list[0])
        self.ppos_noconsensus_2 = Ppos(self.rpc_list[0],
                                       self.account_list[1],
                                       self.chainid,
                                       privatekey=self.privatekey_list[1])
        self.ppos_noconsensus_3 = Ppos(self.rpc_list[0],
                                       self.account_list[2],
                                       self.chainid,
                                       privatekey=self.privatekey_list[2])
        self.ppos_noconsensus_4 = Ppos(self.rpc_list[0],
                                       self.account_list[3],
                                       self.chainid,
                                       privatekey=self.privatekey_list[3])
        self.ppos_noconsensus_5 = Ppos(self.rpc_list[0],
                                       self.account_list[4],
                                       self.chainid,
                                       privatekey=self.privatekey_list[4])
        self.ppos_noconsensus_6 = Ppos(self.rpc_list[0],
                                       self.account_list[5],
                                       self.chainid,
                                       privatekey=self.privatekey_list[5])
        self.eth = Eth(self.w3_list[0])

    def transaction(self,
                    w3,
                    from_address,
                    to_address=None,
                    value=1000000000000000000000000000000000,
                    gas=91000000,
                    gasPrice=9000000000,
                    pwd=conf.PASSWORD):
        """"
        转账公共方法
        """
        personal = Personal(w3)
        personal.unlockAccount(from_address, pwd, 666666)
        params = {
            'to': to_address,
            'from': from_address,
            'gas': gas,
            'gasPrice': gasPrice,
            'value': value
        }
        tx_hash = w3.eth.sendTransaction(params)
        result = w3.eth.waitForTransactionReceipt(HexBytes(tx_hash).hex())
        return result

    def getCandidateList(self):
        """
        获取实时验证人的nodeID list
        """
        msg = self.ppos_noconsensus_1.getCandidateList()
        recive_list = msg.get("Data")
        nodeid_list = []
        if recive_list is None:
            return recive_list
        else:
            for node_info in recive_list:
                nodeid_list.append(node_info.get("NodeId"))
        return nodeid_list

##############################赎回####################################################

    @allure.title("委托人未达到锁定期申请赎回")
    @pytest.mark.P0
    def test_unDelegate_part(self):
        """
         用例id 106 申请赎回委托
         用例id 111 委托人未达到锁定期申请赎回
         申请部分赎回
        """
        log.info("转账到钱包3")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[2])
        log.info("转账到钱包4")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[3])
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[2])
        if msg['Data'] == "":
            log.info("质押节点3:{}成为验证节点".format(self.nodeid_list2[2]))
            self.ppos_noconsensus_3.createStaking(0, self.account_list[2],
                                                  self.nodeid_list2[2],
                                                  self.externalId,
                                                  self.nodeName, self.website,
                                                  self.details, self.amount,
                                                  self.programVersion)
        log.info("钱包4 {}委托到3 {}".format(self.account_list[3],
                                        self.account_list[2]))
        value = 100
        self.ppos_noconsensus_4.delegate(0, self.nodeid_list2[2], value)
        log.info("查询当前节点质押信息")
        msg = self.ppos_noconsensus_3.getCandidateInfo(self.nodeid_list2[2])
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        log.info("发起质押的区高{}".format(stakingBlockNum))
        delegate_value = 20
        self.ppos_noconsensus_4.unDelegate(stakingBlockNum,
                                           self.nodeid_list2[2],
                                           delegate_value)
        log.info("查询钱包{}的委托信息".format(self.account_list[3]))
        msg = self.ppos_noconsensus_4.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[3],
                                                      self.nodeid_list2[2])
        print(msg)
        data = msg["Data"]
        """不清楚msg["Data"]对应value是str类型,需要再转字典"""
        data = json.loads(data)
        print(data)
        assert Web3.toChecksumAddress(data["Addr"]) == self.account_list[3]
        assert data["NodeId"] == self.nodeid_list2[2]
        print(data["ReleasedHes"])
        value = value - delegate_value
        result_value = Web3.toWei(value, "ether")
        assert data["ReleasedHes"] == result_value

    @allure.title("大于委托金额赎回")
    @pytest.mark.P0
    def test_unDelegate_iff(self):
        """
        验证 大于委托金额赎回
        """
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[2])
        if msg['Data'] == "":
            log.info("质押节点3成为验证节点")
            self.ppos_noconsensus_3.createStaking(0, self.account_list[2],
                                                  self.nodeid_list2[2],
                                                  self.externalId,
                                                  self.nodeName, self.website,
                                                  self.details, self.amount,
                                                  self.programVersion)
        log.info("钱包4 委托到3 {}")
        value = 100
        self.ppos_noconsensus_4.delegate(0, self.nodeid_list2[2], value)
        msg = self.ppos_noconsensus_3.getCandidateInfo(self.nodeid_list2[2])
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        msg = self.ppos_noconsensus_4.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[3],
                                                      self.nodeid_list2[2])
        data = msg["Data"]
        """不清楚msg["Data"]对应value是str类型,需要再转字典"""
        data = json.loads(data)
        releasedHes = data["ReleasedHes"]
        releasedHes = Web3.fromWei(releasedHes, 'ether')
        log.info("委托钱包可赎回的金额单位eth:{}".format(releasedHes))
        delegate_value = releasedHes + 20
        msg = self.ppos_noconsensus_4.unDelegate(stakingBlockNum,
                                                 self.nodeid_list2[2],
                                                 delegate_value)
        assert msg["Status"] == False
        err_msg = "withdrewDelegate err: The von of delegate is not enough"
        assert err_msg in msg["ErrMsg"]

    @allure.title("赎回全部委托的金额与赎回金额为0")
    @pytest.mark.P1
    def test_unDelegate_all(self):
        """
        验证 赎回全部委托的金额
        验证 赎回金额为0
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[0])
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[1])

        log.info("节点1质押成为验证人")
        self.ppos_noconsensus_1.createStaking(0, self.account_list[0],
                                              self.nodeid_list2[0],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)

        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        log.info("查询节点质押信息,质押块高{}".format(stakingBlockNum))
        log.info("钱包2进行委托")
        value = 80
        self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], value)
        msg = self.ppos_noconsensus_2.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[1],
                                                      self.nodeid_list2[0])
        data = msg["Data"]
        """不清楚msg["Data"]对应value是str类型,需要再转字典"""
        data = json.loads(data)
        log.info(data)
        releasedHes = data["ReleasedHes"]
        releasedHes = Web3.fromWei(releasedHes, 'ether')
        log.info("委托钱包可赎回的金额单位eth:{}".format(releasedHes))
        account_before = self.eth.getBalance(self.account_list[1])
        msg = self.ppos_noconsensus_2.unDelegate(stakingBlockNum,
                                                 self.nodeid_list2[0],
                                                 releasedHes)
        assert msg["Status"] == True
        account_after = self.eth.getBalance(self.account_list[1])
        result_value = account_after - account_before
        ##为什么会赎回多那么多钱?1000000000000159999910972325109760
        assert account_before + data["ReleasedHes"] > account_after
        assert 70 < Web3.fromWei(result_value,
                                 "ether") < releasedHes, "赎回的金额减去gas应在这范围"
        log.info("全部委托金额赎回后,查询委托金额".format(account_after))
        msg = self.ppos_noconsensus_2.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[1],
                                                      self.nodeid_list2[0])
        log.info(msg)
        """如果全部金额赎回,再查getDelegateInfo返回数据为空"""
        assert msg["Status"] == False
        assert msg["ErrMsg"] == "Delegate info is not found"

    @allure.title("多次委托,多次赎回")
    @pytest.mark.P1
    def test_multiple_delegate_undelegate(self):
        """
        验证多次委托,多次赎回
        """
        log.info("转账到钱包5")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[4])
        log.info("转账到钱包6")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[5])
        msg = self.ppos_noconsensus_5.getCandidateInfo(self.nodeid_list2[4])
        if msg['Data'] == "":
            log.info("质押节点5成为验证节点")
            self.ppos_noconsensus_5.createStaking(0, self.account_list[4],
                                                  self.nodeid_list2[4],
                                                  self.externalId,
                                                  self.nodeName, self.website,
                                                  self.details, self.amount,
                                                  self.programVersion)
        msg = self.ppos_noconsensus_5.getCandidateInfo(self.nodeid_list2[4])
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        log.info("查询节点质押信息回去质押块高{}".format(stakingBlockNum))
        value_list = [10, 11, 12, 13, 14, 15, 16, 17, 18]
        for value in value_list:
            log.info("钱包6 委托金额{}".format(value))
            self.ppos_noconsensus_6.delegate(0, self.nodeid_list2[4], value)
        msg = self.ppos_noconsensus_6.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[5],
                                                      self.nodeid_list2[4])
        log.info(msg)
        data = json.loads(msg["Data"])
        releasedHes = Web3.fromWei(data["ReleasedHes"], 'ether')
        log.info("查询委托的金额{}eth".format(releasedHes))
        delegate_value = 0
        for i in value_list:
            delegate_value = i + delegate_value
        assert delegate_value == releasedHes, "委托的金额与查询到的金额不一致"
        for value in value_list:
            log.info("赎回的金额:{}eth".format(value))
            log.info("钱包6进行赎回")
            self.ppos_noconsensus_6.unDelegate(stakingBlockNum,
                                               self.nodeid_list2[4], value)
        log.info("赎回委托金额后查询委托信息")
        msg = self.ppos_noconsensus_6.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[5],
                                                      self.nodeid_list2[4])
        """如果全部金额赎回,再查getDelegateInfo返回数据为空"""
        log.info(msg)
import allure
import pytest

from common import log
from deploy.deploy import AutoDeployPlaton
from common.connect import connect_web3
from conf import setting as conf
from common.load_file import get_f, get_node_info, get_node_list

node_yml = conf.NODE_YML
collusion_list, _ = get_node_list(node_yml)
f = int(get_f(collusion_list))
n = len(collusion_list)
auto = AutoDeployPlaton()
url_list, enode_list, nodeid_list, ip_list, _ = get_node_info(
    node_yml)["collusion"]
genesis_file = conf.GENESIS_TMP
static_node_file = conf.STATIC_NODE_FILE


def teardown_function():
    log.info("关闭所有节点")
    auto.kill_of_yaml(node_yml)


def teardown_module():
    auto.start_all_node(node_yml)


@allure.title("正常启动所有节点")
def test_start_all_node():
class TestDelegate():
    node_yml_path = conf.NODE_YML
    node_info = get_node_info(node_yml_path)
    rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
        'collusion')
    rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
        'nocollusion')

    address = Web3.toChecksumAddress(conf.ADDRESS)
    privatekey = conf.PRIVATE_KEY
    account_list = conf.account_list
    privatekey_list = conf.privatekey_list
    externalId = "1111111111"
    nodeName = "platon"
    website = "https://www.test.network"
    details = "supper node"
    programVersion = 1792
    illegal_nodeID = conf.illegal_nodeID
    genesis_path = conf.GENESIS_TMP


    """替换config.json"""
    get_config_data()
    config_json_path = conf.PLATON_CONFIG_PATH
    config_dict = LoadFile(config_json_path).get_data()
    amount_delegate = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['MinimumThreshold']), 'ether')
    amount = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['StakeThreshold']), 'ether')


    def setup_class(self):
        self.auto = AutoDeployPlaton()
        self.auto.start_all_node(self.node_yml_path)
        self.genesis_dict = LoadFile(self.genesis_path).get_data()
        self.chainid = int(self.genesis_dict["config"]["chainId"])
        self.ppos_link = Ppos(
            self.rpc_list[0],self.address,self.chainid)
        self.w3_list = [connect_web3(url) for url in self.rpc_list]
        """用新的钱包地址和未质押过的节点id封装对象"""
        self.ppos_noconsensus_1 = Ppos(self.rpc_list[0], self.account_list[0],self.chainid,privatekey=self.privatekey_list[0])
        self.ppos_noconsensus_2 = Ppos(self.rpc_list[0], self.account_list[1],self.chainid,privatekey=self.privatekey_list[1])
        self.ppos_noconsensus_3 = Ppos(self.rpc_list[0], self.account_list[2],self.chainid,privatekey=self.privatekey_list[2])
        self.ppos_noconsensus_4 = Ppos(self.rpc_list[0], self.account_list[3],self.chainid,privatekey=self.privatekey_list[3])
        self.ppos_noconsensus_5 = Ppos(self.rpc_list[0], self.account_list[4],self.chainid,privatekey=self.privatekey_list[4])
        self.ppos_noconsensus_6 = Ppos(self.rpc_list[0], self.account_list[5],self.chainid,privatekey=self.privatekey_list[5])
        self.eth = Eth(self.w3_list[0])


    def transaction(self,w3, from_address, to_address=None,value=1000000000000000000000000000000000,
                    gas=91000000, gasPrice=9000000000,pwd=conf.PASSWORD):
        """"
        转账公共方法
        """
        personal = Personal(w3)
        personal.unlockAccount(from_address, pwd, 666666)
        params = {
            'to': to_address,
            'from': from_address,
            'gas': gas,
            'gasPrice': gasPrice,
            'value': value
        }
        tx_hash = w3.eth.sendTransaction(params)
        result = w3.eth.waitForTransactionReceipt(HexBytes(tx_hash).hex())
        return result


    def getCandidateList(self):
        """
        获取实时验证人的nodeID list
        """
        msg = self.ppos_noconsensus_1.getCandidateList()
        recive_list = msg.get("Data")
        nodeid_list = []
        if recive_list is None:
            return recive_list
        else:
            for node_info in recive_list:
                nodeid_list.append(node_info.get("NodeId"))
        return nodeid_list


    @allure.title("委托金额分别为{amount}")
    @pytest.mark.P1
    @pytest.mark.parametrize('amount', [amount_delegate-1, 0])
    def test_illege_delegate(self,amount):
        """
        用例id 委托金额小于门槛
        """
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],self.address,to_address=to_account)
        log.info("质押节点1:{}成为验证人".format(self.nodeid_list2[0]))

        self.ppos_noconsensus_1.createStaking(0, self.account_list[0], self.nodeid_list2[0],
                                              self.externalId, self.nodeName, self.website, self.details,
                                              self.amount, self.programVersion)
        log.info("钱包2委托金额")
        msg = self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], amount)
        log.info(msg)
        assert msg.get("Status") == False,"委托金额异常"


    @allure.title("质押过的钱包委托失败")
    @pytest.mark.P1
    def test_delegate_verifier(self):
        """
        测试质押过的钱包不能去委托
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[0])
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[1])
        amount = self.amount_delegate
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        if msg['Data']!= "":
            log.info("质押过的钱包1不能再去质押")
            msg = self.ppos_noconsensus_1.delegate(0, self.nodeid_list2[0], amount)
            # print(msg)
            assert msg.get("Status") == False
            msg_string = "is not allowed to be used for delegating"
            assert msg_string in msg["ErrMsg"], "质押过的钱包不能进行质押出现异常"
        else:
            log.info("质押节点1:{}成为验证人".format(self.nodeid_list2[0]))
            self.ppos_noconsensus_1.createStaking(0, self.account_list[0], self.nodeid_list2[0],
                                                  self.externalId, self.nodeName, self.website, self.details,
                                                  self.amount, self.programVersion)
            log.info("质押过的钱包1不能再去质押")
            msg = self.ppos_noconsensus_1.delegate(0, self.nodeid_list2[0], amount)
            assert msg.get("Status") == False
            log.info(msg)
            msg_string = "is not allowed to be used for delegating"
            assert msg_string in msg["ErrMsg"], "质押过的钱包不能进行质押出现异常"


    @allure.title("发起委托成功")
    @pytest.mark.P0
    def test_delegate(self):
        """
        用例id 95 委托成功,查询节点信息,金额
        用例id 98 委托人与验证人验证,验证人存在
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[0])
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[1])
        amount = self.amount_delegate
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        if msg['Data']!= "":
            log.info("钱包2委托节点1")
            msg = self.ppos_noconsensus_2.delegate(0,self.nodeid_list2[0],amount)
            assert msg.get("Status") == True
            assert msg.get("ErrMsg") == 'ok'
        else:
            log.info("质押节点1:{}成为验证人".format(self.nodeid_list2[0]))
            self.ppos_noconsensus_1.createStaking(0, self.account_list[0], self.nodeid_list2[0],
                                                  self.externalId, self.nodeName, self.website, self.details,
                                                  self.amount, self.programVersion)
            msg = self.ppos_noconsensus_2.delegate(0,self.nodeid_list2[0],amount)
            assert msg.get("Status") == True
            assert msg.get("ErrMsg") == 'ok'


    @allure.title("查询当前单个委托信息")
    @pytest.mark.P0
    def test_getDelegateInfo(self):
        """
        用例id 94 查询当前单个委托信息
        """

        log.info("转账到钱包5")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[4])
        log.info("转账到钱包6")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[5])

        log.info("质押节点5成为验证人")
        self.ppos_noconsensus_5.createStaking(0, self.account_list[4], self.nodeid_list2[4],
                                              self.externalId, self.nodeName, self.website, self.details,
                                              self.amount, self.programVersion)
        msg = self.ppos_noconsensus_6.delegate(0, self.nodeid_list2[4], self.amount_delegate)
        assert msg.get("Status") == True
        assert msg.get("ErrMsg") == 'ok'
        log.info("查询质押节点5信息")
        msg = self.ppos_noconsensus_5.getCandidateInfo(self.nodeid_list2[4])
        assert msg["Data"]["NodeId"] == self.nodeid_list2[4]
        log.info("查询质押+委托的金额正确")
        assert Web3.fromWei(msg["Data"]["Shares"], 'ether') == self.amount + self.amount_delegate
        assert Web3.fromWei(msg["Data"]["ReleasedHes"], 'ether') == self.amount
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        log.info("质押的块高{}".format(stakingBlockNum))
        msg = self.ppos_noconsensus_6.getDelegateInfo(stakingBlockNum, self.account_list[5], self.nodeid_list2[4])
        data = msg["Data"]
        data = json.loads(data)
        assert Web3.toChecksumAddress(data["Addr"]) == self.account_list[5]
        assert data["NodeId"] == self.nodeid_list2[4]
        assert Web3.fromWei(data["ReleasedHes"], 'ether') == self.amount_delegate


    @allure.title("余额不足委托失败")
    @pytest.mark.P2
    def test_insufficient_delegate(self):
        """
        用例96 余额不足委托失败
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[0])
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[1])
        amount = 1000000000000000000000000000000
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        if msg['Data']!= "":
            msg = self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], amount)
            # print(msg)
            assert msg.get("Status") == False
            assert msg.get("ErrMsg") == 'Delegate failed: The von of account is not enough'
        else:
            log.info("质押节点1:{}成为验证人".format(self.nodeid_list2[0]))
            self.ppos_noconsensus_1.createStaking(0, self.account_list[0], self.nodeid_list2[0],
                                                  self.externalId, self.nodeName, self.website, self.details,
                                                  self.amount, self.programVersion)
            msg = self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], amount)
            # print(msg)
            assert msg.get("Status") == False
            assert msg.get("ErrMsg") == 'Delegate failed: The von of account is not enough'


    @allure.title("验证人不存在进行委托")
    @pytest.mark.P2
    def test_not_nodeId_delegate(self):
        """
        用例72 验证人不存在进行委托
        """
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[1])
        value = self.amount_delegate
        nodeid = conf.illegal_nodeID
        msg = self.ppos_noconsensus_2.delegate(0, nodeid, value)
        print(msg)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == 'This candidate is not exist'


    @allure.title("验证人退出后,委托人信息还存在")
    @pytest.mark.P1
    def test_back_unStaking_commissioned(self):
        """
        用例id 82 验证人申请退回质押金,委托金额还生效
        用例id 83 验证人退出后,委托人信息还存在
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[0])
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[1])
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        if msg['Data']== "":
            log.info("节点1再次成为验证人")
            self.ppos_noconsensus_1.createStaking(0, self.account_list[0], self.nodeid_list2[0],
                                                  self.externalId, self.nodeName, self.website, self.details,
                                                  self.amount, self.programVersion)
            log.info("钱包2进行委托100")
            self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], 100)
            log.info("节点1退出验证人")
            self.ppos_noconsensus_1.unStaking(self.nodeid_list2[0])
            msg = self.ppos_noconsensus_2.getDelegateListByAddr(self.account_list[1])
            log.info(msg)
            StakingBlockNum = msg["Data"][0]["StakingBlockNum"]
            msg = self.ppos_noconsensus_2.getDelegateInfo(StakingBlockNum,self.account_list[1],self.nodeid_list2[0])
            log.info(msg)
            data = msg["Data"]
            data = json.loads(data)
            log.info(data)
            assert Web3.toChecksumAddress(data["Addr"]) == self.account_list[1]
            assert data["NodeId"] == self.nodeid_list2[0]
        else:
            log.info("钱包2进行委托100")
            self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], 100)
            log.info("节点1退出验证人")
            self.ppos_noconsensus_1.unStaking(self.nodeid_list2[0])
            msg = self.ppos_noconsensus_2.getDelegateListByAddr(self.account_list[1])
            log.info(msg)
            StakingBlockNum = msg["Data"][0]["StakingBlockNum"]
            msg = self.ppos_noconsensus_2.getDelegateInfo(StakingBlockNum,self.account_list[1],self.nodeid_list2[0])
            log.info(msg)
            data = msg["Data"]
            data = json.loads(data)
            log.info(data)
            assert Web3.toChecksumAddress(data["Addr"]) == self.account_list[1]
            assert data["NodeId"] == self.nodeid_list2[0]



    @allure.title("验证节点退出后,再成为验证节点,钱包委托信息有2个")
    @pytest.mark.P2
    def test_identifier_quit_delegate(self):
        """
        委托验证节点,验证节点退出后,再成为验证节点,再去委托:预期有2个委托消息
        """
        log.info("转账到钱包3")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[2])
        log.info("转账到钱包4")
        self.transaction(self.w3_list[0], self.address, to_address=self.account_list[3])

        log.info("质押节点3:{}成为验证节点".format(self.nodeid_list2[2]))
        self.ppos_noconsensus_3.createStaking(0, self.account_list[2], self.nodeid_list2[2],
                                              self.externalId, self.nodeName, self.website, self.details,
                                              self.amount, self.programVersion)
        log.info("钱包4:{}进行委托".format(self.account_list[3]))
        self.ppos_noconsensus_4.delegate(0,self.nodeid_list2[2],50)
        log.info("质押节点3退出验证人{}".format(self.nodeid_list2[2]))
        self.ppos_noconsensus_3.unStaking(self.nodeid_list2[2])
        log.info("{}再次成为验证人".format(self.nodeid_list2[2]))
        self.ppos_noconsensus_3.createStaking(0, self.account_list[2],self.nodeid_list2[2],self.externalId,
                                           self.nodeName, self.website, self.details,self.amount,self.programVersion)
        log.info("钱包4:{}再次进行委托".format(self.account_list[3]))
        msg = self.ppos_noconsensus_4.delegate(0,self.nodeid_list2[2],100)
        print(msg)
        log.info("查询钱包的委托情况")
        msg = self.ppos_noconsensus_4.getDelegateListByAddr(self.account_list[3])
        log.info(msg)
        log.info(msg["Data"])
        print(len(msg["Data"]))
        assert len(msg["Data"]) == 2
        for i in msg["Data"]:
            assert Web3.toChecksumAddress(i["Addr"]) == self.account_list[3]
            assert i["NodeId"] == self.nodeid_list2[2]
Beispiel #12
0
class TestAddstaking():
    node_yml_path = conf.NODE_YML
    node_info = get_node_info(node_yml_path)
    rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
        'collusion')
    rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
        'nocollusion')

    address = Web3.toChecksumAddress(conf.ADDRESS)
    pwd = conf.PASSWORD
    privatekey = conf.PRIVATE_KEY
    account_list = conf.account_list
    privatekey_list = conf.privatekey_list
    externalId = "1111111111"
    nodeName = "platon"
    website = "https://www.test.network"
    details = "supper node"
    programVersion = 1792
    illegal_nodeID = conf.illegal_nodeID

    genesis_path = conf.GENESIS_TMP
    """替换config.json"""
    get_config_data()
    config_json_path = conf.PLATON_CONFIG_PATH
    config_dict = LoadFile(config_json_path).get_data()
    amount_delegate = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['MinimumThreshold']),
        'ether')
    amount = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['StakeThreshold']),
        'ether')

    def setup_class(self):
        self.auto = AutoDeployPlaton()
        self.auto.start_all_node(self.node_yml_path)
        self.genesis_dict = LoadFile(self.genesis_path).get_data()
        self.chainid = int(self.genesis_dict["config"]["chainId"])
        self.ppos_link = Ppos(self.rpc_list[0], self.address, self.chainid)
        self.ppos_link1 = Ppos(self.rpc_list[1], self.address, self.chainid)
        self.w3_list = [connect_web3(url) for url in self.rpc_list]
        """用新的钱包地址和未质押过的节点id封装对象"""
        self.ppos_noconsensus_1 = Ppos(self.rpc_list[0],
                                       self.account_list[0],
                                       self.chainid,
                                       privatekey=self.privatekey_list[0])
        self.ppos_noconsensus_2 = Ppos(self.rpc_list[0],
                                       self.account_list[1],
                                       self.chainid,
                                       privatekey=self.privatekey_list[1])
        self.ppos_noconsensus_3 = Ppos(self.rpc_list[0],
                                       self.account_list[2],
                                       self.chainid,
                                       privatekey=self.privatekey_list[2])
        self.ppos_noconsensus_4 = Ppos(self.rpc_list[0],
                                       self.account_list[3],
                                       self.chainid,
                                       privatekey=self.privatekey_list[3])
        self.ppos_noconsensus_5 = Ppos(self.rpc_list[0],
                                       self.account_list[4],
                                       self.chainid,
                                       privatekey=self.privatekey_list[4])
        self.ppos_noconsensus_6 = Ppos(self.rpc_list[0],
                                       self.account_list[5],
                                       self.chainid,
                                       privatekey=self.privatekey_list[5])
        self.eth = Eth(self.w3_list[0])

    def transaction(self,
                    w3,
                    from_address,
                    to_address=None,
                    value=1000000000000000000000000000000000,
                    gas=91000000,
                    gasPrice=9000000000,
                    pwd="88888888"):
        """"
        转账公共方法
        """
        personal = Personal(w3)
        personal.unlockAccount(from_address, pwd, 666666)
        params = {
            'to': to_address,
            'from': from_address,
            'gas': gas,
            'gasPrice': gasPrice,
            'value': value
        }
        tx_hash = w3.eth.sendTransaction(params)
        result = w3.eth.waitForTransactionReceipt(HexBytes(tx_hash).hex())
        return result

    def getCandidateList(self):
        """
        获取实时验证人的nodeID list
        """
        msg = self.ppos_noconsensus_1.getCandidateList()
        recive_list = msg.get("Data")
        nodeid_list = []
        if recive_list is None:
            return recive_list
        else:
            for node_info in recive_list:
                nodeid_list.append(node_info.get("NodeId"))
        return nodeid_list

    @allure.title("增加质押分别为{amount}")
    @pytest.mark.P1
    @pytest.mark.parametrize('amount', [100, 10000000, 1000000])
    def test_add_staking(self, amount):
        """
        用例id 72 账户余额足够,增加质押成功
        用例id 74 验证人在质押锁定期内增持的质押数量不限制
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[0])
        nodeId = self.nodeid_list2[0]
        log.info("钱包1做一笔质押")
        self.ppos_noconsensus_1.createStaking(0, self.account_list[0], nodeId,
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)
        log.info("分别验证增持{}".format(amount))
        msg = self.ppos_noconsensus_1.addStaking(nodeId, typ=0, amount=amount)
        print(msg)
        assert msg.get("Status") == True, "返回状态错误"
        assert msg.get("ErrMsg") == 'ok', "返回消息错误"

        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        nodeid = msg["Data"]["NodeId"]
        assert nodeid == self.nodeid_list2[0]
        if amount == 100:
            assert Web3.fromWei(msg["Data"]["Shares"],
                                'ether') == self.amount + 100
        if amount == 10000000:
            assert Web3.fromWei(msg["Data"]["Shares"],
                                'ether') == self.amount + 100 + 10000000
        if amount == 1000000:
            assert Web3.fromWei(
                msg["Data"]["Shares"],
                'ether') == self.amount + 100 + 10000000 + 1000000

    @allure.title("非验证人增持质押")
    @pytest.mark.P2
    def test_not_illegal_addstaking(self):
        """
        用例id 78 非验证人增持质押
        """
        log.info("转账到钱包1")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[0])
        nodeId = conf.illegal_nodeID
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        if msg['Data'] == "":
            log.info("节点1成为验证人")
            self.ppos_noconsensus_1.createStaking(0, self.account_list[0],
                                                  self.nodeid_list2[0],
                                                  self.externalId,
                                                  self.nodeName, self.website,
                                                  self.details, self.amount,
                                                  self.programVersion)
        msg = self.ppos_noconsensus_1.addStaking(nodeId=nodeId,
                                                 typ=0,
                                                 amount=100)
        assert msg.get("Status") == False, "返回状态错误"
        assert msg.get("ErrMsg") == 'This candidate is not exist', "非验证人增持质押异常"

    @allure.title("编辑验证人信息-未成为验证人的nodeID")
    @pytest.mark.P1
    def test_editCandidate_nodeid(self):
        """
        验证修改未成为验证人的nodeID
        """
        externalId = "88888888"
        nodeName = "wuyiqin"
        website = "www://baidu.com"
        details = "node_1"
        account = self.account_list[0]
        nodeid = conf.illegal_nodeID

        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[1])
        log.info("转账到钱包2")
        nodeId = self.nodeid_list2[1]
        msg = self.ppos_noconsensus_2.getCandidateInfo(nodeId)
        if msg['Data'] == "":
            log.info("节点2成为验证人")
            msg = self.ppos_noconsensus_2.createStaking(
                0, self.account_list[1], nodeId, self.externalId,
                self.nodeName, self.website, self.details, self.amount,
                self.programVersion)
            assert msg.get("Status") == True, "返回状态错误"
            assert msg.get("ErrMsg") == 'ok', "返回消息错误"
        log.info("节点2修改节点信息")
        msg = self.ppos_noconsensus_2.updateStakingInfo(
            account, nodeid, externalId, nodeName, website, details)
        log.info(msg)
        assert msg.get("Status") == False, "返回状态错误"

    @allure.title("编辑验证人信息-参数有效性验证")
    @pytest.mark.P0
    def test_editCandidate(self):
        """
        用例id 70 编辑验证人信息-参数有效性验证
        """
        externalId = "88888888"
        nodeName = "wuyiqin"
        website = "www://baidu.com"
        details = "node_1"
        account = self.account_list[0]

        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[1])
        log.info("转账到钱包2")
        nodeId = self.nodeid_list2[1]
        msg = self.ppos_noconsensus_2.getCandidateInfo(nodeId)
        if msg['Data'] == "":
            log.info("节点2成为验证人")
            msg = self.ppos_noconsensus_2.createStaking(
                0, self.account_list[1], nodeId, self.externalId,
                self.nodeName, self.website, self.details, self.amount,
                self.programVersion)
            assert msg.get("Status") == True, "返回状态错误"
            assert msg.get("ErrMsg") == 'ok', "返回消息错误"
        log.info("节点2修改节点信息")
        msg = self.ppos_noconsensus_2.updateStakingInfo(
            account, self.nodeid_list2[1], externalId, nodeName, website,
            details)
        assert msg.get("Status") == True, "返回状态错误"
        assert msg.get("ErrMsg") == 'ok', "返回消息错误"
        log.info("查看节点2的信息")
        msg = self.ppos_noconsensus_2.getCandidateInfo(self.nodeid_list2[1])
        log.info(msg)
        assert msg["Data"]["ExternalId"] == externalId
        assert msg["Data"]["NodeName"] == nodeName
        assert msg["Data"]["Website"] == website
        assert msg["Data"]["Details"] == details
        log.info(self.account_list[0])
        BenefitAddress = Web3.toChecksumAddress(msg["Data"]["BenefitAddress"])
        log.info(BenefitAddress)
        assert BenefitAddress == account

    @allure.title("修改钱包地址,更改后的地址收益正常")
    @pytest.mark.P2
    def test_alter_address(self):
        """
        修改钱包地址,更改后的地址收益正常
        """
        log.info("转账到钱包2")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[1])
        externalId = "88888888"
        nodeName = "helloword"
        website = "www://dddddd.com"
        details = "node_2"
        ####没钱的钱包#####
        account = conf.no_money[0]
        balance_before = self.eth.getBalance(account)
        assert balance_before == 0
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[1])
        if msg['Data'] == "":
            log.info("质押节点2成为验证节点")
            msg = self.ppos_noconsensus_2.createStaking(
                0, self.account_list[0], self.nodeid_list2[1], self.externalId,
                self.nodeName, self.website, self.details, self.amount,
                self.programVersion)
            assert msg.get("Status") == True, "返回状态错误"
            assert msg.get("ErrMsg") == 'ok', "返回消息错误"
        log.info("修改节点2的信息")
        msg = self.ppos_noconsensus_2.updateStakingInfo(
            account, self.nodeid_list2[1], externalId, nodeName, website,
            details)
        assert msg.get("Status") == True, "返回状态错误"
        assert msg.get("ErrMsg") == 'ok', "返回消息错误"
        log.info("进入第2个结算周期")
        get_block_number(self.w3_list[0])
        log.info("进入第3个结算周期")
        get_block_number(self.w3_list[0])
        balance_after = self.eth.getBalance(account)
        log.info(balance_after)
        assert balance_after > 0, "修改后的钱包余额没增加"
        assert balance_after > balance_before, "地址更改后未发现余额增加"

    @allure.title("增加质押为{x}")
    @pytest.mark.P2
    @pytest.mark.parametrize('x', [0, (amount_delegate - 1)])
    def test_add_staking_zero(self, x):
        """测试增持金额为0,低于门槛"""

        log.info("转账到钱包3")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[2])
        log.info("质押节点3,成为验证人")
        nodeId = self.nodeid_list2[2]
        self.ppos_noconsensus_3.createStaking(0, self.account_list[2], nodeId,
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)
        log.info("节点3增持质押".format(x))
        msg = self.ppos_noconsensus_3.addStaking(nodeId, typ=0, amount=x)
        log.info(msg)
        assert msg.get("Status") == False, "返回状态错误"

    @allure.title("账户余额不足增加质押")
    @pytest.mark.P2
    def test_Insufficient_addStaking(self):
        """
        用例id 73 账户余额不足,增加质押失败
        """
        log.info("转账到钱包5")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[4])
        log.info("质押节点5成为验证人")
        nodeId = self.nodeid_list2[4]
        msg = self.ppos_noconsensus_5.createStaking(
            0, self.account_list[4], nodeId, self.externalId, self.nodeName,
            self.website, self.details, self.amount, self.programVersion)
        assert msg.get("Status") == True, "返回状态错误"
        amount = 100000000000000000000000000000000000
        msg = self.ppos_noconsensus_5.addStaking(nodeId=nodeId,
                                                 typ=0,
                                                 amount=amount)
        assert msg.get("Status") == False, "返回状态错误"
        msg_string = "The von of account is not enough"
        assert msg_string in msg.get("ErrMsg"), "余额不足发生质押异常"

    # @allure.title("验证人已申请退出中,申请增持质押")
    # def test_quit_and_addstaking(self):
    #     """
    #     用例id 77 验证人已申请退出中,申请增持质押
    #     """
    #     nodeId = self.nodeid_list2[0]
    #     msg = self.ppos_noconsensus_1.unStaking(nodeId)
    #     assert msg.get("Status") == True, "返回状态错误"
    #     assert msg.get("ErrMsg") == 'ok', "返回消错误"
    #     log.info("{}已经退出验证人.".format(nodeId))
    #     node_list = self.getCandidateList()
    #     log.info(self.nodeid_list2[0])
    #     log.info(node_list)
    #     assert self.nodeid_list2[0] not in node_list
    #     """验证人退出后,查询实时验证人列表返回的是空,可能是bug"""
    #     msg = self.ppos_noconsensus_1.addStaking(nodeId, typ=0, amount=100)
    #     assert msg.get("Status") == True, "返回状态错误"
    #     assert msg.get("ErrMsg") == 'This candidate is not exist'

    @allure.title("验证人已申请退出中,申请增持质押")
    @pytest.mark.P1
    def test_quit_and_addstaking(self):
        """
        用例id 77 验证人已申请退出中,申请增持质押
        """
        log.info("转账到钱包4")
        self.transaction(self.w3_list[0],
                         self.address,
                         to_address=self.account_list[3])

        nodeId = self.nodeid_list2[3]
        log.info("节点4发起质押")
        msg = self.ppos_noconsensus_4.createStaking(
            0, self.account_list[3], nodeId, self.externalId, self.nodeName,
            self.website, self.details, self.amount, self.programVersion)
        assert msg.get("Status") == True, "质押失败"
        log.info("节点4退出质押")
        msg = self.ppos_noconsensus_4.unStaking(nodeId)
        # print(msg)
        assert msg.get("Status") == True, "返回状态错误"
        assert msg.get("ErrMsg") == 'ok', "返回消息错误"
        log.info("{}已经退出验证人.".format(nodeId))
        node_list = self.getCandidateList()
        # print(nodeId)
        # print(node_list)
        assert nodeId not in node_list
        msg = self.ppos_noconsensus_1.getCandidateInfo(nodeId)
        assert msg['Data'] == ""
        msg = self.ppos_noconsensus_4.addStaking(nodeId, typ=0, amount=100)
        assert msg.get("Status") == False, "返回状态错误"
        assert msg.get("ErrMsg") == 'This candidate is not exist'
Beispiel #13
0
class TestPledge():
    node_yml_path = conf.PPOS_NODE_YML
    node_info = get_node_info(node_yml_path)
    rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
        'collusion')
    rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
        'nocollusion')
    address = Web3.toChecksumAddress(conf.ADDRESS)
    pwd = conf.PASSWORD
    privatekey = conf.PRIVATE_KEY
    account_list = conf.account_list
    privatekey_list = conf.privatekey_list
    externalId = "1111111111"
    nodeName = "platon"
    website = "https://www.test.network"
    details = "supper node"
    amount = 1000000
    programVersion = 1792
    illegal_nodeID = conf.illegal_nodeID


    def setup_class(self):
        self.ppos_link = Ppos(
            self.rpc_list[0], self.address)
        self.w3_list = [connect_web3(url) for url in self.rpc_list]
        """用新的钱包地址和未质押过的节点id封装对象"""
        self.ppos_noconsensus_1 = Ppos(self.rpc_list[0], self.account_list[0], privatekey= self.privatekey_list[0])
        self.ppos_noconsensus_2 = Ppos(self.rpc_list[0], self.account_list[1], privatekey=self.privatekey_list[1])
        self.ppos_noconsensus_3 = Ppos(self.rpc_list[0], self.account_list[2], privatekey=self.privatekey_list[2])
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],self.address,to_account)

    def transaction(self,w3, from_address, to_address=None, value=100000000000000000000000000000000,
                    gas=91000000, gasPrice=9000000000):
        personal = Personal(self.w3_list[0])
        personal.unlockAccount(self.address, self.pwd, 666666)
        params = {
            'to': to_address,
            'from': from_address,
            'gas': gas,
            'gasPrice': gasPrice,
            'value': value
        }
        tx_hash = w3.eth.sendTransaction(params)
        return tx_hash

    def test_initial_identifier(self):
        """
        用例id 54,55
        测试验证人参数有效性验证
        """
        recive = self.ppos_link.getVerifierList()
        recive_list = recive.get("Data")
        nodeid_list=[]
        # 查看查询当前结算周期的验证人队列
        for node_info in recive_list:
            nodeid_list.append(node_info.get("NodeId"))
            StakingAddress = node_info.get("StakingAddress")
            assert StakingAddress == self.address,"内置钱包地址错误{}".format(StakingAddress)
        # print(recive)
        # print(nodeid_list)
        assert nodeid_list == nodeid_list, "正常的nodeID列表{},异常的nodeID列表{}".format(nodeid_list,recive_list)

    def test_initial_cannot_entrust(self):
        """
        用例id 56 初始验证人不能接受委托
        """
        msg = self.ppos_link.delegate(typ = 1,nodeId=self.nodeid_list[0],amount=50)
        assert msg.get("Status") == False ,"返回状态错误"
        assert msg.get("ErrMsg") == 'This candidate is not allow to delegate',"返回提示语错误"

    def test_initial_add_pledge(self):
        """
        用例id 57 初始验证人增持质押
        """
        msg = self.ppos_link.addStaking(nodeId=self.nodeid_list[0],typ=0,amount=1000)
        print(msg)
        assert msg.get("Status") == True
        assert msg.get("ErrMsg") == 'ok'

    def test_initial_quit(self):
        """
        用例id 58 初始验证人退出
        """
        msg = self.ppos_link.unStaking(nodeId=self.nodeid_list[0])
        print(self.nodeid_list[0])
        assert msg.get("Status") ==True
        assert msg.get("ErrMsg") == 'ok'
        """暂时没配置参数所以还要调整"""
        time.sleep(10)
        recive = self.ppos_link.getCandidateList()
        recive_list = recive.get("Data")
        for node_info in recive_list:
            # print(node_info)
            assert node_info.get("NodeId") != self.nodeid_list[0]

    def test_staking(self):
        """
        用例 62 非初始验证人做质押
        """
        nodeId = self.nodeid_list2[0]
        """非共识节点做一笔质押"""
        msg = self.ppos_noconsensus_1.createStaking(0, self.account_list[1],
                                           nodeId,self.externalId,self.nodeName, self.website,self.details,
                                                    self.amount,self.programVersion)
        print(msg)
        assert msg.get("Status") ==True
        assert msg.get("ErrMsg") == 'ok'
        """暂时没配置参数所以还要调整"""
        ##查看实时验证人信息
        recive = self.ppos_noconsensus_1.getCandidateList()
        recive_list = recive.get("Data")
        nodeid_list = []
        for node_info in recive_list:
            nodeid_list.append(node_info.get("NodeId"))
        assert self.nodeid_list2[0] in nodeid_list,"非初始验证人质押失败"

    def test_staking_zero(self):
        """
        用例 64 非初始验证人做质押,质押金额小于最低门槛
        """
        benifitAddress = self.account_list[1]
        nodeId = self.nodeid_list2[0]
        """非共识节点做一笔质押"""
        amount = 100000
        msg = self.ppos_noconsensus_1.createStaking(0, benifitAddress,
                                           nodeId,self.externalId,self.nodeName, self.website, self.details,amount,self.programVersion)
        print(msg)
        assert msg.get("Status") ==False

    def test_not_illegal_addstaking(self):
        """
        用例id 78 非初始验证人成为验证人后,增持质押
        """
        nodeId = conf.illegal_nodeID
        msg = self.ppos_noconsensus_1.addStaking(nodeId=nodeId, typ=0, amount=100)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == 'This candidate is not exist'

    def test_illegal_pledge(self):
        """
        用例id 63 非链上的nodeID去质押
        """
        benifitAddress = self.account_list[1]
        msg = self.ppos_noconsensus_2.createStaking(0, benifitAddress,self.illegal_nodeID,self.externalId,
                                           self.nodeName, self.website, self.details,self.amount,self.programVersion)
        print(msg)
        assert msg.get("Status") ==True
        assert msg.get("ErrMsg") == 'ok'

    def test_getCandidateInfo(self):
        """
        用例69 查询验证人信息,调用质押节点信息
        """
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        nodeid = msg["Data"]["NodeId"]
        """验证质押金额"""
        assert  msg["Data"]["Shares"] == 1000000000000000000000000
        assert nodeid == self.nodeid_list[0]
        msg = self.ppos_link.getCandidateInfo(self.nodeid_list[0])
        # print(msg)
        nodeid = msg["Data"]["NodeId"]
        assert nodeid == self.nodeid_list[0]

    # @pytest.mark.parametrize("externalId,nodeName,website,details",[("88888888","jay_wu","https://baidu.com,node_1"),
    #                                                                       ("","","","")])
    # def test_editCandidate(self,externalId,nodeName,website,details):
    #     """
    #     用例id 70 编辑验证人信息-参数有效性验证
    #     """
    #     msg = self.ppos_noconsensus_1.updateStakingInfo(self.account_list[0], self.nodeid_list2[0],
    #                                                     externalId, nodeName, website, details)
    #     print(msg)
    #     msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
    #     print(msg)

    def test_editCandidate(self):
        """
        用例id 70 编辑验证人信息-参数有效性验证
        """
        externalId = "88888888"
        nodeName = "jay_wu"
        website = "www://baidu.com"
        details = "node_1"
        msg = self.ppos_noconsensus_1.updateStakingInfo(self.account_list[0], self.nodeid_list2[0],
                                                        externalId, nodeName, website, details)
        assert msg.get("Status") ==True
        assert msg.get("ErrMsg") == 'ok'
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        print(msg)
        assert msg["Data"]["ExternalId"] == externalId
        assert msg["Data"]["nodeName"] == nodeName
        assert msg["Data"]["website"] == website
        assert msg["Data"]["details"] == details

    @pytest.mark.parametrize('amount', [(100),(10000000),(1000000)])
    def test_add_staking(self,amount):
        """
        用例id 72 账户余额足够,增加质押成功
        用例id 74 验证人在质押锁定期内增持的质押数量不限制
        """
        nodeId = self.nodeid_list2[0]
        msg = self.ppos_noconsensus_1.addStaking(nodeId,typ=0,amount=amount)
        assert msg.get("Status") == True
        assert msg.get("ErrMsg") == 'ok'

    def test_add_staking_zero(self):
        """测试增持金额为0"""
        nodeId = self.nodeid_list2[0]
        msg = self.ppos_noconsensus_1.addStaking(nodeId,typ=0,amount=0)
        assert msg.get("Status") == False

    def test_Insufficient_delegate(self):
        """
        用例id 73 账户余额不足,增加质押失败
        """
        amount = 100000000000000000000000000000000000
        nodeId = self.nodeid_list2[0]
        msg = self.ppos_noconsensus_1.addStaking(nodeId=nodeId,typ=0,amount=amount)
        # print(msg)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == 'The von of account is not enough'

    def test_quit_and_addstaking(self):
        """
        用例id 77 验证人已申请退出中,申请增持质押
        """
        nodeId = self.nodeid_list2[0]
        msg  = self.ppos_noconsensus_1.unStaking(nodeId)
        assert msg.get("Status") == True
        assert msg.get("ErrMsg") == 'ok'
        time.sleep(2)
        msg = self.ppos_noconsensus_1.addStaking(nodeId,typ=0,amount=100)
        assert msg.get("Status") == True
        assert msg.get("ErrMsg") == 'This candidate is not exist'

    # def test_getDelegateInfo(self):
    #     """
    #     用例id 94 查询委托参数验证
    #     """
    #     stakingBlockNum = ""
    #     msg = self.ppos_noconsensus_1.getDelegateInfo(stakingBlockNum,delAddr,nodeId)

    def test_illege_delegate(self):
        """
        用例id 首次委托金额必须大于10 eth
        """
        amount = 9
        msg = self.ppos_noconsensus_2.delegate(0,self.nodeid_list2[0],amount)
        print(msg)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == "Delegate deposit too low"
        amount = 0
        msg = self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], amount)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == "This amount is illege"

    def test_delegate(self):
        """
        用例95 委托成功,查询节点信息,金额
        用例id 98 委托人与验证人验证,验证人存在
        """
        amount = 1000
        msg = self.ppos_noconsensus_2.delegate(0,self.illegal_nodeID,amount)
        assert msg.get("Status") == True
        assert msg.get("ErrMsg") == 'ok'

    def test_getDelegateInfo(self):
        """
        用例id 94 查询委托参数验证
        """
        msg = self.ppos_noconsensus_2.getCandidateInfo(self.illegal_nodeID)
        print(msg)
        assert msg["Data"]["NodeId"] == self.illegal_nodeID
        """查询当前候选人总共质押加被委托的von数目"""
        assert msg["Data"]["Shares"] == 1001000000000000000000000
        assert msg["Data"]["ReleasedHes"] == 1000000000000000000000000
        """通过查询"""
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        # print(stakingBlockNum)
        msg = self.ppos_noconsensus_2.getDelegateInfo(stakingBlockNum,self.account_list[1],self.illegal_nodeID)
        print(msg)
        assert msg["Data"]["Addr"] == self.account_list[1]
        assert msg["Data"]["NodeId"] == self.illegal_nodeID
        assert msg["Data"]["ReleasedHes"] == 1000000000000000000000

    def test_insufficient_delegate(self):
        """
        用例96 余额不足委托失败
        """
        amount = 100000000000000000000000000
        msg = self.ppos_noconsensus_2.delegate(0,self.illegal_nodeID,amount)
        # print(msg)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == 'Delegate failed: The von of account is not enough'

    def test_not_nodeId_delegate(self):
        """
        用例72 验证人不存在进行委托
        """
        amount = 1000
        msg = self.ppos_noconsensus_2.delegate(0,self.nodeid_list2[2],amount)
        print(msg)
        assert msg.get("Status") == False
        assert msg.get("ErrMsg") == 'This candidate is not exist'

    def test_restrictingPlan_delegate(self):
        """
        用例id 101 委托人使用锁仓Token进行委托
        """
        pass

    def test_restrictingPlan_insufficient_delegate(self):
        """
        用例id 103委托人使用锁仓Token(余额不足)进行委托
        """

    def
class TestBuildBlockChain:
    node_yml = conf.NODE_YML
    collusion_list, nocollusion_list = get_node_list(node_yml)
    one_collusion_url = nocollusion_list[0]["url"]
    data = get_node_info(node_yml)
    rpc_urls, enode_list, nodeid_list, _, _ = data["collusion"]
    w3_list = [connect_web3(url) for url in rpc_urls]
    genesis_file = conf.GENESIS_TMP
    auto = AutoDeployPlaton()

    def setup(self):
        self.auto.start_all_node(self.node_yml)

    def setup_class(self):
        self.w3_list = [connect_web3(url) for url in self.rpc_urls]

    def teardown_class(self):
        self.auto.start_all_node(self.node_yml)

    @allure.title("区块增长")
    def test_blocknumber_increase(self):
        '''
        测试块高是否正常增长
        '''
        for w3 in self.w3_list:
            for i in range(91):
                if w3.eth.blockNumber > 0:
                    break
                time.sleep(1)
                if i == 90:
                    raise Exception('区块不增长,块高:{}'.format(w3.eth.blockNumber))

    # TODO: need fix python-sdk nonce bug
    # @allure.title("区块信息是否一致")
    # def test_block_synchronize(self):
    #     '''
    #     测试所有节点区块信息是否一致
    #     '''
    #     w3 = self.w3_list[0]
    #     blocknumber = w3.eth.blockNumber
    #     if blocknumber == 0:
    #         time.sleep(15)
    #         blocknumber = w3.eth.blockNumber
    #     blockinfo = w3.eth.getBlock(blocknumber)['hash']
    #     for w in self.w3_list[1:-1]:
    #         info = w.eth.getBlock(blocknumber)['hash']
    #         assert blockinfo == info, "不同节点的相同块高信息不一致区块号:{}".format(
    #             blocknumber)

    # TODO: need fix python-sdk nonce bug
    # @allure.title("区块连续性,验证hash")
    # def test_hash_continuous(self):
    #     """
    #     测试区块的连续性,验证一定数量的区块,区块哈希必须是连续的
    #     """
    #     w3 = self.w3_list[0]
    #     i = 0
    #     while True:
    #         if w3.eth.blockNumber >= 100:
    #             break
    #         time.sleep(10)
    #         i += 10
    #         if i >= 150:
    #             assert False, "出块不正常"
    #     block_hash = HexBytes(w3.eth.getBlock(1).get("hash")).hex()
    #     for i in range(2, 100):
    #         block = w3.eth.getBlock(i)
    #         parent_hash = HexBytes(block.get("parentHash")).hex()
    #         assert block_hash == parent_hash, "父区块哈希值错误"
    #         block_hash = HexBytes(block.get("hash")).hex()

    @allure.title("不初始化启动节点和不同创世文件的节点互连")
    def test_no_init_no_join_chain(self):
        '''
        不初始化启动节点
        '''
        self.auto.start_of_list(self.nocollusion_list[0:1],
                                is_need_init=False,
                                clean=True)
        time.sleep(1)
        w3 = connect_web3(self.one_collusion_url)
        start_block = w3.eth.blockNumber
        time.sleep(10)
        end_block = w3.eth.blockNumber
        assert start_block == end_block, "区块高度增长了,开始块高{}-结束块高{}".format(
            start_block, end_block)
        w3.admin.addPeer(self.enode_list[0])
        time.sleep(5)
        net_num = w3.net.peerCount
        assert net_num == 0, "连接节点数有增加"

    @allure.title("测试部署单节点私链")
    def test_build_one_node_privatechain(self):
        '''
        部署单节点私链
        '''
        auto = AutoDeployPlaton(genesis=conf.GENESIS_TEMPLATE2)
        auto.start_of_list(self.nocollusion_list[0:1],
                           genesis_path=conf.GENESIS_TMP_OTHER)
        time.sleep(2)
        w3 = connect_web3(self.one_collusion_url)
        start_block = w3.eth.blockNumber
        log.info("start block number:{}".format(start_block))
        time.sleep(10)
        end_block = w3.eth.blockNumber
        log.info("end block number:{}".format(end_block))
        assert start_block < end_block, "区块高度没有增长"

    @allure.title("测试不同initnode创始文件之间节点互连")
    def test_init_diff_genesis_join_chain(self):
        '''
        使用不同genesis.json,addPeer
        '''
        self.auto.start_of_list(self.nocollusion_list[0:1],
                                genesis_path=conf.GENESIS_TMP_OTHER)
        time.sleep(2)
        net_num_1 = self.w3_list[0].net.peerCount
        w3 = connect_web3(self.one_collusion_url)
        w3.admin.addPeer(self.enode_list[0])
        time.sleep(5)
        net_num_2 = self.w3_list[0].net.peerCount
        assert net_num_2 == net_num_1, "节点数有增加"
        peers = w3.net.peerCount
        log.info("加入其他链后,连接节点数{}".format(peers))
        assert peers is 0, "peers节点数不为空"

    @allure.title("测试相同创始文件之间节点互连")
    def test_init_same_genesis_join_chain(self):
        '''
        测试相同的genesis.json节点加入addPeer
        '''
        self.auto.start_of_list(self.nocollusion_list[0:1],
                                genesis_file=self.genesis_file)
        time.sleep(2)
        w3 = connect_web3(self.one_collusion_url)
        w3.admin.addPeer(self.enode_list[0])
        time.sleep(5)
        assert w3.net.peerCount > 0, "加入链失败"

    @allure.title("测试区块同步")
    def test_deconsensus_block_synchronize(self):
        '''
        非共识节点块高同步
        '''
        w3 = connect_web3(self.one_collusion_url)
        log.info(w3.net.peerCount)
        time.sleep(10)
        block_number = w3.eth.blockNumber
        assert block_number > 0, "非共识节点同步区块失败,块高:{}".format(block_number)

    @allure.title("测试fast模式同步")
    def test_syncmode(self):
        """
        同步
        :return:
        """
        auto = AutoDeployPlaton(syncmode="fast")
        auto.start_of_list(self.nocollusion_list[0:1],
                           genesis_file=self.genesis_file)
        time.sleep(2)
        w3 = connect_web3(self.one_collusion_url)
        w3.admin.addPeer(self.enode_list[0])
        time.sleep(5)
        collusion_w3 = self.w3_list[0]
        if collusion_w3.eth.blockNumber < 250:
            log.info("sleep,非共识节点需要229个块之后才会开始同步")
            time.sleep(250 - collusion_w3.eth.blockNumber)
        assert w3.net.peerCount > 0, "加入链失败"
        assert w3.eth.blockNumber >= 200, "区块同步失败,当前块高{}".format(
            w3.eth.blockNumber)

    # 目前没有测试网配置
    # @allure.title("测试种子节点")
    # def test_testnet(self):
    #     """
    #     测试testnet连接
    #     :return:
    #     """
    #     if conf.IS_TEST_NET:
    #         auto = AutoDeployPlaton(net_type="testnet")
    #         auto.start_all_node(conf.TEST_NET_NODE,
    #                             is_need_init=False, clean=True)
    #         collusion, nocollusion = get_node_list(conf.TEST_NET_NODE)
    #         time.sleep(10)
    #         block_list = []
    #         net_list = []
    #         for nodedict in collusion:
    #             url = nodedict["url"]
    #             w3 = connect_web3(url)
    #             block_list.append(w3.eth.blockNumber)
    #             net_list.append(w3.net.peerCount)
    #         log.info(block_list, net_list)
    #         assert min(block_list) > 0, "区块没有增长"
    #         for net in net_list:
    #             assert net >= len(collusion) - \
    #                 1, "共识节点连接节点数少于{}个".format(len(collusion) - 1)
    #         nocollusion_block_list = []
    #         nocollusion_net_list = []
    #         if max(block_list) < 250:
    #             time.sleep(250 - max(block_list) + 10)
    #         for nodedict in nocollusion:
    #             url = nodedict["url"]
    #             w3 = connect_web3(url)
    #             nocollusion_block_list.append(w3.eth.blockNumber)
    #             nocollusion_net_list.append(w3.net.peerCount)
    #         log.info(nocollusion_block_list, nocollusion_net_list)
    #         assert min(nocollusion_block_list) > 0, "区块没有增长"
    #         for net in nocollusion_net_list:
    #             assert net >= 1, "非共识节点没有连上测试网"
    #     else:
    #         pass

    @allure.title("测试platon文件的版本号")
    def test_platon_versions(self):
        collusion_list, _ = get_node_list(self.node_yml)
        node = collusion_list[0]
        ssh, sftp, t = connect_linux(node['host'],
                                     username=node['username'],
                                     password=node['password'])
        cmd_list = run_ssh(
            ssh, "{}/node-{}/platon version".format(conf.DEPLOY_PATH,
                                                    node["port"]))
        versions = conf.VERSION
        assert versions in cmd_list[1], "版本号不正确"

    @allure.title("测试重启所有共识节点")
    def test_restart_all(self):
        current_block = self.w3_list[0].eth.blockNumber
        log.info("重启前块高:{}".format(current_block))
        self.auto.restart_list(self.collusion_list)
        log.info("重启所有共识节点成功")
        time.sleep(30)
        after_block = self.w3_list[0].eth.blockNumber
        log.info("重启后块高为:{}".format(after_block))
        assert after_block - current_block >= 10, "重启后区块没有正常增长"
Beispiel #15
0
class TestLockup():
    node_yml_path = conf.NODE_YML
    node_info = get_node_info(node_yml_path)
    rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
        'collusion')
    rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
        'nocollusion')

    address = Web3.toChecksumAddress(conf.ADDRESS)
    privatekey = conf.PRIVATE_KEY
    account_list = conf.account_list
    privatekey_list = conf.privatekey_list
    externalId = "1111111111"
    nodeName = "platon"
    website = "https://www.test.network"
    details = "supper node"
    programVersion = 1792
    illegal_nodeID = conf.illegal_nodeID

    genesis_path = conf.GENESIS_TMP

    get_config_data()
    config_json_path = conf.PLATON_CONFIG_PATH
    config_dict = LoadFile(config_json_path).get_data()
    amount_delegate = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['MinimumThreshold']),
        'ether')
    amount = Web3.fromWei(
        int(config_dict['EconomicModel']['Staking']['StakeThreshold']),
        'ether')

    def setup_class(self):
        self.auto = AutoDeployPlaton()
        self.auto.start_all_node(self.node_yml_path)
        self.genesis_dict = LoadFile(self.genesis_path).get_data()
        self.chainid = int(self.genesis_dict["config"]["chainId"])
        self.ppos_link = Ppos(self.rpc_list[0], self.address, self.chainid)
        self.w3_list = [connect_web3(url) for url in self.rpc_list]
        """用新的钱包地址和未质押过的节点id封装对象"""
        self.ppos_noconsensus_1 = Ppos(self.rpc_list[0],
                                       self.account_list[0],
                                       self.chainid,
                                       privatekey=self.privatekey_list[0])
        self.ppos_noconsensus_2 = Ppos(self.rpc_list[0],
                                       self.account_list[1],
                                       self.chainid,
                                       privatekey=self.privatekey_list[1])
        self.ppos_noconsensus_3 = Ppos(self.rpc_list[0],
                                       self.account_list[2],
                                       self.chainid,
                                       privatekey=self.privatekey_list[2])
        self.ppos_noconsensus_4 = Ppos(self.rpc_list[0],
                                       self.account_list[3],
                                       self.chainid,
                                       privatekey=self.privatekey_list[3])
        self.ppos_noconsensus_5 = Ppos(self.rpc_list[0],
                                       self.account_list[4],
                                       self.chainid,
                                       privatekey=self.privatekey_list[4])
        self.ppos_noconsensus_6 = Ppos(self.rpc_list[0],
                                       self.account_list[5],
                                       self.chainid,
                                       privatekey=self.privatekey_list[5])
        self.eth = Eth(self.w3_list[0])

    def transaction(self,
                    w3,
                    from_address,
                    to_address=None,
                    value=100000000000000000000000000000000,
                    gas=91000000,
                    gasPrice=9000000000,
                    pwd=conf.PASSWORD):
        """"
        转账公共方法,转账1000w eth
        """
        personal = Personal(w3)
        personal.unlockAccount(from_address, pwd, 666666)
        params = {
            'to': to_address,
            'from': from_address,
            'gas': gas,
            'gasPrice': gasPrice,
            'value': value
        }
        tx_hash = w3.eth.sendTransaction(params)
        result = w3.eth.waitForTransactionReceipt(HexBytes(tx_hash).hex())
        return result

    def getCandidateList(self):
        """
        获取实时验证人的nodeID list
        """
        msg = self.ppos_noconsensus_1.getCandidateList()
        recive_list = msg.get("Data")
        nodeid_list = []
        if recive_list is None:
            return recive_list
        else:
            for node_info in recive_list:
                nodeid_list.append(node_info.get("NodeId"))
        return nodeid_list

    @allure.title("验证人退回质押金(未到达可解锁期)")
    @pytest.mark.P0
    def test_back_unstaking(self):
        """
        验证人退回质押金(未到达可解锁期)
        质押成为下个周期验证人,退出后,下一个结算周期退出
        """
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],
                             self.address,
                             to_address=to_account)
        log.info("节点1质押金额{} eth".format(self.amount))
        self.ppos_noconsensus_1.createStaking(0, self.account_list[0],
                                              self.nodeid_list2[0],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)
        account_1 = self.eth.getBalance(self.account_list[0])
        log.info(account_1)
        get_block_number(self.w3_list[0])
        log.info("查询第2个结算周期的验证人")
        node_list = getVerifierList()
        log.info(node_list)
        assert self.nodeid_list2[0] in node_list

        log.info("节点1在第2结算周期,锁定期申请退回")
        self.ppos_noconsensus_1.unStaking(nodeId=self.nodeid_list2[0])
        """发起退回消耗一定gas"""
        account_2 = self.eth.getBalance(self.account_list[0])
        log.info(account_2)
        assert account_1 > account_2, "发起退回的交易钱包异常"

        log.info("进入第3个结算周期")
        get_block_number(w3=self.w3_list[0])
        account_3 = self.eth.getBalance(self.account_list[0])
        log.info(account_3)
        assert account_3 > account_2
        assert account_3 - account_2 < Web3.toWei(self.amount, "ether")
        log.info(account_3 - account_2)

        node_list = getVerifierList()
        log.info(node_list)
        assert self.nodeid_list2[0] not in node_list

        log.info("进入第4个结算周期")
        get_block_number(w3=self.w3_list[0])
        account_4 = self.eth.getBalance(self.account_list[0])
        log.info(account_4)
        """ 第3个结算周期结束后质押金额已退 """
        log.info(account_4 - account_3)
        assert account_4 - account_3 > Web3.toWei(self.amount, "ether")
        assert account_4 - account_2 > Web3.toWei(self.amount, "ether")

    @allure.title("锁定期增加质押与委托")
    @pytest.mark.P0
    def test_lockup_addstaking(self):
        """
        用例id74 锁定期增加质押
        用例id 112 锁定期委托人进行委托
        """
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],
                             self.address,
                             to_address=to_account)
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        if msg["Data"] == "":
            log.info("节点1质押金额{} eth".format(self.amount))
            self.ppos_noconsensus_1.createStaking(0, self.account_list[0],
                                                  self.nodeid_list2[0],
                                                  self.externalId,
                                                  self.nodeName, self.website,
                                                  self.details, self.amount,
                                                  self.programVersion)
        log.info("进入锁定期")
        get_block_number(self.w3_list[0])
        value = 100
        msg = self.ppos_noconsensus_1.addStaking(self.nodeid_list2[0], 0,
                                                 value)
        assert msg.get("Status") == True
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[0])
        log.info(msg)
        nodeid = msg["Data"]["NodeId"]
        log.info("增持后验证质押金额")
        assert msg["Data"]["Shares"] == 1000100000000000000000000
        assert msg["Data"]["Released"] == 1000000000000000000000000
        assert msg["Data"]["ReleasedHes"] == 100000000000000000000
        assert nodeid == self.nodeid_list2[0]
        self.ppos_noconsensus_2.delegate(0, self.nodeid_list2[0], 10)
        msg = self.ppos_noconsensus_2.getCandidateInfo(self.nodeid_list2[0])
        log.info(msg)
        assert msg["Data"]["Shares"] == 1000110000000000000000000
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        msg = self.ppos_noconsensus_2.getDelegateInfo(stakingBlockNum,
                                                      self.account_list[1],
                                                      self.nodeid_list2[0])
        data = msg["Data"]
        data = json.loads(data)
        assert Web3.toChecksumAddress(data["Addr"]) == self.account_list[1]
        assert data["NodeId"] == self.nodeid_list2[0]
        # assert Web3.fromWei(data["ReleasedHes"], 'ether') == 10

    @allure.title("验证根据质押+委托金额金额排名")
    @pytest.mark.P2
    def test_taking_cycle_ranking(self):
        """
        验证根据质押金额排名
        """
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],
                             self.address,
                             to_address=to_account)

        log.info("质押节点2")
        self.ppos_noconsensus_2.createStaking(0, self.account_list[1],
                                              self.nodeid_list2[1],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)
        log.info("质押节点3")
        self.ppos_noconsensus_3.createStaking(0, self.account_list[2],
                                              self.nodeid_list2[2],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 130,
                                              self.programVersion)
        log.info("进入到下个结算周期")
        get_block_number(w3=self.w3_list[0])
        node_list = getVerifierList()
        log.info(node_list)

        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[1])
        log.info(msg)
        msg = self.ppos_noconsensus_1.getCandidateInfo(self.nodeid_list2[2])
        log.info(msg)

        assert self.nodeid_list2[2] in node_list
        assert self.nodeid_list2[1] in node_list
        assert self.nodeid_list2[2] == node_list[0]

        log.info("钱包4委托节点2 70eth")
        msg = self.ppos_noconsensus_4.delegate(0,
                                               nodeId=self.nodeid_list2[1],
                                               amount=70)
        print(msg)
        log.info("节点2增加质押61 eth")
        msg = self.ppos_noconsensus_2.addStaking(self.nodeid_list2[1],
                                                 0,
                                                 amount=61)
        print(msg)
        log.info("进入下一个结算周期")
        get_block_number(self.w3_list[0])

        node_list = getVerifierList()
        log.info(node_list)
        log.info(self.nodeid_list2[1])
        log.info(self.nodeid_list2[2])
        """预期节点2排在节点3之前"""
        msg = self.ppos_noconsensus_2.getCandidateInfo(self.nodeid_list2[1])
        log.info(msg)

        msg = self.ppos_noconsensus_3.getCandidateInfo(self.nodeid_list2[2])
        log.info(msg)

        assert node_list[0] == self.nodeid_list2[1]
        assert node_list[1] == self.nodeid_list2[2]

    @allure.title("质押相等的金额,按照时间先早排序")
    @pytest.mark.P1
    def test_same_amount_cycle(self):
        """
        质押相等的金额,按照时间先早排序
        """
        self.auto = AutoDeployPlaton()
        self.auto.start_all_node(self.node_yml_path)
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],
                             self.address,
                             to_address=to_account)

        log.info("质押节点4金额200eth")
        self.ppos_noconsensus_4.createStaking(0, self.account_list[3],
                                              self.nodeid_list2[3],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 200,
                                              self.programVersion)
        log.info("质押节点5金额200eth")
        self.ppos_noconsensus_5.createStaking(0, self.account_list[4],
                                              self.nodeid_list2[4],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 200,
                                              self.programVersion)
        log.info("进入到下个结算周期")
        get_block_number(self.w3_list[0])

        node_list = getVerifierList()
        log.info(node_list)
        log.info(self.nodeid_list2[3])
        log.info(self.nodeid_list2[4])
        assert node_list[0] == self.nodeid_list2[3]
        assert node_list[1] == self.nodeid_list2[4]

    @allure.title("验证人申请退回所有质押金(包含初始质押金和当前结算期内质押金)")
    @pytest.mark.P2
    def test_unstaking_all(self):
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],
                             self.address,
                             to_address=to_account)
        value_before = self.eth.getBalance(self.account_list[5])
        log.info(value_before)
        self.ppos_noconsensus_6.createStaking(0, self.account_list[5],
                                              self.nodeid_list2[5],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)

        log.info("进入第2个结算周期")
        get_block_number(self.w3_list[0])
        log.info("节点6增持金额")
        self.ppos_noconsensus_6.addStaking(self.nodeid_list2[5], 0,
                                           self.amount + 1000)
        log.info("进入第3个结算周期")
        get_block_number(self.w3_list[0])
        log.info("节点6发起退回")
        self.ppos_noconsensus_6.unStaking(nodeId=self.nodeid_list2[5])
        log.info("进入第4个结算周期")
        get_block_number(self.w3_list[0])
        value = self.eth.getBalance(self.account_list[5])
        log.info(value)
        assert value < value_before, "钱还在锁定期,预期未退回,实际异常"
        log.info("进入第5个结算周期")
        get_block_number(self.w3_list[0])
        value_after = self.eth.getBalance(self.account_list[5])
        log.info(value_after)
        log.info(value_after - value_before)
        amount_sum = self.amount * 2 + 1000
        log.info(Web3.toWei(amount_sum, "ether"))
        assert value_after > value_before, "出块奖励异常"
        assert value_after > value + Web3.toWei(
            amount_sum, "ether"), "解锁期的余额大于锁定期的余额+质押+增持金额,但是发生异常"

    @allure.title("根据金额排名,从高到低排名")
    @pytest.mark.P0
    def test_ranking(self):
        """
        测试根据金额排名,从高到低排名
        """
        self.auto = AutoDeployPlaton()
        self.auto.start_all_node(self.node_yml_path)
        log.info("转账每个钱包")
        for to_account in self.account_list:
            self.transaction(self.w3_list[0],
                             self.address,
                             to_address=to_account)

        self.ppos_noconsensus_1.createStaking(0, self.account_list[0],
                                              self.nodeid_list2[0],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 50,
                                              self.programVersion)
        self.ppos_noconsensus_2.createStaking(0, self.account_list[1],
                                              self.nodeid_list2[1],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 40,
                                              self.programVersion)
        self.ppos_noconsensus_3.createStaking(0, self.account_list[2],
                                              self.nodeid_list2[2],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 30,
                                              self.programVersion)
        self.ppos_noconsensus_4.createStaking(0, self.account_list[3],
                                              self.nodeid_list2[3],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 20,
                                              self.programVersion)
        self.ppos_noconsensus_5.createStaking(0, self.account_list[4],
                                              self.nodeid_list2[4],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount + 10,
                                              self.programVersion)
        self.ppos_noconsensus_6.createStaking(0, self.account_list[5],
                                              self.nodeid_list2[5],
                                              self.externalId, self.nodeName,
                                              self.website, self.details,
                                              self.amount, self.programVersion)
        log.info("进入下个周期")
        get_block_number(self.w3_list[0])
        node_list = getVerifierList()
        log.info(node_list)
        """根据config配置验证人数"""
        # assert self.nodeid_list2[5] not in node_list
        assert node_list[0] == self.nodeid_list2[0]
        assert node_list[1] == self.nodeid_list2[1]
        assert node_list[2] == self.nodeid_list2[2]
        assert node_list[3] == self.nodeid_list2[3]
        assert node_list[4] == self.nodeid_list2[4]
        assert node_list[5] == self.nodeid_list2[-1]
Beispiel #16
0
class TestDpos:
    node_yml_path = conf.NODE_YML
    cbft_json_path = conf.CBFT2
    node_info = get_node_info(node_yml_path)
    rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
        'collusion')
    rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
        'nocollusion')
    cbft_dict = LoadFile(cbft_json_path).get_data()
    address = Web3.toChecksumAddress(conf.ADDRESS)
    pwd = conf.PASSWORD
    ticket_price = Web3.fromWei(
        int(cbft_dict['ppos']['ticket']['ticketPrice']), 'ether')
    allowed = int(cbft_dict['ppos']['candidate']['allowed'])
    total_ticket = int(cbft_dict['ppos']['ticket']['maxCount'])
    rpc_list += rpc_list2
    enode_list += enode_list2
    nodeid_list += nodeid_list2
    ip_list += ip_list2
    port_list += port_list2
    key_list = ["node" + str(i) for i in range(1, 1 + len(rpc_list))]
    rpc_dict = dict(zip(key_list, rpc_list))
    enode_dict = dict(zip(key_list, enode_list))
    nodeid_dict = dict(zip(key_list, nodeid_list))
    ip_dict = dict(zip(key_list, ip_list))
    port_dict = dict(zip(key_list, port_list))
    abi = conf.DPOS_CONTRACT_ABI

    def setup_class(self):
        self.auto = AutoDeployPlaton(cbft=self.cbft_json_path)
        self.auto.start_all_node(self.node_yml_path)
        self.platon_dpos1 = PlatonDpos(
            self.rpc_list[0], self.address, self.pwd, abi=self.abi)
        self.w3_list = [connect_web3(url) for url in self.rpc_list]
        self.new_address = Web3.toChecksumAddress(
            self.platon_dpos1.web3.personal.newAccount(self.pwd))
        self.send_data = {
            "to": self.new_address,
            "from": self.address,
            "gas": '9000',
            "gasPrice": '1000000000',
            "value": self.w3_list[0].toWei(100000, 'ether'),
        }
        tx_hash = self.platon_dpos1.eth.sendTransaction(self.send_data)
        self.platon_dpos1.eth.waitForTransactionReceipt(tx_hash)
        self.platon_dpos2 = PlatonDpos(
            self.rpc_list[0], self.new_address, self.pwd, abi=self.abi)
        self.fee = int(1000).to_bytes(4, 'big')
        self.extra = "Test"

    # def teardown_class(self):
    #     self.auto.start_all_node(self.node_yml_path)

    def check_event(self, msg):
        event_data, func_name = msg
        func_name += "Event"
        assert func_name in event_data, "{}中不包含{}键".format(
            event_data, func_name)
        event = event_data[func_name][0]
        event = json.loads(event)
        assert event["Ret"], "质押结果状态错误"
        assert event["ErrMsg"] == "success", "质押结果msg错误"

    def test_candidate_deposit(self):
        '''
        @Description: 质押节点,使其成为候选人
        @param {type} @@@@
        @return: @@@@
        '''
        result = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node5'], self.new_address, self.fee,
                                                    self.ip_dict['node5'],
                                                    self.port_dict['node5'], self.extra, value=100)
        self.check_event(result)
        candidate_info = self.platon_dpos1.GetCandidateDetails(
            self.nodeid_dict['node5'])
        assert isinstance(candidate_info, dict), "返回结果错误{}".format(
            candidate_info)
        assert candidate_info["Deposit"] == self.platon_dpos1.web3.toWei(
            100, 'ether')
        assert candidate_info["Host"] == self.ip_dict["node5"], "质押ip与传输的ip不一致"
        assert candidate_info["CandidateId"] == self.nodeid_dict["node5"], "质押nodeid与传输的不一致"
        assert candidate_info["Port"] == self.port_dict['node5'], "质押端口与传输的不一致,获取port:{},实际质押port:{}".format(
            candidate_info["Port"], self.port_dict['node5'])
        assert self.platon_dpos1.web3.toChecksumAddress(
            candidate_info["Owner"]) == self.new_address, "质押地址不正确"
        candidate_list = self.platon_dpos2.GetCandidateList()
        # 校验candidate_list包含节点179
        assert candidate_info in candidate_list, "候选人列表不包含节点{}".format(
            self.ip_dict['node5'])

    # @pytest.mark.skip
    # def add_pledge(self):
    #     '''
    #     已不支持增加质押,用例暂不执行
    #     增加质押
    #     :return:
    #     '''
    #     result = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node5'], self.new_address, self.fee,
    #                                                 self.ip_dict['node5'],
    #                                                 self.port_dict['node5'], self.extra, value=10)
    #     self.check_event(result)
    #     candidate_info = self.platon_dpos1.GetCandidateDetails(
    #         self.nodeid_dict['node5'])
    #     # candidate_info为节点179的质押信息
    #     assert isinstance(candidate_info, dict), "返回结果错误{}".format(
    #         candidate_info)
    #     assert candidate_info["Deposit"] == self.platon_dpos1.web3.toWei(
    #         60, 'ether')

    # @pytest.mark.skip
    # def test_refund_10(self):
    #     '''
    #     已不支持部分退款,用例暂不执行
    #     @Description: 查询退款金额低于10%
    #     @param {type} @@@@
    #     @return: @@@@
    #     '''
    #     i = 500000000000000000
    #     status = 0
    #     try:
    #         self.platon_dpos2.CandidateApplyWithdraw(
    #             self.nodeid_dict['node5'], i)
    #     except:
    #         status = 1
    #     assert status == 1, "低于10%应不允许提取"

    def test_refund(self):
        '''
        @Description: 查询退款是否正常,是否退出候选人列表
        @param {type} @@@@
        @return: @@@@
        '''
        i = 50000000000000000000
        start_balance = self.platon_dpos2.eth.getBalance(self.new_address)
        result = self.platon_dpos2.CandidateDeposit(self.nodeid_dict['node6'], self.new_address, self.fee,
                                                    self.ip_dict['node6'],
                                                    self.port_dict['node6'], self.extra, value=50)
        candidate_info = self.platon_dpos1.GetCandidateDetails(
            self.nodeid_dict['node6'])
        self.check_event(result)
        result = self.platon_dpos2.CandidateApplyWithdraw(
            self.nodeid_dict['node6'], i)
        self.check_event(result)
        time.sleep(3)
        withdraw_list = self.platon_dpos2.GetCandidateWithdrawInfos(
            self.nodeid_dict['node6'])
        assert withdraw_list["Balance"] == i, "申请退款的金额与查询结果不一致"
        result = self.platon_dpos1.CandidateWithdraw(self.nodeid_dict["node6"])
        self.check_event(result)
        end_balance = self.platon_dpos1.eth.getBalance(self.new_address)
        assert end_balance - start_balance < 100000000000000000, "退款金额错误,退款前:{}|退款后:{}".format(
            self.platon_dpos1.web3.fromWei(start_balance, 'ether'), self.platon_dpos1.web3.fromWei(end_balance, 'ether'))
        candidate_list = self.platon_dpos1.GetCandidateList()
        assert candidate_info not in candidate_list, "node6还在候选人列表中"

    def test_candidate_sort(self):
        '''
        @Description: 候选人排序
        @param {type} @@@@
        @return: @@@@
        '''
        # result_1 = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node5'], self.new_address, self.fee,
        #                                               self.ip_dict['node5'],
        #                                               self.port_dict['node5'], self.extra, value=45)
        # self.check_event(result_1)
        result_2 = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node6'], self.new_address, self.fee,
                                                      self.ip_dict['node6'],
                                                      self.port_dict['node6'], self.extra, value=160)
        self.check_event(result_2)
        candidate_list = self.platon_dpos1.GetCandidateList()
        candidate_info = self.platon_dpos1.GetCandidateDetails(
            self.nodeid_dict['node6'])
        assert candidate_list[0] == candidate_info, "候选人列表排序错误"

    def test_candidate_cap(self):
        '''
        @Description: 候选人列表容量
        @param {type} @@@@
        @return: @@@@
        '''
        status = 0
        candidate_info = self.platon_dpos1.GetCandidateDetails(
            self.nodeid_dict['node5'])
        result_1 = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node1'], self.new_address, self.fee,
                                                      self.ip_dict['node1'],
                                                      self.port_dict['node1'], self.extra, value=131)
        self.check_event(result_1)
        result_2 = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node2'], self.new_address, self.fee,
                                                      self.ip_dict['node2'],
                                                      self.port_dict['node2'], self.extra, value=135)
        self.check_event(result_2)
        result_3 = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node3'], self.new_address, self.fee,
                                                      self.ip_dict['node3'],
                                                      self.port_dict['node3'], self.extra, value=135)
        self.check_event(result_3)
        result_4 = self.platon_dpos1.CandidateDeposit(self.nodeid_dict['node4'], self.new_address, self.fee,
                                                      self.ip_dict['node4'],
                                                      self.port_dict['node4'], self.extra, value=140)
        self.check_event(result_4)
        candidate_list = self.platon_dpos1.GetCandidateList()
        log.info("入围节点列表:{}".format(candidate_list))
        assert candidate_info not in candidate_list, "node5还在候选人列表中"

    def test_ticket_price(self):
        '''校验票价是否与配置文件中一致'''
        price = self.platon_dpos1.GetTicketPrice()
        config_price = Web3.toWei(self.ticket_price, 'ether')
        assert config_price == price, '实际票价:{},与配置文件中:{},不一致'.format(
            config_price, price)

    def test_vote_ticket(self):
        '''投票'''
        value = self.allowed * self.ticket_price
        vote_info, _ = self.platon_dpos1.VoteTicket(self.allowed, self.ticket_price, self.nodeid_dict['node6'],
                                                    self.new_address, value)
        self.platon_dpos1.VoteTicket(self.allowed, self.ticket_price, self.nodeid_dict['node1'],
                                     self.new_address, value)
        self.platon_dpos1.VoteTicket(self.allowed, self.ticket_price, self.nodeid_dict['node2'],
                                     self.new_address, value)
        self.platon_dpos1.VoteTicket(self.allowed, self.ticket_price, self.nodeid_dict['node3'],
                                     self.new_address, value)
        vote_info, _ = self.platon_dpos1.VoteTicket(self.allowed - 1, self.ticket_price, self.nodeid_dict['node4'],
                                     self.new_address, value - 1)
        assert 'success' in vote_info['VoteTicketEvent'][0], '投票失败,结果:{}'.format(
            vote_info)

    # @pytest.skip
    # def test_ticket_detail(self):
    #     '''
    #     接口已经删除,用例屏蔽
    #     验证节点下选票数量、选票的详细信息
    #     '''
    #     ticket_ids = self.platon_dpos1.GetCandidateTicketIds(self.nodeid_dict['node1'])
    #     ticket_num = len(ticket_ids)
    #     assert ticket_num == self.allowed, '节点选票数:{}与已投票数:{}不一致'.format(ticket_num, self.allowed)
    #     ticket_detail = self.platon_dpos1.GetTicketDetail(ticket_ids[0])
    #     owner = Web3.toChecksumAddress(ticket_detail[0]['Owner'])
    #     assert owner == self.new_address, '投票人:{}与投票时用的钱包地址:{}不一致'.format(owner, self.new_address)
    #     dposite = ticket_detail[0]['Deposit']
    #     price = Web3.toWei(self.ticket_price, 'ether')
    #     assert dposite == price, '投票金额:{}与票价:{}不一致'.format(dposite, price)
    #     candidateid = ticket_detail[0]['CandidateId']
    #     assert candidateid == self.nodeid_dict['node1'], '票详情中节点id:{},与投票时节点id不一致:{}'.format(candidateid,
    #                                                                                          self.nodeid_dict['node1'])

    # @pytest.skip
    # def test_batch_ticket_detail(self):
    #     '''
    #     接口已删除,用例屏蔽
    #     验证批量获取节点下选票数量、选票的详细信息
    #     '''
    #     batch_ticket_ids = self.platon_dpos1.GetBatchCandidateTicketIds(
    #         [self.nodeid_dict['node1'], self.nodeid_dict['node2']])
    #     print('batch_ticket_ids = ', batch_ticket_ids)
    #     ticket_ids = batch_ticket_ids[0].get(self.nodeid_dict['node1'])
    #     ticket_ids_one = self.platon_dpos1.GetCandidateTicketIds(self.nodeid_dict['node1'])
    #     assert ticket_ids == ticket_ids_one, '批量获取详情{}\n单独获取详情{}不一致'.format(ticket_ids, ticket_ids_one)
    #     node1_tickets = batch_ticket_ids[0].get(self.nodeid_dict['node1'])
    #     node2_tickets = batch_ticket_ids[0].get(self.nodeid_dict['node2'])
    #     ticket_details = self.platon_dpos1.GetBatchTicketDetail([node1_tickets[0], node2_tickets[0]])
    #     ticket_detail = ticket_details[0]
    #     ticket_detail_one = self.platon_dpos1.GetTicketDetail(ticket_details[0]['TicketId'])[0]
    #     assert ticket_detail == ticket_detail_one, '批量获取的票详情{}与单独查询票详情不一致{}'.format(ticket_detail, ticket_detail_one)
    #     assert len(ticket_details) == 2, '批量获取票详情数{}不等于请求数2'.format(len(ticket_details))

    def test_vote_undpos_node(self):
        '''向非备选池节点投票'''
        value = self.allowed * self.ticket_price
        status = 0
        try:
            self.platon_dpos1.VoteTicket(self.allowed, self.ticket_price, self.nodeid_dict['node5'],
                                         self.new_address, value)
        except:
            status = 1
        assert status, '不在备选池的节点不能投票成功'

    def test_ticket_pool_remainder(self):
        '''验证票池剩余数量'''
        remaind = self.platon_dpos1.GetPoolRemainder()
        should_remaind = self.total_ticket - (self.allowed * 5 - 1)
        assert remaind == should_remaind, '票池剩余票:{}与已消费后应剩余数:{}不一致'.format(
            remaind, should_remaind)

    # @pytest.skip
    # def test_get_candidate_epoch(self):
    #     '''
    #     获取票龄详情接口已删除,无法获取选票产生区块,用例无法验证
    #     该接口以后会去掉,用例暂不运行
    #     验证候选人票龄
    #     '''
    #     ticket_ids = self.platon_dpos1.GetCandidateTicketIds(self.nodeid_dict['node1'])
    #     vote_block_number = self.platon_dpos1.GetTicketDetail(ticket_ids[0])[0]['BlockNumber']
    #     should_epoch = (self.platon_dpos1.eth.blockNumber - vote_block_number + 1) * len(ticket_ids)
    #     epoch = self.platon_dpos1.GetCandidateEpoch(self.nodeid_dict['node1'])
    #     assert epoch == should_epoch, '候选人票龄计算结果:{},与预期结果:{}不一致'.format(epoch, should_epoch)

    def test_get_candidate_ticket_count(self):
        '''批量查询候选节点的有效选票数量'''
        ctc_dict = self.platon_dpos1.GetCandidateTicketCount(
            '{}:{}:{}:{}'.format(self.nodeid_dict['node1'], self.nodeid_dict['node2'], self.nodeid_dict['node3'],
                                 self.nodeid_dict['node4']))
        count1 = int(ctc_dict.get(self.nodeid_dict['node1']))
        count2 = int(ctc_dict.get(self.nodeid_dict['node2']))
        count3 = int(ctc_dict.get(self.nodeid_dict['node3']))
        count4 = int(ctc_dict.get(self.nodeid_dict['node4']))
        assert count1 == self.allowed, '候选节点有效选票数量{},与预期结果{}不一致'.format(
            count1, self.allowed)
        assert count2 == self.allowed, '候选节点有效选票数量{},与预期结果{}不一致'.format(
            count2, self.allowed)
        assert count3 == self.allowed, '候选节点有效选票数量{},与预期结果{}不一致'.format(
            count3, self.allowed)
        assert count4 == self.allowed - \
            1, '候选节点有效选票数量{},与预期结果{}不一致'.format(count4, self.allowed)

    # def test_get_ticket_count_by_tx_hash(self):
    #     '''批量查询交易的有效选票数量'''
    #     _, tx_hash1 = self.platon_dpos1.VoteTicket(
    #         self.allowed, 1, self.nodeid_dict['node1'], self.address, 10)
    #     _, tx_hash2 = self.platon_dpos1.VoteTicket(
    #         self.allowed, 1, self.nodeid_dict['node2'], self.address, 10)
    #     _, tx_hash3 = self.platon_dpos1.VoteTicket(
    #         self.allowed, 1, self.nodeid_dict['node3'], self.address, 10)
    #     _, tx_hash4 = self.platon_dpos1.VoteTicket(
    #         self.allowed, 1, self.nodeid_dict['node4'], self.address, 10)
    #     tc_dict = self.platon_dpos1.GetTicketCountByTxHash(
    #         '{}:{}:{}:{}'.format(tx_hash1, tx_hash2, tx_hash3, tx_hash4))
    #     assert tc_dict.get(tx_hash1) == self.allowed, '交易的有效选票数量{},与预期结果{}不一致'.format(tc_dict.get(tx_hash1),
    #                                                                                   self.allowed)
    #     assert tc_dict.get(tx_hash2) == self.allowed, '交易的有效选票数量{},与预期结果{}不一致'.format(tc_dict.get(tx_hash2),
    #                                                                                   self.allowed)
    #     assert tc_dict.get(tx_hash3) == self.allowed, '交易的有效选票数量{},与预期结果{}不一致'.format(tc_dict.get(tx_hash3),
    #                                                                                   self.allowed)
    #     assert tc_dict.get(tx_hash4) == self.allowed, '交易的有效选票数量{},与预期结果{}不一致'.format(tc_dict.get(tx_hash4),
    #                                                                                   self.allowed)

    def test_verifiers(self):
        '''
        @Description: 验证人为候选人列表的前四,幸运票奖励发放
        @param {type} @@@@
        @return: @@@@
        '''
        before_reward = self.platon_dpos1.eth.getBalance(self.new_address)
        candidate_list = self.platon_dpos1.GetCandidateList()
        log.info("新的的入围节点列表:{}".format(candidate_list))
        candidate_id = [i['CandidateId'] for i in candidate_list]
        block_number = self.platon_dpos1.eth.blockNumber
        sleep_time = get_sleep_time(block_number)
        time.sleep(sleep_time)
        verfier_info_list = self.platon_dpos1.GetVerifiersList()
        log.info("验证人列表:{}".format(verfier_info_list))
        assert len(verfier_info_list) > 0,"查询结果异常,验证人列表为空。"
        verfier_list = [info['CandidateId'] for info in verfier_info_list]
        assert verfier_list == candidate_id[:4], "验证人没有取候选人的前四,验证人id:{}\n候选人id:{}".format(verfier_list,
                                                                                            candidate_list[:4])
        status = 1
        for verfier in verfier_list:
            if self.nodeid_dict['node4'] in verfier:
                status = 0
        assert status, '投票不达到门槛不能成为见证人'
        # 校验幸运选票是否发放奖励
        after_reward = self.platon_dpos1.eth.getBalance(self.new_address)
        assert after_reward > before_reward, '见证人奖励未发放,发放前余额:{},发放后余额:{}'.format(
            before_reward, after_reward)

    def test_verify_transaction(self):
        '''
        @Description: 切换验证人后,测试交易是否成功,所有节点块高是否一致
        @param {type} @@@@
        @return: @@@@
        '''
        tx_hash = self.platon_dpos1.eth.sendTransaction(self.send_data)
        self.platon_dpos1.eth.waitForTransactionReceipt(tx_hash)
        block_list = []
        for w in self.w3_list:
            block_list.append(w.eth.blockNumber)
        assert min(block_list) > 60, "区块没有正常增加"
        assert max(block_list) - min(block_list) < 5, "各节点区块高度差距过高"
        time.sleep(60)
        w3 = Web3(Web3.HTTPProvider(self.rpc_dict["node6"]))
        assert w3.net.peerCount >= 3, "节点node6连接的节点数少于3个"
Beispiel #17
0
"""
@Author: wuyiqin
@Date: 2019/8/16 11:45
@Description:主要是增持和修改节点信息用例
"""
from client_sdk_python import Web3
from common.connect import connect_web3
import json
from utils.platon_lib.ppos_wyq import Ppos
from conf import setting as conf
import time
from common import log
from common.load_file import LoadFile, get_node_info

node_yml_path = conf.PPOS_NODE_YML
node_info = get_node_info(node_yml_path)
rpc_list, enode_list, nodeid_list, ip_list, port_list = node_info.get(
    'collusion')
rpc_list2, enode_list2, nodeid_list2, ip_list2, port_list2 = node_info.get(
    'nocollusion')

address = Web3.toChecksumAddress(conf.ADDRESS)
privatekey = conf.PRIVATE_KEY
account_list = conf.account_list
privatekey_list = conf.privatekey_list

genesis_path = conf.GENESIS_TMP
genesis_dict = LoadFile(genesis_path).get_data()
chainid = int(genesis_dict["config"]["chainId"])

config_json_path = conf.PLATON_CONFIG_PATH