Пример #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]
Пример #2
0
 def test_fee_income(self):
     '''
     1、验证初始化之后普通账户转账内置账户
     2、验证初始内置账户没有基金会Staking奖励和出块奖励只有手续费收益
     :return:
     '''
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     incentive_pool_balance_befor = platon_ppos.eth.getBalance(
         conf.INCENTIVEPOOLADDRESS)
     log.info('交易前激励池查询余额:{}'.format(incentive_pool_balance_befor))
     address1, private_key1 = CommonMethod.read_private_key_list()
     # 签名转账
     result = platon_ppos.send_raw_transaction(
         '', Web3.toChecksumAddress(self.address),
         Web3.toChecksumAddress(address1), self.base_gas_price,
         self.base_gas, self.value, self.privatekey)
     return_info = platon_ppos.eth.waitForTransactionReceipt(result)
     assert return_info is not None, "转账:{}失败".format(self.value)
     incentive_pool_balance_after = platon_ppos.eth.getBalance(
         conf.INCENTIVEPOOLADDRESS)
     log.info('交易后激励池查询余额:{}'.format(incentive_pool_balance_after))
     difference = incentive_pool_balance_after - incentive_pool_balance_befor
     log.info('手续费的金额:{}'.format(difference))
     assert difference == 1260000000000000000, "手续费{}有误".format(difference)
Пример #3
0
    def test_loukupplan_Moredeadline(self, balace1, balace2):
        '''
        验证一个锁仓计划里有多个解锁期
        amount : 锁仓
        balace1 : 第一个锁仓期的锁仓金额
        balace2 : 第二个锁仓期的锁仓金额
        :return:
        '''
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info is not None, "转账:{}失败".format(self.value)
        loukupbalace1 = Web3.toWei(balace1, 'ether')
        loukupbalace2 = Web3.toWei(balace2, 'ether')
        if (balace1 + balace2) < self.value:
            plan = [{
                'Epoch': 1,
                'Amount': loukupbalace1
            }, {
                'Epoch': 2,
                'Amount': loukupbalace2
            }]
            result = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
        elif (balace1 + balace2) >= self.value:
            plan = [{
                'Epoch': 1,
                'Amount': loukupbalace1
            }, {
                'Epoch': 2,
                'Amount': loukupbalace2
            }]
            result = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result['Status'] == False, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
        else:
            log.info('锁仓输入的金额:{}出现异常'.format((loukupbalace1 + loukupbalace2)))
            Status = 1
            assert Status == 0, 'error:创建锁仓失败'
Пример #4
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)
Пример #5
0
    def get_next_consensus_wheel(self, number=1, file=conf.PLATON_CONFIG_PATH):
        '''
        获取下个共识轮
        :param :
        :return:
        '''
        data = LoadFile(file).get_data()
        Interval = data['EconomicModel']['Common']['Interval']
        PerRoundBlocks = data['EconomicModel']['Common']['PerRoundBlocks']
        ValidatorCount = data['EconomicModel']['Common']['ValidatorCount']
        ConsensusSize = Interval * PerRoundBlocks * ValidatorCount
        ConsensusSize = ConsensusSize * number
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        current_block = platon_ppos.eth.blockNumber
        differ_block = ConsensusSize - (current_block % ConsensusSize)
        current_end_block = current_block + differ_block
        log.info('当前块高:{} ,下个共识轮周期结束块高:{}'.format(current_block,
                                                  current_end_block))

        while 1:
            time.sleep(self.time_interval)
            current_block = platon_ppos.eth.blockNumber
            differ_block = ConsensusSize - (current_block % ConsensusSize)
            log.info('当前块高度:{},还差块高:{}'.format((current_block), differ_block))
            if current_block > current_end_block:
                break
Пример #6
0
 def test_init_token(self):
     '''
     验证链初始化后token各内置账户初始值
     :return:
     '''
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     FOUNDATION = platon_ppos.eth.getBalance(
         Web3.toChecksumAddress(conf.FOUNDATIONADDRESS))
     FOUNDATIONLOCKUP = platon_ppos.eth.getBalance(
         Web3.toChecksumAddress(conf.FOUNDATIONLOCKUPADDRESS))
     STAKING = platon_ppos.eth.getBalance(
         Web3.toChecksumAddress(conf.STAKINGADDRESS))
     INCENTIVEPOOL = platon_ppos.eth.getBalance(
         Web3.toChecksumAddress(conf.INCENTIVEPOOLADDRESS))
     DEVELOPERS = platon_ppos.eth.getBalance(
         Web3.toChecksumAddress(conf.DEVELOPERSADDRESS))
     token_init_total = conf.TOKENTOTAL
     if self.initial_amount['FOUNDATION'] != FOUNDATION:
         log.info("基金会初始金额:{}有误".format(FOUNDATION))
     elif self.initial_amount['FOUNDATIONLOCKUP'] != FOUNDATIONLOCKUP:
         log.info("基金会锁仓初始金额:{}有误".format(FOUNDATIONLOCKUP))
     elif self.initial_amount['STAKING'] != STAKING:
         log.info("质押账户初始金额:{}有误".format(STAKING))
     elif self.initial_amount['INCENTIVEPOOL'] != INCENTIVEPOOL:
         log.info("奖励池初始金额:{}有误".format(INCENTIVEPOOL))
     elif self.initial_amount['DEVELOPERS'] != DEVELOPERS:
         log.info("预留账户初始金额:{}有误".format(DEVELOPERS))
     reality_total = FOUNDATION + FOUNDATIONLOCKUP + STAKING + INCENTIVEPOOL + DEVELOPERS
     assert token_init_total == (
         reality_total), "初始化发行值{}有误".format(reality_total)
Пример #7
0
 def query_blockNumber(self):
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     while 1:
         current_block = platon_ppos.eth.blockNumber
         time.sleep(10)
         print(current_block)
