github.com/platonnetwork/platon-go@v0.7.6/cases/tests/ppos/test_unlock_period.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 6 from common.log import log 7 from client_sdk_python import Web3 8 from decimal import Decimal 9 from tests.lib import EconomicConfig, Genesis, StakingConfig, Staking, check_node_in_list, assert_code, von_amount, \ 10 get_governable_parameter_value 11 12 13 def create_account_amount(client, amount1, amount2): 14 # create account1 15 lock_address, _ = client.economic.account.generate_account(client.node.web3, amount1) 16 # create account2 17 release_address, _ = client.economic.account.generate_account(client.node.web3, amount2) 18 return lock_address, release_address 19 20 21 def restricting_plan_validation_release(client, economic, node): 22 # create account 23 address1, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 24 # create Restricting Plan 25 amount = economic.create_staking_limit 26 plan = [{'Epoch': 1, 'Amount': amount}] 27 result = client.restricting.createRestrictingPlan(address1, plan, address1) 28 assert_code(result, 0) 29 return address1 30 31 32 def restricting_plan_validation_staking(client, economic, node): 33 # create restricting plan 34 address1 = restricting_plan_validation_release(client, economic, node) 35 # create staking 36 staking_amount = economic.create_staking_limit 37 result = client.staking.create_staking(1, address1, address1, amount=staking_amount) 38 assert_code(result, 0) 39 return address1 40 41 42 @pytest.mark.P2 43 @pytest.mark.compatibility 44 def test_UP_FV_001(client_new_node): 45 """ 46 只有一个锁仓期,到达释放期返回解锁金额 47 :param client_new_node: 48 :return: 49 """ 50 client = client_new_node 51 economic = client.economic 52 node = client.node 53 # create restricting plan 54 address1 = restricting_plan_validation_release(client, economic, node) 55 # view Account balance 56 balance = node.eth.getBalance(address1) 57 log.info("Account balance: {}".format(balance)) 58 # Waiting for the end of the settlement period 59 economic.wait_settlement_blocknum(node) 60 # view Account balance again 61 balance1 = node.eth.getBalance(address1) 62 log.info("Account balance: {}".format(balance1)) 63 assert balance1 == balance + economic.create_staking_limit, "ErrMsg:Account balance: {}".format(balance1) 64 65 66 @pytest.mark.P1 67 def test_UP_FV_002(client_new_node): 68 """ 69 只有一个锁仓期,未达释放期返回解锁金额 70 :param client_new_node: 71 :return: 72 """ 73 client = client_new_node 74 economic = client.economic 75 node = client.node 76 # create restricting plan 77 address1 = restricting_plan_validation_release(client, economic, node) 78 # view restricting plan index 0 amount 79 restricting_info = client.ppos.getRestrictingInfo(address1) 80 log.info("restricting plan information: {}".format(restricting_info)) 81 amount = restricting_info['Ret']['plans'][0]['amount'] 82 # view Account balance 83 balance = node.eth.getBalance(address1) 84 log.info("Account balance: {}".format(balance)) 85 # Waiting for the end of the settlement period 86 economic.wait_consensus_blocknum(node) 87 # view restricting plan index 0 amount again 88 restricting_info = client.ppos.getRestrictingInfo(address1) 89 amount1 = restricting_info['Ret']['plans'][0]['amount'] 90 # view Account balance again 91 balance1 = node.eth.getBalance(address1) 92 log.info("Account balance: {}".format(balance1)) 93 assert amount1 == amount, "ErrMsg:restricting index 0 amount: {}".format(amount1) 94 assert balance1 == balance, "ErrMsg:Account balance: {}".format(balance1) 95 96 97 @pytest.mark.P1 98 def test_UP_FV_003(client_new_node): 99 """ 100 多个锁仓期,依次部分释放期返回解锁金额 101 :param client_new_node: 102 :return: 103 """ 104 client = client_new_node 105 economic = client.economic 106 node = client.node 107 # create account 108 address1, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 109 # create Restricting Plan 110 amount = von_amount(economic.delegate_limit, 10) 111 plan = [{'Epoch': 1, 'Amount': amount}, {'Epoch': 2, 'Amount': amount}] 112 result = client.restricting.createRestrictingPlan(address1, plan, address1) 113 assert_code(result, 0) 114 # view Restricting Plan again 115 restricting_info = client.ppos.getRestrictingInfo(address1) 116 log.info("restricting plan information: {}".format(restricting_info)) 117 assert len(restricting_info['Ret']['plans']) == 2, "ErrMsg:Planned releases: {}".format( 118 len(restricting_info['Ret']['plans'])) 119 # Waiting for the end of the settlement period 120 economic.wait_settlement_blocknum(node) 121 # view Restricting Plan 122 restricting_info = client.ppos.getRestrictingInfo(address1) 123 log.info("restricting plan information: {}".format(restricting_info)) 124 assert len(restricting_info['Ret']['plans']) == 1, "ErrMsg:Planned releases: {}".format( 125 len(restricting_info['Ret']['plans'])) 126 127 128 @pytest.mark.P1 129 def test_UP_FV_004(client_new_node): 130 """ 131 锁仓账户申请质押到释放期后释放锁定金额不足 132 :param client_new_node: 133 :return: 134 """ 135 client = client_new_node 136 economic = client.economic 137 node = client.node 138 # create restricting plan 139 address1 = restricting_plan_validation_release(client, economic, node) 140 # create staking 141 staking_amount = economic.create_staking_limit 142 result = client.staking.create_staking(1, address1, address1, amount=staking_amount) 143 assert_code(result, 0) 144 # Waiting for the end of the settlement period 145 economic.wait_settlement_blocknum(node) 146 # view restricting plan 147 restricting_info = client.ppos.getRestrictingInfo(address1) 148 log.info("restricting plan informtion: {}".format(restricting_info)) 149 info = restricting_info['Ret'] 150 assert info['debt'] == economic.create_staking_limit, 'ErrMsg: restricting debt amount {}'.format( 151 info['debt']) 152 153 154 @pytest.mark.P1 155 def test_UP_FV_005(client_new_node): 156 """ 157 到达释放期释放锁仓金额之后再申请退回质押金 158 :param client_new_node: 159 :return: 160 """ 161 client = client_new_node 162 economic = client.economic 163 node = client.node 164 # create restricting plan and staking 165 address1 = restricting_plan_validation_staking(client, economic, node) 166 # Waiting for the end of the settlement period 167 economic.wait_settlement_blocknum(node) 168 # Application for return of pledge 169 result = client.staking.withdrew_staking(address1) 170 assert_code(result, 0) 171 # view restricting plan 172 restricting_info = client.ppos.getRestrictingInfo(address1) 173 log.info("restricting plan informtion: {}".format(restricting_info)) 174 info = restricting_info['Ret'] 175 assert info['debt'] == economic.create_staking_limit, 'ErrMsg: restricting debt amount {}'.format( 176 info['debt']) 177 # Waiting for the end of the settlement period 178 economic.wait_settlement_blocknum(node, 2) 179 # view restricting plan again 180 restricting_info = client.ppos.getRestrictingInfo(address1) 181 assert_code(restricting_info, 304005) 182 183 184 @pytest.mark.P1 185 def test_UP_FV_006(client_new_node): 186 """ 187 多个锁仓期,质押一部分锁仓金额再依次释放 188 :param client_new_node: 189 :return: 190 """ 191 client = client_new_node 192 economic = client.economic 193 node = client.node 194 # create account1 195 address1, _ = client.economic.account.generate_account(client.node.web3, 196 von_amount(economic.create_staking_limit, 2)) 197 # create Restricting Plan 198 amount1 = economic.create_staking_limit 199 amount2 = von_amount(economic.add_staking_limit, 10) 200 plan = [{'Epoch': 1, 'Amount': amount1}, {'Epoch': 2, 'Amount': amount2}] 201 result = client.restricting.createRestrictingPlan(address1, plan, address1) 202 assert_code(result, 0) 203 # create staking 204 staking_amount = economic.create_staking_limit 205 result = client.staking.create_staking(1, address1, address1, amount=staking_amount) 206 assert_code(result, 0) 207 # view restricting plan 208 restricting_info = client.ppos.getRestrictingInfo(address1) 209 log.info("restricting plan informtion: {}".format(restricting_info)) 210 # Waiting for the end of the settlement period 211 economic.wait_settlement_blocknum(node) 212 # view restricting plan 213 restricting_info = client.ppos.getRestrictingInfo(address1) 214 log.info("restricting plan informtion: {}".format(restricting_info)) 215 info = restricting_info['Ret'] 216 assert info['debt'] == amount1 - amount2, 'ErrMsg: restricting debt amount {}'.format( 217 info['debt']) 218 assert info['plans'][0]['amount'] == amount2, 'ErrMsg: restricting plans amount {}'.format( 219 info['plans'][0]['amount']) 220 # Waiting for the end of the settlement period 221 economic.wait_settlement_blocknum(node) 222 # view restricting plan again 223 restricting_info = client.ppos.getRestrictingInfo(address1) 224 log.info("restricting plan informtion: {}".format(restricting_info)) 225 info = restricting_info['Ret'] 226 assert info['debt'] == amount1, 'ErrMsg: restricting debt amount {}'.format( 227 info['debt']) 228 assert info['plans'] is None, 'ErrMsg: restricting plans'.format(info['plans']) 229 230 231 @pytest.mark.P1 232 def test_UP_FV_007(client_new_node): 233 """ 234 锁仓账户申请委托到释放期后释放锁定金额不足 235 :param client_new_node: 236 :return: 237 """ 238 client = client_new_node 239 economic = client.economic 240 node = client.node 241 # create account 242 amount1 = von_amount(economic.create_staking_limit, 2) 243 amount2 = von_amount(economic.create_staking_limit, 1) 244 address1, address2 = create_account_amount(client, amount1, amount2) 245 # create Restricting Plan 246 delegate_amount = von_amount(economic.delegate_limit, 10) 247 plan = [{'Epoch': 1, 'Amount': delegate_amount}] 248 result = client.restricting.createRestrictingPlan(address2, plan, address2) 249 assert_code(result, 0) 250 # view restricting plan 251 restricting_info = client.ppos.getRestrictingInfo(address2) 252 log.info("restricting plan informtion: {}".format(restricting_info)) 253 # create staking 254 result = client.staking.create_staking(0, address1, address1) 255 assert_code(result, 0) 256 # Application for Commission 257 result = client.delegate.delegate(1, address2, amount=delegate_amount) 258 assert_code(result, 0) 259 # view restricting plan 260 restricting_info = client.ppos.getRestrictingInfo(address2) 261 log.info("restricting plan informtion: {}".format(restricting_info)) 262 # Waiting for the end of the settlement period 263 economic.wait_settlement_blocknum(node) 264 # view restricting plan 265 restricting_info = client.ppos.getRestrictingInfo(address2) 266 log.info("restricting plan informtion: {}".format(restricting_info)) 267 info = restricting_info['Ret'] 268 assert info['debt'] == delegate_amount, 'ErrMsg: restricting debt amount {}'.format( 269 info['debt']) 270 271 272 @pytest.mark.P1 273 def test_UP_FV_008(client_new_node): 274 """ 275 到达释放期释放锁仓金额之后再申请赎回委托 276 :param client_new_node: 277 :return: 278 """ 279 client = client_new_node 280 economic = client.economic 281 node = client.node 282 # create account 283 amount1 = von_amount(economic.create_staking_limit, 2) 284 amount2 = von_amount(economic.create_staking_limit, 1) 285 address1, address2 = create_account_amount(client, amount1, amount2) 286 # create Restricting Plan 287 delegate_amount = von_amount(economic.delegate_limit, 10) 288 plan = [{'Epoch': 1, 'Amount': delegate_amount}] 289 result = client.restricting.createRestrictingPlan(address2, plan, address2) 290 assert_code(result, 0) 291 # create staking 292 result = client.staking.create_staking(0, address1, address1) 293 assert_code(result, 0) 294 # Application for Commission 295 result = client.delegate.delegate(1, address2, amount=delegate_amount) 296 assert_code(result, 0) 297 # Waiting for the end of the settlement period 298 economic.wait_settlement_blocknum(node) 299 # view restricting plan 300 restricting_info = client.ppos.getRestrictingInfo(address2) 301 log.info("restricting plan informtion: {}".format(restricting_info)) 302 info = restricting_info['Ret'] 303 assert info['debt'] == delegate_amount, 'ErrMsg: restricting debt amount {}'.format( 304 info['debt']) 305 # Access to pledge information 306 candidate_info = client.ppos.getCandidateInfo(node.node_id) 307 info = candidate_info['Ret'] 308 staking_blocknum = info['StakingBlockNum'] 309 # withdrew delegate 310 result = client.delegate.withdrew_delegate(staking_blocknum, address2, amount=delegate_amount) 311 assert_code(result, 0) 312 # view restricting plan 313 restricting_info = client.ppos.getRestrictingInfo(address1) 314 assert_code(restricting_info, 304005) 315 316 317 @pytest.mark.P1 318 def test_UP_FV_009(clients_new_node): 319 """ 320 锁仓账号申请质押,验证人违规被扣除节点自有质押金k 321 :param clients_new_node: 322 :return: 323 """ 324 client1 = clients_new_node[0] 325 client2 = clients_new_node[1] 326 economic = client1.economic 327 node = client1.node 328 # create restricting plan and staking 329 address1 = restricting_plan_validation_staking(client1, economic, node) 330 # Waiting for the end of the settlement period 331 economic.wait_settlement_blocknum(node) 332 # Obtain block bonus and pledge bonus 333 block_reward, staking_reward = client1.economic.get_current_year_reward(node) 334 # Get penalty blocks 335 slash_blocks = get_governable_parameter_value(client1, 'slashBlocksReward') 336 # view restricting plan 337 restricting_info = client1.ppos.getRestrictingInfo(address1) 338 log.info("restricting plan informtion: {}".format(restricting_info)) 339 info = restricting_info['Ret'] 340 assert info['debt'] == economic.create_staking_limit, 'ErrMsg: restricting debt amount {}'.format( 341 info['debt']) 342 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 343 # stop node 344 client1.node.stop() 345 # Waiting for a 3 consensus round 346 client2.economic.wait_consensus_blocknum(client2.node, 3) 347 log.info("Current block height: {}".format(client2.node.eth.blockNumber)) 348 # view verifier list 349 verifier_list = client2.ppos.getVerifierList() 350 log.info("verifier_list: {}".format(verifier_list)) 351 punishment_amonut = int(Decimal(str(block_reward)) * Decimal(str(slash_blocks))) 352 log.info("punishment_amonut: {}".format(punishment_amonut)) 353 # view restricting plan again 354 restricting_info = client2.ppos.getRestrictingInfo(address1) 355 log.info("restricting plan informtion: {}".format(restricting_info)) 356 info = restricting_info['Ret'] 357 if punishment_amonut < economic.create_staking_limit: 358 assert (info['balance'] == economic.create_staking_limit - punishment_amonut) or (info['balance'] == economic.create_staking_limit - punishment_amonut * 2), 'ErrMsg: restricting balance amount {}'.format( 359 info['balance']) 360 else: 361 assert_code(restricting_info, 304005) 362 363 364 @pytest.mark.P2 365 def test_UP_FV_010(client_new_node, reset_environment): 366 """ 367 锁仓验证人违规被剔除验证人列表,申请质押节点 368 :param client_new_node: 369 :return: 370 """ 371 client1 = client_new_node 372 economic = client1.economic 373 node = client1.node 374 # create account 375 amount1 = von_amount(economic.create_staking_limit, 3) 376 amount2 = von_amount(economic.create_staking_limit, 1) 377 address1, report_address = create_account_amount(client1, amount1, amount2) 378 # create Restricting Plan 379 delegate_amount = von_amount(economic.create_staking_limit, 2) 380 plan = [{'Epoch': 3, 'Amount': delegate_amount}] 381 result = client1.restricting.createRestrictingPlan(address1, plan, address1) 382 assert_code(result, 0) 383 # view restricting plan again 384 restricting_info = client1.ppos.getRestrictingInfo(address1) 385 log.info("restricting plan informtion: {}".format(restricting_info)) 386 # create staking 387 result = client1.staking.create_staking(1, address1, address1) 388 assert_code(result, 0) 389 # view restricting plan again 390 restricting_info = client1.ppos.getRestrictingInfo(address1) 391 log.info("restricting plan informtion: {}".format(restricting_info)) 392 # Waiting for the end of the settlement period 393 economic.wait_settlement_blocknum(node) 394 # 395 for i in range(4): 396 result = check_node_in_list(node.node_id, client1.ppos.getValidatorList) 397 log.info("Current node in consensus list status:{}".format(result)) 398 if result: 399 # view current block 400 current_block = node.eth.blockNumber 401 log.info("Current block: {}".format(current_block)) 402 # Report prepareblock signature 403 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, current_block) 404 log.info("Report information: {}".format(report_information)) 405 result = client1.duplicatesign.reportDuplicateSign(1, report_information, report_address) 406 assert_code(result, 0) 407 time.sleep(3) 408 # create staking 409 result = client1.staking.create_staking(1, address1, address1) 410 assert_code(result, 301101) 411 break 412 else: 413 # wait consensus block 414 client1.economic.wait_consensus_blocknum(node) 415 416 417 @pytest.mark.P2 418 def test_UP_FV_011(client_new_node, reset_environment): 419 """ 420 锁仓验证人违规被剔除验证人列表,申请委托节点 421 :param client_new_node: 422 :return: 423 """ 424 client1 = client_new_node 425 economic = client1.economic 426 node = client1.node 427 # create account 428 amount1 = von_amount(economic.create_staking_limit, 2) 429 amount2 = von_amount(economic.create_staking_limit, 1) 430 address1, report_address = create_account_amount(client1, amount1, amount2) 431 # create Restricting Plan 432 delegate_amount = von_amount(economic.delegate_limit, 10) 433 plan = [{'Epoch': 3, 'Amount': delegate_amount}] 434 result = client1.restricting.createRestrictingPlan(report_address, plan, report_address) 435 assert_code(result, 0) 436 # create staking 437 result = client1.staking.create_staking(0, address1, address1) 438 assert_code(result, 0) 439 # Application for Commission 440 result = client1.delegate.delegate(1, report_address) 441 assert_code(result, 0) 442 # Waiting for the end of the settlement period 443 economic.wait_settlement_blocknum(node) 444 # 445 for i in range(4): 446 result = check_node_in_list(node.node_id, client1.ppos.getValidatorList) 447 log.info("Current node in consensus list status:{}".format(result)) 448 if result: 449 # view current block 450 current_block = node.eth.blockNumber 451 log.info("Current block: {}".format(current_block)) 452 # Report prepareblock signature 453 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, current_block) 454 log.info("Report information: {}".format(report_information)) 455 result = client1.duplicatesign.reportDuplicateSign(1, report_information, report_address) 456 assert_code(result, 0) 457 time.sleep(3) 458 # Application for Commission 459 result = client1.delegate.delegate(1, report_address) 460 assert_code(result, 301103) 461 break 462 else: 463 # wait consensus block 464 client1.economic.wait_consensus_blocknum(node) 465 466 467 @pytest.mark.P2 468 def test_UP_FV_012(client_new_node, reset_environment): 469 """ 470 锁仓验证人违规被剔除验证人列表,申请增持质押 471 :param client_new_node: 472 :return: 473 """ 474 client1 = client_new_node 475 economic = client1.economic 476 node = client1.node 477 # create account 478 amount1 = von_amount(economic.create_staking_limit, 3) 479 amount2 = von_amount(economic.create_staking_limit, 1) 480 address1, report_address = create_account_amount(client1, amount1, amount2) 481 # create Restricting Plan 482 staking_amount = von_amount(economic.create_staking_limit, 2) 483 plan = [{'Epoch': 3, 'Amount': staking_amount}] 484 result = client1.restricting.createRestrictingPlan(address1, plan, address1) 485 assert_code(result, 0) 486 # create staking 487 result = client1.staking.create_staking(1, address1, address1) 488 assert_code(result, 0) 489 # Apply for additional pledge 490 result = client1.staking.increase_staking(1, address1) 491 assert_code(result, 0) 492 # Waiting for the end of the settlement period 493 economic.wait_settlement_blocknum(node) 494 # 495 for i in range(4): 496 result = check_node_in_list(node.node_id, client1.ppos.getValidatorList) 497 log.info("Current node in consensus list status:{}".format(result)) 498 if result: 499 # view current block 500 current_block = node.eth.blockNumber 501 log.info("Current block: {}".format(current_block)) 502 # Report prepareblock signature 503 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, current_block) 504 log.info("Report information: {}".format(report_information)) 505 result = client1.duplicatesign.reportDuplicateSign(1, report_information, report_address) 506 assert_code(result, 0) 507 time.sleep(3) 508 # Apply for additional pledge 509 result = client1.staking.increase_staking(1, address1) 510 assert_code(result, 301103) 511 break 512 else: 513 # wait consensus block 514 client1.economic.wait_consensus_blocknum(node) 515 516 517 @pytest.mark.P2 518 def test_UP_FV_013(client_new_node, reset_environment): 519 """ 520 锁仓验证人违规被剔除验证人列表,申请退回质押金 521 :param client_new_node: 522 :return: 523 """ 524 client1 = client_new_node 525 economic = client1.economic 526 node = client1.node 527 # create account 528 amount1 = von_amount(economic.create_staking_limit, 3) 529 amount2 = von_amount(economic.create_staking_limit, 1) 530 address1, report_address = create_account_amount(client1, amount1, amount2) 531 # create Restricting Plan 532 delegate_amount = von_amount(economic.create_staking_limit, 2) 533 plan = [{'Epoch': 3, 'Amount': delegate_amount}] 534 result = client1.restricting.createRestrictingPlan(address1, plan, address1) 535 assert_code(result, 0) 536 # view restricting plan again 537 restricting_info = client1.ppos.getRestrictingInfo(address1) 538 log.info("restricting plan informtion: {}".format(restricting_info)) 539 # create staking 540 result = client1.staking.create_staking(1, address1, address1) 541 assert_code(result, 0) 542 # view restricting plan again 543 restricting_info = client1.ppos.getRestrictingInfo(address1) 544 log.info("restricting plan informtion: {}".format(restricting_info)) 545 # Waiting for the end of the settlement period 546 economic.wait_settlement_blocknum(node) 547 # 548 for i in range(4): 549 result = check_node_in_list(node.node_id, client1.ppos.getValidatorList) 550 log.info("Current node in consensus list status:{}".format(result)) 551 if result: 552 # view current block 553 current_block = node.eth.blockNumber 554 log.info("Current block: {}".format(current_block)) 555 # Report prepareblock signature 556 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, current_block) 557 log.info("Report information: {}".format(report_information)) 558 result = client1.duplicatesign.reportDuplicateSign(1, report_information, report_address) 559 assert_code(result, 0) 560 time.sleep(3) 561 # withdrew staking 562 result = client1.staking.withdrew_staking(address1) 563 assert_code(result, 301103) 564 break 565 else: 566 # wait consensus block 567 client1.economic.wait_consensus_blocknum(node) 568 569 570 @pytest.mark.P2 571 def test_UP_FV_014(client_new_node, reset_environment): 572 """ 573 锁仓验证人违规被剔除验证人列表,申请赎回委托金 574 :param client_new_node: 575 :param reset_environment: 576 :return: 577 """ 578 client = client_new_node 579 economic = client.economic 580 node = client.node 581 # create account 582 amount1 = von_amount(economic.create_staking_limit, 2) 583 amount2 = von_amount(economic.create_staking_limit, 1) 584 address1, report_address = create_account_amount(client, amount1, amount2) 585 # create Restricting Plan 586 delegate_amount = von_amount(economic.delegate_limit, 10) 587 plan = [{'Epoch': 3, 'Amount': delegate_amount}] 588 result = client.restricting.createRestrictingPlan(report_address, plan, report_address) 589 assert_code(result, 0) 590 # create staking 591 result = client.staking.create_staking(0, address1, address1) 592 assert_code(result, 0) 593 # Application for Commission 594 result = client.delegate.delegate(1, report_address) 595 assert_code(result, 0) 596 # Waiting for the end of the settlement period 597 economic.wait_settlement_blocknum(node) 598 # 599 for i in range(4): 600 result = check_node_in_list(node.node_id, client.ppos.getValidatorList) 601 log.info("Current node in consensus list status:{}".format(result)) 602 if result: 603 # view current block 604 current_block = node.eth.blockNumber 605 log.info("Current block: {}".format(current_block)) 606 # Report prepareblock signature 607 report_information = mock_duplicate_sign(1, node.nodekey, node.blsprikey, current_block) 608 log.info("Report information: {}".format(report_information)) 609 result = client.duplicatesign.reportDuplicateSign(1, report_information, report_address) 610 assert_code(result, 0) 611 time.sleep(3) 612 # Access to pledge information 613 candidate_info = client.ppos.getCandidateInfo(node.node_id) 614 info = candidate_info['Ret'] 615 staking_blocknum = info['StakingBlockNum'] 616 # withdrew delegate 617 result = client.delegate.withdrew_delegate(staking_blocknum, report_address) 618 assert_code(result, 0) 619 break 620 else: 621 # wait consensus block 622 client.economic.wait_consensus_blocknum(node) 623 624 625 @pytest.mark.P2 626 def test_UP_FV_015(client_new_node): 627 """ 628 锁仓账户申请之后到达释放期,账户锁仓不足再新增新的锁仓计划 629 :param client_new_node: 630 :return: 631 """ 632 client = client_new_node 633 economic = client.economic 634 node = client.node 635 # create restricting plan and staking 636 address1 = restricting_plan_validation_staking(client, economic, node) 637 # create account2 638 address2, _ = economic.account.generate_account(node.web3, von_amount(economic.create_staking_limit, 2)) 639 # Waiting for the end of the settlement period 640 economic.wait_settlement_blocknum(node) 641 # view restricting plan 642 restricting_info = client.ppos.getRestrictingInfo(address1) 643 log.info("restricting plan informtion: {}".format(restricting_info)) 644 info = restricting_info['Ret'] 645 assert info['debt'] == economic.create_staking_limit, 'ErrMsg: restricting debt amount {}'.format( 646 info['debt']) 647 # create Restricting Plan 648 delegate_amount = von_amount(economic.create_staking_limit, 1) 649 plan = [{'Epoch': 1, 'Amount': delegate_amount}] 650 result = client.restricting.createRestrictingPlan(address1, plan, address2) 651 assert_code(result, 0) 652 # view restricting plan 653 restricting_info = client.ppos.getRestrictingInfo(address1) 654 log.info("restricting plan informtion: {}".format(restricting_info)) 655 info = restricting_info['Ret'] 656 assert info['debt'] == 0, 'ErrMsg: restricting debt amount {}'.format(info['debt']) 657 658 659 @pytest.mark.P1 660 def test_UP_FV_016(client_new_node): 661 """ 662 自由资金质押,锁仓再增持 663 :param client_new_node: 664 :return: 665 """ 666 client = client_new_node 667 economic = client.economic 668 node = client.node 669 # create account 670 amount1 = von_amount(economic.create_staking_limit, 2) 671 amount2 = von_amount(economic.create_staking_limit, 1) 672 address1, address2 = create_account_amount(client, amount1, amount2) 673 # create Restricting Plan 674 delegate_amount = von_amount(economic.add_staking_limit, 10) 675 plan = [{'Epoch': 3, 'Amount': delegate_amount}] 676 result = client.restricting.createRestrictingPlan(address1, plan, address1) 677 assert_code(result, 0) 678 # create staking 679 result = client.staking.create_staking(0, address1, address1) 680 assert_code(result, 0) 681 # Apply for additional pledge 682 result = client.staking.increase_staking(1, address1) 683 assert_code(result, 0) 684 # Waiting for the end of the settlement period 685 economic.wait_settlement_blocknum(node) 686 # Apply for additional pledge 687 result = client.staking.increase_staking(1, address1) 688 assert_code(result, 0) 689 690 691 @pytest.mark.P1 692 def test_UP_FV_017(client_new_node): 693 """ 694 锁仓账户质押,自由资金再增持 695 :param client_new_node: 696 :return: 697 """ 698 client = client_new_node 699 economic = client.economic 700 node = client.node 701 # create account 702 amount1 = von_amount(economic.create_staking_limit, 2) 703 amount2 = von_amount(economic.create_staking_limit, 1) 704 address1, address2 = create_account_amount(client, amount1, amount2) 705 # create Restricting Plan 706 delegate_amount = von_amount(economic.create_staking_limit, 1) 707 plan = [{'Epoch': 3, 'Amount': delegate_amount}] 708 result = client.restricting.createRestrictingPlan(address1, plan, address1) 709 assert_code(result, 0) 710 # create staking 711 result = client.staking.create_staking(1, address1, address1) 712 assert_code(result, 0) 713 # Apply for additional pledge 714 result = client.staking.increase_staking(0, address1) 715 assert_code(result, 0) 716 # Waiting for the end of the settlement period 717 economic.wait_settlement_blocknum(node) 718 # Apply for additional pledge 719 result = client.staking.increase_staking(0, address1) 720 assert_code(result, 0) 721 722 723 @pytest.mark.P1 724 def test_UP_FV_018(client_new_node): 725 """ 726 账户自由金额和锁仓金额申请委托同一个验证人,再申请赎回 727 :param client_new_node: 728 :return: 729 """ 730 client = client_new_node 731 economic = client.economic 732 node = client.node 733 # create account 734 amount1 = von_amount(economic.create_staking_limit, 2) 735 amount2 = von_amount(economic.create_staking_limit, 1) 736 address1, address2 = create_account_amount(client, amount1, amount2) 737 # create Restricting Plan 738 delegate_amount = von_amount(economic.delegate_limit, 10) 739 plan = [{'Epoch': 1, 'Amount': delegate_amount}] 740 result = client.restricting.createRestrictingPlan(address2, plan, address2) 741 assert_code(result, 0) 742 # create staking 743 result = client.staking.create_staking(0, address1, address1) 744 assert_code(result, 0) 745 # Lock in amount Application for delegate 746 result = client.delegate.delegate(1, address2, amount=delegate_amount) 747 assert_code(result, 0) 748 # Free amount Application for delegate 749 result = client.delegate.delegate(0, address2, amount=delegate_amount) 750 assert_code(result, 0) 751 # Waiting for the end of the settlement period 752 economic.wait_settlement_blocknum(node) 753 # Access to pledge information 754 candidate_info = client.ppos.getCandidateInfo(node.node_id) 755 info = candidate_info['Ret'] 756 staking_blocknum = info['StakingBlockNum'] 757 # withdrew delegate 758 withdrew_amount = von_amount(economic.delegate_limit, 15) 759 result = client.delegate.withdrew_delegate(staking_blocknum, address2, amount=withdrew_amount) 760 assert_code(result, 0) 761 # view restricting plan 762 restricting_info = client.ppos.getRestrictingInfo(address2) 763 log.info("restricting plan informtion: {}".format(restricting_info)) 764 info = restricting_info['Ret'] 765 assert info['debt'] == von_amount(economic.delegate_limit, 5), 'ErrMsg: restricting debt amount {}'.format(info['debt'])