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_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'])