Пример #8
0
    def test_loukupplan(self):
        '''
        验证正常锁仓功能
        参数输入:
        Epoch:1
        Amount:50 ether
        :return:
        '''
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()
        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info is not None, "转账:{}失败".format(self.value)
        #查询锁仓账户的余额
        lockup_before = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("发起锁仓账户的余额:{}".format(lockup_before))

        #创建锁仓计划
        loukupbalace = Web3.toWei(50, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan(
            address1,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回状态为:{} 有误".format(
            result['Status'])
        lockup_after = platon_ppos.eth.getBalance(conf.FOUNDATIONLOCKUPADDRESS)
        assert lockup_after == lockup_before + loukupbalace, "锁仓账户金额:{}有误".format(
            lockup_after)

        #查看锁仓计划明细
        detail = platon_ppos.GetRestrictingInfo(address1)
        assert detail['Status'] == True, "查询锁仓计划信息返回状态为:{}".format(
            result['Status'])
        RestrictingInfo = json.loads(detail['Data'])
        assert RestrictingInfo[
            'balance'] == loukupbalace, "创建锁仓计划金额:{}有误".format(lockup_after)
Пример #9
0
 def test_init_loukup(self):
     '''
     查询初始化链后基金会锁仓金额
     以及查询初始锁仓计划信息的有效性
     :return:
     '''
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     lockupbalance = platon_ppos.eth.getBalance(
         conf.FOUNDATIONLOCKUPADDRESS)
     FOUNDATIONLOCKUP = self.initial_amount['FOUNDATIONLOCKUP']
     assert lockupbalance == FOUNDATIONLOCKUP
     result = platon_ppos.GetRestrictingInfo(conf.INCENTIVEPOOLADDRESS)
     assert result['Status'] == True, ",锁仓计划信息查询状态为{}".format(
         result['Status'])
     dict_info = json.loads(result['Data'])
     assert dict_info['balance'] == self.initial_amount[
         'FOUNDATIONLOCKUP'], '锁仓初始金额{}有误'.format(lockupbalance)
Пример #10
0
 def test_transfer_normal(self):
     '''
     验证初始化之后账户之间转账
     :return:
     '''
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     address1, private_key1 = CommonMethod.read_private_key_list()
     # 签名转账
     result = platon_ppos.send_raw_transaction(
         '', Web3.toChecksumAddress(self.address),
         Web3.toChecksumAddress(address1), self.base_gas_price,
         self.base_gas, self.value, self.privatekey)
     return_info = platon_ppos.eth.waitForTransactionReceipt(result)
     assert return_info is not None, "转账:{}失败".format(self.value)
     balance = platon_ppos.eth.getBalance(address1)
     log.info("转账金额{}".format(balance))
     assert Web3.toWei(self.value,
                       'ether') == balance, "转账金额:{}失败".format(balance)
Пример #11
0
 def query_amount(self):
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     # lockup_after = platon_ppos.eth.getBalance (conf.FOUNDATIONLOCKUPADDRESS)
     # log.info ("退回质押金之后锁仓账户金额:{}".format (lockup_after))
     # Staking_after = platon_ppos.eth.getBalance (conf.STAKINGADDRESS)
     # log.info ("退回质押金之后Staking账户金额:{}".format (Staking_after))
     while 1:
         current_block = platon_ppos.eth.blockNumber
         log.info("当前块高:{}".format(current_block))
         time.sleep(10)
Пример #12
0
    def test_punishment_income(self):
        '''
        验证低出块率验证节点的处罚金自动转账到激励池
        :return:
        '''
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        incentive_pool_balance_befor = platon_ppos.eth.getBalance(
            conf.INCENTIVEPOOLADDRESS)
        log.info('处罚之前激励池查询余额:{}'.format(incentive_pool_balance_befor))

        #获取节点内置质押节点信息
        nodeId = CommonMethod.read_out_nodeId(self, 'collusion')
        log.info("节点ID:{}".format(nodeId))
        con_node, no_node = get_node_list(self.node_yml_path)
        nodes = con_node + no_node
        for node in nodes:
            if nodeId in node.values():
                node_data = node

        #获取节点质押金额
        punishment_CandidateInfo = platon_ppos.getCandidateInfo(nodeId)
        assert punishment_CandidateInfo['Status'] == True, "查询锁仓信息失败"
        pledge_amount1 = punishment_CandidateInfo['Data']['Released']
        log.info("质押节点质押金:{}".format(pledge_amount1))

        # 停止其中一个正在出块的节点信息
        self.auto = AutoDeployPlaton()
        self.auto.kill(node_data)
        platon_ppos1 = connect_web3(node_data['url'])
        assert not platon_ppos1.isConnected(), "节点:{} 连接异常".format(
            node_data['host'])
        CommonMethod.get_next_settlement_interval(self)
        punishment_CandidateInfo = platon_ppos.getCandidateInfo(nodeId)
        pledge_amount3 = punishment_CandidateInfo['Data']['Released']
        log.info("节点低出块率后节点质押金:{}".format(pledge_amount3))
        incentive_pool_balance_after = platon_ppos.eth.getBalance(
            conf.INCENTIVEPOOLADDRESS)
        log.info('处罚之后激励池查询余额:{}'.format(incentive_pool_balance_after))
        assert incentive_pool_balance_after == incentive_pool_balance_befor + (
            pledge_amount1 - pledge_amount3)
Пример #13
0
 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)
Пример #14
0
 def test_loukupplan_amount(self):
     url = CommonMethod.link_list(self)
     platon_ppos = Ppos(url, self.address, self.chainid)
     address1, private_key1 = CommonMethod.read_private_key_list()
     # 签名转账
     result = platon_ppos.send_raw_transaction(
         '', Web3.toChecksumAddress(self.address),
         Web3.toChecksumAddress(address1), self.base_gas_price,
         self.base_gas, self.value, self.privatekey)
     return_info = platon_ppos.eth.waitForTransactionReceipt(result)
     assert return_info is not None, "转账:{}失败".format(self.value)
     loukupbalace = Web3.toWei(10000, 'ether')
     plan = [{'Epoch': 1, 'Amount': loukupbalace}]
     result = platon_ppos.CreateRestrictingPlan(
         address1,
         plan,
         privatekey=private_key1,
         from_address=address1,
         gasPrice=self.base_gas_price,
         gas=self.staking_gas)
     assert result['Status'] == False, '创建锁仓计划返回状态为{},用例失败'.format(
         result['Status'])
