github.com/platonnetwork/platon-go@v0.7.6/cases/tests/ppos/test_general_punishment.py (about) 1 import time 2 import pytest 3 import allure 4 from dacite import from_dict 5 from common.key import get_pub_key, mock_duplicate_sign, generate_key 6 from common.log import log 7 from client_sdk_python import Web3 8 from decimal import Decimal 9 10 from tests.conftest import get_clients_noconsensus 11 from tests.lib import EconomicConfig, Genesis, StakingConfig, Staking, check_node_in_list, assert_code, von_amount, \ 12 get_governable_parameter_value, Client, update_param_by_dict, get_param_by_dict 13 14 15 def get_out_block_penalty_parameters(client, node, amount_type): 16 # view Consensus Amount of pledge 17 candidate_info = client.ppos.getCandidateInfo(node.node_id) 18 log.info("Pledge node information: {}".format(candidate_info)) 19 pledge_amount1 = candidate_info['Ret'][amount_type] 20 # view block_reward 21 log.info("block: {}".format(node.eth.blockNumber)) 22 block_reward, staking_reward = client.economic.get_current_year_reward(node) 23 log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 24 # Get governable parameters 25 slash_blocks = get_governable_parameter_value(client, 'slashBlocksReward') 26 return pledge_amount1, block_reward, slash_blocks 27 28 29 def penalty_proportion_and_income(client): 30 # view Pledge amount 31 candidate_info1 = client.ppos.getCandidateInfo(client.node.node_id) 32 pledge_amount1 = candidate_info1['Ret']['Released'] 33 # view Parameter value before treatment 34 penalty_ratio = get_governable_parameter_value(client, 'slashFractionDuplicateSign') 35 proportion_ratio = get_governable_parameter_value(client, 'duplicateSignReportReward') 36 return pledge_amount1, int(penalty_ratio), int(proportion_ratio) 37 38 39 @pytest.fixture() 40 def client_new_node_obj_list_reset(global_test_env, staking_cfg): 41 """ 42 Get new node Client object list 43 """ 44 global_test_env.deploy_all() 45 yield get_clients_noconsensus(global_test_env, staking_cfg) 46 global_test_env.deploy_all() 47 48 49 def verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount, type): 50 log.info("Start stopping the current node :{} process".format(first_client.node.url)) 51 first_client.node.stop() 52 log.info("Start waiting for the end of the three consensus rounds") 53 second_client.economic.wait_consensus_blocknum(second_client.node, 3) 54 log.info("Current block height: {}".format(second_client.node.eth.blockNumber)) 55 verifier_list = second_client.ppos.getVerifierList() 56 log.info("Current billing cycle certifier list: {}".format(verifier_list)) 57 candidate_info = second_client.ppos.getCandidateInfo(first_client.node.node_id) 58 log.info("stopped pledge node information: {}".format(candidate_info)) 59 amount_after_punishment = candidate_info['Ret'][type] 60 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 61 log.info("Low block rate penalty amount: {}".format(punishment_amonut)) 62 if punishment_amonut < pledge_amount: 63 assert (amount_after_punishment == pledge_amount - punishment_amonut) or ( 64 amount_after_punishment == pledge_amount - punishment_amonut * 2), "ErrMsg:The pledge node is penalized after the amount {} is incorrect".format( 65 amount_after_punishment) 66 else: 67 assert amount_after_punishment == 0, "ErrMsg:The pledge node is penalized after the amount {} is incorrect".format( 68 amount_after_punishment) 69 70 71 def VP_GPFV_001_002(client_new_node_obj_list_reset): 72 """ 73 VP_GPFV_001:共识轮里一个节点出块两次,第一次出够10个块,第二次只出2个块 74 VP_GPFV_002:出块数大于0小于每轮出块数 75 :param client_new_node_obj_list_reset: 76 :return: 77 """ 78 first_client = client_new_node_obj_list_reset[0] 79 log.info("Current connection node:{}".format(first_client.node.node_mark)) 80 economic = first_client.economic 81 node = first_client.node 82 log.info("Start creating a pledge account Pledge_address") 83 Pledge_address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 84 log.info( 85 "Created, account address: {} Amount: {}".format(Pledge_address, von_amount(economic.create_staking_limit, 2))) 86 log.info("Start applying for a pledge node") 87 result = first_client.staking.create_staking(0, Pledge_address, Pledge_address) 88 assert_code(result, 0) 89 log.info("Apply for pledge node completion") 90 log.info("Waiting for the current billing cycle to end") 91 economic.wait_settlement_blocknum(node) 92 for i in range(4): 93 result = check_node_in_list(node.node_id, first_client.ppos.getValidatorList) 94 log.info("View current node in consensus list status:{}".format(result)) 95 if result: 96 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 97 economic.wait_consensus_blocknum(node, 3) 98 log.info("Waiting for the end of 3 consensus rounds") 99 block_num = economic.get_block_count_number(node, 5) 100 log.info("Get the number of outbound blocks in the 5 consensus rounds of the current pledge node:{}".format( 101 block_num)) 102 candidate_info = first_client.ppos.getCandidateInfo(node.node_id) 103 log.info("Pledged node information:{}".format(candidate_info)) 104 info = candidate_info['Ret'] 105 assert info['Released'] == economic.create_staking_limit, "ErrMsg:Pledged Amount {}".format( 106 info['Released']) 107 validator_list = first_client.ppos.getValidatorList() 108 log.info("validator_list: {}".format(validator_list)) 109 assert len(validator_list['Ret']) == 4, "ErrMsg: Number of verification {}".format(len(validator_list)) 110 else: 111 log.info("Waiting for the current consensus round of settlement") 112 economic.wait_consensus_blocknum(node) 113 114 115 @pytest.mark.P0 116 @pytest.mark.compatibility 117 def test_VP_GPFV_003(client_new_node_obj_list_reset): 118 """ 119 低出快率最高处罚标准 120 :param client_new_node_obj_list_reset: 121 :return: 122 """ 123 first_client = client_new_node_obj_list_reset[0] 124 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 125 second_client = client_new_node_obj_list_reset[1] 126 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 127 economic = first_client.economic 128 node = first_client.node 129 log.info("Start creating a pledge account address") 130 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 131 log.info("Start applying for a pledge node") 132 result = first_client.staking.create_staking(0, address, address) 133 assert_code(result, 0) 134 log.info("Pledge completed, waiting for the end of the current billing cycle") 135 economic.wait_settlement_blocknum(node) 136 log.info("Get the current pledge node amount and the low block rate penalty block number and the block reward") 137 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(first_client, node, 'Released') 138 log.info( 139 "Current node deposit amount: {} Current year block reward: {} Current low block rate penalty block: {}".format( 140 pledge_amount1, block_reward, slash_blocks)) 141 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 142 log.info("Start verification penalty amount") 143 verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount1, 'Released') 144 log.info("Check amount completed") 145 146 147 @pytest.mark.P0 148 def test_VP_GPFV_004(client_new_node_obj_list_reset): 149 """ 150 锁仓质押被惩罚最高处罚标准 151 :param client_new_node_obj_list_reset: 152 :return: 153 """ 154 first_client = client_new_node_obj_list_reset[0] 155 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 156 second_client = client_new_node_obj_list_reset[1] 157 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 158 economic = first_client.economic 159 node = first_client.node 160 # create account 161 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 162 # create Restricting Plan 163 amount = von_amount(economic.create_staking_limit, 1) 164 plan = [{'Epoch': 2, 'Amount': amount}] 165 result = first_client.restricting.createRestrictingPlan(address, plan, address) 166 assert_code(result, 0) 167 # create staking 168 result = first_client.staking.create_staking(1, address, address) 169 assert_code(result, 0) 170 # Wait for the settlement round to end 171 economic.wait_settlement_blocknum(node) 172 # get pledge amount1 and block reward 173 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(first_client, node, 'RestrictingPlan') 174 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 175 verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount1, 176 'RestrictingPlan') 177 log.info("Check amount completed") 178 179 180 @pytest.mark.P2 181 def test_VP_GPFV_005(client_new_node_obj_list_reset): 182 """ 183 锁仓增持/委托后被惩罚 184 :param client_new_node_obj_list_reset: 185 :return: 186 """ 187 first_client = client_new_node_obj_list_reset[0] 188 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 189 second_client = client_new_node_obj_list_reset[1] 190 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 191 economic = first_client.economic 192 node = first_client.node 193 # create account 194 pledge_address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 195 # create account 196 entrust_address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 1)) 197 # create Restricting Plan 198 amount1 = von_amount(economic.create_staking_limit, 2) 199 plan = [{'Epoch': 1, 'Amount': amount1}] 200 result = first_client.restricting.createRestrictingPlan(pledge_address, plan, pledge_address) 201 assert_code(result, 0) 202 # create Restricting Plan 203 amount2 = von_amount(economic.delegate_limit, 100) 204 plan = [{'Epoch': 1, 'Amount': amount2}] 205 result = first_client.restricting.createRestrictingPlan(entrust_address, plan, entrust_address) 206 assert_code(result, 0) 207 # create staking 208 result = first_client.staking.create_staking(1, pledge_address, pledge_address) 209 assert_code(result, 0) 210 # increase staking 211 result = first_client.staking.increase_staking(1, pledge_address) 212 assert_code(result, 0) 213 # Additional pledge 214 result = first_client.delegate.delegate(1, entrust_address, amount=von_amount(economic.delegate_limit, 100)) 215 assert_code(result, 0) 216 # Wait for the settlement round to end 217 economic.wait_settlement_blocknum(node) 218 # get pledge amount1 and block reward 219 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(first_client, node, 'RestrictingPlan') 220 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 221 verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount1, 222 'RestrictingPlan') 223 log.info("Check amount completed") 224 225 226 @pytest.mark.P2 227 def test_VP_GPFV_006(client_new_node_obj_list_reset): 228 """ 229 自由金额增持/委托后被惩罚 230 :param client_new_node_obj_list_reset: 231 :return: 232 """ 233 first_client = client_new_node_obj_list_reset[0] 234 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 235 second_client = client_new_node_obj_list_reset[1] 236 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 237 economic = first_client.economic 238 node = first_client.node 239 # create account 240 address1, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 241 # create account 242 address2, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 1)) 243 # create staking 244 result = first_client.staking.create_staking(0, address1, address1) 245 assert_code(result, 0) 246 # increase staking 247 result = first_client.staking.increase_staking(0, address1) 248 assert_code(result, 0) 249 # Additional pledge 250 result = first_client.delegate.delegate(0, address2, amount=von_amount(economic.delegate_limit, 100)) 251 assert_code(result, 0) 252 # Wait for the settlement round to end 253 economic.wait_settlement_blocknum(node) 254 # get pledge amount1 and block reward 255 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(first_client, node, 'Released') 256 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 257 verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount1, 'Released') 258 log.info("Check amount completed") 259 260 261 @pytest.mark.P2 262 def test_VP_GPFV_007(client_new_node_obj_list_reset): 263 """ 264 在被惩罚前退出质押 265 :param client_new_node_obj_list_reset: 266 :return: 267 """ 268 first_client = client_new_node_obj_list_reset[0] 269 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 270 second_client = client_new_node_obj_list_reset[1] 271 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 272 economic = first_client.economic 273 node = first_client.node 274 # create account 275 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 276 # create staking 277 result = first_client.staking.create_staking(0, address, address) 278 assert_code(result, 0) 279 # Wait for the settlement round to end 280 economic.wait_settlement_blocknum(node) 281 # get pledge amount1 and block reward 282 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(first_client, node, 'Released') 283 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 284 verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount1, 'Released') 285 log.info("Check amount completed") 286 287 288 @pytest.mark.P2 289 def test_VP_GPFV_008(client_new_node_obj_list_reset): 290 """ 291 被处罚前进行增持 292 :param client_new_node_obj_list_reset: 293 :return: 294 """ 295 first_client = client_new_node_obj_list_reset[0] 296 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 297 second_client = client_new_node_obj_list_reset[1] 298 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 299 economic = first_client.economic 300 node = first_client.node 301 # create account 302 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 303 # create staking 304 result = first_client.staking.create_staking(0, address, address) 305 assert_code(result, 0) 306 # Wait for the settlement round to end 307 economic.wait_settlement_blocknum(node) 308 # get pledge amount1 and block reward 309 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(first_client, node, 'Released') 310 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 311 verify_low_block_rate_penalty(first_client, second_client, block_reward, slash_blocks, pledge_amount1, 'Released') 312 log.info("Check amount completed") 313 314 315 def test_VP_GPFV_009(client_new_node_obj_list_reset): 316 """ 317 节点被处罚后马上重新质押(高惩罚) 318 :param client_new_node_obj_list_reset: 319 :return: 320 """ 321 first_client = client_new_node_obj_list_reset[0] 322 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 323 second_client = client_new_node_obj_list_reset[1] 324 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 325 economic = first_client.economic 326 node = first_client.node 327 program_version = node.program_version 328 program_version_sign = node.program_version_sign 329 bls_pubkey = node.blspubkey 330 bls_proof = node.schnorr_NIZK_prove 331 # create account 332 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 333 # create staking 334 result = first_client.staking.create_staking(0, address, address) 335 assert_code(result, 0) 336 # Wait for the settlement round to end 337 economic.wait_settlement_blocknum(node) 338 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 339 # stop node 340 node.stop() 341 # Waiting for a settlement round 342 second_client.economic.wait_consensus_blocknum(second_client.node, 3) 343 log.info("Current block height: {}".format(second_client.node.eth.blockNumber)) 344 # create staking again 345 result = second_client.staking.create_staking(0, address, address, node_id=node.node_id, 346 program_version=program_version, 347 program_version_sign=program_version_sign, bls_pubkey=bls_pubkey, 348 bls_proof=bls_proof) 349 assert_code(result, 301101) 350 351 352 @pytest.mark.P2 353 def test_VP_GPFV_010(client_new_node_obj_list_reset): 354 """ 355 节点被处罚后马上重新增持质押(高惩罚) 356 :param client_new_node_obj_list_reset: 357 :return: 358 """ 359 client1 = client_new_node_obj_list_reset[0] 360 log.info("Current connection node1: {}".format(client1.node.node_mark)) 361 client2 = client_new_node_obj_list_reset[1] 362 log.info("Current connection node2: {}".format(client2.node.node_mark)) 363 economic = client1.economic 364 node = client1.node 365 # create account 366 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 367 # create staking 368 result = client1.staking.create_staking(0, address, address) 369 assert_code(result, 0) 370 # Wait for the settlement round to end 371 economic.wait_settlement_blocknum(node) 372 # stop node 373 client1.node.stop() 374 # Waiting for a settlement round 375 client2.economic.wait_consensus_blocknum(client2.node, 3) 376 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 377 # Additional pledge 378 result = client2.staking.increase_staking(0, address, node_id=node.node_id) 379 assert_code(result, 301103) 380 381 382 @pytest.mark.P2 383 def test_VP_GPFV_011(client_new_node_obj_list_reset): 384 """ 385 先低出块率再双签 386 :param client_new_node_obj_list_reset: 387 :return: 388 """ 389 client1 = client_new_node_obj_list_reset[0] 390 log.info("Current connection node1: {}".format(client1.node.node_mark)) 391 client2 = client_new_node_obj_list_reset[1] 392 log.info("Current connection node2: {}".format(client2.node.node_mark)) 393 economic = client1.economic 394 node = client1.node 395 # create account 396 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 397 # create account 398 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 399 # create staking 400 result = client1.staking.create_staking(0, address, address) 401 assert_code(result, 0) 402 # Wait for the settlement round to end 403 economic.wait_settlement_blocknum(node) 404 # get pledge amount1 and block reward 405 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(client1, node, 'Released') 406 for i in range(4): 407 result = check_node_in_list(node.node_id, client2.ppos.getValidatorList) 408 log.info("Current node in consensus list status:{}".format(result)) 409 if result: 410 # stop node 411 client1.node.stop() 412 report_block = client2.node.eth.blockNumber 413 log.info("Current block height: {}".format(report_block)) 414 # view Parameter value before treatment 415 penalty_ratio = get_governable_parameter_value(client2, 'slashFractionDuplicateSign') 416 proportion_ratio = get_governable_parameter_value(client2, 'duplicateSignReportReward') 417 # view Amount of penalty 418 proportion_reward, incentive_pool_reward = economic.get_report_reward(pledge_amount1, int(penalty_ratio), 419 int(proportion_ratio)) 420 # Obtain evidence of violation 421 report_information = mock_duplicate_sign(1, client1.node.nodekey, client1.node.blsprikey, report_block) 422 log.info("Report information: {}".format(report_information)) 423 result = client2.duplicatesign.reportDuplicateSign(1, report_information, report_address) 424 assert_code(result, 0) 425 # Query pledge node information: 426 candidate_info = client2.ppos.getCandidateInfo(node.node_id) 427 log.info("pledge node information: {}".format(candidate_info)) 428 info = candidate_info['Ret'] 429 # block_penalty = Decimal(str(block_reward)) * Decimal(str(slash_blocks)) 430 duplicateSign_penalty = proportion_reward + incentive_pool_reward 431 # total_punish = block_penalty + duplicateSign_penalty 432 assert info['Released'] == pledge_amount1 - duplicateSign_penalty, "ErrMsg:pledge node account {}".format( 433 info['Released']) 434 break 435 else: 436 # wait consensus block 437 economic.wait_consensus_blocknum(node) 438 439 440 @pytest.mark.P2 441 def test_VP_GPFV_012(client_new_node_obj_list_reset): 442 """ 443 先双签再低出块率 444 :param client_new_node_obj_list_reset: 445 :return: 446 """ 447 first_client = client_new_node_obj_list_reset[0] 448 log.info("Current connection node1: {}".format(first_client.node.node_mark)) 449 second_client = client_new_node_obj_list_reset[1] 450 log.info("Current connection node2: {}".format(second_client.node.node_mark)) 451 economic = first_client.economic 452 node = first_client.node 453 # create account1 454 pledge_address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 455 # create account2 456 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 457 # create staking 458 result = first_client.staking.create_staking(0, pledge_address, pledge_address) 459 assert_code(result, 0) 460 # Wait for the settlement round to end 461 economic.wait_settlement_blocknum(node) 462 for i in range(4): 463 result = check_node_in_list(node.node_id, first_client.ppos.getValidatorList) 464 log.info("Current node in consensus list status:{}".format(result)) 465 if result: 466 # Query current block height 467 report_block = first_client.node.eth.blockNumber 468 log.info("Current block height: {}".format(report_block)) 469 # Obtain penalty proportion and income 470 pledge_amount1, penalty_ratio, proportion_ratio = penalty_proportion_and_income(first_client) 471 # view Amount of penalty 472 proportion_reward, incentive_pool_reward = economic.get_report_reward(pledge_amount1, penalty_ratio, 473 proportion_ratio) 474 # Obtain evidence of violation 475 report_information = mock_duplicate_sign(1, first_client.node.nodekey, first_client.node.blsprikey, 476 report_block) 477 log.info("Report information: {}".format(report_information)) 478 result = second_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 479 assert_code(result, 0) 480 # Waiting for a consensus round 481 second_client.economic.wait_consensus_blocknum(second_client.node) 482 # stop node 483 first_client.node.stop() 484 # Waiting for 2 consensus round 485 second_client.economic.wait_consensus_blocknum(second_client.node, 3) 486 # view block_reward 487 block_reward, staking_reward = second_client.economic.get_current_year_reward(second_client.node) 488 log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 489 # Query pledge node information: 490 candidate_info = second_client.ppos.getCandidateInfo(node.node_id) 491 log.info("pledge node information: {}".format(candidate_info)) 492 info = candidate_info['Ret'] 493 duplicateSign_penalty = proportion_reward + incentive_pool_reward 494 assert info['Released'] == pledge_amount1 - duplicateSign_penalty, "ErrMsg:pledge node account {}".format( 495 info['Released']) 496 break 497 else: 498 # wait consensus block 499 economic.wait_consensus_blocknum(node) 500 501 502 @pytest.mark.P2 503 def test_VP_GPFV_013(new_genesis_env, clients_consensus): 504 """ 505 验证人被处罚后质押金=>创建验证人的最小质押门槛金额K 506 :param new_genesis_env: 507 :param new_genesis_env: 508 :return: 509 """ 510 # Change configuration parameters 511 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 512 genesis.economicModel.slashing.slashBlocksReward = 5 513 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 514 genesis.to_file(new_file) 515 new_genesis_env.deploy_all(new_file) 516 517 client1 = clients_consensus[0] 518 log.info("Current connection node1: {}".format(client1.node.node_mark)) 519 client2 = clients_consensus[1] 520 log.info("Current connection node2: {}".format(client2.node.node_mark)) 521 economic = client1.economic 522 node = client1.node 523 # Wait for the consensus round to end 524 economic.wait_consensus_blocknum(node, 1) 525 # get pledge amount1 and block reward 526 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(client1, node, 'Released') 527 log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 528 # stop node 529 client1.node.stop() 530 # Waiting for a 3 consensus round 531 client2.economic.wait_consensus_blocknum(client2.node, 3) 532 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 533 # view verifier list 534 verifier_list = client2.ppos.getVerifierList() 535 log.info("verifier_list: {}".format(verifier_list)) 536 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 537 log.info("Pledge node information: {}".format(candidate_info)) 538 pledge_amount2 = candidate_info['Ret']['Released'] 539 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 540 log.info("punishment_amonut: {}".format(punishment_amonut)) 541 assert pledge_amount2 == pledge_amount1 - punishment_amonut * 2, "ErrMsg:Consensus Amount of pledge {}".format( 542 pledge_amount2) 543 544 545 @pytest.mark.P2 546 def test_VP_GPFV_014(new_genesis_env, clients_noconsensus): 547 """ 548 低出块率被最高处罚金低于质押金额(自由金额质押) 549 :param new_genesis_env: 550 :param new_genesis_env: 551 :return: 552 """ 553 # Change configuration parameters 554 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 555 genesis.economicModel.slashing.slashBlocksReward = 5 556 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 557 genesis.to_file(new_file) 558 new_genesis_env.deploy_all(new_file) 559 560 client1 = clients_noconsensus[0] 561 log.info("Current connection node1: {}".format(client1.node.node_mark)) 562 client2 = clients_noconsensus[1] 563 log.info("Current connection node2: {}".format(client2.node.node_mark)) 564 economic = client1.economic 565 node = client1.node 566 # create account 567 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 568 # create Restricting Plan 569 amount = economic.create_staking_limit 570 plan = [{'Epoch': 1, 'Amount': amount}] 571 result = client1.restricting.createRestrictingPlan(address, plan, address) 572 assert_code(result, 0) 573 # create staking 574 result = client1.staking.create_staking(0, address, address) 575 assert_code(result, 0) 576 # increase staking 577 increase_amount = von_amount(economic.create_staking_limit, 0.5) 578 result = client1.staking.increase_staking(1, address, amount=increase_amount) 579 assert_code(result, 0) 580 # Wait for the settlement round to end 581 economic.wait_settlement_blocknum(node) 582 # get pledge amount1 and block reward 583 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(client1, node, 'Released') 584 log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 585 # stop node 586 client1.node.stop() 587 # Waiting for a settlement round 588 client2.economic.wait_consensus_blocknum(client2.node, 3) 589 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 590 # view verifier list 591 verifier_list = client2.ppos.getVerifierList() 592 log.info("verifier_list: {}".format(verifier_list)) 593 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 594 log.info("Pledge node information: {}".format(candidate_info)) 595 info = candidate_info['Ret'] 596 pledge_amount2 = info['Released'] 597 pledge_amount3 = info['RestrictingPlan'] 598 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 599 log.info("punishment_amonut: {}".format(punishment_amonut)) 600 assert (pledge_amount2 == pledge_amount1 - punishment_amonut * 2) or ( 601 pledge_amount2 == pledge_amount1 - punishment_amonut), "ErrMsg:Pledge Released {}".format( 602 pledge_amount2) 603 assert pledge_amount3 == increase_amount, "ErrMsg:Pledge RestrictingPlan {}".format(pledge_amount3) 604 605 606 # @pytest.mark.P2 607 # def test_VP_GPFV_015(new_genesis_env, clients_noconsensus): 608 # """ 609 # 低出块率被最高处罚金等于于自由处罚金(自由金额质押) 610 # :param new_genesis_env: 611 # :return: 612 # """ 613 # # Change configuration parameters 614 # genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 615 # genesis.economicModel.slashing.slashBlocksReward = 13 616 # new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 617 # genesis.to_file(new_file) 618 # new_genesis_env.deploy_all(new_file) 619 # 620 # client1 = clients_noconsensus[0] 621 # log.info("Current connection node1: {}".format(client1.node.node_mark)) 622 # client2 = clients_noconsensus[1] 623 # log.info("Current connection node2: {}".format(client2.node.node_mark)) 624 # economic = client1.economic 625 # node = client1.node 626 # # create account 627 # address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 4)) 628 # # create Restricting Plan 629 # amount = economic.create_staking_limit 630 # plan = [{'Epoch': 1, 'Amount': amount}] 631 # result = client1.restricting.createRestrictingPlan(address, plan, address) 632 # assert_code(result, 0) 633 # # view block_reward 634 # block_reward, staking_reward = client1.economic.get_current_year_reward(node) 635 # log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 636 # # Get governable parameters 637 # slash_blocks = get_governable_parameter_value(client1, 'slashBlocksReward') 638 # # create staking 639 # staking_amount = int(Decimal(str(block_reward)) * Decimal(slash_blocks)) 640 # result = client1.staking.create_staking(0, address, address, amount=staking_amount * 2) 641 # assert_code(result, 0) 642 # # increase staking 643 # increase_amount = von_amount(economic.create_staking_limit, 0.5) 644 # result = client1.staking.increase_staking(1, address, amount=increase_amount) 645 # assert_code(result, 0) 646 # # Wait for the settlement round to end 647 # economic.wait_settlement_blocknum(node) 648 # # view Consensus Amount of pledge 649 # candidate_info = client1.ppos.getCandidateInfo(node.node_id) 650 # log.info("Pledge node information: {}".format(candidate_info)) 651 # pledge_amount1 = candidate_info['Ret']['Released'] 652 # log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 653 # # stop node 654 # client1.node.stop() 655 # # Waiting for a settlement round 656 # client2.economic.wait_consensus_blocknum(client2.node, 3) 657 # log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 658 # # view verifier list 659 # verifier_list = client2.ppos.getVerifierList() 660 # log.info("verifier_list: {}".format(verifier_list)) 661 # candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 662 # log.info("Pledge node information: {}".format(candidate_info)) 663 # info = candidate_info['Ret'] 664 # pledge_amount2 = info['Released'] 665 # pledge_amount3 = info['RestrictingPlan'] 666 # punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 667 # assert pledge_amount2 == pledge_amount1 - punishment_amonut * 2, "ErrMsg:Pledge Released {}".format( 668 # pledge_amount2) 669 # assert pledge_amount3 == increase_amount, "ErrMsg:Pledge RestrictingPlan {}".format(pledge_amount3) 670 671 @pytest.mark.P2 672 def test_VP_GPFV_016(new_genesis_env, clients_noconsensus): 673 """ 674 低出块率被最高处罚金大于自由处罚金(自由金额质押) 675 :param new_genesis_env: 676 :return: 677 """ 678 # Change configuration parameters 679 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 680 genesis.economicModel.slashing.slashBlocksReward = 30 681 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 682 genesis.to_file(new_file) 683 new_genesis_env.deploy_all(new_file) 684 685 client1 = clients_noconsensus[0] 686 log.info("Current connection node1: {}".format(client1.node.node_mark)) 687 client2 = clients_noconsensus[1] 688 log.info("Current connection node2: {}".format(client2.node.node_mark)) 689 economic = client1.economic 690 node = client1.node 691 # create account 692 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 4)) 693 # create Restricting Plan 694 amount = economic.create_staking_limit 695 plan = [{'Epoch': 1, 'Amount': amount}] 696 result = client1.restricting.createRestrictingPlan(address, plan, address) 697 assert_code(result, 0) 698 # view block_reward 699 block_reward, staking_reward = client1.economic.get_current_year_reward(node) 700 log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 701 # Get governable parameters 702 slash_blocks = get_governable_parameter_value(client1, 'slashBlocksReward') 703 # create staking 704 staking_amount = von_amount(economic.create_staking_limit, 2) 705 result = client1.staking.create_staking(0, address, address, amount=staking_amount) 706 assert_code(result, 0) 707 # increase staking 708 increase_amount = von_amount(economic.create_staking_limit, 0.5) 709 result = client1.staking.increase_staking(1, address, amount=increase_amount) 710 assert_code(result, 0) 711 # Wait for the settlement round to end 712 economic.wait_settlement_blocknum(node) 713 # view Consensus Amount of pledge 714 candidate_info = client1.ppos.getCandidateInfo(node.node_id) 715 log.info("Pledge node information: {}".format(candidate_info)) 716 pledge_amount1 = candidate_info['Ret']['Released'] 717 log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 718 # stop node 719 client1.node.stop() 720 # Waiting for a settlement round 721 client2.economic.wait_consensus_blocknum(client2.node, 3) 722 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 723 # view verifier list 724 verifier_list = client2.ppos.getVerifierList() 725 log.info("verifier_list: {}".format(verifier_list)) 726 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 727 log.info("Pledge node information: {}".format(candidate_info)) 728 info = candidate_info['Ret'] 729 pledge_amount2 = info['Released'] 730 pledge_amount3 = info['RestrictingPlan'] 731 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 732 log.info("punishment_amonut: {}".format(punishment_amonut)) 733 assert (pledge_amount2 == 0) or ( 734 pledge_amount2 == pledge_amount1 - punishment_amonut), "ErrMsg:Pledge Released {}".format( 735 pledge_amount2) 736 assert (pledge_amount3 == increase_amount - (punishment_amonut * 2 - pledge_amount1)) or ( 737 pledge_amount3 == 0), "ErrMsg:Pledge RestrictingPlan {}".format(pledge_amount3) 738 739 740 @pytest.mark.P2 741 def test_VP_GPFV_017(new_genesis_env, clients_noconsensus): 742 """ 743 低出块率被最高处罚金低于质押金额(锁仓金额质押) 744 :param new_genesis_env: 745 :return: 746 """ 747 # Change configuration parameters 748 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 749 genesis.economicModel.slashing.slashBlocksReward = 10 750 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 751 genesis.to_file(new_file) 752 new_genesis_env.deploy_all(new_file) 753 754 client1 = clients_noconsensus[0] 755 log.info("Current connection node1: {}".format(client1.node.node_mark)) 756 client2 = clients_noconsensus[1] 757 log.info("Current connection node2: {}".format(client2.node.node_mark)) 758 economic = client1.economic 759 node = client1.node 760 # create account 761 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 762 # create Restricting Plan 763 amount = economic.create_staking_limit 764 plan = [{'Epoch': 1, 'Amount': amount}] 765 result = client1.restricting.createRestrictingPlan(address, plan, address) 766 assert_code(result, 0) 767 # create staking 768 result = client1.staking.create_staking(1, address, address) 769 assert_code(result, 0) 770 # increase staking 771 increase_amount = von_amount(economic.create_staking_limit, 0.5) 772 result = client1.staking.increase_staking(0, address, amount=increase_amount) 773 assert_code(result, 0) 774 # Wait for the settlement round to end 775 economic.wait_settlement_blocknum(node) 776 # get pledge amount1 and block reward 777 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(client1, node, 'Released') 778 log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 779 # stop node 780 client1.node.stop() 781 # Waiting for a settlement round 782 client2.economic.wait_consensus_blocknum(client2.node, 3) 783 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 784 # view verifier list 785 verifier_list = client2.ppos.getVerifierList() 786 log.info("verifier_list: {}".format(verifier_list)) 787 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 788 log.info("Pledge node information: {}".format(candidate_info)) 789 info = candidate_info['Ret'] 790 pledge_amount2 = info['Released'] 791 pledge_amount3 = info['RestrictingPlan'] 792 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 793 log.info("punishment_amonut: {}".format(punishment_amonut)) 794 assert pledge_amount2 == 0, "ErrMsg:Pledge Released {}".format( 795 pledge_amount2) 796 assert pledge_amount3 == economic.create_staking_limit - ( 797 punishment_amonut * 2 - increase_amount), "ErrMsg:Pledge RestrictingPlan {}".format(pledge_amount3) 798 799 800 # 801 # @pytest.mark.P2 802 # def test_VP_GPFV_018(new_genesis_env, clients_noconsensus): 803 # """ 804 # 低出块率被最高处罚金等于质押金额(锁仓金额质押) 805 # :param new_genesis_env: 806 # :return: 807 # """ 808 # # Change configuration parameters 809 # genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 810 # genesis.economicModel.slashing.slashBlocksReward = 13 811 # new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 812 # genesis.to_file(new_file) 813 # new_genesis_env.deploy_all(new_file) 814 # 815 # client1 = clients_noconsensus[0] 816 # log.info("Current connection node1: {}".format(client1.node.node_mark)) 817 # client2 = clients_noconsensus[1] 818 # log.info("Current connection node2: {}".format(client2.node.node_mark)) 819 # economic = client1.economic 820 # node = client1.node 821 # # create account 822 # address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 4)) 823 # # create Restricting Plan 824 # amount = von_amount(economic.create_staking_limit, 3) 825 # plan = [{'Epoch': 1, 'Amount': amount}] 826 # result = client1.restricting.createRestrictingPlan(address, plan, address) 827 # assert_code(result, 0) 828 # # view block_reward 829 # block_reward, staking_reward = client1.economic.get_current_year_reward(node) 830 # log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 831 # # Get governable parameters 832 # slash_blocks = get_governable_parameter_value(client1, 'slashBlocksReward') 833 # # create staking 834 # staking_amount = von_amount(block_reward, 26) 835 # log.info("staking_amount: {}".format(staking_amount)) 836 # result = client1.staking.create_staking(1, address, address, amount=staking_amount) 837 # assert_code(result, 0) 838 # # increase staking 839 # increase_amount = von_amount(economic.create_staking_limit, 0.5) 840 # result = client1.staking.increase_staking(0, address, amount=increase_amount) 841 # assert_code(result, 0) 842 # # Wait for the settlement round to end 843 # economic.wait_settlement_blocknum(node) 844 # # view Consensus Amount of pledge 845 # candidate_info = client1.ppos.getCandidateInfo(node.node_id) 846 # log.info("Pledge node information: {}".format(candidate_info)) 847 # pledge_amount1 = candidate_info['Ret']['Released'] 848 # log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 849 # # stop node 850 # client1.node.stop() 851 # # Waiting for a settlement round 852 # client2.economic.wait_consensus_blocknum(client2.node, 3) 853 # log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 854 # # view verifier list 855 # verifier_list = client2.ppos.getVerifierList() 856 # log.info("verifier_list: {}".format(verifier_list)) 857 # candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 858 # log.info("Pledge node information: {}".format(candidate_info)) 859 # info = candidate_info['Ret'] 860 # pledge_amount2 = info['Released'] 861 # pledge_amount3 = info['RestrictingPlan'] 862 # punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 863 # log.info("punishment_amonut: {}".format(punishment_amonut)) 864 # assert pledge_amount2 == 0, "ErrMsg:Pledge Released {}".format(pledge_amount2) 865 # assert (pledge_amount3 == staking_amount - (von_amount(punishment_amonut, 2) - increase_amount)) or ( 866 # pledge_amount3 == staking_amount - ( 867 # punishment_amonut - increase_amount)), "ErrMsg:Pledge RestrictingPlan {}".format(pledge_amount3) 868 869 870 @pytest.mark.P2 871 def test_VP_GPFV_019(new_genesis_env, clients_noconsensus): 872 """ 873 低出块率被最高处罚金大于质押金额(锁仓金额质押) 874 :param new_genesis_env: 875 :param clients_noconsensus: 876 :return: 877 """ 878 # Change configuration parameters 879 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 880 genesis.economicModel.slashing.slashBlocksReward = 25 881 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 882 genesis.to_file(new_file) 883 new_genesis_env.deploy_all(new_file) 884 885 client1 = clients_noconsensus[0] 886 log.info("Current connection node1: {}".format(client1.node.node_mark)) 887 client2 = clients_noconsensus[1] 888 log.info("Current connection node2: {}".format(client2.node.node_mark)) 889 economic = client1.economic 890 node = client1.node 891 # create account 892 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 4)) 893 # create Restricting Plan 894 amount = von_amount(economic.create_staking_limit, 2) 895 plan = [{'Epoch': 1, 'Amount': amount}] 896 result = client1.restricting.createRestrictingPlan(address, plan, address) 897 assert_code(result, 0) 898 # Get governable parameters 899 slash_blocks = get_governable_parameter_value(client1, 'slashBlocksReward') 900 # create staking 901 result = client1.staking.create_staking(1, address, address, amount=amount) 902 assert_code(result, 0) 903 # increase staking 904 increase_amount = von_amount(economic.create_staking_limit, 0.5) 905 result = client1.staking.increase_staking(0, address, amount=increase_amount) 906 assert_code(result, 0) 907 # Wait for the settlement round to end 908 economic.wait_settlement_blocknum(node) 909 # view Consensus Amount of pledge 910 candidate_info = client1.ppos.getCandidateInfo(node.node_id) 911 log.info("Pledge node information: {}".format(candidate_info)) 912 pledge_amount1 = candidate_info['Ret']['Released'] 913 log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 914 # view block_reward 915 block_reward, staking_reward = client1.economic.get_current_year_reward(node) 916 log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 917 # stop node 918 client1.node.stop() 919 # Waiting for a settlement round 920 client2.economic.wait_consensus_blocknum(client2.node, 3) 921 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 922 # view verifier list 923 verifier_list = client2.ppos.getVerifierList() 924 log.info("verifier_list: {}".format(verifier_list)) 925 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 926 log.info("Pledge node information: {}".format(candidate_info)) 927 info = candidate_info['Ret'] 928 pledge_amount2 = info['Released'] 929 pledge_amount3 = info['RestrictingPlan'] 930 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 931 log.info("punishment_amonut: {}".format(punishment_amonut)) 932 assert pledge_amount2 == 0, "ErrMsg:Pledge Released {}".format(pledge_amount2) 933 assert (pledge_amount3 == amount - (punishment_amonut * 2 - pledge_amount1)) or (pledge_amount3 == amount - ( 934 punishment_amonut - pledge_amount1)), "ErrMsg:Pledge RestrictingPlan {}".format(pledge_amount3) 935 936 937 @pytest.mark.P2 938 def test_VP_GPFV_020(new_genesis_env, clients_noconsensus): 939 """ 940 移出PlatON验证人与候选人名单,(扣除以后剩余自有质押金),未申请退回质押金 941 :param clients_noconsensus: 942 :return: 943 """ 944 # Change configuration parameters 945 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 946 genesis.economicModel.slashing.slashBlocksReward = 5 947 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 948 genesis.to_file(new_file) 949 new_genesis_env.deploy_all(new_file) 950 951 client1 = clients_noconsensus[0] 952 log.info("Current connection node1: {}".format(client1.node.node_mark)) 953 client2 = clients_noconsensus[1] 954 log.info("Current connection node2: {}".format(client2.node.node_mark)) 955 economic = client1.economic 956 node = client1.node 957 # create account 958 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 959 address1, _ = economic.account.generate_account(node.web3, 0) 960 # create staking 961 result = client1.staking.create_staking(0, address1, address) 962 assert_code(result, 0) 963 # Wait for the settlement round to end 964 economic.wait_settlement_blocknum(node) 965 # get pledge amount1 and block reward 966 pledge_amount1, block_reward, slash_blocks = get_out_block_penalty_parameters(client1, node, 'Released') 967 log.info("Current block height: {}".format(client1.node.eth.blockNumber)) 968 # stop node 969 client1.node.stop() 970 # Waiting for a settlement round 971 client2.economic.wait_consensus_blocknum(client2.node, 3) 972 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 973 # view verifier list 974 verifier_list = client2.ppos.getVerifierList() 975 log.info("verifier_list: {}".format(verifier_list)) 976 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 977 log.info("Pledge node information: {}".format(candidate_info)) 978 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 979 log.info("punishment_amonut: {}".format(punishment_amonut)) 980 # Query pledge account balance 981 balance1 = client2.node.eth.getBalance(address) 982 log.info("pledge account balance: {}".format(balance1)) 983 # Wait for the 2 settlement round to end 984 economic.wait_settlement_blocknum(client2.node, 2) 985 # Query pledge account balance 986 balance2 = client2.node.eth.getBalance(address) 987 log.info("pledge account balance: {}".format(balance2)) 988 assert balance2 == balance1 + (pledge_amount1 - punishment_amonut * 2), "ErrMsg:pledge account balance {}".format( 989 balance2) 990 991 992 @pytest.mark.P2 993 def test_VP_GPFV_021(client_new_node_obj_list_reset): 994 """ 995 移出PlatON验证人与候选人名单,委托人可在处罚所在结算周期,申请赎回全部委托金 996 :param client_new_node_obj_list_reset: 997 :return: 998 """ 999 client1 = client_new_node_obj_list_reset[0] 1000 log.info("Current connection node1: {}".format(client1.node.node_mark)) 1001 client2 = client_new_node_obj_list_reset[1] 1002 log.info("Current connection node2: {}".format(client2.node.node_mark)) 1003 economic = client1.economic 1004 node = client1.node 1005 # create pledge address 1006 pledge_address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 3)) 1007 # create report address 1008 delegate_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 1009 # create staking 1010 result = client1.staking.create_staking(0, pledge_address, pledge_address) 1011 assert_code(result, 0) 1012 # Additional pledge 1013 result = client1.delegate.delegate(0, delegate_address) 1014 assert_code(result, 0) 1015 # Wait for the settlement round to end 1016 economic.wait_settlement_blocknum(node) 1017 # stop node 1018 client1.node.stop() 1019 # Waiting for a settlement round 1020 client2.economic.wait_consensus_blocknum(client2.node, 3) 1021 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 1022 # view verifier list 1023 verifier_list = client2.ppos.getVerifierList() 1024 log.info("verifier_list: {}".format(verifier_list)) 1025 candidate_info = client2.ppos.getCandidateInfo(client1.node.node_id) 1026 log.info("Pledge node information: {}".format(candidate_info)) 1027 time.sleep(3) 1028 # Access to pledge information 1029 candidate_info = client2.ppos.getCandidateInfo(node.node_id) 1030 info = candidate_info['Ret'] 1031 staking_blocknum = info['StakingBlockNum'] 1032 # To view the entrusted account balance 1033 delegate_balance = client2.node.eth.getBalance(delegate_address) 1034 log.info("report address balance: {}".format(delegate_balance)) 1035 # withdrew delegate 1036 result = client2.delegate.withdrew_delegate(staking_blocknum, delegate_address, node_id=node.node_id) 1037 assert_code(result, 0) 1038 # To view the entrusted account balance 1039 delegate_balance1 = client2.node.eth.getBalance(delegate_address) 1040 log.info("report address balance: {}".format(delegate_balance1)) 1041 assert delegate_balance + economic.delegate_limit - delegate_balance1 < client2.node.web3.toWei(1, 1042 'ether'), "ErrMsg:Ireport balance {}".format( 1043 delegate_balance1)