github.com/platonnetwork/platon-go@v0.7.6/cases/tests/ppos_2/test_increase_staking.py (about) 1 # -*- coding: utf-8 -*- 2 from tests.lib.utils import * 3 import pytest 4 import allure 5 6 7 @allure.title("Normal overweight") 8 @pytest.mark.P0 9 def test_AS_001_002_009(client_new_node): 10 """ 11 001:Normal overweight 12 002:The verifier initiates the overweight with the amount of free account, meeting the minimum threshold 13 009:Hesitation period add pledge, inquire pledge information 14 """ 15 StakeThreshold = get_governable_parameter_value(client_new_node, "StakeThreshold") 16 log.info(StakeThreshold) 17 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 18 10 ** 18 * 10000000) 19 result = client_new_node.staking.create_staking(0, address, address) 20 assert_code(result, 0) 21 result = client_new_node.staking.increase_staking(0, address) 22 assert_code(result, 0) 23 result = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 24 staking_amount = client_new_node.economic.create_staking_limit 25 add_staking_amount = client_new_node.economic.add_staking_limit 26 assert result["Ret"]["Shares"] == staking_amount + add_staking_amount 27 28 29 @allure.title("The verifier is not on the verifier and candidate list") 30 @pytest.mark.P2 31 def test_AS_003(client_new_node): 32 """ 33 :param client_new_node_obj: 34 :param get_generate_account: 35 :return: 36 """ 37 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 38 10 ** 18 * 10000000) 39 result = client_new_node.staking.increase_staking(0, address) 40 log.info(result) 41 assert_code(result, 301102) 42 43 44 @allure.title("Undersupply of gas") 45 @pytest.mark.P3 46 def test_AS_004(client_new_node): 47 """ 48 :param client_new_node_obj: 49 :param get_generate_account: 50 :return: 51 """ 52 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 53 10 ** 18 * 10000000) 54 client_new_node.staking.create_staking(0, address, address) 55 fig = {"gas": 1} 56 status = 0 57 try: 58 result = client_new_node.staking.increase_staking(0, address, transaction_cfg=fig) 59 log.info(result) 60 except BaseException: 61 status = 1 62 assert status == 1 63 64 65 @allure.title("Insufficient balance initiated overweight") 66 @pytest.mark.P3 67 def test_AS_005(client_new_node): 68 """ 69 :param client_new_node_obj: 70 :return: 71 """ 72 account = client_new_node.economic.account 73 node = client_new_node.node 74 address, _ = account.generate_account(node.web3, 10) 75 status = 0 76 try: 77 result = client_new_node.staking.increase_staking(0, address) 78 log.info(result) 79 except BaseException: 80 status = 1 81 assert status == 1 82 83 84 @allure.title("(hesitation period) holdings less than the minimum threshold") 85 @pytest.mark.P1 86 def test_AS_007(client_new_node): 87 """ 88 :param client_new_node_obj: 89 :return: 90 """ 91 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 92 10 ** 18 * 10000000) 93 client_new_node.staking.create_staking(0, address, address) 94 add_staking_amount = client_new_node.economic.add_staking_limit 95 result = client_new_node.staking.increase_staking(0, address, amount=add_staking_amount - 1) 96 log.info(result) 97 assert_code(result, 301104) 98 99 100 @allure.title("(hesitation period) when the verifier revoks the pledge, he/she shall apply for adding the pledge") 101 @pytest.mark.P1 102 def test_AS_008(client_new_node): 103 """ 104 :param client_new_node_obj: 105 :return: 106 """ 107 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 108 10 ** 18 * 10000000) 109 client_new_node.staking.create_staking(0, address, address) 110 log.info("进入下个周期") 111 client_new_node.economic.wait_settlement_blocknum(client_new_node.node) 112 client_new_node.staking.withdrew_staking(address) 113 result = client_new_node.staking.increase_staking(0, address) 114 log.info(result) 115 assert_code(result, 301103) 116 117 118 @allure.title("(lockup period) normal increase") 119 @pytest.mark.P0 120 @pytest.mark.compatibility 121 def test_AS_011_012_013_014(client_new_node): 122 """ 123 011:(lockup period) normal increase 124 012:(lockup period) overweight meets the minimum threshold 125 013:(lock-up period) gas underinitiation overweight 126 014:(lockup period) insufficient balance to initiate overweight pledge 127 :param client_new_node_obj: 128 :return: 129 """ 130 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 131 10 ** 18 * 10000000) 132 client_new_node.staking.create_staking(0, address, address) 133 log.info("进入下个周期") 134 client_new_node.economic.wait_settlement_blocknum(client_new_node.node) 135 result = client_new_node.staking.increase_staking(0, address) 136 log.info(result) 137 assert_code(result, 0) 138 result = client_new_node.ppos.getCandidateInfo(client_new_node.node.node_id) 139 log.info(result) 140 staking_amount = client_new_node.economic.create_staking_limit 141 add_staking_amount = client_new_node.economic.add_staking_limit 142 assert result["Ret"]["Shares"] == staking_amount + add_staking_amount 143 assert result["Ret"]["Released"] == staking_amount 144 assert result["Ret"]["ReleasedHes"] == add_staking_amount 145 fig = {"gas": 1} 146 status = 0 147 try: 148 result = client_new_node.staking.increase_staking(0, address, transaction_cfg=fig) 149 log.info(result) 150 except BaseException: 151 status = 1 152 assert status == 1 153 account = client_new_node.economic.account 154 node = client_new_node.node 155 address, _ = account.generate_account(node.web3, 10) 156 status = 0 157 try: 158 result = client_new_node.staking.increase_staking(0, address, address) 159 log.info(result) 160 except BaseException: 161 status = 1 162 assert status == 1 163 164 165 @allure.title("The free amount is insufficient, the lock position is sufficient, and the free amount is added") 166 @pytest.mark.P1 167 def test_AS_015(client_new_node): 168 """ 169 :param client_new_node_obj: 170 :param get_generate_account: 171 :return: 172 """ 173 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 174 10 ** 18 * 10000000) 175 result = client_new_node.staking.create_staking(0, address, address) 176 log.info(result) 177 node = client_new_node.node 178 amount = node.eth.getBalance(address) 179 log.info("Wallet balance{}".format(amount)) 180 locked_amount = amount - node.web3.toWei(1, "ether") 181 182 plan = [{'Epoch': 1, 'Amount': locked_amount}] 183 log.info("The balance of the wallet is used as a lock") 184 result = client_new_node.restricting.createRestrictingPlan(address, plan, address) 185 log.info(result) 186 amount = node.eth.getBalance(address) 187 log.info("Check your wallet balance{}".format(amount)) 188 result = client_new_node.staking.increase_staking(0, address) 189 assert_code(result, 301111) 190 191 192 @allure.title("The free amount is insufficient, the lock position is sufficient, and the free amount is added") 193 @pytest.mark.P1 194 def test_AS_016(client_new_node): 195 """ 196 :param client_new_node_obj: 197 :return: 198 """ 199 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 200 10 ** 18 * 10000000) 201 result = client_new_node.staking.create_staking(0, address, address) 202 log.info(result) 203 node = client_new_node.node 204 amount = node.eth.getBalance(address) 205 log.info("Wallet balance{}".format(amount)) 206 locked_amount = 100000000000000000000 207 plan = [{'Epoch': 1, 'Amount': locked_amount}] 208 result = client_new_node.restricting.createRestrictingPlan(address, plan, address) 209 log.info(result) 210 assert_code(result, 0) 211 value = 101000000000000000000 212 result = client_new_node.staking.increase_staking(1, address, amount=value) 213 log.info(result) 214 assert_code(result, 304013) 215 216 217 @allure.title("The amount of the increase is less than the threshold") 218 @pytest.mark.P1 219 def test_AS_017(client_new_node): 220 """ 221 :param client_new_node_obj: 222 :return: 223 """ 224 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 225 10 ** 18 * 10000000) 226 result = client_new_node.staking.create_staking(0, address, address) 227 log.info(result) 228 add_staking_amount = client_new_node.economic.add_staking_limit 229 result = client_new_node.staking.increase_staking(0, address, amount=add_staking_amount - 1) 230 log.info(result) 231 assert_code(result, 301104) 232 233 234 @allure.title("Increase the number of active withdrawal but still in the freeze period of the candidate") 235 @pytest.mark.P0 236 def test_AS_018_019(client_new_node): 237 """ 238 018:Increase the number of active withdrawal but still in the freeze period of the candidate 239 019:Candidates whose holdings have been actively withdrawn and who have passed the freeze period 240 :param client_new_node_obj: 241 :return: 242 """ 243 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 244 10 ** 18 * 10000000) 245 result = client_new_node.staking.create_staking(0, address, address) 246 assert_code(result, 0) 247 log.info("Next settlement period") 248 client_new_node.economic.wait_settlement_blocknum(client_new_node.node) 249 result = client_new_node.staking.withdrew_staking(address) 250 assert_code(result, 0) 251 result = client_new_node.staking.increase_staking(0, address) 252 log.info(result) 253 assert_code(result, 301103) 254 log.info("Next settlement period") 255 client_new_node.economic.wait_settlement_blocknum(client_new_node.node, number=2) 256 result = client_new_node.staking.increase_staking(0, address) 257 log.info(result) 258 assert_code(result, 301102) 259 260 261 @allure.title("Add to the list of candidates who have been penalized and are still in the freeze period") 262 @pytest.mark.P0 263 def test_AS_020_021(clients_new_node, client_consensus): 264 """ 265 020:Add to the list of candidates who have been penalized and are still in the freeze period 266 021:A candidate whose holdings have been penalized has passed the freeze period 267 :param client_new_node_obj: 268 :return: 269 """ 270 client = clients_new_node[0] 271 node = client.node 272 other_node = client_consensus.node 273 economic = client.economic 274 address, pri_key = economic.account.generate_account(node.web3, 10 ** 18 * 10000000) 275 276 value = economic.create_staking_limit * 2 277 result = client.staking.create_staking(0, address, address, amount=value) 278 assert_code(result, 0) 279 economic.wait_consensus_blocknum(other_node, number=4) 280 validator_list = get_pledge_list(other_node.ppos.getValidatorList) 281 assert node.node_id in validator_list 282 candidate_info = other_node.ppos.getCandidateInfo(node.node_id) 283 log.info(candidate_info) 284 log.info("Close one node") 285 node.stop() 286 for i in range(4): 287 economic.wait_consensus_blocknum(other_node, number=i) 288 candidate_info = other_node.ppos.getCandidateInfo(node.node_id) 289 log.info(candidate_info) 290 if candidate_info["Ret"]["Released"] < value: 291 break 292 log.info("Restart the node") 293 node.start() 294 time.sleep(10) 295 result = client.staking.increase_staking(0, address) 296 log.info(result) 297 assert_code(result, 301103) 298 log.info("Next settlement period") 299 economic.wait_settlement_blocknum(node, number=2) 300 result = client.staking.increase_staking(0, address) 301 assert_code(result, 301102) 302 303 304 @allure.title("Increase your holdings with a new wallet") 305 @pytest.mark.P3 306 def test_AS_022(client_new_node): 307 """ 308 :param client_new_node_obj: 309 :return: 310 """ 311 address, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 312 10 ** 18 * 10000000) 313 address1, _ = client_new_node.economic.account.generate_account(client_new_node.node.web3, 314 10 ** 18 * 10000000) 315 result = client_new_node.staking.create_staking(0, address, address) 316 assert_code(result, 0) 317 result = client_new_node.staking.increase_staking(0, address1) 318 log.info(result) 319 assert_code(result, 301006)