github.com/platonnetwork/platon-go@v0.7.6/cases/tests/ppos/test_governance_penalty_parameters.py (about) 1 import pytest 2 from dacite import from_dict 3 from common.key import mock_duplicate_sign 4 from common.log import log 5 from decimal import Decimal 6 from tests.conftest import (param_governance_verify, 7 param_governance_verify_before_endblock, 8 get_client_consensus, 9 staking_cfg 10 ) 11 from tests.lib import (EconomicConfig, 12 Genesis, check_node_in_list, 13 assert_code, get_governable_parameter_value, 14 wait_block_number, von_amount 15 ) 16 17 18 def pledge_punishment(clients): 19 """ 20 :return: 21 """ 22 first_index = 0 23 second_index = 1 24 first_client = clients[first_index] 25 second_client = clients[second_index] 26 log.info("Current block height: {}".format(first_client.node.eth.blockNumber)) 27 # stop node 28 first_client.node.stop() 29 # Waiting for a settlement round 30 second_client.economic.wait_consensus_blocknum(second_client.node, 3) 31 log.info("Current block height: {}".format(second_client.node.eth.blockNumber)) 32 # view verifier list 33 verifier_list = second_client.ppos.getVerifierList() 34 log.info("verifier_list: {}".format(verifier_list)) 35 candidate_info = second_client.ppos.getCandidateInfo(first_client.node.node_id) 36 log.info("Pledge node information: {}".format(candidate_info)) 37 return candidate_info 38 39 40 def information_before_slash_blocks(client): 41 node = client.node 42 # view Consensus Amount of pledge 43 first_candidate_info = client.ppos.getCandidateInfo(node.node_id) 44 first_pledge_amount = first_candidate_info['Ret']['Released'] 45 # view block_reward 46 log.info("block: {}".format(node.eth.blockNumber)) 47 block_reward, staking_reward = client.economic.get_current_year_reward(node) 48 log.info("block_reward: {} staking_reward: {}".format(block_reward, staking_reward)) 49 # Get governable parameters 50 first_slash_blocks = get_governable_parameter_value(client, 'slashBlocksReward') 51 return first_pledge_amount, block_reward, first_slash_blocks 52 53 54 def verify_changed_parameters(clients, first_pledge_amount, block_reward, slash_blocks): 55 # Verify changed parameters 56 candidate_info = pledge_punishment(clients) 57 second_pledge_amount = candidate_info['Ret']['Released'] 58 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 59 if punishment_amonut < first_pledge_amount: 60 assert (second_pledge_amount == first_pledge_amount - punishment_amonut) or (second_pledge_amount == first_pledge_amount - punishment_amonut * 2), "ErrMsg:Consensus Amount of pledge {}".format( 61 second_pledge_amount) 62 else: 63 assert second_pledge_amount == 0, "ErrMsg:Consensus Amount of pledge {}".format(second_pledge_amount) 64 65 66 @pytest.mark.P1 67 @pytest.mark.parametrize('mark', [False, True]) 68 def test_PIP_PVF_001_002(clients_consensus, mark, reset_environment): 69 """ 70 PIP_PVF_001:治理修改低0出块率扣除验证人自有质押金块数投票失败 71 PIP_PVF_002:理修改低0出块率扣除验证人自有质押金块数成功处于未生效期 72 :param clients_consensus: 73 :return: 74 """ 75 index = 0 76 first_client = clients_consensus[index] 77 # get pledge amount1 and block reward 78 first_pledge_amount, block_reward, first_slash_blocks = information_before_slash_blocks(first_client) 79 # create Parametric proposal 80 param_governance_verify_before_endblock(first_client, 'slashing', 'slashBlocksReward', '0', mark) 81 # Get governable parameters again 82 second_slash_blocks = get_governable_parameter_value(first_client, 'slashBlocksReward') 83 assert first_slash_blocks == second_slash_blocks, "ErrMsg:slash blocks {}".format(second_slash_blocks) 84 # Verify changed parameters 85 verify_changed_parameters(clients_consensus, first_pledge_amount, block_reward, first_slash_blocks) 86 87 88 @pytest.mark.P1 89 def test_PIP_PVF_003(clients_consensus, reset_environment): 90 """ 91 治理修改低0出块率扣除验证人自有质押金块数成功处于已生效期 92 :param clients_consensus: 93 :param reset_environment: 94 :return: 95 """ 96 first_index = 0 97 first_client = clients_consensus[first_index] 98 log.info("当前连接节点:{}".format(first_client.node.node_mark)) 99 node = first_client.node 100 # get pledge amount1 and block reward 101 first_pledge_amount, block_reward, first_slash_blocks = information_before_slash_blocks(first_client) 102 # create Parametric proposal 103 param_governance_verify(first_client, 'slashing', 'slashBlocksReward', '0') 104 log.info("Current block height: {}".format(node.eth.blockNumber)) 105 # Get governable parameters again 106 second_slash_blocks = get_governable_parameter_value(first_client, 'slashBlocksReward') 107 assert second_slash_blocks == '0', "ErrMsg:Change parameters {}".format(second_slash_blocks) 108 # Verify changed parameters 109 verify_changed_parameters(clients_consensus, first_pledge_amount, block_reward, second_slash_blocks) 110 111 112 @pytest.mark.P1 113 def test_PIP_PVF_004(client_consensus, clients_noconsensus, reset_environment): 114 """ 115 治理修改低0出块率扣除验证人自有质押金块数成功扣除区块奖励块数49999-自由金额质押 116 :param client_consensus: 117 :param clients_noconsensus: 118 :param reset_environment: 119 :return: 120 """ 121 consensus_client = client_consensus 122 log.info("Current connection consensus node".format(consensus_client.node.node_mark)) 123 first_index = 0 124 first_client = clients_noconsensus[first_index] 125 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 126 economic = consensus_client.economic 127 node = consensus_client.node 128 change_parameter_value = '49999' 129 # get pledge amount1 and block reward 130 consensus_pledge_amount, block_reward, first_slash_blocks = information_before_slash_blocks(consensus_client) 131 # create Parametric proposal 132 param_governance_verify(consensus_client, 'slashing', 'slashBlocksReward', change_parameter_value) 133 log.info("Current block height: {}".format(node.eth.blockNumber)) 134 # Get governable parameters again 135 second_slash_blocks = get_governable_parameter_value(consensus_client, 'slashBlocksReward') 136 assert second_slash_blocks == change_parameter_value, "ErrMsg:Change parameters {}".format(second_slash_blocks) 137 # create account 138 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 139 # create staking 140 result = first_client.staking.create_staking(0, address, address) 141 assert_code(result, 0) 142 # wait settlement block 143 economic.wait_settlement_blocknum(node) 144 candidate_info = consensus_client.ppos.getCandidateInfo(first_client.node.node_id) 145 first_pledge_amount = candidate_info['Ret']['Released'] 146 log.info("Current pledge node amount:{}".format(first_pledge_amount)) 147 for i in range(4): 148 result = check_node_in_list(node.node_id, consensus_client.ppos.getValidatorList) 149 log.info("Current node in consensus list status:{}".format(result)) 150 if result: 151 # Verify changed parameters 152 verify_changed_parameters(clients_noconsensus, first_pledge_amount, block_reward, second_slash_blocks) 153 break 154 else: 155 # wait consensus block 156 economic.wait_consensus_blocknum(node) 157 158 159 @pytest.mark.P1 160 def test_PIP_PVF_005(client_consensus, clients_noconsensus, reset_environment): 161 """ 162 治理修改低出块率扣除验证人自有质押金比例扣除区块奖励块数49999-锁仓金额质押 163 :param client_consensus: 164 :param clients_noconsensus: 165 :param reset_environment: 166 :return: 167 """ 168 consensus_client = client_consensus 169 log.info("Current connection consensus node".format(consensus_client.node.node_mark)) 170 first_index = 0 171 first_client = clients_noconsensus[first_index] 172 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 173 economic = consensus_client.economic 174 node = consensus_client.node 175 change_parameter_value = '4999' 176 # get pledge amount1 and block reward 177 consensus_pledge_amount, block_reward, first_slash_blocks = information_before_slash_blocks(consensus_client) 178 # create Parametric proposal 179 param_governance_verify(consensus_client, 'slashing', 'slashBlocksReward', change_parameter_value) 180 log.info("Current block height: {}".format(node.eth.blockNumber)) 181 # Get governable parameters 182 second_slash_blocks = get_governable_parameter_value(consensus_client, 'slashBlocksReward') 183 assert second_slash_blocks == change_parameter_value, "ErrMsg:Change parameters {}".format(second_slash_blocks) 184 # create account 185 address, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 186 address1, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 187 # Create restricting plan 188 plan = [{'Epoch': 1, 'Amount': economic.create_staking_limit}] 189 result = consensus_client.restricting.createRestrictingPlan(address1, plan, address) 190 assert_code(result, 0) 191 # create staking 192 result = first_client.staking.create_staking(1, address1, address1) 193 assert_code(result, 0) 194 # wait settlement block 195 economic.wait_settlement_blocknum(node) 196 candidate_info = consensus_client.ppos.getCandidateInfo(first_client.node.node_id) 197 first_pledge_amount = candidate_info['Ret']['RestrictingPlan'] 198 log.info("Current pledge node amount:{}".format(first_pledge_amount)) 199 for i in range(4): 200 result = check_node_in_list(node.node_id, consensus_client.ppos.getValidatorList) 201 # log.info("Current node in consensus list status:{}".format(result)) 202 if result: 203 # Verify changed parameters 204 verify_changed_parameters(clients_noconsensus, first_pledge_amount, block_reward, second_slash_blocks) 205 break 206 else: 207 # wait consensus block 208 economic.wait_consensus_blocknum(node) 209 210 211 def adjust_initial_parameters(new_genesis_env): 212 # Change configuration parameters 213 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 214 genesis.economicModel.staking.unStakeFreezeDuration = 3 215 genesis.economicModel.slashing.maxEvidenceAge = 2 216 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 217 genesis.to_file(new_file) 218 new_genesis_env.deploy_all(new_file) 219 220 221 @pytest.mark.P1 222 @pytest.mark.parametrize('mark', [False, True]) 223 def test_PIP_PVF_006_007(new_genesis_env, mark): 224 """ 225 治理修改区块双签-证据有效期投票失败 226 :param new_genesis_env: 227 :return: 228 """ 229 # Change configuration parameters 230 adjust_initial_parameters(new_genesis_env) 231 first_client = get_client_consensus(new_genesis_env, staking_cfg) 232 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 233 economic = first_client.economic 234 node = first_client.node 235 # view Parameter value before treatment 236 first_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 237 # create Parametric proposal 238 param_governance_verify_before_endblock(first_client, 'slashing', 'maxEvidenceAge', '1', mark) 239 # view Parameter value before treatment again 240 second_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 241 assert second_slash_blocks == first_slash_blocks, "ErrMsg:Parameter value after treatment {}".format( 242 second_slash_blocks) 243 report_address, _ = first_client.economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 244 # wait consensus block 245 economic.wait_consensus_blocknum(node) 246 # Verify changed parameters 247 effective_block = economic.get_front_settlement_switchpoint(node, 2) 248 if effective_block < economic.consensus_size: 249 log.info("Current block: {}".format(node.eth.blockNumber)) 250 effective_block = economic.consensus_size + 1 251 log.info("Effective block height: {}".format(effective_block)) 252 # Report prepareblock signature 253 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, effective_block) 254 log.info("Report information: {}".format(report_information)) 255 result = first_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 256 assert_code(result, 0) 257 258 259 @pytest.mark.P1 260 def test_PIP_PVF_008(new_genesis_env): 261 """ 262 治理修改区块双签-证据有效期处于已生效期 263 :param new_genesis_env: 264 :return: 265 """ 266 # Change configuration parameters 267 adjust_initial_parameters(new_genesis_env) 268 first_client = get_client_consensus(new_genesis_env, staking_cfg) 269 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 270 economic = first_client.economic 271 node = first_client.node 272 change_parameter_value = '1' 273 # view Parameter value before treatment 274 first_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 275 # create Parametric proposal 276 param_governance_verify(first_client, 'slashing', 'maxEvidenceAge', change_parameter_value) 277 # view Parameter value before treatment again 278 second_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 279 assert second_slash_blocks != first_slash_blocks, "ErrMsg:Parameter value after treatment {}".format( 280 second_slash_blocks) 281 assert second_slash_blocks == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format( 282 second_slash_blocks) 283 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 284 # wait consensus block 285 economic.wait_consensus_blocknum(node) 286 # Verify changed parameters 287 effective_block = economic.get_front_settlement_switchpoint(node, int(second_slash_blocks)) 288 log.info("effective_block block height: {}".format(effective_block)) 289 # wait consensus block 290 economic.wait_consensus_blocknum(node) 291 # first Report prepareblock signature 292 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, economic.consensus_size + 1) 293 log.info("Report information: {}".format(report_information)) 294 result = first_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 295 assert_code(result, 303003) 296 # second Report prepareblock signature 297 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, effective_block) 298 log.info("Report information: {}".format(report_information)) 299 result = first_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 300 assert_code(result, 0) 301 302 303 @pytest.mark.P1 304 def test_PIP_PVF_009(new_genesis_env): 305 """ 306 治理修改区块双签-证据有效期(节点质押退回锁定周期-1) 307 :param new_genesis_env: 308 :return: 309 """ 310 # Change configuration parameters 311 genesis = from_dict(data_class=Genesis, data=new_genesis_env.genesis_config) 312 genesis.economicModel.staking.unStakeFreezeDuration = 3 313 genesis.economicModel.slashing.maxEvidenceAge = 1 314 new_file = new_genesis_env.cfg.env_tmp + "/genesis.json" 315 genesis.to_file(new_file) 316 new_genesis_env.deploy_all(new_file) 317 318 first_client = get_client_consensus(new_genesis_env, staking_cfg) 319 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 320 economic = first_client.economic 321 node = first_client.node 322 change_parameter_value = '2' 323 # view Parameter value before treatment 324 first_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 325 # create Parametric proposal 326 param_governance_verify(first_client, 'slashing', 'maxEvidenceAge', change_parameter_value) 327 # view Parameter value before treatment again 328 second_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 329 assert second_slash_blocks != first_slash_blocks, "ErrMsg:Parameter value after treatment {}".format( 330 second_slash_blocks) 331 assert second_slash_blocks == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format( 332 second_slash_blocks) 333 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 334 # wait consensus block 335 economic.wait_consensus_blocknum(node) 336 # Verify changed parameters 337 first_effective_block = economic.get_front_settlement_switchpoint(node, int(first_slash_blocks)) 338 log.info("first effective block height: {}".format(first_effective_block)) 339 second_effective_block = economic.get_front_settlement_switchpoint(node, int(second_slash_blocks)) 340 log.info("second effective block height: {}".format(second_effective_block)) 341 # first Report prepareblock signature 342 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, first_effective_block) 343 log.info("Report information: {}".format(report_information)) 344 result = first_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 345 assert_code(result, 0) 346 # second Report prepareblock signature 347 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, second_effective_block) 348 log.info("Report information: {}".format(report_information)) 349 result = first_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 350 assert_code(result, 303000) 351 352 353 @pytest.mark.P1 354 def test_PIP_PVF_010(new_genesis_env, clients_consensus): 355 """ 356 治理修改区块双签-证据有效期(超出有效期) 357 :param new_genesis_env: 358 :return: 359 """ 360 # Change configuration parameters 361 adjust_initial_parameters(new_genesis_env) 362 363 first_client = get_client_consensus(new_genesis_env, staking_cfg) 364 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 365 economic = first_client.economic 366 node = first_client.node 367 change_parameter_value = '1' 368 # view Parameter value before treatment 369 first_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 370 assert first_slash_blocks == '2', "ErrMsg:Parameter value before treatment {}".format(first_slash_blocks) 371 # create Parametric proposal 372 param_governance_verify(first_client, 'slashing', 'maxEvidenceAge', change_parameter_value) 373 # view Parameter value before treatment again 374 second_slash_blocks = get_governable_parameter_value(first_client, 'maxEvidenceAge') 375 assert second_slash_blocks == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format( 376 second_slash_blocks) 377 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 378 # wait consensus block 379 economic.wait_consensus_blocknum(node) 380 # Verify changed parameters 381 effective_block = economic.get_front_settlement_switchpoint(node, int(first_slash_blocks)) 382 log.info("Effective1 block height: {}".format(effective_block)) 383 # Report1 prepareblock signature 384 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, effective_block) 385 log.info("Report information: {}".format(report_information)) 386 result = first_client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 387 assert_code(result, 303003) 388 389 390 def information_before_penalty_ratio(client): 391 # view Pledge amount 392 first_candidate_info = client.ppos.getCandidateInfo(client.node.node_id) 393 first_pledge_amount = first_candidate_info['Ret']['Released'] 394 # view Parameter value before treatment 395 first_penalty_ratio = get_governable_parameter_value(client, 'slashFractionDuplicateSign') 396 return first_pledge_amount, first_penalty_ratio 397 398 399 def duplicate_sign(client, report_address, report_block): 400 if report_block <= client.economic.consensus_size: 401 report_block = client.economic.consensus_size + 1 402 # Report1 prepareblock signature 403 report_information = mock_duplicate_sign(1, client.node.nodekey, client.node.blsprikey, report_block) 404 log.info("Report information: {}".format(report_information)) 405 result = client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 406 assert_code(result, 0) 407 408 409 def assret_penalty_amount(clients, first_pledge_amount, penalty_ratio=None): 410 # view Pledge amount after punishment 411 proportion_reward, incentive_pool_reward = clients[1].economic.get_report_reward(first_pledge_amount, penalty_ratio) 412 log.info("Whistleblower benefits:{} Incentive pool income:{}".format(proportion_reward, incentive_pool_reward)) 413 # view Pledge amount again 414 candidate_info = clients[1].ppos.getCandidateInfo(clients[0].node.node_id) 415 second_pledge_amount = candidate_info['Ret']['Released'] 416 assert second_pledge_amount == first_pledge_amount - proportion_reward - incentive_pool_reward, "ErrMsg:Pledge amount {}".format( 417 second_pledge_amount) 418 419 420 @pytest.mark.P1 421 @pytest.mark.parametrize('mark', [False, True]) 422 def test_PIP_PVF_011_012(clients_consensus, mark, reset_environment): 423 """ 424 治理修改区块双签-最高处罚比例投票失败 425 :param clients_consensus: 426 :param mark: 427 :param reset_environment: 428 :return: 429 """ 430 first_index = 0 431 first_client = clients_consensus[first_index] 432 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 433 economic = first_client.economic 434 node = first_client.node 435 change_parameter_value = '1000' 436 # view Pledge amount and Parameter value before treatment 437 first_pledge_amount, first_penalty_ratio = information_before_penalty_ratio(first_client) 438 # create Parametric proposal 439 param_governance_verify_before_endblock(first_client, 'slashing', 'slashFractionDuplicateSign', 440 change_parameter_value, mark) 441 # view Parameter value after treatment again 442 second_penalty_ratio = get_governable_parameter_value(first_client, 'slashFractionDuplicateSign') 443 assert second_penalty_ratio == first_penalty_ratio, "ErrMsg:Parameter value after treatment {}".format( 444 second_penalty_ratio) 445 # wait consensus block 446 economic.wait_consensus_blocknum(node) 447 # create account 448 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 449 # Verify changed parameters 450 current_block = node.eth.blockNumber 451 log.info("Current block height: {}".format(current_block)) 452 # Verify changed parameters report 453 duplicate_sign(first_client, report_address, current_block) 454 # assret penalty amount 455 assret_penalty_amount(clients_consensus, first_pledge_amount) 456 457 458 @pytest.mark.P1 459 def test_PIP_PVF_013(clients_consensus, reset_environment): 460 """ 461 治理修改区块双签-最高处罚比例处于已生效期 462 :param clients_consensus: 463 :param reset_environment: 464 :return: 465 """ 466 first_index = 0 467 first_client = clients_consensus[first_index] 468 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 469 economic = first_client.economic 470 node = first_client.node 471 change_parameter_value = '1000' 472 # view Pledge amount and Parameter value before treatment 473 first_pledge_amount, first_penalty_ratio = information_before_penalty_ratio(first_client) 474 # create Parametric proposal 475 param_governance_verify(first_client, 'slashing', 'slashFractionDuplicateSign', change_parameter_value) 476 # view Parameter value before treatment again 477 second_penalty_ratio = get_governable_parameter_value(first_client, 'slashFractionDuplicateSign') 478 assert second_penalty_ratio == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format( 479 second_penalty_ratio) 480 # create account 481 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 482 # Verify changed parameters 483 current_block = node.eth.blockNumber 484 log.info("Current block height: {}".format(current_block)) 485 # Verify changed parameters report 486 duplicate_sign(first_client, report_address, current_block) 487 # assret penalty amount 488 assret_penalty_amount(clients_consensus, first_pledge_amount, int(change_parameter_value)) 489 490 491 @pytest.mark.P1 492 def test_PIP_PVF_014(clients_consensus, reset_environment): 493 """ 494 治理修改区块双签-最高处罚比例为10000‱ 495 :param clients_consensus: 496 :param reset_environment: 497 :return: 498 """ 499 first_index = 0 500 first_client = clients_consensus[first_index] 501 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 502 economic = first_client.economic 503 node = first_client.node 504 change_parameter_value = '10000' 505 # view Pledge amount and Parameter value before treatment 506 first_pledge_amount, first_penalty_ratio = information_before_penalty_ratio(first_client) 507 # create Parametric proposal 508 param_governance_verify(first_client, 'slashing', 'slashFractionDuplicateSign', change_parameter_value) 509 # view Parameter value before treatment again 510 second_penalty_ratio = get_governable_parameter_value(first_client, 'slashFractionDuplicateSign') 511 assert second_penalty_ratio == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format( 512 second_penalty_ratio) 513 # create account 514 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 515 # Verify changed parameters 516 current_block = node.eth.blockNumber 517 log.info("Current block height: {}".format(current_block)) 518 # Verify changed parameters report 519 duplicate_sign(first_client, report_address, current_block) 520 # assret penalty amount 521 assret_penalty_amount(clients_consensus, first_pledge_amount, int(change_parameter_value)) 522 523 524 @pytest.mark.P1 525 def test_PIP_PVF_015(clients_consensus, reset_environment): 526 """ 527 治理修改区块双签-最高处罚比例为1‱ 528 :param clients_consensus: 529 :param reset_environment: 530 :return: 531 """ 532 first_index = 0 533 first_client = clients_consensus[first_index] 534 log.info("Current connection non-consensus node:{}".format(first_client.node.node_mark)) 535 economic = first_client.economic 536 node = first_client.node 537 change_parameter_value = '1' 538 # view Pledge amount and Parameter value before treatment 539 first_pledge_amount, first_penalty_ratio = information_before_penalty_ratio(first_client) 540 # create Parametric proposal 541 param_governance_verify(first_client, 'slashing', 'slashFractionDuplicateSign', change_parameter_value) 542 # view Parameter value before treatment again 543 second_penalty_ratio = get_governable_parameter_value(first_client, 'slashFractionDuplicateSign') 544 assert second_penalty_ratio == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format( 545 second_penalty_ratio) 546 # create account 547 report_address, _ = economic.account.generate_account(node.web3, node.web3.toWei(1000, 'ether')) 548 # Verify changed parameters 549 current_block = node.eth.blockNumber 550 log.info("Current block height: {}".format(current_block)) 551 # Verify changed parameters report 552 duplicate_sign(first_client, report_address, current_block) 553 # assret penalty amount 554 assret_penalty_amount(clients_consensus, first_pledge_amount, int(change_parameter_value)) 555 556 557 def information_before_report_reward(client): 558 # view Pledge amount 559 first_candidate_info = client.ppos.getCandidateInfo(client.node.node_id) 560 first_pledge_amount = first_candidate_info['Ret']['Released'] 561 # view Parameter value before treatment 562 first_report_reward = get_governable_parameter_value(client, 'duplicateSignReportReward') 563 return first_pledge_amount, first_report_reward 564 565 566 def get_account_amount(client): 567 # create report account 568 report_address, _ = client.economic.account.generate_account(client.node.web3, client.node.web3.toWei( 569 1000, 'ether')) 570 # view report amount 571 first_report_amount = client.node.eth.getBalance(report_address) 572 # view Incentive pool account 573 first_incentive_pool_account = client.node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS) 574 return report_address, first_report_amount, first_incentive_pool_account 575 576 577 def asster_income_account_amount(client, first_report_amount, first_incentive_pool_account, report_address, 578 proportion_reward, 579 incentive_pool_reward): 580 # view report amount 581 second_report_amount = client.node.eth.getBalance(report_address) 582 # view Incentive pool account 583 second_incentive_pool_account = client.node.eth.getBalance(EconomicConfig.INCENTIVEPOOL_ADDRESS) 584 # asster amount reward 585 log.info("first_report_amount {} ,proportion_reward {} , second_report_amount {}".format(first_report_amount, 586 proportion_reward, 587 second_report_amount)) 588 assert first_report_amount + proportion_reward - second_report_amount < client.node.web3.toWei(1, 589 'ether'), "ErrMsg:report amount {}".format( 590 second_report_amount) 591 log.info("second_incentive_pool_account {} ,first_incentive_pool_account {} , incentive_pool_reward {}".format( 592 second_incentive_pool_account, first_incentive_pool_account, incentive_pool_reward)) 593 assert second_incentive_pool_account == first_incentive_pool_account + incentive_pool_reward + ( 594 first_report_amount + proportion_reward - second_report_amount), "ErrMsg:Incentive pool account {}".format( 595 second_incentive_pool_account) 596 597 598 @pytest.mark.P1 599 @pytest.mark.parametrize('mark', [False, True]) 600 def test_PIP_PVF_016_017(clients_consensus, mark, reset_environment): 601 """ 602 PIP_PVF_016:治理修改区块双签-举报奖励比例投票失败 603 PIP_PVF_017:治理修改区块双签-举报奖励比例处于未生效期 604 :param clients_consensus: 605 :param reset_environment: 606 :return: 607 """ 608 first_index = 0 609 second_index = 1 610 first_client = clients_consensus[first_index] 611 log.info("Current connection non-consensus first node:{}".format(first_client.node.node_mark)) 612 second_client = clients_consensus[second_index] 613 log.info("Current connection non-consensus second node:{}".format(second_client.node.node_mark)) 614 economic = first_client.economic 615 node = first_client.node 616 change_parameter_value = '60' 617 first_pledge_amount, first_report_reward = information_before_report_reward(first_client) 618 # create Parametric proposal 619 param_governance_verify_before_endblock(first_client, 'slashing', 'duplicateSignReportReward', change_parameter_value, mark) 620 # view Parameter value after treatment 621 second_report_reward = get_governable_parameter_value(first_client, 'duplicateSignReportReward') 622 assert first_report_reward == second_report_reward, "ErrMsg:Parameter value after treatment {}".format(second_report_reward) 623 # wait consensus block 624 economic.wait_consensus_blocknum(node) 625 # get account amount 626 report_address, first_report_amount, first_incentive_pool_account = get_account_amount(first_client) 627 # Verify changed parameters 628 current_block = node.eth.blockNumber 629 log.info("Current block height: {}".format(current_block)) 630 # Verify changed parameters report 631 duplicate_sign(first_client, report_address, current_block) 632 # view Pledge amount after punishment 633 proportion_reward, incentive_pool_reward = economic.get_report_reward(first_pledge_amount) 634 log.info("Whistleblower benefits:{} Incentive pool income:{}".format(proportion_reward, incentive_pool_reward)) 635 # asster account amount 636 asster_income_account_amount(second_client, first_report_amount, first_incentive_pool_account, 637 report_address, proportion_reward, incentive_pool_reward) 638 639 640 @pytest.mark.P1 641 def testt(client_consensus): 642 a = client_consensus.node.eth.getTransactionCount(client_consensus.economic.account.account_with_money['address']) 643 print(a) 644 645 646 @pytest.mark.P1 647 def test_PIP_PVF_018(clients_consensus, reset_environment): 648 """ 649 治理修改区块双签-举报奖励比例处于已生效期 650 :param clients_consensus: 651 :param reset_environment: 652 :return: 653 """ 654 first_index = 0 655 second_index = 1 656 first_client = clients_consensus[first_index] 657 log.info("Current connection non-consensus first node:{}".format(first_client.node.node_mark)) 658 second_client = clients_consensus[second_index] 659 log.info("Current connection non-consensus second node:{}".format(second_client.node.node_mark)) 660 node = first_client.node 661 change_parameter_value = '60' 662 # get first_pledge_amount first_report_amount first_incentive_pool_account first_report_reward 663 first_pledge_amount, first_report_reward = information_before_report_reward(first_client) 664 # create Parametric proposal 665 param_governance_verify(first_client, 'slashing', 'duplicateSignReportReward', change_parameter_value) 666 # view Parameter value after treatment 667 second_report_reward = get_governable_parameter_value(first_client, 'duplicateSignReportReward') 668 assert second_report_reward == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format(second_report_reward) 669 # get account amount 670 report_address, first_report_amount, first_incentive_pool_account = get_account_amount(first_client) 671 # Verify changed parameters 672 current_block = node.eth.blockNumber 673 log.info("Current block height: {}".format(current_block)) 674 # Verify changed parameters report 675 duplicate_sign(first_client, report_address, current_block) 676 # view Pledge amount after punishment 677 proportion_reward, incentive_pool_reward = second_client.economic.get_report_reward(first_pledge_amount, None, int(change_parameter_value)) 678 log.info("Whistleblower benefits:{} Incentive pool income:{}".format(proportion_reward, incentive_pool_reward)) 679 # asster account amount 680 asster_income_account_amount(second_client, first_report_amount, first_incentive_pool_account, 681 report_address, proportion_reward, incentive_pool_reward) 682 683 684 @pytest.mark.P1 685 def test_PIP_PVF_019(clients_consensus, reset_environment): 686 """ 687 治理修改区块双签-举报奖励比例为80% 688 :param clients_consensus: 689 :param reset_environment: 690 :return: 691 """ 692 first_index = 0 693 second_index = 1 694 first_client = clients_consensus[first_index] 695 log.info("Current connection non-consensus first node:{}".format(first_client.node.node_mark)) 696 second_client = clients_consensus[second_index] 697 log.info("Current connection non-consensus second node:{}".format(second_client.node.node_mark)) 698 economic = first_client.economic 699 node = first_client.node 700 change_parameter_value = '80' 701 # get first_pledge_amount first_report_reward 702 first_pledge_amount, first_report_reward = information_before_report_reward(first_client) 703 # create Parametric proposal 704 param_governance_verify(first_client, 'slashing', 'duplicateSignReportReward', change_parameter_value) 705 # view Parameter value after treatment 706 second_report_reward = get_governable_parameter_value(first_client, 'duplicateSignReportReward') 707 assert second_report_reward == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format(second_report_reward) 708 # get account amount 709 report_address, first_report_amount, first_incentive_pool_account = get_account_amount(first_client) 710 # Verify changed parameters 711 current_block = node.eth.blockNumber 712 log.info("Current block height: {}".format(current_block)) 713 # Verify changed parameters report 714 duplicate_sign(first_client, report_address, current_block) 715 # view Pledge amount after punishment 716 proportion_reward, incentive_pool_reward = economic.get_report_reward(first_pledge_amount, None, int(change_parameter_value)) 717 log.info("Whistleblower benefits:{} Incentive pool income:{}".format(proportion_reward, incentive_pool_reward)) 718 # asster account amount 719 asster_income_account_amount(second_client, first_report_amount, first_incentive_pool_account, 720 report_address, proportion_reward, incentive_pool_reward) 721 722 723 @pytest.mark.P1 724 def test_PIP_PVF_020(clients_consensus, reset_environment): 725 """ 726 治理修改区块双签-举报奖励比例为1% 727 :param clients_consensus: 728 :param reset_environment: 729 :return: 730 """ 731 first_index = 0 732 second_index = 1 733 first_client = clients_consensus[first_index] 734 log.info("Current connection non-consensus first node:{}".format(first_client.node.node_mark)) 735 second_client = clients_consensus[second_index] 736 log.info("Current connection non-consensus second node:{}".format(second_client.node.node_mark)) 737 economic = first_client.economic 738 node = first_client.node 739 change_parameter_value = '1' 740 # get first_pledge_amount first_report_reward 741 first_pledge_amount, first_report_reward = information_before_report_reward(first_client) 742 # create Parametric proposal 743 param_governance_verify(first_client, 'slashing', 'duplicateSignReportReward', change_parameter_value) 744 # view Parameter value after treatment 745 second_report_reward = get_governable_parameter_value(first_client, 'duplicateSignReportReward') 746 assert second_report_reward == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format(second_report_reward) 747 # get account amount 748 report_address, first_report_amount, first_incentive_pool_account = get_account_amount(first_client) 749 # Verify changed parameters 750 current_block = node.eth.blockNumber 751 log.info("Current block height: {}".format(current_block)) 752 # Verify changed parameters report 753 duplicate_sign(first_client, report_address, current_block) 754 # view Pledge amount after punishment 755 proportion_reward, incentive_pool_reward = economic.get_report_reward(first_pledge_amount, None, int(change_parameter_value)) 756 log.info("Whistleblower benefits:{} Incentive pool income:{}".format(proportion_reward, incentive_pool_reward)) 757 # asster account amount 758 asster_income_account_amount(second_client, first_report_amount, first_incentive_pool_account, 759 report_address, proportion_reward, incentive_pool_reward) 760 761 762 @pytest.mark.parametrize('mark', [False, True]) 763 @pytest.mark.P1 764 def test_PIP_MG_001_002(client_consensus, mark, reset_environment): 765 """ 766 PIP_MG_001:治理修改默认每个区块的最大Gas 投票失败 767 PIP_MG_002:治理修改默认每个区块的最大Gas 处于未生效期 768 :param client_consensus: 769 :param reset_environment: 770 :return: 771 """ 772 first_client = client_consensus 773 log.info("Current connection non-consensus first node:{}".format(first_client.node.node_mark)) 774 node = first_client.node 775 # view Parameter value before treatment 776 first_max_gas_limit = get_governable_parameter_value(first_client, 'maxBlockGasLimit') 777 # create Parametric proposal 778 block = param_governance_verify_before_endblock(first_client, 'block', 'maxBlockGasLimit', '4712389', mark) 779 # view Parameter value after treatment 780 second_max_gas_limit = get_governable_parameter_value(first_client, 'maxBlockGasLimit') 781 # wait block 782 wait_block_number(node, block) 783 assert second_max_gas_limit == first_max_gas_limit, "ErrMsg:Parameter value after treatment {}".format(second_max_gas_limit) 784 785 786 @pytest.mark.P1 787 def test_PIP_MG_003(client_consensus, reset_environment): 788 """ 789 治理修改默认每个区块的最大Gas 处于已生效期 790 :param client_consensus: 791 :param reset_environment: 792 :return: 793 """ 794 first_client = client_consensus 795 log.info("Current connection non-consensus first node:{}".format(first_client.node.node_mark)) 796 node = first_client.node 797 change_parameter_value = '4712389' 798 # view Parameter value before treatment 799 first_max_gas_limit = get_governable_parameter_value(first_client, 'maxBlockGasLimit') 800 # create Parametric proposal 801 param_governance_verify(first_client, 'block', 'maxBlockGasLimit', change_parameter_value) 802 # view Parameter value after treatment 803 second_max_gas_limit = get_governable_parameter_value(first_client, 'maxBlockGasLimit') 804 assert second_max_gas_limit != first_max_gas_limit, "ErrMsg:Parameter value after treatment {}".format(second_max_gas_limit) 805 assert second_max_gas_limit == change_parameter_value, "ErrMsg:Parameter value after treatment {}".format(second_max_gas_limit)