github.com/platonnetwork/platon-go@v0.7.6/cases/tests/ppos_2/test_edit_candidate.py (about) 1 # -*- coding: utf-8 -*- 2 3 from tests.lib.utils import * 4 import pytest 5 import allure 6 7 8 @allure.title("Modify node information") 9 @pytest.mark.P0 10 @pytest.mark.compatibility 11 def test_MPI_001_002(client_new_node): 12 """ 13 Modify node information 14 :param client_new_node_obj: 15 :return: 16 """ 17 external_id = "ID1" 18 node_name = "LIDA" 19 website = "WEBSITE" 20 details = "talent" 21 address, pri_key = client_new_node.economic.account.generate_account(client_new_node.node.web3, 22 10 ** 18 * 10000000) 23 result = client_new_node.staking.create_staking(0, address, address) 24 assert_code(result, 0) 25 result = client_new_node.ppos.editCandidate(address, client_new_node.node.node_id, external_id, 26 node_name, website, details, pri_key) 27 assert_code(result, 0) 28 result = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 29 log.info(result) 30 assert result["Ret"]["ExternalId"] == external_id 31 assert result["Ret"]["NodeName"] == node_name 32 assert result["Ret"]["Website"] == website 33 assert result["Ret"]["Details"] == details 34 35 36 @allure.title("Node becomes consensus validator when modifying revenue address") 37 @pytest.mark.P2 38 def test_MPI_003(clients_new_node): 39 """ 40 :param client_new_node: 41 :return: 42 """ 43 client = clients_new_node[0] 44 address, _ = client.economic.account.generate_account(client.node.web3, 45 10 ** 18 * 10000000) 46 value = client.economic.create_staking_limit * 2 47 result = client.staking.create_staking(0, address, address, amount=value) 48 assert_code(result, 0) 49 msg = client.ppos.getCandidateInfo(client.node.node_id) 50 log.info(msg) 51 log.info("Next settlement period") 52 client.economic.wait_settlement_blocknum(client.node) 53 log.info("Next consensus cycle") 54 client.economic.wait_consensus_blocknum(client.node) 55 validator_list = get_pledge_list(client.ppos.getValidatorList) 56 log.info("validator_list:{}".format(validator_list)) 57 log.info("new node{}".format(client.node.node_id)) 58 msg = client.ppos.getValidatorList() 59 log.info("validator_list info{}".format(msg)) 60 assert client.node.node_id in validator_list 61 result = client.staking.edit_candidate(address, address) 62 assert_code(result, 0) 63 64 65 @allure.title("The original verifier beneficiary's address modifies the ordinary address") 66 @pytest.mark.P1 67 def test_MPI_004(client_consensus): 68 """ 69 :param client_consensus_obj: 70 :return: 71 """ 72 address, _ = client_consensus.economic.account.generate_account(client_consensus.node.web3, 73 10 ** 18 * 10000000) 74 INCENTIVEPOOL_ADDRESS = client_consensus.economic.cfg.INCENTIVEPOOL_ADDRESS 75 DEVELOPER_FOUNDATAION_ADDRESS = client_consensus.economic.cfg.DEVELOPER_FOUNDATAION_ADDRESS 76 77 result = client_consensus.staking.edit_candidate(DEVELOPER_FOUNDATAION_ADDRESS, address) 78 log.info(result) 79 msg = client_consensus.ppos.getCandidateInfo(client_consensus.node.node_id) 80 log.info(msg) 81 assert msg["Ret"]["BenefitAddress"] == INCENTIVEPOOL_ADDRESS 82 83 84 @allure.title("The beneficiary address of the non-initial verifier is changed to the incentive pool address") 85 @pytest.mark.P1 86 def test_MPI_005_006(client_new_node): 87 """ 88 005:The beneficiary address of the non-initial verifier is changed to the incentive pool address 89 006:and then to the ordinary address 90 :param client_new_node_obj: 91 :param get_generate_account: 92 :return: 93 """ 94 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 95 10 ** 18 * 10000000) 96 INCENTIVEPOOL_ADDRESS = client_new_node.economic.cfg.INCENTIVEPOOL_ADDRESS 97 result = client_new_node.staking.create_staking(0, address, address) 98 assert_code(result, 0) 99 log.info("Change to excitation pool address") 100 result = client_new_node.staking.edit_candidate(address, INCENTIVEPOOL_ADDRESS) 101 log.info(result) 102 assert_code(result, 0) 103 msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 104 log.info(msg) 105 assert msg["Ret"]["BenefitAddress"] == INCENTIVEPOOL_ADDRESS 106 107 result = client_new_node.staking.edit_candidate(address, address) 108 log.info(result) 109 assert_code(result, 0) 110 msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 111 log.info(msg) 112 assert msg["Ret"]["BenefitAddress"] == INCENTIVEPOOL_ADDRESS 113 114 115 @allure.title("Edit wallet address as legal") 116 @pytest.mark.P1 117 def test_MPI_007(client_new_node, client_noconsensus): 118 """ 119 :param client_new_node_obj: 120 :param client_noconsensus_obj: 121 :return: 122 """ 123 address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 124 10 ** 18 * 10000000) 125 log.info(address1) 126 result = client_new_node.staking.create_staking(0, address1, address1) 127 assert_code(result, 0) 128 account = client_noconsensus.economic.account 129 node = client_noconsensus.node 130 address2, _ = account.generate_account(node.web3, 10 ** 18 * 20000000) 131 result = client_new_node.staking.edit_candidate(address1, address2) 132 log.info(address2) 133 log.info(result) 134 assert_code(result, 0) 135 msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 136 log.info(msg) 137 assert client_new_node.node.web3.toChecksumAddress(msg["Ret"]["BenefitAddress"]) == address2 138 139 140 @allure.title("It is illegal to edit wallet addresses") 141 @pytest.mark.P1 142 def test_MPI_008(client_new_node): 143 """ 144 :param client_new_node_obj: 145 :return: 146 """ 147 address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 148 10 ** 18 * 10000000) 149 log.info(address1) 150 result = client_new_node.staking.create_staking(0, address1, address1) 151 assert_code(result, 0) 152 address2 = "0x111111111111111111111111111111" 153 status = 0 154 try: 155 result = client_new_node.staking.edit_candidate(address1, address2) 156 log.info(result) 157 except BaseException: 158 status = 1 159 assert status == 1 160 161 162 @allure.title("Insufficient gas to initiate modification node") 163 @pytest.mark.P3 164 def test_MPI_009(client_new_node): 165 """ 166 :param client_new_node_obj: 167 :return: 168 """ 169 170 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 171 10 ** 18 * 10000000) 172 result = client_new_node.staking.create_staking(0, address, address) 173 assert_code(result, 0) 174 cfg = {"gas": 1} 175 status = 0 176 try: 177 result = client_new_node.staking.edit_candidate(address, address, transaction_cfg=cfg) 178 log.info(result) 179 except BaseException: 180 status = 1 181 assert status == 1 182 183 184 @allure.title("Insufficient balance to initiate the modification node") 185 @pytest.mark.P3 186 def test_MPI_010(client_new_node): 187 """ 188 :param client_new_node_obj: 189 :return: 190 """ 191 192 account = client_new_node.economic.account 193 client = client_new_node 194 node = client.node 195 address, _ = account.generate_account(node.web3, 10 ** 18 * 10000000) 196 result = client.staking.create_staking(0, address, address) 197 assert_code(result, 0) 198 balance = node.eth.getBalance(address) 199 status = 0 200 try: 201 result = client.staking.edit_candidate(address, address, transaction_cfg={"gasPrice": balance}) 202 log.info(result) 203 except BaseException: 204 status = 1 205 assert status == 1 206 207 208 @allure.title("During the hesitation period, withdraw pledge and modify node information") 209 @pytest.mark.P1 210 def test_MPI_011(client_new_node): 211 """ 212 :param client_new_node_obj: 213 :return: 214 """ 215 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 216 10 ** 18 * 10000000) 217 result = client_new_node.staking.create_staking(0, address, address) 218 assert_code(result, 0) 219 result = client_new_node.staking.withdrew_staking(address) 220 log.info(result) 221 result = client_new_node.staking.edit_candidate(address, address) 222 log.info(result) 223 assert_code(result, 301102) 224 225 226 @allure.title("Lock period exit pledge, modify node information") 227 @pytest.mark.P2 228 def test_MPI_012_013(client_new_node): 229 """ 230 012:Lock period exit pledge, modify node information 231 013:After the lockout pledge is complete, the node information shall be modified 232 :param client_new_node_obj: 233 :return: 234 """ 235 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 236 10 ** 18 * 10000000) 237 result = client_new_node.staking.create_staking(0, address, address) 238 assert_code(result, 0) 239 log.info("Next settlement period") 240 client_new_node.economic.wait_settlement_blocknum(client_new_node.node) 241 log.info("The lock shall be depledged at regular intervals") 242 result = client_new_node.staking.withdrew_staking(address) 243 assert_code(result, 0) 244 msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 245 log.info(msg) 246 assert msg["Code"] == 0 247 result = client_new_node.staking.edit_candidate(address, address) 248 log.info(result) 249 assert_code(result, 301103) 250 log.info("Next two settlement period") 251 client_new_node.economic.wait_settlement_blocknum(client_new_node.node, number=2) 252 msg = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 253 log.info(msg) 254 assert msg["Code"] == 301204 255 result = client_new_node.staking.edit_candidate(address, address) 256 log.info(result) 257 assert_code(result, 301102) 258 259 260 @allure.title("Non-verifier, modify node information") 261 @pytest.mark.P3 262 def test_MPI_014(client_new_node): 263 """ 264 Non-verifier, modify node information 265 :param client_new_node_obj: 266 :return: 267 """ 268 external_id = "ID1" 269 node_name = "LIDA" 270 website = "WEBSITE" 271 details = "talent" 272 illegal_nodeID = "7ee3276fd6b9c7864eb896310b5393324b6db785a2528c00cc28ca8c" \ 273 "3f86fc229a86f138b1f1c8e3a942204c03faeb40e3b22ab11b8983c35dc025de42865990" 274 address, pri_key = client_new_node.economic.account.generate_account(client_new_node.node.web3, 275 10 ** 18 * 10000000) 276 result = client_new_node.staking.create_staking(0, address, address) 277 assert_code(result, 0) 278 result = client_new_node.ppos.editCandidate(address, illegal_nodeID, external_id, 279 node_name, website, details, pri_key) 280 log.info(result) 281 assert_code(result, 301102) 282 283 284 @allure.title("Candidates whose commissions have been penalized are still frozen") 285 @pytest.mark.P2 286 def test_MPI_015_016(clients_new_node, client_consensus): 287 """ 288 015:Candidates whose commissions have been penalized are still frozen 289 016:A candidate whose mandate has expired after a freeze period 290 :param client_new_node_obj: 291 :return: 292 """ 293 client = clients_new_node[0] 294 node = client.node 295 other_node = client_consensus.node 296 economic = client.economic 297 address, pri_key = economic.account.generate_account(node.web3, 298 10 ** 18 * 10000000) 299 300 value = economic.create_staking_limit * 2 301 result = client.staking.create_staking(0, address, address, amount=value) 302 assert_code(result, 0) 303 economic.wait_consensus_blocknum(other_node, number=4) 304 validator_list = get_pledge_list(other_node.ppos.getValidatorList) 305 assert node.node_id in validator_list 306 candidate_info = other_node.ppos.getCandidateInfo(node.node_id) 307 log.info(candidate_info) 308 log.info("Close one node") 309 node.stop() 310 for i in range(4): 311 economic.wait_consensus_blocknum(other_node, number=i) 312 candidate_info = other_node.ppos.getCandidateInfo(node.node_id) 313 log.info(candidate_info) 314 if candidate_info["Ret"]["Released"] < value: 315 break 316 317 log.info("Restart the node") 318 node.start() 319 time.sleep(10) 320 result = client.staking.edit_candidate(address, address) 321 log.info(result) 322 assert_code(result, 301103) 323 log.info("Next settlement period") 324 economic.wait_settlement_blocknum(node, number=2) 325 result = client.staking.edit_candidate(address, address) 326 assert_code(result, 301102) 327 328 329 @allure.title("The length of the overflow") 330 @pytest.mark.P2 331 def test_MPI_017(client_new_node): 332 external_id = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111" 333 node_name = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111" 334 website = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 " 335 details = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 " 336 337 address, pri_key = client_new_node.economic.account.generate_account(client_new_node.node.web3, 338 10 ** 18 * 10000000) 339 340 result = client_new_node.ppos.editCandidate(address, client_new_node.node.node_id, 341 external_id, node_name, website, details, pri_key) 342 log.info(result) 343 assert_code(result, 301102)