Пример #15
0
    def test_loukupplan_abnormal(self, number, amount):
        '''
        创建锁仓计划时,参数有效性验证
        number : 锁仓解锁期
        amount : 锁仓金额
        :param number:
        :param amount:
        :return:
        '''

        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()
        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info is not None, "转账:{}失败".format(self.value)
        loukupbalace = Web3.toWei(amount, 'ether')
        #loukupbalace = amount
        plan = [{'Epoch': number, 'Amount': loukupbalace}]
        log.info("创建锁仓计划参数:{}".format(plan))

        if type(number) == int and type(amount) == int:
            if 0 < number <= 36 and 1 <= amount:

                result = platon_ppos.CreateRestrictingPlan(
                    address1,
                    plan,
                    privatekey=private_key1,
                    from_address=address1,
                    gasPrice=self.base_gas_price,
                    gas=self.staking_gas)
                assert result['Status'] == True, '创建锁仓状态为:{},用例失败'.format(
                    result['Status'])

            else:
                result = platon_ppos.CreateRestrictingPlan(
                    address1,
                    plan,
                    privatekey=private_key1,
                    from_address=address1,
                    gasPrice=self.base_gas_price,
                    gas=self.staking_gas)
                assert result['Status'] == False, '创建锁仓状态为:{},用例失败'.format(
                    result['Status'])
        else:
            result = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result['Status'] == False, '创建锁仓状态为:{},用例失败'.format(
                result['Status'])
    def test_multiple_unlock_Normal(self):
        '''
        多个锁仓期,到达部分解锁期返回解锁金额
        :return:
        '''
        url = CommonMethod.link_list (self)
        platon_ppos = Ppos (url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list ()
        address2, private_key2 = CommonMethod.read_private_key_list ()

        # 签名转账
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address1),
                                                   self.base_gas_price, self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None,"转账:{}失败".format(self.value)
        loukupbalace = Web3.toWei (50, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace},{'Epoch': 2, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address2, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回状态为:{} 有误".format (result['Status'])
        balance = platon_ppos.eth.getBalance (address2)
        log.info ("锁仓之后账户余额:{}".format (balance))
        log.info ("当前块高:{}".format (platon_ppos.eth.blockNumber))
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == loukupbalace*2, "锁仓金额:{}有误".format (dict_Info['balance'])

        # 验证到达锁仓第一个解锁期之后账户金额
        CommonMethod.get_next_settlement_interval (self)
        balance2 = platon_ppos.eth.getBalance (address2)
        log.info ("到达第一个解锁期后账户余额:{}".format (balance2))
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        balance = platon_ppos.eth.getBalance (address2)
        assert dict_Info['balance'] == loukupbalace, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['Entry'][0]['amount'] == loukupbalace,"第二个解锁期待释放金额:{}".format(dict_Info['Entry'][0]['amount'])
        assert balance2 == loukupbalace, "返回的释放锁仓金额:{} 有误".format (balance)

        #验证到达锁仓第二个解锁期之后账户金额
        CommonMethod.get_next_settlement_interval (self)
        balance3 = platon_ppos.eth.getBalance (address2)
        log.info ("到达第二个解锁期后账户余额:{}".format (balance2))
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        balance = platon_ppos.eth.getBalance (address2)
        assert dict_Info['balance'] == 0, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert balance3 == loukupbalace*2, "返回的释放锁仓金额:{} 有误".format (balance)
    def test_unlock_point_delegtion_notbalance(self):
        '''
        1、到达解锁时间点用锁仓金额去委托节点,到达解锁期账户锁仓不足
        2、到达解锁期账户申请部分赎回委托
        3、全部赎回委托
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list (self)
        url = CommonMethod.link_list (self)
        platon_ppos = Ppos (url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list ()
        address2, private_key2 = CommonMethod.read_private_key_list ()

        # 签名转账
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address1),
                                                   self.base_gas_price, self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账质押账号手续费:{}失败".format (self.value)

        # 给锁仓账号转手续费
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address2),
                                                   self.base_gas_price, self.base_gas, self.value,
                                                   conf.PRIVATE_KEY)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账锁仓账号手续费:{}失败".format (self.value)
        Balance = platon_ppos.eth.getBalance (address1)
        log.info ("{}发起锁仓账户余额:{}".format (address1, Balance))
        Balance1 = platon_ppos.eth.getBalance (address1)
        log.info ("{}发起质押账号余额:{}".format (address2, Balance1))

        # 申请质押节点
        version = get_version (platon_ppos)
        amount = 100
        result = platon_ppos.createStaking (0, address1, nodeId, 'externalId', 'nodeName', 'website', 'details',
                                            amount, version, privatekey=private_key1, from_address=address1,
                                            gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},{},用例失败".format (result['Status'], result['ErrMsg'])
        Balance2 = platon_ppos.eth.getBalance (address1)
        log.info ("{}申请质押节点后账户余额:{}".format (address1, Balance2))

        # 创建锁仓计划
        lockupamoutn = 100
        loukupbalace = Web3.toWei (lockupamoutn, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address2, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format (result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == loukupbalace, "锁仓计划金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == False, "锁仓的状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == 0, "欠释放锁仓金额:{} 有误".format (dict_Info['debt'])
        Balance3 = platon_ppos.eth.getBalance (address1)
        log.info ("{}创建锁仓计划后账户余额:{}".format (address1, Balance3))

        # 申请委托验证人节点
        amount = 100
        result = platon_ppos.delegate (1, nodeId, amount, privatekey=private_key2, from_address=address2,
                                              gasPrice=self.base_gas_price, gas=self.staking_gas)
        log.info ("申请委托地址:{}".format (address2))
        assert result['Status'] == True, "申请委托返回的状态:{},用例失败".format (result['Status'])
        balance4 = platon_ppos.eth.getBalance (address2)
        log.info ("{}申请委托验证人节点后账户余额:{}".format (address2,balance4))

        # 到达解锁期之后锁仓账号余额
        CommonMethod.get_next_settlement_interval (self)
        balance5 = platon_ppos.eth.getBalance (address2)
        log.info ("{}到达解锁期后实际账户余额:{}".format (address2,balance5))
        assert balance5 == balance4, "锁仓账户金额:{} 有误".format (balance5)
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == 0, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == True, "锁仓的状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == loukupbalace, "欠释放锁仓金额:{} 有误".format (dict_Info['debt'])

        #申请赎回部分委托金
        partamount = 50
        msg = platon_ppos.getCandidateInfo (nodeId)
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        delegate_info = platon_ppos.unDelegate (stakingBlockNum, nodeId, partamount, privatekey=private_key2,
                                                from_address=address2, gasPrice=self.base_gas_price,
                                                gas=self.staking_gas)
        assert delegate_info['Status'] == True, "申请赎回委托返回的状态:{},用例失败".format (result['Status'])
        balance6 = platon_ppos.eth.getBalance (address2)
        log.info ("{}到达解锁期发起赎回部分委托后账户余额:{}".format (address2,balance6))

        #到达下个解锁期释放部分委托金
        CommonMethod.get_next_settlement_interval (self)
        balance7 = platon_ppos.eth.getBalance (address2)
        log.info ("赎回部分委托金后锁仓账户余额:{}".format (balance7))
        assert balance7 == balance6 + Web3.toWei (partamount, 'ether'),"到达解锁期赎回部分委托后账户余额:{}".format (balance7)
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == 0, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == True, "锁仓的状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == loukupbalace - Web3.toWei (partamount, 'ether'), "欠释放锁仓金额:{} 有误".format (dict_Info[                                                                                         'debt'])
        #申请赎回全部委托金
        delegate_info = platon_ppos.unDelegate (stakingBlockNum, nodeId, lockupamoutn - partamount, privatekey=private_key2,
                                                from_address=address2, gasPrice=self.base_gas_price,
                                                gas=self.staking_gas)
        assert delegate_info['Status'] == True, "申请赎回委托返回的状态:{},用例失败".format (result['Status'])
        balance8 = platon_ppos.eth.getBalance (address2)
        log.info ("{}赎回全部委托金后锁仓账户余额:{}".format (address2,balance8))

        #到达下个解锁期释放全部委托金
        CommonMethod.get_next_settlement_interval (self)
        balance9 = platon_ppos.eth.getBalance (address2)
        log.info ("{}赎回全部委托金后实际账户余额:{}".format (address2,balance9))
        log.info ("{}赎回全部委托金后预期账户余额:{}".format (address2,balance8 + Web3.toWei (lockupamoutn - partamount, 'ether')))
        assert balance9 == balance8 + loukupbalace - Web3.toWei (partamount, 'ether'), "到达解锁期赎回委托后账户余额:{}".format                                                                                             (balance9)
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == 0, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == False, "锁仓的状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == 0, "欠释放锁仓金额:{} 有误".format (dict_Info['debt'])
    def test_unlock_point_pledge_amount(self):
        '''
        到达解锁时间点,锁仓金额质押后在解锁期之后再申请退回质押金
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list (self)
        url = CommonMethod.link_list (self)
        platon_ppos = Ppos (url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list ()
        address2, private_key2 = CommonMethod.read_private_key_list ()

        # 签名转账
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address1),
                                                   self.base_gas_price, self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None,"转账:{}失败".format(self.value)

        # 给锁仓账号转手续费
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address2),
                                                   self.base_gas_price, self.base_gas, self.value,
                                                   self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账:{}失败".format (self.value)
        Balance = platon_ppos.eth.getBalance(address1)
        log.info("{}发起锁仓账户余额:{}".format(address1,Balance))
        Balance1 = platon_ppos.eth.getBalance (address1)
        log.info ("{}发起质押账号余额:{}".format (address2, Balance1))

        # 创建锁仓计划
        lockupamoutn = 900
        loukupbalace = Web3.toWei (lockupamoutn, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address2, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format (result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])
        info = json.loads(RestrictingInfo['Data'])
        assert info['balance'] == loukupbalace,"锁仓计划可用余额:{},有误".format(info['balance'])
        balance2 = platon_ppos.eth.getBalance (address1)
        log.info ("{}创建锁仓后余额:{}".format (address1,balance2))

        # 申请质押节点
        version = get_version (platon_ppos)
        amount = 800
        result = platon_ppos.createStaking (1, address2, nodeId, 'externalId', 'nodeName', 'website', 'details',
                                            amount, version, privatekey=private_key2, from_address=address2,
                                            gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},{},用例失败".format (result['Status'], result['ErrMsg'])
        balance3 = platon_ppos.eth.getBalance (address2)
        log.info ("{}质押完账户余额:{}".format (address2,balance3))
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == Web3.toWei(lockupamoutn - amount,'ether'), "锁仓金额:{}有误".format (dict_Info['balance'])

        # 到达解锁期之后锁仓账号余额
        CommonMethod.get_next_settlement_interval (self)
        balance4 = platon_ppos.eth.getBalance (address2)
        log.info("到达解锁期后预期账户余额:{}".format(balance3 + Web3.toWei(lockupamoutn - amount,'ether')))
        log.info("到达解锁期后实际账户余额:{}".format (balance4))
        assert balance4 == balance3 + Web3.toWei(lockupamoutn - amount,'ether'),"锁仓账户金额:{} 有误".format(balance4)
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == 0, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == True,"锁仓的状态:{} 有误".format(dict_Info['symbol'])
        assert dict_Info['debt'] == Web3.toWei(amount,'ether'),"欠释放锁仓金额:{} 有误".format(dict_Info['debt'])

        # 申请退回质押金
        result = platon_ppos.unStaking (nodeId, privatekey=private_key2, from_address=address2,
                                        gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == True, "申请质押退回质押金返回的状态:{},用例失败".format (result['Status'])
        balance5 = platon_ppos.eth.getBalance (address2)
        log.info ("到达解锁期申请退回质押金后账户余额:{}".format (balance5))

        # 等待两个结算周期后查询锁仓账号情况
        CommonMethod.get_next_settlement_interval (self,3)
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        balance6 = platon_ppos.eth.getBalance (address2)
        log.info ("到达解锁期退回质押金后预期账户金额:{}".format (balance5 + loukupbalace))
        log.info ("到达解锁期退回质押金后实际账户余额:{}".format (balance6))
        assert balance6 == balance5 + loukupbalace, "锁仓账户金额:{} 有误".format (balance6)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == 0, "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == False, "锁仓的状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == 0, "欠释放锁仓金额:{} 有误".format (dict_Info['debt'])
Пример #19
0
    def test_loukupplan_sameperiod(self, Status):
        '''
        验证一个锁仓计划里有多个相同解锁期
        code =1 :同个account在一个锁仓计划里有相同解锁期
        code =2 :同个account在不同锁仓计划里有相同解锁期
        :return:
        '''
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)

        address1, private_key1 = CommonMethod.read_private_key_list()

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info is not None, "转账:{}失败".format(self.value)
        period1 = 1
        period2 = 2
        loukupbalace = Web3.toWei(100, 'ether')

        if Status == 1:
            plan = [{
                'Epoch': period1,
                'Amount': loukupbalace
            }, {
                'Epoch': period1,
                'Amount': loukupbalace
            }]
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)
            json_data = json.loads(RestrictingInfo['Data'])
            assert json_data['Entry'][0]['amount'] == (
                loukupbalace + loukupbalace), '锁仓金额{}有误'.format(
                    json_data['Entry'][0]['amount'])

        elif Status == 2:
            plan = [{'Epoch': period1, 'Amount': loukupbalace}]
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result1 = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result1['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)
            json_data = json.loads(RestrictingInfo['Data'])
            assert json_data['balance'] == (loukupbalace +
                                            loukupbalace), '锁仓金额{}有误'.format(
                                                json_data['balance'])
            assert json_data['Entry'][0]['amount'] == (
                loukupbalace + loukupbalace), '锁仓金额{}有误'.format(
                    json_data['Entry'][0]['amount'])
        elif Status == 3:
            plan = [{'Epoch': period1, 'Amount': loukupbalace}]
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result1 = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result1['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)

            plan = [{'Epoch': period2, 'Amount': loukupbalace}]
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result1 = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result1['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)
            json_data = json.loads(RestrictingInfo['Data'])
            assert json_data['balance'] == (loukupbalace *
                                            2), '锁仓金额{}有误'.format(
                                                json_data['balance'])
            assert json_data['Entry'][0]['amount'] + json_data['Entry'][1][
                'amount'] == json_data[
                    'balance'], '锁仓金额{}有误                           '.format(
                        json_data['Entry'][0]['amount'] +
                        json_data['Entry'][1]['amount'])

        elif Status == 4:
            plan = [{
                'Epoch': 2,
                'Amount': loukupbalace
            }, {
                'Epoch': 3,
                'Amount': loukupbalace
            }]
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result1 = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result1['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)

            plan = [{
                'Epoch': 2,
                'Amount': loukupbalace
            }, {
                'Epoch': 3,
                'Amount': loukupbalace
            }]
            log.info("锁仓参数:{}".format(plan))
            log.info("当前块高:{}".format(platon_ppos.eth.blockNumber))
            result1 = platon_ppos.CreateRestrictingPlan(
                address1,
                plan,
                privatekey=private_key1,
                from_address=address1,
                gasPrice=self.base_gas_price,
                gas=self.staking_gas)
            assert result1['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
                result['Status'])
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)
            json_data = json.loads(RestrictingInfo['Data'])
            assert json_data['balance'] == (loukupbalace *
                                            4), '锁仓金额{}有误'.format(
                                                json_data['balance'])
            assert json_data['Entry'][0]['amount'] + json_data['Entry'][1][
                'amount'] == json_data[
                    'balance'], '锁仓金额{}有误                           '.format(
                        json_data['Entry'][0]['amount'] +
                        json_data['Entry'][1]['amount'])

        else:
            Status = 1
            assert Status == 0, '输入的Status:{}有误'.format(Status)
Пример #20
0
    def test_lockup_redemption_of_entrust(self):
        '''
        锁仓账户发起委托之后赎回委托验证
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list(self)
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()
        address2, private_key2 = CommonMethod.read_private_key_list()

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info2 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info2 is not None, "转账:{}失败".format(self.value)

        # 给锁仓账号转手续费
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address2), self.base_gas_price,
            self.base_gas, self.value, conf.PRIVATE_KEY)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)

        assert return_info is not None, "转账锁仓账号手续费:{}失败".format(self.value)

        # 申请质押节点
        version = get_version(platon_ppos)
        amount = 100
        result = platon_ppos.createStaking(0,
                                           address1,
                                           nodeId,
                                           'externalId',
                                           'nodeName',
                                           'website',
                                           'details',
                                           amount,
                                           version,
                                           privatekey=private_key1,
                                           from_address=address1,
                                           gasPrice=self.base_gas_price,
                                           gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},{}用例失败".format(
            result['Status'], result['ErrMsg'])

        # 创建锁仓计划
        loukupbalace = Web3.toWei(500, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan(
            address2,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
            result['Status'])
        # RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        # assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])

        balance = platon_ppos.eth.getBalance(address2)
        log.info("发起锁仓账户余额:{}".format(balance))
        lockup_before = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("申请委托之前锁仓账户金额:{}".format(lockup_before))
        Staking_before = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("申请委托之前Staking账户金额:{}".format(Staking_before))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        RestrictingInfo = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划可用余额:{}".format(RestrictingInfo['balance']))

        #申请委托验证人节点
        amount = 500
        delegate_info = platon_ppos.delegate(1,
                                             nodeId,
                                             amount,
                                             privatekey=private_key2,
                                             from_address=address2,
                                             gasPrice=self.base_gas_price,
                                             gas=self.staking_gas)
        assert delegate_info['Status'] == True, "申请委托返回的状态:{},用例失败".format(
            result['Status'])

        lockup_back_before = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("申请委托之后锁仓账户金额:{}".format(lockup_back_before))
        Staking_back_before = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("申请委托之后Staking账户金额:{}".format(Staking_back_before))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        RestrictingInfo = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划可用余额:{}".format(RestrictingInfo['balance']))

        #申请赎回委托
        msg = platon_ppos.getCandidateInfo(nodeId)
        stakingBlockNum = msg["Data"]["StakingBlockNum"]
        delegate_info = platon_ppos.unDelegate(stakingBlockNum,
                                               nodeId,
                                               amount,
                                               privatekey=private_key2,
                                               from_address=address2,
                                               gasPrice=self.base_gas_price,
                                               gas=self.staking_gas)
        assert delegate_info['Status'] == True, "申请赎回委托返回的状态:{},用例失败".format(
            result['Status'])

        lockup_end = platon_ppos.eth.getBalance(conf.FOUNDATIONLOCKUPADDRESS)
        log.info("赎回委托之后锁仓账户金额:{}".format(lockup_end))
        Staking_end = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("赎回委托之后Staking账户金额:{}".format(Staking_end))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        Info = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划余额:{}".format(Info['balance']))

        assert lockup_end == lockup_before, "质押金退回后锁仓金额:{}有误".format(
            lockup_end)
        assert Staking_end == Staking_before, "质押金退回后Staking金额:{}有误".format(
            Staking_end)
        assert Info['balance'] == loukupbalace, "锁仓计划金额:{}有误".format(
            RestrictingInfo['balance'])
    def test_owe_amountstack_lock_plan(self):
        '''
        到达解锁时间点,如果账户锁仓不足再新增新的锁仓计划
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list (self)
        url = CommonMethod.link_list (self)
        platon_ppos = Ppos (url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list ()
        address2, private_key2 = CommonMethod.read_private_key_list ()

        # 签名转账
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address1),
                                                   self.base_gas_price, self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账:{}失败".format (self.value)

        # 创建锁仓计划
        lockupamoutn = 500
        loukupbalace = Web3.toWei (lockupamoutn, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address2, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format (result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])

        # 给锁仓账号转手续费
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address2),
                                                   self.base_gas_price, self.base_gas, self.value,
                                                   self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账:{}失败".format (self.value)
        balance = platon_ppos.eth.getBalance(address2)
        log.info("锁仓账户余额:{}".format(balance))

        # 申请质押节点
        version = get_version (platon_ppos)
        amount = 500
        result = platon_ppos.createStaking (1, address2, nodeId, 'externalId', 'nodeName', 'website', 'details',
                                            amount, version, privatekey=private_key2, from_address=address2,
                                            gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},{},用例失败".format (result['Status'], result['ErrMsg'])

        #到达解锁期释放锁仓金额
        CommonMethod.get_next_settlement_interval (self)
        platon_ppos.GetRestrictingInfo(address2)
        balance = platon_ppos.eth.getBalance(address2)
        log.info("到达解锁期释放锁仓余额:{}".format(balance))

        # 创建锁仓计划
        lockupamoutn = 100
        loukupbalace = Web3.toWei (lockupamoutn, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address2, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format (result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == Web3.toWei (100, 'ether'), "锁仓金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == True, "锁仓的状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == Web3.toWei (500, 'ether'), "欠释放锁仓金额:{} 有误".format (dict_Info['debt'])
Пример #22
0
    def test_morelockup_pledge(self):
        '''
        验证锁仓账户和释放到账账户为不同时锁仓质押扣费情况
        amount:质押金额
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list(self)
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)

        address1, private_key1 = CommonMethod.read_private_key_list()
        address2, private_key2 = CommonMethod.read_private_key_list()

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info is not None, "转账:{}失败".format(self.value)

        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address2), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)

        assert return_info is not None, "转账:{}失败".format(self.value)
        balance = platon_ppos.eth.getBalance(address1)
        log.info("发起锁仓账户余额:{}".format(balance))
        loukupbalace = Web3.toWei(900, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]

        #创建锁仓计划
        result = platon_ppos.CreateRestrictingPlan(
            address2,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓信息返回的状态:{},用例失败".format(
            result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        assert RestrictingInfo['Status'] == True, "创建锁仓信息返回的状态:{},用例失败".format(
            result['Status'])

        # 锁仓账号发起质押

        version = get_version(platon_ppos)
        result = platon_ppos.createStaking(1,
                                           address1,
                                           nodeId,
                                           'externalId',
                                           'nodeName',
                                           'website',
                                           'details',
                                           900,
                                           version,
                                           privatekey=private_key1,
                                           from_address=address1,
                                           gasPrice=self.base_gas_price,
                                           gas=self.staking_gas)
        assert result['Status'] == False, "创建锁仓信息返回的状态:{},用例失败".format(
            result['Status'])
Пример #23
0
    def test_lockup_entrust(self, amount):
        '''
        锁仓账户和释放到账账户为同一个时委托扣费验证
        :param amount:
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list(self)
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()
        address2, private_key2 = CommonMethod.read_private_key_list()
        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address2), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info1 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info1 is not None, "转账:{}失败".format(self.value)
        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info2 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info2 is not None, "转账:{}失败".format(self.value)
        balance1 = platon_ppos.eth.getBalance(address1)
        log.info("{}发起锁仓和质押的账户余额:{}".format(address1, balance1))
        balance = platon_ppos.eth.getBalance(address2)
        log.info("{}发起委托账户余额:{}".format(address2, balance))
        loukupbalace = Web3.toWei(300, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]

        # 创建锁仓计划
        result = platon_ppos.CreateRestrictingPlan(
            address2,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
            result['Status'])
        lockup_after = platon_ppos.eth.getBalance(conf.FOUNDATIONLOCKUPADDRESS)
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        info = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划可用余额:{}".format(info['balance']))
        balance2 = platon_ppos.eth.getBalance(address1)
        log.info("{}发起锁仓后账户余额:{}".format(address1, balance2))
        lock_balance1 = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("委托前锁仓合约地址余额:{}".format(lock_balance1))

        # 发起质押
        version = get_version(platon_ppos)
        result = platon_ppos.createStaking(0,
                                           address1,
                                           nodeId,
                                           'externalId',
                                           'nodeName',
                                           'website',
                                           'details',
                                           100,
                                           version,
                                           privatekey=private_key1,
                                           from_address=address1,
                                           gasPrice=self.base_gas_price,
                                           gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓信息返回的状态:{},用例失败".format(
            result['Status'])
        balance3 = platon_ppos.eth.getBalance(address1)
        log.info("{}发起质押后账户余额:{}".format(address1, balance3))
        staking_befor = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("委托前质押合约地址余额:{}".format(staking_befor))

        #委托金额小于锁仓金额发起委托
        if 0 < Web3.toWei(amount, 'ether') <= loukupbalace:
            log.info("委托金额:{}".format(Web3.toWei(amount, 'ether')))
            delegate_info = platon_ppos.delegate(1,
                                                 nodeId,
                                                 amount,
                                                 privatekey=private_key2,
                                                 from_address=address2,
                                                 gasPrice=self.base_gas_price,
                                                 gas=self.staking_gas)
            assert delegate_info[
                'Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format(
                    result['Status'])
            balance4 = platon_ppos.eth.getBalance(address2)
            log.info("{}发起委托后账户余额:{}".format(address2, balance4))
            #质押账户余额增加
            staking_after = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
            log.info("委托后质押合约地址余额:{}".format(staking_after))
            assert staking_after == staking_befor + Web3.toWei(
                amount, 'ether'), "质押账户余额:{}".format(staking_after)
            #锁仓合约地址余额减少
            lock_balance = platon_ppos.eth.getBalance(
                conf.FOUNDATIONLOCKUPADDRESS)
            log.info("委托后锁仓合约地址余额:{}".format(lock_balance))
            assert lock_balance == lockup_after - Web3.toWei(
                amount, 'ether'), "锁仓合约余额:{}".format(lock_balance)
        #委托金额大于锁仓金额发起委托
        else:
            delegate_info = platon_ppos.delegate(1,
                                                 nodeId,
                                                 amount,
                                                 privatekey=private_key2,
                                                 from_address=address2,
                                                 gasPrice=self.base_gas_price,
                                                 gas=self.staking_gas)
            assert delegate_info[
                'Status'] == False, "申请委托返回的状态:{},用例失败".format(
                    result['Status'])
Пример #24
0
    def test_morelockup_entrust(self):
        '''
        验证锁仓账户和释放到账账户为不同时锁仓委托扣费情况
        code:1、锁仓账户有余额支付委托手续费。
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list(self)
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()
        address2, private_key2 = CommonMethod.read_private_key_list()
        # 为质押和锁仓账户转账手续费
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info2 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info2 is not None, "转账:{}失败".format(self.value)
        #为委托账号转账手续费
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address2), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info1 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info1 is not None, "转账:{}失败".format(self.value)
        Balance = platon_ppos.eth.getBalance(address1)
        log.info("{}质押和锁仓账户:{}".format(address1, Balance))
        Balance1 = platon_ppos.eth.getBalance(address2)
        log.info("{}委托账号:{}".format(address2, Balance1))

        # 发起质押
        version = get_version(platon_ppos)
        result = platon_ppos.createStaking(0,
                                           address1,
                                           nodeId,
                                           'externalId',
                                           'nodeName',
                                           'website',
                                           'details',
                                           100,
                                           version,
                                           privatekey=private_key1,
                                           from_address=address1,
                                           gasPrice=self.base_gas_price,
                                           gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓信息返回的状态:{},用例失败".format(
            result['Status'])
        Balance2 = platon_ppos.eth.getBalance(address1)
        log.info("{}质押后账户余额:{}".format(address1, Balance2))

        # 创建锁仓计划
        loukupbalace = Web3.toWei(500, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan(
            address2,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
            result['Status'])
        # RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        # assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])
        Balance3 = platon_ppos.eth.getBalance(address1)
        log.info("{}创建锁仓后账户余额:{}".format(address1, Balance3))

        # 锁仓账号发起委托
        delegate_info = platon_ppos.delegate(1,
                                             nodeId,
                                             500,
                                             privatekey=private_key2,
                                             from_address=address2,
                                             gasPrice=self.base_gas_price,
                                             gas=self.staking_gas)
        assert delegate_info['Status'] == True, "申请委托返回的状态:{},用例失败".format(
            result['Status'])
        Balance4 = platon_ppos.eth.getBalance(address2)
        log.info("{}委托后账户余额:{}".format(address2, Balance4))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        info = json.loads(RestrictingInfo['Data'])
        assert info['balance'] == 0, "锁仓可用余额:{},有误".format(info['balance'])
Пример #25
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
    def test_unlock_point_pledge_punish_amount(self):
        '''
        到达解锁期后处罚节点后锁仓账户的余额情况
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list (self)
        log.info("质押节点ID:{}".format(nodeId))
        url = CommonMethod.link_list (self)
        platon_ppos = Ppos (url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list ()
        address2, private_key2 = CommonMethod.read_private_key_list ()

        # 给发起锁仓账户转手续费
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address1),
                                                   self.base_gas_price, self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账:{}失败".format (self.value)

        # 给发起质押账号转手续费
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address2),
                                                   self.base_gas_price, self.base_gas, self.value,
                                                   self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账:{}失败".format (self.value)

        Balance = platon_ppos.eth.getBalance (address1)
        log.info ("{}账户余额:{}".format (address1, Balance))
        Balance1 = platon_ppos.eth.getBalance (address1)
        log.info ("{}账号余额:{}".format (address2, Balance1))

        # 创建锁仓计划
        lockupamoutn = 900
        loukupbalace = Web3.toWei (lockupamoutn, 'ether')
        plan = [{'Epoch': 3, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address2, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format (result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])
        Balance2 = platon_ppos.eth.getBalance (address1)
        log.info ("{}发起锁仓后账户余额:{}".format (address1, Balance2))

        # 申请质押节点
        version = get_version (platon_ppos)
        amount = 900
        result = platon_ppos.createStaking (1, address2, nodeId, 'externalId', 'nodeName', 'website', 'details',
                                            amount, version, privatekey=private_key2, from_address=address2,
                                            gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},{},用例失败".format (result['Status'], result['ErrMsg'])
        platon_ppos.GetRestrictingInfo(address2)
        result = platon_ppos.getCandidateInfo(nodeId)
        assert result['Status'] == True, "获取质押节点返回状态为:{} 有误".format (result['Status'])
        RestrictingPlan = result['Data']['RestrictingPlanHes']
        assert RestrictingPlan == Web3.toWei (amount, 'ether'),'质押金额:{} 有误'.format(RestrictingPlan)
        Balance3 = platon_ppos.eth.getBalance (address2)
        log.info ("{}质押完锁仓账户余额:{}".format (address2,Balance3))

        #等待验证人加入共识出块节点
        CommonMethod.get_next_settlement_interval (self,1)
        Balance4 = platon_ppos.eth.getBalance (address2)
        log.info ("{}加入共识验证人后账户余额:{}".format (address2, Balance4))

        # 获取节点内置质押节点信息
        con_node, no_node = get_node_list (self.node_yml_path)
        nodes = con_node + no_node
        for node in nodes:
            if nodeId in node.values ():
                node_data = node
        log.info("{}质押节点信息:{}".format(address2,node_data))

        #停止质押节点
        self.auto = AutoDeployPlaton ()
        self.auto.kill (node_data)
        platon_ppos1 = connect_web3 (node_data['url'])
        assert not platon_ppos1.isConnected(),"节点:{} 连接异常".format(node_data['host'])

        # 到达解锁期后处罚节点后锁仓账户
        CommonMethod.get_next_settlement_interval (self,1)
        Balance5 = platon_ppos.eth.getBalance (address2)
        log.info ("{}到达解锁期后处罚节点后预期账户余额:{}".format (address2,Balance4 + Web3.toWei (amount-(amount * 0.2), 'ether')))
        log.info ("{}到达解锁期后处罚节点后实际账户余额:{}".format (address2,Balance5))
        result = platon_ppos.getCandidateInfo(nodeId)
        assert Balance5 == Balance4 + Web3.toWei (amount-(amount * 0.2), 'ether'), "锁仓账户金额:{} 有误".format (Balance4)
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        assert RestrictingInfo['Status'] == True, "获取锁仓计划返回状态为:{} 有误".format (result['Status'])
        dict_Info = json.loads (RestrictingInfo['Data'])
        assert dict_Info['balance'] == 0, "锁仓计划可用金额:{}有误".format (dict_Info['balance'])
        assert dict_Info['symbol'] == True, "欠释放状态:{} 有误".format (dict_Info['symbol'])
        assert dict_Info['debt'] == Web3.toWei (amount-(amount * 0.2), 'ether'), "欠释放锁仓金额:{} 有误".format (dict_Info['debt'])
    def test_eliminated_verifier_create_lockup(self):
        '''
        验证人违规被剔除验证人列表,申请质押节点
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list (self)
        url = CommonMethod.link_list (self)
        platon_ppos = Ppos (url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list ()

        # 签名转账
        result = platon_ppos.send_raw_transaction ('', Web3.toChecksumAddress (self.address),
                                                   Web3.toChecksumAddress (address1),
                                                   self.base_gas_price, self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt (result)
        assert return_info is not None, "转账:{}失败".format (self.value)

        balance = platon_ppos.eth.getBalance (address1)
        log.info ("{}发起锁仓账户余额:{}".format (address1,balance))

        # 创建锁仓计划
        lockupamoutn = 900
        loukupbalace = Web3.toWei (lockupamoutn, 'ether')
        plan = [{'Epoch': 5, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan (address1, plan, privatekey=private_key1,
                                                    from_address=address1, gasPrice=self.base_gas_price,
                                                    gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format (result['Status'])
        RestrictingInfo = platon_ppos.GetRestrictingInfo (address1)
        assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])

        # 申请质押节点
        version = get_version (platon_ppos)
        amount = 200
        result = platon_ppos.createStaking (1, address1, nodeId, 'externalId', 'nodeName', 'website', 'details',
                                            amount, version, privatekey=private_key1, from_address=address1,
                                            gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},{},用例失败".format (result['Status'], result['ErrMsg'])
        result = platon_ppos.getCandidateInfo(nodeId)
        log.info("质押节点信息:{}".format(result))

        # 等待成为共识验证人
        CommonMethod.get_next_settlement_interval (self)
        CandidateInfo = platon_ppos.getCandidateInfo(nodeId)
        log.info("验证人信息{}".format(CandidateInfo))
        VerifierList = platon_ppos.getVerifierList ()
        log.info ("当前验证人列表:{}".format (VerifierList))
        ValidatorList = platon_ppos.getValidatorList()
        log.info("当前共识验证人列表:{}".format(ValidatorList))



        # for dictinfo in CandidateInfo['Data']:
        #     if nodeId == dictinfo['NodeId']:
        #         log.info("节点id:{}已成为共识验证人".format(nodeId))
        #         break
        #     else:
        #         log.info("节点id:{}未成为共识验证人".format(nodeId))
        #         status=0
        #         assert status == 1

        # 获取节点内置质押节点信息
        con_node, no_node = get_node_list (self.node_yml_path)
        nodes = con_node + no_node
        for node in nodes:
            if nodeId in node.values ():
                node_data = node

        # 停止其中一个正在出块的节点信息
        self.auto = AutoDeployPlaton ()
        self.auto.kill (node_data)
        platon_ppos1 = connect_web3 (node_data['url'])
        assert not platon_ppos1.isConnected (), "节点:{} 连接异常".format (node_data['host'])

        # 等待节点被剔除验证人列表
        CommonMethod.get_next_consensus_wheel (self,2)

        # 申请质押节点
        version = get_version (platon_ppos)
        amount = 200
        result = platon_ppos.createStaking (1, address1, nodeId, 'externalId', 'nodeName', 'website', 'details',
                                            amount, version, privatekey=private_key1, from_address=address1,
                                            gasPrice=self.base_gas_price, gas=self.staking_gas)
        assert result['Status'] == False, "申请质押返回的状态:{},用例失败".format (result['Status'])
Пример #28
0
    def test_lockup_pledge(self, amount):
        '''
        验证锁仓账户和释放到账账户为同一个时锁仓质押扣费情况
        amount:质押金额
        :return:
        '''
        nodeId = CommonMethod.read_out_nodeId(self, 'nocollusion')
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)

        address1, private_key1 = CommonMethod.read_private_key_list()

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info is not None, "转账:{}失败".format(self.value)
        loukupbalace = Web3.toWei(900, 'ether')
        plan = [{'Epoch': 1, 'Amount': loukupbalace}]
        balance = platon_ppos.eth.getBalance(address1)
        log.info("锁仓账号余额:{}".format(balance))

        lockup_before = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("创建锁仓计划之前锁仓合约余额:{}".format(lockup_before))

        #创建锁仓计划
        result = platon_ppos.CreateRestrictingPlan(
            address1,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
            result['Status'])
        lockup_after = platon_ppos.eth.getBalance(conf.FOUNDATIONLOCKUPADDRESS)
        log.info("创建锁仓计划之后锁仓合约余额:{}".format(lockup_after))
        assert lockup_after == lockup_before + loukupbalace, "锁仓计划金额{}".format(
            lockup_after)
        staking_befor = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("发起验证人质押之前质押合约余额:{}".format(staking_befor))

        if 0 < Web3.toWei(amount, 'ether') <= loukupbalace:
            # 发起质押
            version = get_version(platon_ppos)
            result = platon_ppos.createStaking(1,
                                               address1,
                                               nodeId,
                                               'externalId',
                                               'nodeName',
                                               'website',
                                               'details',
                                               amount,
                                               version,
                                               privatekey=private_key1,
                                               from_address=address1,
                                               gasPrice=self.base_gas_price,
                                               gas=self.staking_gas)
            assert result['Status'] == True, "申请质押返回的状态:{},用例失败".format(
                result['Status'])

            #质押账户余额增加
            staking_after = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
            log.info("发起验证人质押之后质押合约余额:{}".format(staking_after))
            assert staking_after == staking_befor + Web3.toWei(
                amount, 'ether'), "质押账户余额:{}有误".format(staking_after)

            #锁仓合约地址余额减少
            lock_balance = platon_ppos.eth.getBalance(
                conf.FOUNDATIONLOCKUPADDRESS)
            log.info("发起验证人质押之后锁仓合约余额:{}".format(lock_balance))
            assert lock_balance == lockup_after - Web3.toWei(
                amount, 'ether'), "锁仓合约余额:{}有误".format(lock_balance)

            #发起锁仓账户余额减少手续费
            pledge_balance_after = platon_ppos.eth.getBalance(address1)
            log.info("锁仓账号余额:{}".format(pledge_balance_after))
            assert balance > pledge_balance_after, "发起锁仓账户余额减少{}手续费有误".format(
                address1)
            RestrictingInfo = platon_ppos.GetRestrictingInfo(address1)
            assert result['Status'] == True, "查询锁仓信息返回的状态:{},用例失败".format(
                result['Status'])

            #验证锁仓计划里的锁仓可用余额减少
            Info = json.loads(RestrictingInfo['Data'])
            assert loukupbalace == Info['balance'] + Web3.toWei(
                amount,
                'ether'), "查询{}锁仓余额失败".format(Info['balance'] +
                                              Web3.toWei(amount, 'ether'))

        else:
            # 发起质押
            version = get_version(platon_ppos)
            nodeId = CommonMethod.get_no_candidate_list(self)
            result = platon_ppos.createStaking(1,
                                               address1,
                                               nodeId,
                                               'externalId',
                                               'nodeName',
                                               'website',
                                               'details',
                                               amount,
                                               version,
                                               privatekey=private_key1,
                                               from_address=address1,
                                               gasPrice=self.base_gas_price,
                                               gas=self.staking_gas)
            assert result['Status'] == False, "创建锁仓信息返回的状态:{},用例失败".format(
                result['Status'])
 def testss(self):
     url = CommonMethod.link_list (self)
     platon_ppos = Ppos (url, self.address, self.chainid)
     while 1:
         block = platon_ppos.eth.blockNumber
         print(block)
Пример #30
0
    def test_lockup_Withdrawal_of_pledge(self):
        '''
        锁仓账户申请完质押后又退回质押金
        :return:
        '''
        nodeId = CommonMethod.get_no_candidate_list(self)
        url = CommonMethod.link_list(self)
        platon_ppos = Ppos(url, self.address, self.chainid)
        address1, private_key1 = CommonMethod.read_private_key_list()
        address2, private_key2 = CommonMethod.read_private_key_list()

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address1), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info2 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info2 is not None, "转账:{}失败".format(self.value)

        # 创建锁仓计划
        balance = platon_ppos.eth.getBalance(address1)
        log.info("发起锁仓账户余额:{}".format(balance))
        loukupbalace = Web3.toWei(800, 'ether')
        plan = [{'Epoch': 2, 'Amount': loukupbalace}]
        result = platon_ppos.CreateRestrictingPlan(
            address2,
            plan,
            privatekey=private_key1,
            from_address=address1,
            gasPrice=self.base_gas_price,
            gas=self.staking_gas)
        assert result['Status'] == True, "创建锁仓计划返回的状态:{},用例失败".format(
            result['Status'])
        # RestrictingInfo = platon_ppos.GetRestrictingInfo (address2)
        # assert RestrictingInfo['Status'] == True, "查询锁仓计划返回的状态:{},用例失败".format (result['Status'])

        lockup_before = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("申请质押节点之前锁仓账户金额:{}".format(lockup_before))
        Staking_before = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("申请质押节点之前Staking账户金额:{}".format(Staking_before))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        RestrictingInfo = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划可用余额:{}".format(RestrictingInfo['balance']))

        # 签名转账
        result = platon_ppos.send_raw_transaction(
            '', Web3.toChecksumAddress(self.address),
            Web3.toChecksumAddress(address2), self.base_gas_price,
            self.base_gas, self.value, self.privatekey)
        return_info2 = platon_ppos.eth.waitForTransactionReceipt(result)
        assert return_info2 is not None, "转账:{}失败".format(self.value)

        # 发起质押
        version = get_version(platon_ppos)
        amount = 800
        result = platon_ppos.createStaking(1,
                                           address2,
                                           nodeId,
                                           'externalId',
                                           'nodeName',
                                           'website',
                                           'details',
                                           amount,
                                           version,
                                           privatekey=private_key2,
                                           from_address=address2,
                                           gasPrice=self.base_gas_price,
                                           gas=self.staking_gas)
        assert result['Status'] == True, "申请质押返回的状态:{},用例失败".format(
            result['Status'])

        #查询每个账户余额
        CandidateInfo = platon_ppos.getCandidateInfo(nodeId)
        log.info("质押节点信息:{}".format(CandidateInfo))
        lockup_Back_before = platon_ppos.eth.getBalance(
            conf.FOUNDATIONLOCKUPADDRESS)
        log.info("退回质押金之前锁仓账户金额:{}".format(lockup_Back_before))
        Staking_Back_before = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("退回质押金之前Staking账户金额:{}".format(Staking_Back_before))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        RestrictingInfo = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划可用余额:{}".format(RestrictingInfo['balance']))

        #申请退回质押金
        result = platon_ppos.unStaking(nodeId,
                                       privatekey=private_key2,
                                       from_address=address2,
                                       gasPrice=self.base_gas_price,
                                       gas=self.staking_gas)
        assert result['Status'] == True, "申请质押退回质押金返回的状态:{},用例失败".format(
            result['Status'])
        lockup_end = platon_ppos.eth.getBalance(conf.FOUNDATIONLOCKUPADDRESS)
        log.info("退回质押金之后锁仓账户金额:{}".format(lockup_end))
        Staking_end = platon_ppos.eth.getBalance(conf.STAKINGADDRESS)
        log.info("退回质押金之后Staking账户金额:{}".format(Staking_end))
        RestrictingInfo = platon_ppos.GetRestrictingInfo(address2)
        RestrictingInfo = json.loads(RestrictingInfo['Data'])
        log.info("锁仓计划可用余额:{}".format(RestrictingInfo['balance']))
        assert lockup_end == lockup_before, "质押金退回后锁仓金额:{}有误".format(
            lockup_end)
        assert Staking_end == Staking_before, "质押金退回后Staking金额:{}有误".format(
            Staking_end)
        assert RestrictingInfo[
            'balance'] == loukupbalace, "锁仓计划金额:{}有误".format(
                RestrictingInfo['balance'])